Skip to content
Merged

Fixs #121

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
black reformating
  • Loading branch information
ludwigVonKoopa committed Dec 8, 2021
commit aba7c3d29ef5ab9980a8b9d6d957bb6ef3bd386e
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
6 changes: 1 addition & 5 deletions examples/06_grid_manipulation/pet_lavd.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,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
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 @@ -422,20 +422,14 @@ def identify_time(str_date):
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 @@ -646,8 +640,7 @@ def identify_time(str_date):
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
18 changes: 4 additions & 14 deletions src/py_eddy_tracker/appli/eddies.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ def browse_dataset_in(
filenames = bytes_(glob(full_path))

dataset_list = empty(
len(filenames),
dtype=[("filename", "S500"), ("date", "datetime64[s]")],
len(filenames), dtype=[("filename", "S500"), ("date", "datetime64[s]")],
)
dataset_list["filename"] = filenames

Expand Down Expand Up @@ -372,8 +371,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 @@ -383,14 +381,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 @@ -499,8 +490,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
35 changes: 24 additions & 11 deletions src/py_eddy_tracker/appli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ def build_network():
)

parser.add_argument(
"--min-overlap", "-p", type=float, help="minimum overlap area to associate observations", default=0.2
"--min-overlap",
"-p",
type=float,
help="minimum overlap area to associate observations",
default=0.2,
)
parser.add_argument(
"--minimal-area",
action="store_true",
help="If True, use intersection/little polygon, else intersection/union",
action="store_true",
help="If True, use intersection/little polygon, else intersection/union",
)

parser.contour_intern_arg()
Expand All @@ -42,7 +46,9 @@ def build_network():
intern=args.intern,
memory=args.memory,
)
group = n.group_observations(min_overlap=args.min_overlap, minimal_area=args.minimal_area)
group = n.group_observations(
min_overlap=args.min_overlap, minimal_area=args.minimal_area
)
n.build_dataset(group).write_file(filename=args.out)


Expand All @@ -55,12 +61,16 @@ def divide_network():
"--window", "-w", type=int, help="Half time window to search eddy", default=1
)
parser.add_argument(
"--min-overlap", "-p", type=float, help="minimum overlap area to associate observations", default=0.2
"--min-overlap",
"-p",
type=float,
help="minimum overlap area to associate observations",
default=0.2,
)
parser.add_argument(
"--minimal-area",
action="store_true",
help="If True, use intersection/little polygon, else intersection/union",
action="store_true",
help="If True, use intersection/little polygon, else intersection/union",
)
args = parser.parse_args()
contour_name = TrackEddiesObservations.intern(args.intern, public_label=True)
Expand All @@ -70,7 +80,12 @@ def divide_network():
)
n = NetworkObservations.from_split_network(
TrackEddiesObservations.load_file(args.input, raw_data=True),
e.split_network(intern=args.intern, window=args.window, min_overlap=args.min_overlap, minimal_area=args.minimal_area),
e.split_network(
intern=args.intern,
window=args.window,
min_overlap=args.min_overlap,
minimal_area=args.minimal_area,
),
)
n.write_file(filename=args.out)

