Skip to content

Commit 1a490b3

Browse files
committed
2 parents eb79b9d + 31abfe8 commit 1a490b3

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

notebooks/python_module/02_eddy_identification/pet_filter_and_detection.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
"name": "python",
177177
"nbconvert_exporter": "python",
178178
"pygments_lexer": "ipython3",
179-
"version": "3.7.7"
179+
"version": "3.7.6"
180180
}
181181
},
182182
"nbformat": 4,

src/py_eddy_tracker/observations/observation.py

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
@njit(cache=True, fastmath=True)
7272
def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5):
7373
"""
74-
work only if major is an array but faster * 6
74+
Work only if major is an array but faster * 6
7575
"""
7676
# c = (major ** 2 - minor ** 2) ** .5 + major
7777
c = major
@@ -190,7 +190,8 @@ def _repr_html_(self):
190190
return f"""<b>{infos['nb_obs']} observations from {infos['t0']} to {infos['t1']} </b>"""
191191

192192
def hist(self, varname, x, bins, percent=False, mean=False, nb=False):
193-
"""
193+
""" Build histograms.
194+
194195
:param str varname: variable to use to compute stat
195196
:param str x: variable to use to know in which bins
196197
:param array bins:
@@ -217,7 +218,7 @@ def box_display(value):
217218

218219
def __repr__(self):
219220
"""
220-
Return general informations on dataset as a string
221+
Return general informations on dataset as strings.
221222
222223
:return: informations on datasets
223224
:rtype: str
@@ -299,7 +300,7 @@ def obs_dimension(cls, handler):
299300

300301
def add_fields(self, fields=list(), array_fields=list()):
301302
"""
302-
Add a new field
303+
Add a new field.
303304
"""
304305
nb_obs = self.obs.shape[0]
305306
new = self.__class__(
@@ -328,7 +329,7 @@ def add_rotation_type(self):
328329

329330
def circle_contour(self, only_virtual=False):
330331
"""
331-
Set contour as a circle with radius and center data
332+
Set contours as a circles from radius and center data.
332333
333334
.. minigallery:: py_eddy_tracker.EddiesObservations.circle_contour
334335
"""
@@ -353,7 +354,7 @@ def circle_contour(self, only_virtual=False):
353354

354355
@property
355356
def dtype(self):
356-
"""Return dtype to build numpy array
357+
"""Return dtype to build numpy array.
357358
"""
358359
dtype = list()
359360
for elt in self.elements:
@@ -370,7 +371,7 @@ def dtype(self):
370371

371372
@property
372373
def elements(self):
373-
"""Return all the names of the variables
374+
"""Return all the names of the variables.
374375
"""
375376
elements = [i for i in self.ELEMENTS]
376377
if self.track_array_variables > 0:
@@ -383,7 +384,7 @@ def elements(self):
383384
return list(set(elements))
384385

385386
def coherence(self, other):
386-
"""Check coherence between two dataset
387+
"""Check coherence between two datasets.
387388
"""
388389
test = self.track_extra_variables == other.track_extra_variables
389390
test *= self.track_array_variables == other.track_array_variables
@@ -409,7 +410,7 @@ def concatenate(cls, observations):
409410
return eddies
410411

411412
def merge(self, other):
412-
"""Merge two dataset
413+
"""Merge two datasets.
413414
"""
414415
nb_obs_self = len(self)
415416
nb_obs = nb_obs_self + len(other)
@@ -431,7 +432,7 @@ def reset(self):
431432

432433
@property
433434
def obs(self):
434-
"""Return an array observations
435+
"""Return observations.
435436
"""
436437
return self.observations
437438

@@ -444,7 +445,7 @@ def __iter__(self):
444445

445446
def iter_on(self, xname, bins=None):
446447
"""
447-
Yield observation group for each bin
448+
Yield observation group for each bin.
448449
449450
:param str varname:
450451
:param array bins: bounds of each bin ,
@@ -478,7 +479,7 @@ def iter_on(self, xname, bins=None):
478479

479480
def align_on(self, other, var_name="time", **kwargs):
480481
"""
481-
Align the time indexes of two datasets
482+
Align the time indexes of two datasets.
482483
"""
483484
iter_self, iter_other = (
484485
self.iter_on(var_name, **kwargs),
@@ -497,7 +498,7 @@ def align_on(self, other, var_name="time", **kwargs):
497498
yield indexs_self, indexs_other, b0_self, b1_self
498499

499500
def insert_observations(self, other, index):
500-
"""Insert other obs in self at the index
501+
"""Insert other obs in self at the index.
501502
"""
502503
if not self.coherence(other):
503504
raise Exception("Observations with no coherence")
@@ -519,7 +520,7 @@ def insert_observations(self, other, index):
519520
return self
520521

521522
def append(self, other):
522-
"""Merge
523+
"""Merge.
523524
"""
524525
return self + other
525526

@@ -528,7 +529,7 @@ def __add__(self, other):
528529

529530
def distance(self, other):
530531
""" Use haversine distance for distance matrix between every self and
531-
other eddies"""
532+
other eddies."""
532533
return distance_grid(
533534
self.obs["lon"], self.obs["lat"], other.obs["lon"], other.obs["lat"]
534535
)
@@ -545,7 +546,7 @@ def new_like(eddies, new_size):
545546
)
546547

