Skip to content

Commit

Permalink
Add a fill parameter in identify ET
Browse files Browse the repository at this point in the history
  • Loading branch information
stella-bourdin committed Mar 18, 2022
1 parent 2c3d972 commit bd1e821
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions dynamicopy/tc/ET.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import xarray as xr

def identify_ET(tracks, NH_lim, SH_lim, lon_name="longitude", minus_3h=True):
def identify_ET(tracks, NH_lim, SH_lim, lon_name="longitude", minus_3h=True, fill = True):
"""
Parameters
Expand Down Expand Up @@ -41,16 +41,17 @@ def identify_ET(tracks, NH_lim, SH_lim, lon_name="longitude", minus_3h=True):
tracks["lat_STJ_SH"] = SH_lim.sel(time=target_time, longitude=target_lon)
tracks["ET"] = (tracks.lat > tracks.lat_STJ_NH) | (tracks.lat < tracks.lat_STJ_SH)

# Fill trajectories once one point is ET
tracks_ET = tracks.groupby('track_id')["ET"].max().index[tracks.groupby('track_id')["ET"].max()]
dic = {t: False for t in tracks_ET}
for row in tracks[tracks.track_id.isin(tracks_ET)].sort_values("time").itertuples():
if row.ET == True:
dic[row.track_id] = True
if dic[row.track_id] == True:
tracks.loc[row.Index, "ET"] = True
else:
tracks.loc[row.Index, "ET"] = False
if fill :
# Fill trajectories once one point is ET
tracks_ET = tracks.groupby('track_id')["ET"].max().index[tracks.groupby('track_id')["ET"].max()]
dic = {t: False for t in tracks_ET}
for row in tracks[tracks.track_id.isin(tracks_ET)].sort_values("time").itertuples():
if row.ET == True:
dic[row.track_id] = True
if dic[row.track_id] == True:
tracks.loc[row.Index, "ET"] = True
else:
tracks.loc[row.Index, "ET"] = False

return tracks

Expand Down

0 comments on commit bd1e821

Please sign in to comment.