Skip to content
Merged
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
matplotlib
matplotlib<3.5
netCDF4
numba>=0.53
numpy<1.21
Expand Down
4 changes: 3 additions & 1 deletion src/py_eddy_tracker/dataset/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def eddy_identification(
)
z_min, z_max = z_min_p, z_max_p

logger.debug("Levels from %f to %f", z_min, z_max)
levels = arange(z_min - z_min % step, z_max - z_max % step + 2 * step, step)

# Get x and y values
Expand Down Expand Up @@ -1404,7 +1405,8 @@ def convolve_filter_with_dynamic_kernel(
tmp_matrix = ma.zeros((2 * d_lon + data.shape[0], k_shape[1]))
tmp_matrix.mask = ones(tmp_matrix.shape, dtype=bool)
# Slice to apply on input data
sl_lat_data = slice(max(0, i - d_lat), min(i + d_lat, data.shape[1]))
# +1 for upper bound, to take in acount this column
sl_lat_data = slice(max(0, i - d_lat), min(i + d_lat + 1, data.shape[1]))
# slice to apply on temporary matrix to store input data
sl_lat_in = slice(
d_lat - (i - sl_lat_data.start), d_lat + (sl_lat_data.stop - i)
Expand Down
26 changes: 5 additions & 21 deletions src/py_eddy_tracker/observations/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import time
from glob import glob

import netCDF4
import zarr
from numba import njit
from numpy import (
arange,
Expand All @@ -23,9 +25,6 @@
zeros,
)

import netCDF4
import zarr

from ..dataset.grid import GridCollection
from ..generic import build_index, wrap_longitude
from ..poly import bbox_intersection, vertice_overlap
Expand Down Expand Up @@ -680,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 @@ -919,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 @@ -951,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
45 changes: 35 additions & 10 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
from matplotlib.path import Path
from numpy import array, isnan, ma
from numpy import arange, array, isnan, ma, nan, ones, zeros
from pytest import approx

from py_eddy_tracker.data import get_demo_path
from py_eddy_tracker.dataset.grid import RegularGridDataset

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 Expand Up @@ -85,3 +77,36 @@ def test_interp():
assert g.interp("z", x0, y0) == 1.5
assert g.interp("z", x1, y1) == 2
assert isnan(g.interp("z", x2, y2))


def test_convolution():
"""
Add some dummy check on convolution filter
"""
# Fake grid
z = ma.array(
arange(12).reshape((-1, 1)) * arange(10).reshape((1, -1)),
mask=zeros((12, 10), dtype="bool"),
dtype="f4",
)
g = RegularGridDataset.with_array(
coordinates=("x", "y"),
datas=dict(z=z, x=arange(0, 6, 0.5), y=arange(0, 5, 0.5),),
centered=True,
)

def kernel_func(lat):
return ones((3, 3))

# After transpose we must get same result
d = g.convolve_filter_with_dynamic_kernel("z", kernel_func)
assert (d.T[:9, :9] == d[:9, :9]).all()
# We mask one value and check convolution result
z.mask[2, 2] = True
d = g.convolve_filter_with_dynamic_kernel("z", kernel_func)
assert d[1, 1] == z[:3, :3].sum() / 8
# Add nan and check only nearest value is contaminate
z[2, 2] = nan
d = g.convolve_filter_with_dynamic_kernel("z", kernel_func)
assert not isnan(d[0, 0])
assert isnan(d[1:4, 1:4]).all()