Skip to content

Commit 5b44bc8

Browse files
committed
minor changes (testing fork)
1 parent 4bee4c3 commit 5b44bc8

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

src/py_eddy_tracker/observations/observation.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
@njit(cache=True, fastmath=True)
6969
def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5):
7070
"""
71-
work only if major is an array but faster * 6
71+
Work only if major is an array but faster * 6
7272
"""
7373
# c = (major ** 2 - minor ** 2) ** .5 + major
7474
c = major
@@ -203,7 +203,8 @@ def _repr_html_(self):
203203
return f"""<b>{infos['nb_obs']} observations from {infos['t0']} to {infos['t1']} </b>"""
204204

205205
def hist(self, varname, x, bins, percent=False, mean=False, nb=False):
206-
"""
206+
""" Build histograms.
207+
207208
:param str varname: variable to use to compute stat
208209
:param str x: variable to use to know in which bins
209210
:param array bins:
@@ -230,7 +231,7 @@ def box_display(value):
230231

231232
def __repr__(self):
232233
"""
233-
Return general informations on dataset as a string
234+
Return general informations on dataset as strings.
234235
235236
:return: informations on datasets
236237
:rtype: str
@@ -282,7 +283,7 @@ def obs_dimension(cls, handler):
282283

283284
def add_fields(self, fields=list(), array_fields=list()):
284285
"""
285-
Add a new field
286+
Add a new field.
286287
"""
287288
nb_obs = self.obs.shape[0]
288289
new = self.__class__(
@@ -311,7 +312,7 @@ def add_rotation_type(self):
311312

312313
def circle_contour(self):
313314
"""
314-
Set contour as a circle with radius and center data
315+
Set contours as a circles from radius and center data.
315316
316317
.. minigallery:: py_eddy_tracker.EddiesObservations.circle_contour
317318
"""
@@ -334,7 +335,7 @@ def circle_contour(self):
334335

335336
@property
336337
def dtype(self):
337-
"""Return dtype to build numpy array
338+
"""Return dtype to build numpy array.
338339
"""
339340
dtype = list()
340341
for elt in self.elements:
@@ -351,7 +352,7 @@ def dtype(self):
351352

352353
@property
353354
def elements(self):
354-
"""Return all the names of the variables
355+
"""Return all the names of the variables.
355356
"""
356357
elements = [i for i in self.ELEMENTS]
357358
if self.track_array_variables > 0:
@@ -364,7 +365,7 @@ def elements(self):
364365
return list(set(elements))
365366

366367
def coherence(self, other):
367-
"""Check coherence between two dataset
368+
"""Check coherence between two datasets.
368369
"""
369370
test = self.track_extra_variables == other.track_extra_variables
370371
test *= self.track_array_variables == other.track_array_variables
@@ -390,7 +391,7 @@ def concatenate(cls, observations):
390391
return eddies
391392

392393
def merge(self, other):
393-
"""Merge two dataset
394+
"""Merge two datasets.
394395
"""
395396
nb_obs_self = len(self)
396397
nb_obs = nb_obs_self + len(other)
@@ -412,7 +413,7 @@ def reset(self):
412413

413414
@property
414415
def obs(self):
415-
"""Return an array observations
416+
"""Return an array observations.
416417
"""
417418
return self.observations
418419

@@ -425,7 +426,7 @@ def __iter__(self):
425426

426427
def iter_on(self, xname, bins=None):
427428
"""
428-
Yield observation group for each bin
429+
Yield observation group for each bin.
429430
430431
:param str varname:
431432
:param array bins: bounds of each bin ,
@@ -455,7 +456,7 @@ def iter_on(self, xname, bins=None):
455456

456457
def align_on(self, other, var_name="time", **kwargs):
457458
"""
458-
Align the time indexes of two datasets
459+
Align the time indexes of two datasets.
459460
"""
460461
iter_self, iter_other = (
461462
self.iter_on(var_name, **kwargs),
@@ -474,7 +475,7 @@ def align_on(self, other, var_name="time", **kwargs):
474475
yield indexs_self, indexs_other, b0_self, b1_self
475476

476477
def insert_observations(self, other, index):
477-
"""Insert other obs in self at the index
478+
"""Insert other obs in self at the index.
478479
"""
479480
if not self.coherence(other):
480481
raise Exception("Observations with no coherence")
@@ -496,7 +497,7 @@ def insert_observations(self, other, index):
496497
return self
497498

498499
def append(self, other):
499-
"""Merge
500+
"""Merge.
500501
"""
501502
return self + other
502503

@@ -505,7 +506,7 @@ def __add__(self, other):
505506

506507
def distance(self, other):
507508
""" Use haversine distance for distance matrix between every self and
508-
other eddies"""
509+
other eddies."""
509510
return distance_grid(
510511
self.obs["lon"], self.obs["lat"], other.obs["lon"], other.obs["lat"]
511512
)
@@ -522,7 +523,7 @@ def new_like(eddies, new_size):
522523
)
523524

