Skip to content

Commit 32579cb

Browse files
committed
update from AntSimi version
1 parent 52422b8 commit 32579cb

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

src/py_eddy_tracker/appli/eddies.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from numpy import dtype as npdtype
1818
from yaml import safe_load
1919

20-
from .. import EddyParser
20+
from .. import EddyParser, identify_time
2121
from ..observations.observation import EddiesObservations, reverse_index
2222
from ..observations.tracking import TrackEddiesObservations
2323
from ..tracking import Correspondances
@@ -165,7 +165,12 @@ def eddies_tracking():
165165
parser.add_argument(
166166
"--zarr", action="store_true", help="Output will be wrote in zarr"
167167
)
168-
parser.add_argument("--unraw", action="store_true", help="Load unraw data")
168+
parser.add_argument(
169+
"--unraw",
170+
action="store_true",
171+
help="Load unraw data, use only for netcdf."
172+
"If unraw is active, netcdf is loaded without apply scalefactor and add_offset.",
173+
)
169174
parser.add_argument(
170175
"--blank_period",
171176
type=int,
@@ -354,11 +359,13 @@ def track(
354359

355360
short_c = c._copy()
356361
short_c.shorter_than(size_max=nb_obs_min)
357-
c.longer_than(size_min=nb_obs_min)
358-
359-
long_track = c.merge(raw_data=raw)
360362
short_track = short_c.merge(raw_data=raw)
361363

364+
if c.longer_than(size_min=nb_obs_min) is False:
365+
long_track = short_track.empty_dataset()
366+
else:
367+
long_track = c.merge(raw_data=raw)
368+
362369
# We flag obs
363370
if c.virtual:
364371
long_track["virtual"][:] = long_track["time"] == 0

src/py_eddy_tracker/dataset/grid.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ def eddy_identification(
821821

822822
# Here the considered contour passed shape_error test, masked_pixels test,
823823
# values strictly above (AEs) or below (CEs) the contour, number_pixels test)
824+
824825
# Compute amplitude
825826
reset_centroid, amp = self.get_amplitude(
826827
contour,
@@ -832,7 +833,6 @@ def eddy_identification(
832833
mle=mle,
833834
**kwargs,
834835
)
835-
836836
# If we have a valid amplitude
837837
if (not amp.within_amplitude_limits()) or (amp.amplitude == 0):
838838
contour.reject = 4
@@ -1003,7 +1003,6 @@ def get_uavg(
10031003
all_contours.iter(start=level_start + step, step=step)
10041004
):
10051005
level_contour = coll.get_nearest_path_bbox_contain_pt(centlon_e, centlat_e)
1006-
10071006
# Leave loop if no contours at level
10081007
if level_contour is None:
10091008
break
@@ -1097,7 +1096,6 @@ class UnRegularGridDataset(GridDataset):
10971096
def load(self):
10981097
"""Load variable (data)"""
10991098
x_name, y_name = self.coordinates
1100-
11011099
with Dataset(self.filename) as h:
11021100
self.x_dim = h.variables[x_name].dimensions
11031101
self.y_dim = h.variables[y_name].dimensions
@@ -1111,8 +1109,7 @@ def load(self):
11111109
self.y_c = self.vars[y_name]
11121110

11131111
self.init_pos_interpolator()
1114-
1115-
1112+
11161113
@property
11171114
def bounds(self):
11181115
"""Give bounds"""
@@ -2332,13 +2329,26 @@ def from_netcdf_cube(cls, filename, x_name, y_name, t_name, heigth=None):
23322329
@classmethod
23332330
def from_netcdf_list(cls, filenames, t, x_name, y_name, indexs=None, heigth=None):
23342331
new = cls()
2335-
for i, t in enumerate(t):
2336-
d = RegularGridDataset(filenames[i], x_name, y_name, indexs=indexs)
2332+
for i, _t in enumerate(t):
2333+
filename = filenames[i]
2334+
logger.debug(f"load file {i:02d}/{len(t)} t={_t} : {filename}")
2335+
d = RegularGridDataset(filename, x_name, y_name, indexs=indexs)
23372336
if heigth is not None:
23382337
d.add_uv(heigth)
2339-
new.datasets.append((t, d))
2338+
new.datasets.append((_t, d))
23402339
return new
23412340

2341+
def shift_files(self, t, filename, heigth=None, **rgd_kwargs):
2342+
"""Add next file to the list and remove the oldest"""
2343+
2344+
self.datasets = self.datasets[1:]
2345+
2346+
d = RegularGridDataset(filename, **rgd_kwargs)
2347+
if heigth is not None:
2348+
d.add_uv(heigth)
2349+
self.datasets.append((t, d))
2350+
logger.debug(f"shift and adding i={len(self.datasets)} t={t} : {filename}")
2351+
23422352
def interp(self, grid_name, t, lons, lats, method="bilinear"):
23432353
"""
23442354
Compute z over lons, lats
@@ -2498,6 +2508,7 @@ def advect(
24982508
else:
24992509
mask_particule += isnan(x) + isnan(y)
25002510
while True:
2511+
logger.debug(f"advect : t={t}")
25012512
if (backward and t <= t1) or (not backward and t >= t1):
25022513
t0, u0, v0, m0 = t1, u1, v1, m1
25032514
t1, d1 = generator.__next__()
@@ -2524,25 +2535,21 @@ def advect(
25242535
yield t, x, y
25252536

25262537
def get_next_time_step(self, t_init):
2527-
first = True
25282538
for i, (t, dataset) in enumerate(self.datasets):
25292539
if t < t_init:
25302540
continue
2531-
if first:
2532-
first = False
2533-
yield self.datasets[i - 1]
2541+
2542+
logger.debug(f"i={i}, t={t}, dataset={dataset}")
25342543
yield t, dataset
25352544

25362545
def get_previous_time_step(self, t_init):
2537-
first = True
25382546
i = len(self.datasets)
25392547
for t, dataset in reversed(self.datasets):
25402548
i -= 1
25412549
if t > t_init:
25422550
continue
2543-
if first:
2544-
first = False
2545-
yield self.datasets[i + 1]
2551+
2552+
logger.debug(f"i={i}, t={t}, dataset={dataset}")
25462553
yield t, dataset
25472554

25482555

@@ -2616,6 +2623,11 @@ def get_uv_quad(i0, j0, u, v, m, nb_x=0):
26162623
i1, j1 = i0 + 1, j0 + 1
26172624
if nb_x != 0:
26182625
i1 %= nb_x
2626+
i_max, j_max = m.shape
2627+
2628+
if i1 >= i_max or j1 >= j_max:
2629+
return True, nan, nan, nan, nan, nan, nan, nan, nan
2630+
26192631
if m[i0, j0] or m[i0, j1] or m[i1, j0] or m[i1, j1]:
26202632
return True, nan, nan, nan, nan, nan, nan, nan, nan
26212633
# Extract value for u and v

src/py_eddy_tracker/eddy_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
:param float contour_height:
6666
:param array data:
6767
:param float interval:
68-
:param int mle: maximum number of local maxima in contour
68+
:param int mle: maximum number of local extrema in contour
6969
:param int nb_step_min: number of intervals to consider an eddy
7070
:param int nb_step_to_be_mle: number of intervals to be considered as an another maxima
7171
"""

0 commit comments

Comments
 (0)