Skip to content

Commit

Permalink
Change how to normalize longitude after tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
AntSimi committed Jan 22, 2021
1 parent 977236f commit 23a5cca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
[Unreleased]
------------

Changed
^^^^^^^
- `TrackEddiesObservations.filled_by_interpolation` method stop to normalize longitude, to continue to have same
beahviour you must call before `TrackEddiesObservations.normalize_longitude`

Fixed
^^^^^
- Use `safe_load` for yaml load
Expand Down
2 changes: 2 additions & 0 deletions src/py_eddy_tracker/appli/eddies.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ def track(
# We flag obs
if c.virtual:
long_track["virtual"][:] = long_track["time"] == 0
long_track.normalize_longitude()
long_track.filled_by_interpolation(long_track["virtual"] == 1)
short_track["virtual"][:] = short_track["time"] == 0
short_track.normalize_longitude()
short_track.filled_by_interpolation(short_track["virtual"] == 1)

logger.info("Longer track saved have %d obs", c.nb_obs_by_tracks.max())
Expand Down
36 changes: 26 additions & 10 deletions src/py_eddy_tracker/observations/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
radians,
sin,
unique,
where,
zeros,
)

Expand Down Expand Up @@ -167,19 +166,36 @@ def filled_by_interpolation(self, mask):
or var in self.array_variables
):
continue
# to normalize longitude before interpolation
if var == "lon":
lon = self.lon
first = where(self.n == 0)[0]
nb_obs = empty(first.shape, dtype="u4")
nb_obs[:-1] = first[1:] - first[:-1]
nb_obs[-1] = lon.shape[0] - first[-1]
lon0 = (lon[first] - 180).repeat(nb_obs)
self.lon[:] = (lon - lon0) % 360 + lon0
self.obs[var][mask] = interp(
index[mask], index[~mask], self.obs[var][~mask]
)

def normalize_longitude(self):
"""Normalize all longitude
Normalize longitude field and in the same range :
- longitude_max
- contour_lon_e (how to do if in raw)
- contour_lon_s (how to do if in raw)
"""
lon0 = (self.lon[self.index_from_track] - 180).repeat(self.nb_obs_by_track)
logger.debug("Normalize longitude")
self.lon[:] = (self.lon - lon0) % 360 + lon0
if "lon_max" in self.obs.dtype.names:
logger.debug("Normalize longitude_max")
self.lon_max[:] = (self.lon_max - self.lon + 180) % 360 + self.lon - 180
if not self.raw_data:
if "contour_lon_e" in self.obs.dtype.names:
logger.debug("Normalize effective contour longitude")
self.contour_lon_e[:] = (
(self.contour_lon_e.T - self.lon + 180) % 360 + self.lon - 180
).T
if "contour_lon_s" in self.obs.dtype.names:
logger.debug("Normalize speed contour longitude")
self.contour_lon_s[:] = (
(self.contour_lon_s.T - self.lon + 180) % 360 + self.lon - 180
).T

def extract_longer_eddies(self, nb_min, nb_obs, compress_id=True):
"""Select the trajectories longer than nb_min"""
mask = nb_obs >= nb_min
Expand Down

0 comments on commit 23a5cca

Please sign in to comment.