524525
def index(self, index, reverse=False):
525-
"""Return obs from self at the index
526+
"""Return obs from self at the index.
526527
"""
527528
if reverse:
528529
index = reverse_index(index, len(self))
@@ -547,21 +548,24 @@ def zarr_dimension(filename):
547548
@classmethod
548549
def load_file(cls, filename, **kwargs):
549550
"""
550-
Load the netcdf or the zarr file
551+
Load the netcdf or the zarr file.
552+
551553
Load only latitude and longitude on the first 300 obs :
552554
553-
```python
554-
kwargs_latlon_300 = dict(
555-
include_vars=[
556-
"longitude",
557-
"latitude",
558-
],
559-
indexs=dict(obs=slice(0, 300)),
560-
)
561-
small_dataset = TrackEddiesObservations.load_file(
562-
nc_file.nc,
563-
**kwargs_latlon_300)
564-
```
555+
.. code-block:: python
556+
557+
kwargs_latlon_300 = dict(
558+
include_vars=[
559+
"longitude",
560+
"latitude",
561+
],
562+
indexs=dict(obs=slice(0, 300)),
563+
)
564+
small_dataset = TrackEddiesObservations.load_file(filename, **kwargs_latlon_300)
565+
566+
Default **kwargs to load zarr are : raw_data=False, remove_vars=None, include_vars=None
567+
568+
Default **kwargs to load netcdf are : raw_data=False, remove_vars=None, include_vars=None, indexs=None
565569
"""
566570
filename_ = (
567571
filename.filename if isinstance(filename, ExFileObject) else filename
@@ -832,7 +836,7 @@ def propagate(
832836
self, previous_obs, current_obs, obs_to_extend, dead_track, nb_next, model
833837
):
834838
"""
835-
Filled virtual obs (C)
839+
Filled virtual obs (C).
836840
837841
:param previous_obs: previous obs from current (A)
838842
:param current_obs: previous obs from virtual (B)
@@ -891,12 +895,12 @@ def intern(flag, public_label=False):
891895
return labels
892896

893897
def match(self, other, method="overlap", intern=False, cmin=0, **kwargs):
894-
"""Return index and score computed with the chosen method on the effective contour
898+
"""Return index and score computed on the effective contour.
895899
896900
:param EddiesObservations other: Observations to compare
897901
:param str method:
898-
"overlap": the score is computed with contours;
899-
"circle": circles are computed and used for score
902+
- "overlap": the score is computed with contours;
903+
- "circle": circles are computed and used for score (TODO)
900904
:param bool intern: if True, speed contour is used (default = effective contour)
901905
:param float cmin: 0 < cmin < 1, return only couples with score >= cmin
902906
:param dict kwargs: look at :py:meth:`vertice_overlap`
@@ -970,12 +974,14 @@ def mask_function(self, other, distance):
970974

971975
@staticmethod
972976
def cost_function(records_in, records_out, distance):
973-
"""Return cost function between obs to associate
974-
```python
975-
CF = sqrt ( [( amplitude_in - amplitude_out)/amplitude_in]^2 +
976-
[( speed_radius_in - speed_radius_out)/speed_radius_in]^2 +
977-
[ distance / 125]^2 )
978-
```
977+
"""Return the cost function between two obs
978+
979+
.. math::
980+
981+
cost = \sqrt{ ( {Amp_{_{in}} - Amp_{_{out}} \over Amp_{_{in}} } ) ^2 +
982+
( {Rspeed_{_{in}} - Rspeed_{_{out}} \over Rspeed_{_{in}} }) ^2 +
983+
( {distance \over 125} ) ^2
984+
}
979985
980986
:param records_in: starting observations
981987
:param records_out: observations to associate
@@ -1087,7 +1093,7 @@ def solve_conflict(cost):
10871093

10881094
@staticmethod
10891095
def solve_simultaneous(cost):
1090-
"""Write something"""
1096+
"""Write something (TODO)"""
10911097
mask = ~cost.mask
10921098
# Count number of link by self obs and other obs
10931099
self_links = mask.sum(axis=1)
@@ -1459,16 +1465,18 @@ def set_global_attr_netcdf(self, h_nc):
14591465

14601466
def extract_with_area(self, area, **kwargs):
14611467
"""
1462-
Extract geographically with a bounding box
1468+
Extract geographically with a bounding box.
14631469
14641470
:param dict area: 4 coordinates in a dictionary to specify bounding box (lower left corner and upper right corner)
1465-
```python
1466-
area = dict(llcrnrlon=x0, llcrnrlat=y0, urcrnrlon=x1, urcrnrlat=y1)
1467-
```
1468-
:param dict kwargs: look at :py:meth:`extract_with_mask`
1471+
.. code-block:: python
1472+
1473+
area = dict(llcrnrlon=x0, llcrnrlat=y0, urcrnrlon=x1, urcrnrlat=y1)
1474+
1475+
:param dict kwargs: look at :py:meth:`extract_with_mask`
14691476
:return: Return all eddy tracks which are in bounds
14701477
:rtype: EddiesObservations
14711478
1479+
14721480
.. minigallery:: py_eddy_tracker.EddiesObservations.extract_with_area
14731481
"""
14741482
mask = (self.latitude > area["llcrnrlat"]) * (self.latitude < area["urcrnrlat"])
@@ -1479,7 +1487,7 @@ def extract_with_area(self, area, **kwargs):
14791487

14801488
def extract_with_mask(self, mask):
14811489
"""
1482-
Extract a subset of observations
1490+
Extract a subset of observations.
14831491
14841492
:param array(bool) mask: mask to select observations
14851493
:return: same object with selected observations
@@ -1505,6 +1513,8 @@ def extract_with_mask(self, mask):
15051513

15061514
def scatter(self, ax, name=None, ref=None, factor=1, **kwargs):
15071515
"""
1516+
Scatter data.
1517+
15081518
:param matplotlib.axes.Axes ax: matplotlib axe used to draw
15091519
:param str, None name:
15101520
variable used to fill the contour, if None all elements have the same color
@@ -1604,6 +1614,7 @@ def display(
16041614
self, ax, ref=None, extern_only=False, intern_only=False, nobs=True, **kwargs
16051615
):
16061616
"""Plot the speed and effective (dashed) contour of the eddies
1617+
16071618
:param matplotlib.axes.Axes ax: matplotlib axe used to draw
16081619
:param float,None ref: western longitude reference used
16091620
:param bool extern_only: if True, draw only the effective contour

0 commit comments

Comments
 (0)