547548
def index(self, index, reverse=False):
548-
"""Return obs from self at the index
549+
"""Return obs from self at the index.
549550
"""
550551
if reverse:
551552
index = reverse_index(index, len(self))
@@ -570,7 +571,7 @@ def zarr_dimension(filename):
570571
@classmethod
571572
def load_file(cls, filename, **kwargs):
572573
"""
573-
Load the netcdf or the zarr file
574+
Load the netcdf or the zarr file.
574575
575576
Load only latitude and longitude on the first 300 obs :
576577
@@ -584,6 +585,10 @@ def load_file(cls, filename, **kwargs):
584585
indexs=dict(obs=slice(0, 300)),
585586
)
586587
small_dataset = TrackEddiesObservations.load_file(filename, **kwargs_latlon_300)
588+
589+
Default **kwargs to load zarr are : raw_data=False, remove_vars=None, include_vars=None
590+
591+
Default **kwargs to load netcdf are : raw_data=False, remove_vars=None, include_vars=None, indexs=None
587592
"""
588593
filename_ = (
589594
filename.filename if isinstance(filename, ExFileObject) else filename
@@ -855,7 +860,7 @@ def propagate(
855860
self, previous_obs, current_obs, obs_to_extend, dead_track, nb_next, model
856861
):
857862
"""
858-
Filled virtual obs (C)
863+
Filled virtual obs (C).
859864
860865
:param previous_obs: previous obs from current (A)
861866
:param current_obs: previous obs from virtual (B)
@@ -914,16 +919,17 @@ def intern(flag, public_label=False):
914919
return labels
915920

916921
def match(self, other, method="overlap", intern=False, cmin=0, **kwargs):
917-
"""Return index and score computed with the chosen method on the effective contour
922+
"""Return index and score computed on the effective contour.
918923
919924
:param EddiesObservations other: Observations to compare
920925
:param str method:
921926
- "overlap": the score is computed with contours;
922-
- "circle": circles are computed and used for score
927+
- "circle": circles are computed and used for score (TODO)
923928
:param bool intern: if True, speed contour is used (default = effective contour)
924929
:param float cmin: 0 < cmin < 1, return only couples with score >= cmin
925-
:param dict kwargs: look at :py:meth:`py_eddy_tracker.poly.vertice_overlap`
926-
:return: return the indexes of the eddies in self coupled with eddies in other and their associated score
930+
:param dict kwargs: look at :py:meth:`vertice_overlap`
931+
:return: return the indexes of the eddies in self coupled with eddies in
932+
other and their associated score
927933
:rtype: (array(int), array(int), array(float))
928934
929935
.. minigallery:: py_eddy_tracker.EddiesObservations.match
@@ -992,13 +998,14 @@ def mask_function(self, other, distance):
992998

993999
@staticmethod
9941000
def cost_function(records_in, records_out, distance):
995-
"""Return cost function between obs to associate
1001+
"""Return the cost function between two obs.
9961002
997-
.. code-block:: python
1003+
.. math::
9981004
999-
cost = sqrt(((amplitude_in - amplitude_out) / amplitude_in) ** 2 +
1000-
((speed_radius_in - speed_radius_out) / speed_radius_in) ** 2 +
1001-
(distance / 125) ** 2)
1005+
cost = \sqrt{({Amp_{_{in}} - Amp_{_{out}} \over Amp_{_{in}}}) ^2 +
1006+
({Rspeed_{_{in}} - Rspeed_{_{out}} \over Rspeed_{_{in}}}) ^2 +
1007+
({distance \over 125}) ^2
1008+
}
10021009
10031010
:param records_in: starting observations
10041011
:param records_out: observations to associate
@@ -1110,7 +1117,7 @@ def solve_conflict(cost):
11101117

11111118
@staticmethod
11121119
def solve_simultaneous(cost):
1113-
"""Write something"""
1120+
"""Write something (TODO)"""
11141121
mask = ~cost.mask
11151122
# Count number of link by self obs and other obs
11161123
self_links = mask.sum(axis=1)
@@ -1482,7 +1489,7 @@ def set_global_attr_netcdf(self, h_nc):
14821489

14831490
def extract_with_area(self, area, **kwargs):
14841491
"""
1485-
Extract geographically with a bounding box
1492+
Extract geographically with a bounding box.
14861493
14871494
:param dict area: 4 coordinates in a dictionary to specify bounding box (lower left corner and upper right corner)
14881495
:param dict kwargs: look at :py:meth:`extract_with_mask`
@@ -1503,7 +1510,7 @@ def extract_with_area(self, area, **kwargs):
15031510

15041511
def extract_with_mask(self, mask):
15051512
"""
1506-
Extract a subset of observations
1513+
Extract a subset of observations.
15071514
15081515
:param array(bool) mask: mask to select observations
15091516
:return: same object with selected observations
@@ -1529,6 +1536,8 @@ def extract_with_mask(self, mask):
15291536

15301537
def scatter(self, ax, name=None, ref=None, factor=1, **kwargs):
15311538
"""
1539+
Scatter data.
1540+
15321541
:param matplotlib.axes.Axes ax: matplotlib axe used to draw
15331542
:param str,array,None name:
15341543
variable used to fill the contour, if None all elements have the same color

0 commit comments

Comments
 (0)