Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 14 additions & 6 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, windows-latest]
python_version: [3.7, 3.8, 3.9]
name: Run py eddy tracker build tests
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install package
run: |
Expand All @@ -32,4 +40,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
pytest --cov src/py_eddy_tracker
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

Method was described in :

[Pegliasco, C., Delepoulle, A., Morrow, R., Faugère, Y., and Dibarboure, G.: META3.1exp : A new Global Mesoscale Eddy Trajectories Atlas derived from altimetry, Earth Syst. Sci. Data Discuss.](https://doi.org/10.5194/essd-2021-300)

[Mason, E., A. Pascual, and J. C. McWilliams, 2014: A new sea surface height–based code for oceanic mesoscale eddy tracking.](https://doi.org/10.1175/JTECH-D-14-00019.1)

### Use case ###
Expand Down
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()