Skip to content

Commit a2af2e7

Browse files
author
adelepoulle
committed
pylint/peps8
1 parent 344ea40 commit a2af2e7

File tree

4 files changed

+44
-41
lines changed

4 files changed

+44
-41
lines changed

src/py_eddy_tracker/observations.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ class EddiesObservations(object):
6767
Time
6868
"""
6969

70-
def __init__(self, size=0, track_extra_variables=None, track_array_variables=0, array_variables=None):
71-
self.track_extra_variables = track_extra_variables if track_extra_variables is not None else []
70+
def __init__(self, size=0, track_extra_variables=None,
71+
track_array_variables=0, array_variables=None):
72+
self.track_extra_variables = \
73+
track_extra_variables if track_extra_variables is not None else []
7274
self.track_array_variables = track_array_variables
73-
self.array_variables = array_variables if array_variables is not None else []
75+
self.array_variables = \
76+
array_variables if array_variables is not None else []
7477
for elt in self.elements:
7578
if elt not in VAR_DESCR:
7679
raise Exception('Unknown element : %s' % elt)
@@ -116,7 +119,7 @@ def elements(self):
116119
'time'] # 'rtime'
117120
if self.track_array_variables > 0:
118121
elements += self.array_variables
119-
122+
120123
if len(self.track_extra_variables):
121124
elements += self.track_extra_variables
122125
return elements
@@ -171,7 +174,7 @@ def insert_observations(self, other, index):
171174
return self
172175
if index < 0:
173176
index = self_size + index + 1
174-
eddies = self.__class__(new_size,
177+
eddies = self.__class__(new_size,
175178
track_extra_variables=self.track_extra_variables,
176179
track_array_variables=self.track_array_variables,
177180
array_variables=self.array_variables
@@ -217,7 +220,8 @@ def load_from_netcdf(filename):
217220
nb_obs = len(h_nc.dimensions['Nobs'])
218221
kwargs = dict()
219222
if array_dim in h_nc.dimensions:
220-
kwargs['track_array_variables'] = len(h_nc.dimensions[array_dim])
223+
kwargs['track_array_variables'] = len(
224+
h_nc.dimensions[array_dim])
221225
kwargs['array_variables'] = []
222226
for variable in h_nc.variables:
223227
if array_dim in h_nc.variables[variable].dimensions:
@@ -357,8 +361,8 @@ def elements(self):
357361
return elements
358362

359363
@staticmethod
360-
def create_variable(handler_nc, kwargs_variable,
361-
attr_variable, data, scale_factor=None, add_offset=None):
364+
def create_variable(handler_nc, kwargs_variable, attr_variable,
365+
data, scale_factor=None, add_offset=None):
362366
var = handler_nc.createVariable(
363367
zlib=True,
364368
complevel=1,

src/py_eddy_tracker/property_functions.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
from .tracking_objects import nearest
3838
from .observations import EddiesObservations
3939
from .property_objects import Amplitude
40-
from .tools import distance, winding_number_poly, fit_circle_c, poly_contain_poly
40+
from .tools import distance, winding_number_poly, fit_circle_c, \
41+
poly_contain_poly
4142
from matplotlib.path import Path as BasePath
4243
from scipy.interpolate import griddata
4344
from .tools import distance_vector
@@ -172,7 +173,7 @@ def vorticity(u_val, v_val, d_x, d_y):
172173
# Relative vorticity
173174
x_i = vorticity(u_val, v_val, p_m, p_n)
174175
# Okubo
175-
lambda2 = s_n**2 + s_t**2 - x_i**2
176+
lambda2 = s_n ** 2 + s_t ** 2 - x_i ** 2
176177
return lambda2, x_i
177178

178179

@@ -352,11 +353,11 @@ def _fit_circle_path(self):
352353
logging.warning('An edge is only define in one position')
353354
logging.debug('%d coordinates %s,%s', len(self.lon), self.lon,
354355
self.lat)
355-
self._circle_params = 0, -90, nan, nan
356+
self._circle_params = 0, -90, nan, nan
356357

357358
centlon_e, centlat_e = proj(centlon_e, centlat_e, inverse=True)
358359
centlon_e = (centlon_e - lon_mean + 180) % 360 + lon_mean - 180
359-
self._circle_params = centlon_e, centlat_e, eddy_radius_e, aerr
360+
self._circle_params = centlon_e, centlat_e, eddy_radius_e, aerr
360361

361362
BasePath.fit_circle = fit_circle_path
362363
BasePath._fit_circle_path = _fit_circle_path
@@ -489,7 +490,7 @@ def collection_loop(contours, grd, rtime, eddy,
489490
anticyclonic_search)
490491

491492
#~ if eddy.track_array_variables > 0:
492-
493+
493494
#~ if not eddy.track_extra_variables:
494495
if True:
495496
(uavg, contlon_s, contlat_s,
@@ -540,11 +541,13 @@ def collection_loop(contours, grd, rtime, eddy,
540541
properties.obs['lon'] = centlon_s
541542
properties.obs['lat'] = centlat_s
542543
if 'contour_lon_e' in eddy.track_array_variables:
543-
properties.obs['contour_lon_e'], properties.obs['contour_lat_e'] = uniform_resample(
544+
(properties.obs['contour_lon_e'],
545+
properties.obs['contour_lat_e']) = uniform_resample(
544546
cont.lon, cont.lat,
545547
fixed_size=eddy.track_array_variables_sampling)
546548
if 'contour_lon_s' in eddy.track_array_variables:
547-
properties.obs['contour_lon_s'], properties.obs['contour_lat_s'] = uniform_resample(
549+
(properties.obs['contour_lon_s'],
550+
properties.obs['contour_lat_s']) = uniform_resample(
548551
contlon_s, contlat_s,
549552
fixed_size=eddy.track_array_variables_sampling)
550553

@@ -601,7 +604,7 @@ def hann2d_fast(var, n_i, n_j):
601604
weight = 8. - c_c # This is the weight for values on each grid point,
602605
# based on number of valid neighbours
603606
# Final smoothed version of var
604-
hsm = 0.125 * (var_s + weight * var_ext[1:jsz+1, 1:isz+1])
607+
hsm = 0.125 * (var_s + weight * var_ext[1:jsz + 1, 1:isz + 1])
605608
return hsm
606609

607610
for _ in arange(numpasses):

src/py_eddy_tracker/property_objects.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
from scipy.ndimage import minimum_filter
3535
from numpy import array, isfinite, ma, where, ones
3636
from .tools import index_from_nearest_path, \
37-
index_from_nearest_path_with_pt_in_bbox, distance_matrix
38-
import logging
37+
index_from_nearest_path_with_pt_in_bbox
3938

4039

4140
class Amplitude (object):
@@ -59,21 +58,19 @@ class Amplitude (object):
5958
def __init__(self, contlon, contlat, eddy, grd):
6059
"""
6160
"""
62-
self.contlon = contlon.copy()
63-
self.contlat = contlat.copy()
6461
eddy.grd = grd # temporary fix
6562
self.eddy = eddy
6663
self.sla = self.eddy.sla[self.jslice,
6764
self.islice].copy()
6865

6966
if 'RectBivariate' in eddy.interp_method:
70-
h_0 = grd.sla_coeffs.ev(self.contlat[1:], self.contlon[1:])
67+
h_0 = grd.sla_coeffs.ev(contlat[1:], contlon[1:])
7168

7269
elif 'griddata' in eddy.interp_method:
7370
points = array([grd.lon()[self.jslice, self.islice].ravel(),
7471
grd.lat()[self.jslice, self.islice].ravel()]).T
7572
h_0 = griddata(points, self.sla.ravel(),
76-
(self.contlon[1:], self.contlat[1:]),
73+
(contlon[1:], contlat[1:]),
7774
'linear')
7875
else:
7976
raise Exception('Unknown method : %s' % eddy.interp_method)
@@ -82,7 +79,7 @@ def __init__(self, contlon, contlat, eddy, grd):
8279
self.amplitude = 0 # atleast_1d(0.)
8380
self.local_extrema = None # int(0)
8481
self.local_extrema_inds = None
85-
self.sla = ma.masked_where(-self.mask, self.sla)
82+
self.sla = ma.array(self.sla, mask=-self.mask)
8683

8784
@property
8885
def islice(self):
@@ -99,24 +96,22 @@ def mask(self):
9996
@property
10097
def mle(self):
10198
return self.eddy.max_local_extrema
102-
99+
103100
def within_amplitude_limits(self):
104101
"""
105102
"""
106103
return (self.amplitude >= self.eddy.ampmin and
107104
self.amplitude <= self.eddy.ampmax)
108105

109106
def _set_cyc_amplitude(self):
107+
"""Get amplitude for cyclone
110108
"""
111-
"""
112-
self.amplitude = self.h_0
113-
self.amplitude -= self.sla.min()
109+
self.amplitude = self.h_0 - self.sla.min()
114110