Expand All @@ -94,9 +109,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
8 changes: 3 additions & 5 deletions src/py_eddy_tracker/dataset/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,11 @@ def eddy_identification(
xy_i = uniform_resample(
inner_contour.lon,
inner_contour.lat,
num_fac=presampling_multiplier
)
xy_e = uniform_resample(
contour.lon,
contour.lat,
num_fac=presampling_multiplier,
)
xy_e = uniform_resample(
contour.lon, contour.lat, num_fac=presampling_multiplier,
)
xy_s = uniform_resample(
speed_contour.lon,
speed_contour.lat,
Expand Down
4 changes: 2 additions & 2 deletions src/py_eddy_tracker/eddy_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ def __init__(self, x, y, z, levels, wrap_x=False, keep_unclose=False):
closed_contours = 0
# Count level and contour
for i, collection in enumerate(self.contours.collections):
collection.get_nearest_path_bbox_contain_pt = (
lambda x, y, i=i: self.get_index_nearest_path_bbox_contain_pt(i, x, y)
collection.get_nearest_path_bbox_contain_pt = lambda x, y, i=i: self.get_index_nearest_path_bbox_contain_pt(
i, x, y
)
nb_level += 1

Expand Down
12 changes: 10 additions & 2 deletions src/py_eddy_tracker/observations/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,10 @@ def extract_light_with_mask(self, mask, track_extra_variables=[]):
logger.debug("Copy of field %s ...", field)
new.obs[field] = self.obs[field][mask]

if "previous_obs" in track_extra_variables and "next_obs" in track_extra_variables:
if (
"previous_obs" in track_extra_variables
and "next_obs" in track_extra_variables
):
# n & p must be re-index
n, p = self.next_obs[mask], self.previous_obs[mask]
# we add 2 for -1 index return index -1
Expand Down Expand Up @@ -1741,7 +1744,12 @@ def group_observations(self, min_overlap=0.2, minimal_area=False):
for j in range(i + 1, min(self.window + i + 1, self.nb_input)):
xj, yj = self.buffer.load_contour(self.filenames[j])
ii, ij = bbox_intersection(xi, yi, xj, yj)
m = vertice_overlap(xi[ii], yi[ii], xj[ij], yj[ij], minimal_area=minimal_area) > min_overlap
m = (
vertice_overlap(
xi[ii], yi[ii], xj[ij], yj[ij], minimal_area=minimal_area
)
> min_overlap
)
results.append((i, j, ii[m], ij[m]))
if display_iteration:
print()
Expand Down
35 changes: 13 additions & 22 deletions src/py_eddy_tracker/observations/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
logger = logging.getLogger("pet")

# keep only major and minor version number
_software_version_reduced = packaging.version.Version("{v.major}.{v.minor}".format(v=packaging.version.parse(__version__)))
_software_version_reduced = packaging.version.Version(
"{v.major}.{v.minor}".format(v=packaging.version.parse(__version__))
)


def _check_versions(version):
Expand All @@ -90,8 +92,10 @@ def _check_versions(version):

file_version = packaging.version.parse(version) if version is not None else None
if file_version is None or file_version < _software_version_reduced:
logger.warning("File was created with py-eddy-tracker version '%s' but software version is '%s'",
file_version, _software_version_reduced
logger.warning(
"File was created with py-eddy-tracker version '%s' but software version is '%s'",
file_version,
_software_version_reduced,
)


Expand Down Expand Up @@ -727,11 +731,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 @@ -805,7 +805,9 @@ def load_from_zarr(
logger.debug("%d observations will be load", nb_obs)
kwargs = dict()

kwargs["track_array_variables"] = h_zarr.attrs.get("track_array_variables", track_array_variables)
kwargs["track_array_variables"] = h_zarr.attrs.get(
"track_array_variables", track_array_variables
)

array_variables = list()
for variable in var_list:
Expand Down Expand Up @@ -2010,11 +2012,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 @@ -2386,14 +2384,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
13 changes: 7 additions & 6 deletions src/py_eddy_tracker/observations/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,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 Expand Up @@ -730,7 +727,9 @@ def get_previous_obs(
if len(ii) == 0:
continue
c = zeros(len(xj))
c[ij] = vertice_overlap(xi[ii], yi[ii], xj[ij], yj[ij], minimal_area=minimal_area)
c[ij] = vertice_overlap(
xi[ii], yi[ii], xj[ij], yj[ij], minimal_area=minimal_area
)
# We remove low overlap
c[c < min_overlap] = 0
# We get index of maximal overlap
Expand Down Expand Up @@ -773,7 +772,9 @@ def get_next_obs(
if len(ii) == 0:
continue
c = zeros(len(xj))
c[ij] = vertice_overlap(xi[ii], yi[ii], xj[ij], yj[ij], minimal_area=minimal_area)
c[ij] = vertice_overlap(
xi[ii], yi[ii], xj[ij], yj[ij], minimal_area=minimal_area
)
# We remove low overlap
c[c < min_overlap] = 0
# We get index of maximal overlap
Expand Down