Skip to content

Commit 4fc1960

Browse files
committed
Add method to TrackEddiesObservations:
to iterate on track and found close track in an other atlas based on match method
1 parent ea64ae7 commit 4fc1960

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
- Add method to found close tracks in an other atlas
1112
- Allow to give a x reference when we display grid to be able to change xlim
1213
- Add option to EddyId to select data index like `--indexs time=5 depth=2`
1314
- Add a method to merge several indexs type for eddy obs
@@ -26,16 +27,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2627

2728
## [3.2.0] - 2020-09-16
2829

29-
### Added
30-
31-
### Changed
32-
33-
### Removed
34-
3530
## [3.1.0] - 2020-06-25
36-
37-
### Added
38-
39-
### Changed
40-
41-
### Removed

src/py_eddy_tracker/observations/tracking.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ def __init__(self, *args, **kwargs):
7070
self.__obs_by_track = None
7171
self.__nb_track = None
7272

73+
def iter_track(self):
74+
"""
75+
Yield track
76+
"""
77+
for i0, nb in zip(self.index_from_track, self.nb_obs_by_track):
78+
if nb == 0:
79+
continue
80+
yield self.index(slice(i0, i0 + nb))
81+
7382
@property
7483
def nb_tracks(self):
7584
"""
@@ -491,6 +500,13 @@ def extract_with_mask(
491500
new.track = id_translate[new.track]
492501
return new
493502

503+
@staticmethod
504+
def re_reference_index(index, ref):
505+
if isinstance(ref, slice):
506+
return index + ref.start
507+
else:
508+
return ref[index]
509+
494510
def shape_polygon(self, intern=False):
495511
"""
496512
Get polygons which enclosed each track
@@ -528,6 +544,28 @@ def display_shape(self, ax, ref=None, intern=False, **kwargs):
528544
x, y = wrap_longitude(x, y, ref, cut=True)
529545
return ax.plot(x, y, **kwargs)
530546

547+
def close_tracks(self, other, nb_obs_min=10, **kwargs):
548+
"""
549+
Get close from another atlas.
550+
551+
:param self other: Atlas to compare
552+
:param int nb_obs_min: Minimal number of overlap for one track
553+
:param dict kwargs: keyword arguments for match function
554+
:return: return other atlas reduce to common track with self
555+
556+
.. warning::
557+
It could be a costly operation for huge dataset
558+
"""
559+
p0, p1 = self.period
560+
indexs = list()
561+
for i_self, i_other, t0, t1 in self.align_on(other, bins=range(p0, p1 + 2)):
562+
i, j, s = self.index(i_self).match(other.index(i_other), **kwargs)
563+
indexs.append(other.re_reference_index(j, i_other))
564+
indexs = concatenate(indexs)
565+
tr, nb = unique(other.track[indexs], return_counts=True)
566+
return other.extract_ids(tr[nb >= nb_obs_min])
567+
568+
531569
def format_label(self, label):
532570
t0, t1 = self.period
533571
return label.format(

0 commit comments

Comments
 (0)