Skip to content

Commit 18084e5

Browse files
committed
Add doc string
Remove old unused function
1 parent 6df67c0 commit 18084e5

File tree

9 files changed

+90
-56
lines changed

9 files changed

+90
-56
lines changed

examples/02_eddy_identification/pet_eddy_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def start_axes(title):
2626
def update_axes(ax, mappable=None):
2727
ax.grid()
2828
if mappable:
29-
plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
29+
plt.colorbar(mappable, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
3030

3131

3232
# %%

examples/02_eddy_identification/pet_interp_grid_on_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def update_axes(ax, mappable=None):
2424
ax.grid()
2525
ax.legend()
2626
if mappable:
27-
plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
27+
plt.colorbar(mappable, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
2828

2929

3030
# %%

examples/06_grid_manipulation/pet_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def start_axes(title):
2525
def update_axes(ax, mappable=None):
2626
ax.grid()
2727
if mappable:
28-
plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
28+
plt.colorbar(mappable, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
2929

3030

3131
# %%

src/py_eddy_tracker/dataset/grid.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,17 @@ def __init__(
305305
def is_centered(self):
306306
"""Give information if pixel is describe with center position or
307307
a corner
308+
309+
:return: True if centered
310+
:rtype: bool
308311
"""
309312
if self.centered is None:
310313
return True
311314
else:
312315
return self.centered
313316

314317
def load_general_features(self):
315-
"""Load attrs
318+
"""Load attrs to be store in object
316319
"""
317320
logger.debug(
318321
"Load general feature from %(filename)s", dict(filename=self.filename)
@@ -340,6 +343,8 @@ def load_general_features(self):
340343

341344
def write(self, filename):
342345
"""Write dataset output with same format like input
346+
347+
:param str filename: filename which will be used to save grid
343348
"""
344349
with Dataset(filename, "w") as h_out:
345350
for dimension, size in self.dimensions.items():
@@ -373,7 +378,9 @@ def write(self, filename):
373378
setattr(h_out, attr, value)
374379

375380
def load(self):
376-
"""Load variable (data)
381+
"""
382+
Load variable (data).
383+
Get coordinates and setup coordinates function
377384
"""
378385
x_name, y_name = self.coordinates
379386
with Dataset(self.filename) as h:

src/py_eddy_tracker/eddy_feature.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
===========================================================================
43
This file is part of py-eddy-tracker.
54
65
py-eddy-tracker is free software: you can redistribute it and/or modify

src/py_eddy_tracker/generic.py

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
===========================================================================
43
This file is part of py-eddy-tracker.
54
65
py-eddy-tracker is free software: you can redistribute it and/or modify
@@ -46,6 +45,12 @@
4645

4746
@njit(cache=True)
4847
def reverse_index(index, nb):
48+
"""
49+
:param array index: index of group which will be set to False
50+
:param array nb: Count for each group
51+
:return: mask of value selected
52+
:rtype: array
53+
"""
4954
m = ones(nb, dtype=numba_types.bool_)
5055
for i in index:
5156
m[i] = False
@@ -55,6 +60,10 @@ def reverse_index(index, nb):
5560
@njit(cache=True)
5661
def build_index(groups):
5762
"""We expected that variable is monotonous, and return index for each step change
63+
64+
:param array groups: array which contain group to be separated
65+
:return: (first_index of each group, last_index of each group, value to shift group)
66+
:rtype: (array, array, int)
5867
"""
5968
i0, i1 = groups.min(), groups.max()
6069
amplitude = i1 - i0 + 1
@@ -75,12 +84,13 @@ def build_index(groups):
7584
@njit(cache=True, fastmath=True, parallel=False)
7685
def distance_grid(lon0, lat0, lon1, lat1):
7786
"""
78-
:param lon0:
79-
:param lat0:
80-
:param lon1:
81-
:param lat1:
87+
:param array lon0:
88+
:param array lat0:
89+
:param array lon1:
90+
:param array lat1:
8291
8392
:return: nan value for far away point, and km for other
93+
:rtype: array
8494
"""
8595
nb_0 = lon0.shape[0]
8696
nb_1 = lon1.shape[0]
@@ -109,6 +119,16 @@ def distance_grid(lon0, lat0, lon1, lat1):
109119

110120
@njit(cache=True, fastmath=True)
111121
def distance(lon0, lat0, lon1, lat1):
122+
"""
123+
Compute distance between points from each line
124+
125+
:param float lon0:
126+
:param float lat0:
127+
:param float lon1:
128+
:param float lat1:
129+
:return: distance (in m)
130+
:rtype: array
131+
"""
112132
D2R = pi / 180.0
113133
sin_dlat = sin((lat1 - lat0) * 0.5 * D2R)
114134
sin_dlon = sin((lon1 - lon0) * 0.5 * D2R)
@@ -118,31 +138,21 @@ def distance(lon0, lat0, lon1, lat1):
118138
return 6370997.0 * 2 * arctan2(a_val ** 0.5, (1 - a_val) ** 0.5)
119139

120140

121-
@njit(cache=True)
122-
def distance_vincenty(lon0, lat0, lon1, lat1):
123-
""" better than haversine but buggy ??"""
124-
D2R = pi / 180.0
125-
dlon = (lon1 - lon0) * D2R
126-
cos_dlon = cos(dlon)
127-
cos_lat1 = cos(lat0 * D2R)
128-
cos_lat2 = cos(lat1 * D2R)
129-
sin_lat1 = sin(lat0 * D2R)
130-
sin_lat2 = sin(lat1 * D2R)
131-
return 6370997.0 * arctan2(
132-
(
133-
(cos_lat2 * sin(dlon) ** 2)
134-
+ (cos_lat1 * sin_lat2 - sin_lat1 * cos_lat2 * cos_dlon) ** 2
135-
)
136-
** 0.5,
137-
sin_lat1 * sin_lat2 + cos_lat1 * cos_lat2 * cos_dlon,
138-
)
139-
140-
141141
@njit(cache=True, fastmath=True)
142142
def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
143-
"""For geographic grid, test of cicularity
144-
Maybe test if we are out of bounds
145143
"""
144+
For geographic grid, test of cicularity
145+
146+
:param array x_g: coordinates of grid
147+
:param array y_g: coordinates of grid
148+
:param array z_g: Grid value
149+
:param array m_g: Boolean grid, True if value is masked
150+
:param array x: coordinate where interpolate z
151+
:param array y: coordinate where interpolate z
152+
:return: z interpolated
153+
:rtype: array
154+
"""
155+
# TODO : Maybe test if we are out of bounds
146156
x_ref = x_g[0]
147157
y_ref = y_g[0]
148158
x_step = x_g[1] - x_ref
@@ -175,25 +185,6 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
175185
return z
176186

177187

178-
@njit(cache=True, fastmath=True, parallel=False)
179-
def custom_convolution(data, mask, kernel):
180-
"""do sortin at high lattitude big part of value are masked"""
181-
nb_x = kernel.shape[0]
182-
demi_x = int((nb_x - 1) / 2)
183-
demi_y = int((kernel.shape[1] - 1) / 2)
184-
out = empty(data.shape[0] - nb_x + 1)
185-
for i in prange(out.shape[0]):
186-
if mask[i + demi_x, demi_y] == 1:
187-
w = (mask[i : i + nb_x] * kernel).sum()
188-
if w != 0:
189-
out[i] = (data[i : i + nb_x] * kernel).sum() / w
190-
else:
191-
out[i] = nan
192-
else:
193-
out[i] = nan
194-
return out
195-
196-
197188
@njit(cache=True, fastmath=True)
198189
def uniform_resample(x_val, y_val, num_fac=2, fixed_size=None):
199190
"""
@@ -225,8 +216,8 @@ def uniform_resample(x_val, y_val, num_fac=2, fixed_size=None):
225216
def flatten_line_matrix(l_matrix):
226217
"""
227218
Flat matrix and add on between each line
228-
:param l_matrix: matrix of position
229219
220+
:param l_matrix: matrix of position
230221
:return: array with nan between line
231222
"""
232223
nb_line, sampling = l_matrix.shape
@@ -244,6 +235,15 @@ def flatten_line_matrix(l_matrix):
244235

245236
@njit(cache=True)
246237
def simplify(x, y, precision=0.1):
238+
"""
239+
Will remove all middle point which are closer than precision
240+
241+
:param array x:
242+
:param array y:
243+
:param float precision: if two points have distance inferior to precision with remove next point
244+
:return: (x,y)
245+
:rtype: (array,array)
246+
"""
247247
precision2 = precision ** 2
248248
nb = x.shape[0]
249249
x_previous, y_previous = x[0], y[0]
@@ -277,6 +277,7 @@ def simplify(x, y, precision=0.1):
277277
def split_line(x, y, i):
278278
"""
279279
Split x and y at each i change
280+
280281
:param x: array
281282
:param y: array
282283
:param i: array of int at each i change, we cut x, y
@@ -302,6 +303,16 @@ def split_line(x, y, i):
302303

303304
@njit(cache=True)
304305
def wrap_longitude(x, y, ref, cut=False):
306+
"""
307+
Will wrap contiguous longitude with reference like west bound
308+
309+
:param array x:
310+
:param array y:
311+
:param float ref: longitude of reference, all the new value will be between ref and ref + 360
312+
:param bool cut: if True line will be cut at the bounds
313+
:return: lon,lat
314+
:rtype: (array,array)
315+
"""
305316
if cut:
306317
indexs = list()
307318
nb = x.shape[0]
@@ -348,6 +359,16 @@ def wrap_longitude(x, y, ref, cut=False):
348359

349360
@njit(cache=True, fastmath=True)
350361
def coordinates_to_local(lon, lat, lon0, lat0):
362+
"""
363+
Take latlong coordinates to transform in local coordinates (in m)
364+
365+
:param array x: coordinates to transform
366+
:param array y: coordinates to transform
367+
:param float lon0: longitude of local reference
368+
:param float lat0: latitude of local reference
369+
:return: x,y
370+
:retype: (array, array)
371+
"""
351372
D2R = pi / 180.0
352373
R = 6370997
353374
dlon = (lon - lon0) * D2R
@@ -367,6 +388,16 @@ def coordinates_to_local(lon, lat, lon0, lat0):
367388

368389
@njit(cache=True, fastmath=True)
369390
def local_to_coordinates(x, y, lon0, lat0):
391+
"""
392+
Take local coordinates (in m) to transform to latlong
393+
394+
:param array x: coordinates to transform
395+
:param array y: coordinates to transform
396+
:param float lon0: longitude of local reference
397+
:param float lat0: latitude of local reference
398+
:return: lon,lat
399+
:retype: (array, array)
400+
"""
370401
D2R = pi / 180.0
371402
R = 6370997
372403
d = (x ** 2 + y ** 2) ** 0.5 / R

src/py_eddy_tracker/observations/observation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
===========================================================================
43
This file is part of py-eddy-tracker.
54
65
py-eddy-tracker is free software: you can redistribute it and/or modify

src/py_eddy_tracker/observations/tracking.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
===========================================================================
43
This file is part of py-eddy-tracker.
54
65
py-eddy-tracker is free software: you can redistribute it and/or modify

src/py_eddy_tracker/poly.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
===========================================================================
43
This file is part of py-eddy-tracker.
54
65
py-eddy-tracker is free software: you can redistribute it and/or modify

0 commit comments

Comments
 (0)