115111
def _set_acyc_amplitude(self):
112+
"""Get amplitude for anticyclone
116113
"""
117-
"""
118-
self.amplitude = self.sla.max()
119-
self.amplitude -= self.h_0
114+
self.amplitude = self.sla.max() - self.h_0
120115

121116
def all_pixels_below_h0(self, level):
122117
"""
@@ -184,7 +179,7 @@ def _set_local_extrema(self, sign):
184179
"""
185180
self._detect_local_minima(self.sla * sign)
186181

187-
def _detect_local_minima(self, arr):
182+
def _detect_local_minima(self, grid):
188183
"""
189184
Take an array and detect the troughs using the local maximum filter.
190185
Returns a boolean mask of the troughs (i.e., 1 when
@@ -193,12 +188,12 @@ def _detect_local_minima(self, arr):
193188
"""
194189
# Equivalent
195190
neighborhood = ones((3, 3), dtype='bool')
196-
#~ neighborhood = generate_binary_structure(arr.ndim, 2)
191+
#~ neighborhood = generate_binary_structure(grid.ndim, 2)
197192

198193
# Get local mimima
199194
detected_minima = minimum_filter(
200-
arr, footprint=neighborhood) == arr
201-
background = (arr == 0)
195+
grid, footprint=neighborhood) == grid
196+
background = (grid == 0)
202197
# Aims ?
203198
eroded_background = binary_erosion(
204199
background, structure=neighborhood, border_value=1)
@@ -259,11 +254,12 @@ def __init__(self, contour, nearest_contain_in_bbox=False):
259254
self.nb_c_per_l = array(li_list, dtype='u4')
260255
self.l_i = array(self.nb_c_per_l.cumsum() - self.nb_c_per_l,
261256
dtype='u4')
262-
257+
263258
self.nearest_contain_in_bbox = nearest_contain_in_bbox
264259

265260
def get_index_nearest_path_bbox_contain_pt(self, level, xpt, ypt):
266-
"""
261+
"""Get index from the nearest path in the level, if the bbox of the
262+
path contain pt
267263
"""
268264
return index_from_nearest_path_with_pt_in_bbox(
269265
level,
@@ -282,7 +278,7 @@ def get_index_nearest_path_bbox_contain_pt(self, level, xpt, ypt):
282278
)
283279

284280
def get_index_nearest_path(self, level, xpt, ypt):
285-
"""
281+
""" Get index from the nearest path in the level
286282
"""
287283
return index_from_nearest_path(
288284
level,

src/py_eddy_tracker/tools.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,14 @@ def index_from_nearest_path_with_pt_in_bbox(
415415
# We iterate over contour in the same level
416416
for i_elt_c from i_start_c <= i_elt_c < i_end_c:
417417
# if bbox of contour doesn't contain pt, we skip this contour
418-
if x_min_per_c[i_elt_c] > xpt:
419-
continue
420-
if x_max_per_c[i_elt_c] < xpt:
421-
continue
422418
if y_min_per_c[i_elt_c] > ypt:
423419
continue
424420
if y_max_per_c[i_elt_c] < ypt:
425421
continue
422+
if x_min_per_c[i_elt_c] > xpt:
423+
continue
424+
if x_max_per_c[i_elt_c] < xpt:
425+
continue
426426
# Indice of first pt of contour
427427
i_start_pt = indices_of_first_pts[i_elt_c]
428428
# Indice of first pt of the next contour

0 commit comments

Comments
 (0)