Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions examples/02_eddy_identification/pet_eddy_detection_ACC.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def set_fancy_labels(fig, ticklabelsize=14, labelsize=14, labelweight="semibold"
y_name="latitude",
# Manual area subset
indexs=dict(
latitude=slice(100 - margin, 220 + margin),
longitude=slice(0, 230 + margin),
latitude=slice(100 - margin, 220 + margin), longitude=slice(0, 230 + margin),
),
)
g_raw = RegularGridDataset(**kw_data)
Expand Down Expand Up @@ -188,16 +187,10 @@ def set_fancy_labels(fig, ticklabelsize=14, labelsize=14, labelweight="semibold"
ax.set_ylabel("With filter")

ax.plot(
a_[field][i_a] * factor,
a[field][j_a] * factor,
"r.",
label="Anticyclonic",
a_[field][i_a] * factor, a[field][j_a] * factor, "r.", label="Anticyclonic",
)
ax.plot(
c_[field][i_c] * factor,
c[field][j_c] * factor,
"b.",
label="Cyclonic",
c_[field][i_c] * factor, c[field][j_c] * factor, "b.", label="Cyclonic",
)
ax.set_aspect("equal"), ax.grid()
ax.plot((0, 1000), (0, 1000), "g")
Expand Down
11 changes: 4 additions & 7 deletions examples/06_grid_manipulation/pet_lavd.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ def update(i_frame):

kw_video = dict(frames=arange(nb_time), interval=1000.0 / step_by_day / 2, blit=True)
fig, ax, txt = start_ax(dpi=60)
x_g_, y_g_ = arange(0 - step / 2, 36 + step / 2, step), arange(
28 - step / 2, 46 + step / 2, step
x_g_, y_g_ = (
arange(0 - step / 2, 36 + step / 2, step),
arange(28 - step / 2, 46 + step / 2, step),
)
# pcolorfast will be faster than pcolormesh, we could use pcolorfast due to x and y are regular
pcolormesh = ax.pcolorfast(x_g_, y_g_, lavd, **kw_vorticity)
Expand All @@ -158,11 +159,7 @@ def update(i_frame):
# Format LAVD data
lavd = RegularGridDataset.with_array(
coordinates=("lon", "lat"),
datas=dict(
lavd=lavd.T,
lon=x_g,
lat=y_g,
),
datas=dict(lavd=lavd.T, lon=x_g, lat=y_g,),
centered=True,
)

Expand Down
2 changes: 1 addition & 1 deletion examples/07_cube_manipulation/pet_fsle_med.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# ADT in med
# ----------
# :py:meth:`~py_eddy_tracker.dataset.grid.GridCollection.from_netcdf_cube` method is
# made for data stores in time cube, you could use also
# made for data stores in time cube, you could use also
# :py:meth:`~py_eddy_tracker.dataset.grid.GridCollection.from_netcdf_list` method to
# load data-cube from multiple file.
c = GridCollection.from_netcdf_cube(
Expand Down
8 changes: 1 addition & 7 deletions examples/16_network/pet_replay_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,7 @@ def get_obs(dataset):
n_.median_filter(15, "time", "latitude")
kw["s"] = (n_.radius_e * 1e-3) ** 2 / 30 ** 2 * 20
m = n_.scatter_timeline(
ax,
"shape_error_e",
vmin=14,
vmax=70,
**kw,
yfield="lon",
method="all",
ax, "shape_error_e", vmin=14, vmax=70, **kw, yfield="lon", method="all",
)
ax.set_ylabel("Longitude")
cb = update_axes(ax, m["scatter"])
Expand Down
3 changes: 1 addition & 2 deletions examples/16_network/pet_segmentation_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def update(i_frame):

indices_frames = INDICES[i_frame]
mappable_CONTOUR.set_data(
e.contour_lon_e[indices_frames],
e.contour_lat_e[indices_frames],
e.contour_lon_e[indices_frames], e.contour_lat_e[indices_frames],
)
mappable_CONTOUR.set_color(cmap.colors[tr[indices_frames] % len(cmap.colors)])
return (mappable_tracks,)
Expand Down
13 changes: 3 additions & 10 deletions src/py_eddy_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,14 @@ def parse_args(self, *args, **kwargs):
nc_name="previous_cost",
nc_type="float32",
nc_dims=("obs",),
nc_attr=dict(
long_name="Previous cost for previous observation",
comment="",
),
nc_attr=dict(long_name="Previous cost for previous observation", comment="",),
),
next_cost=dict(
attr_name=None,
nc_name="next_cost",
nc_type="float32",
nc_dims=("obs",),
nc_attr=dict(
long_name="Next cost for next observation",
comment="",
),
nc_attr=dict(long_name="Next cost for next observation", comment="",),
),
n=dict(
attr_name=None,
Expand Down Expand Up @@ -633,8 +627,7 @@ def parse_args(self, *args, **kwargs):
nc_type="f4",
nc_dims=("obs",),
nc_attr=dict(
long_name="Log base 10 background chlorophyll",
units="Log(Chl/[mg/m^3])",
long_name="Log base 10 background chlorophyll", units="Log(Chl/[mg/m^3])",
),
),
year=dict(
Expand Down
15 changes: 3 additions & 12 deletions src/py_eddy_tracker/appli/eddies.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ def track(

logger.info("Longer track saved have %d obs", c.nb_obs_by_tracks.max())
logger.info(
"The mean length is %d observations for long track",
c.nb_obs_by_tracks.mean(),
"The mean length is %d observations for long track", c.nb_obs_by_tracks.mean(),
)

long_track.write_file(**kw_write)
Expand All @@ -378,14 +377,7 @@ def track(


def get_group(
dataset1,
dataset2,
index1,
index2,
score,
invalid=2,
low=10,
high=60,
dataset1, dataset2, index1, index2, score, invalid=2, low=10, high=60,
):
group1, group2 = dict(), dict()
m_valid = (score * 100) >= invalid
Expand Down Expand Up @@ -494,8 +486,7 @@ def get_values(v, dataset):
]

labels = dict(
high=f"{high:0.0f} <= high",
low=f"{invalid:0.0f} <= low < {low:0.0f}",
high=f"{high:0.0f} <= high", low=f"{invalid:0.0f} <= low < {low:0.0f}",
)

keys = [labels.get(key, key) for key in list(gr_ref.values())[0].keys()]
Expand Down
4 changes: 1 addition & 3 deletions src/py_eddy_tracker/appli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def subset_network():
help="Remove short dead end, first is for minimal obs number and second for minimal segment time to keep",
)
parser.add_argument(
"--remove_trash",
action="store_true",
help="Remove trash (network id == 0)",
"--remove_trash", action="store_true", help="Remove trash (network id == 0)",
)
parser.add_argument(
"-p",
Expand Down
1 change: 0 additions & 1 deletion src/py_eddy_tracker/observations/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def particle_candidate(x, y, c, eddies, t_start, i_target, pct, **kwargs):
:params dict kwargs: dict of params given to `advect`

"""

# Obs from initial time
m_start = eddies.time == t_start

Expand Down
25 changes: 6 additions & 19 deletions src/py_eddy_tracker/observations/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,7 @@ def display_timeline(
"""
self.only_one_network()
j = 0
line_kw = dict(
ls="-",
marker="+",
markersize=6,
zorder=1,
lw=3,
)
line_kw = dict(ls="-", marker="+", markersize=6, zorder=1, lw=3,)
line_kw.update(kwargs)
mappables = dict(lines=list())

Expand Down Expand Up @@ -918,10 +912,7 @@ def event_map(self, ax, **kwargs):
"""Add the merging and splitting events to a map"""
j = 0
mappables = dict()
symbol_kw = dict(
markersize=10,
color="k",
)
symbol_kw = dict(markersize=10, color="k",)
symbol_kw.update(kwargs)
symbol_kw_split = symbol_kw.copy()
symbol_kw_split["markersize"] += 4
Expand Down Expand Up @@ -950,13 +941,7 @@ def event_map(self, ax, **kwargs):
return mappables

def scatter(
self,
ax,
name="time",
factor=1,
ref=None,
edgecolor_cycle=None,
**kwargs,
self, ax, name="time", factor=1, ref=None, edgecolor_cycle=None, **kwargs,
):
"""
This function scatters the path of each network, with the merging and splitting events
Expand Down Expand Up @@ -1400,7 +1385,9 @@ def segment_coherence(
.. code-block:: python

def date2file(julian_day):
date = datetime.timedelta(days=julian_day) + datetime.datetime(1950, 1, 1)
date = datetime.timedelta(days=julian_day) + datetime.datetime(
1950, 1, 1
)

return f"/tmp/dt_global_allsat_phy_l4_{date.strftime('%Y%m%d')}.nc"

Expand Down
24 changes: 5 additions & 19 deletions src/py_eddy_tracker/observations/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,7 @@ def load_file(cls, filename, **kwargs):
.. code-block:: python

kwargs_latlon_300 = dict(
include_vars=[
"longitude",
"latitude",
],
indexs=dict(obs=slice(0, 300)),
include_vars=["longitude", "latitude",], indexs=dict(obs=slice(0, 300)),
)
small_dataset = TrackEddiesObservations.load_file(
filename, **kwargs_latlon_300
Expand Down Expand Up @@ -1676,7 +1672,8 @@ def write_file(
handler = zarr.open(filename, "w")
self.to_zarr(handler, **kwargs)
else:
with Dataset(filename, "w", format="NETCDF4") as handler:
nc_format = kwargs.pop("format", "NETCDF4")
with Dataset(filename, "w", format=nc_format) as handler:
self.to_netcdf(handler, **kwargs)

@property
Expand Down Expand Up @@ -1967,11 +1964,7 @@ def bins_stat(self, xname, bins=None, yname=None, method=None, mask=None):

def format_label(self, label):
t0, t1 = self.period
return label.format(
t0=t0,
t1=t1,
nb_obs=len(self),
)
return label.format(t0=t0, t1=t1, nb_obs=len(self),)

def display(self, ax, ref=None, extern_only=False, intern_only=False, **kwargs):
"""Plot the speed and effective (dashed) contour of the eddies
Expand Down Expand Up @@ -2330,14 +2323,7 @@ def grid_count_pixel_in(
x_, y_ = reduce_size(x_, y_)
v = create_vertice(x_, y_)
(x_start, x_stop), (y_start, y_stop) = bbox_indice_regular(
v,
x_bounds,
y_bounds,
xstep,
ystep,
N,
is_circular,
x_size,
v, x_bounds, y_bounds, xstep, ystep, N, is_circular, x_size,
)
i, j = get_pixel_in_regular(v, x_c, y_c, x_start, x_stop, y_start, y_stop)
grid_count_(grid, i, j)
Expand Down
5 changes: 1 addition & 4 deletions src/py_eddy_tracker/observations/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,7 @@ def close_tracks(self, other, nb_obs_min=10, **kwargs):
def format_label(self, label):
t0, t1 = self.period
return label.format(
t0=t0,
t1=t1,
nb_obs=len(self),
nb_tracks=(self.nb_obs_by_track != 0).sum(),
t0=t0, t1=t1, nb_obs=len(self), nb_tracks=(self.nb_obs_by_track != 0).sum(),
)

def plot(self, ax, ref=None, **kwargs):
Expand Down
10 changes: 1 addition & 9 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@

G = RegularGridDataset(get_demo_path("mask_1_60.nc"), "lon", "lat")
X = 0.025
contour = Path(
(
(-X, 0),
(X, 0),
(X, X),
(-X, X),
(-X, 0),
)
)
contour = Path(((-X, 0), (X, 0), (X, X), (-X, X), (-X, 0),))


# contour
Expand Down