Skip to content

Commit 7df1dc3

Browse files
committed
apply proposition of checker
1 parent 71fb263 commit 7df1dc3

File tree

4 files changed

+85
-68
lines changed

4 files changed

+85
-68
lines changed

src/py_eddy_tracker/featured_tracking/old_tracker_reference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def mask_function(self, other):
2626
cmax=1.5,
2727
lat1=23,
2828
lat2=5,
29-
)
29+
)
3030
# mask from ellips
3131
mask = self.shifted_ellipsoid_degrees_mask(
3232
other,
@@ -56,10 +56,10 @@ def across_ground(cls, record0, record1):
5656
y0=record0['lat'],
5757
x1=record1['lon'],
5858
y1=record1['lat'],
59-
)
59+
)
6060

6161
data = cls.GROUND.grid('mask')[i, j]
62-
i_ground = unique(arange(len(record0)).repeat(d_pix + 1)[data==1])
62+
i_ground = unique(arange(len(record0)).repeat(d_pix + 1)[data == 1])
6363
mask = ones(record1.shape, dtype='bool')
6464
mask[i_ground] = False
6565
return mask

src/py_eddy_tracker/grid/__init__.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444

4545
def browse_dataset_in(data_dir, files_model, date_regexp, date_model,
46-
start_date=None, end_date=None, sub_sampling_step=1):
46+
start_date=None, end_date=None, sub_sampling_step=1):
4747
pattern_regexp = re_compile('.*/' + date_regexp)
4848
full_path = join_path(data_dir, files_model)
4949
logging.info('Search files : %s', full_path)
@@ -75,7 +75,7 @@ def browse_dataset_in(data_dir, files_model, date_regexp, date_model,
7575
result = pattern_regexp.match(str(item['filename']))
7676
if result:
7777
str_date = result.groups()[0]
78-
78+
7979
if str_date is not None:
8080
item['date'] = datetime.strptime(str_date, date_model).date()
8181

@@ -120,7 +120,7 @@ class BaseData(object):
120120
ROMS: get_ROMS_f_pm_pn
121121
122122
"""
123-
123+
124124
__slots__ = (
125125
'zero_crossing',
126126
'slice_i',
@@ -154,8 +154,8 @@ class BaseData(object):
154154
'pad',
155155
'shape',
156156
'mask',
157-
)
158-
157+
)
158+
159159
GRAVITY = 9.81
160160
earth_radius = 6371315.0
161161

@@ -229,11 +229,11 @@ def read_nc_att(self, varname, att):
229229

230230
@property
231231
def is_regular(self):
232-
steps_lon = unique(self._lon[0, 1:] - self._lon[0,:-1])
232+
steps_lon = unique(self._lon[0, 1:] - self._lon[0, :-1])
233233
steps_lat = unique(self._lat[1:, 0] - self._lat[:-1, 0])
234234
return len(steps_lon) == 1 and len(steps_lat) == 1 and \
235-
steps_lon[0] != 0. and steps_lat[0] != 0.
236-
235+
steps_lon[0] != 0. and steps_lat[0] != 0.
236+
237237
def set_initial_indices(self):
238238
"""
239239
Set indices for desired domain
@@ -276,18 +276,19 @@ def kdt(lon, lat, limits, k=4):
276276
"""
277277
if self.is_regular:
278278
i_1 = int(floor(interp((lonmin - 0.5) % 360,
279-
self._lon[0],
280-
arange(len(self._lon[0])))))
279+
self._lon[0],
280+
arange(len(self._lon[0])))))
281281
i_0 = int(floor(interp((lonmax + 0.5) % 360,
282-
self._lon[0],
283-
arange(len(self._lon[0])))
284-
) + 1)
282+
self._lon[0],
283+
arange(len(self._lon[0])))
284+
) + 1)
285285
else:
286286
def half_limits(lon, lat):
287287
return array([[lon.min(), lon.max(),
288-
lon.max(), lon.min()],
289-
[lat.min(), lat.min(),
290-
lat.max(), lat.max()]]).T
288+
lon.max(), lon.min()],
289+
[lat.min(), lat.min(),
290+
lat.max(), lat.max()]]).T
291+
291292
# Get bounds for right part of grid
292293
lat = self._lat[self._lon >= 360 + lonmin - 0.5]
293294
lon = self._lon[self._lon >= 360 + lonmin - 0.5]
@@ -415,12 +416,14 @@ def u2rho_2d(self, uu_in):
415416
"""
416417
Convert a 2D field at u_val points to a field at rho points
417418
"""
419+
418420
def uu2ur(uu_in, m_p, l_p):
419421
u_out = zeros((m_p, l_p))
420422
u_out[:, 1:-1] = self.half_interp(uu_in[:, :-1], uu_in[:, 1:])
421423
u_out[:, 0] = u_out[:, 1]
422424
u_out[:, -1] = u_out[:, -2]
423425
return u_out.squeeze()
426+
424427
mshp, lshp = uu_in.shape
425428
return uu2ur(uu_in, mshp, lshp + 1)
426429

@@ -432,6 +435,7 @@ def vv2vr(vv_in, m_p, l_p):
432435
v_out[0] = v_out[1]
433436
v_out[-1] = v_out[-2]
434437
return v_out.squeeze()
438+
435439
mshp, lshp = vv_in.shape
436440
return vv2vr(vv_in, mshp + 1, lshp)
437441

@@ -458,7 +462,7 @@ def set_basemap(self, with_pad=True):
458462
llcrnrlat=self.latmin - 1,
459463
urcrnrlat=self.latmax + 1,
460464
lat_ts=0.5 * (self.latmin + self.latmax)
461-
)
465+
)
462466

463467
if with_pad:
464468
x_val, y_val = self.m_val(self.lonpad, self.latpad)
@@ -475,13 +479,13 @@ def set_geostrophic_velocity(self, zeta):
475479
zeta1, zeta2 = zeta.data[1:].view(), zeta.data[:-1].view()
476480
pn1, pn2 = self.p_n[1:].view(), self.p_n[:-1].view()
477481
self.upad[:] = self.v2rho_2d(
478-
ma.array((zeta1 - zeta2) * 0.5 * (pn1 + pn2), mask= self.vmask))
482+
ma.array((zeta1 - zeta2) * 0.5 * (pn1 + pn2), mask=self.vmask))
479483
self.upad *= -self.gof
480484

481485
zeta1, zeta2 = zeta.data[:, 1:].view(), zeta.data[:, :-1].view()
482486
pm1, pm2 = self.p_m[:, 1:].view(), self.p_m[:, :-1].view()
483487
self.vpad[:] = self.u2rho_2d(
484-
ma.array((zeta1 - zeta2) *0.5 * (pm1 + pm2), mask=self.umask))
488+
ma.array((zeta1 - zeta2) * 0.5 * (pm1 + pm2), mask=self.umask))
485489
self.vpad *= self.gof
486490

487491
def set_u_v_eke(self, pad=2):
@@ -495,7 +499,7 @@ def set_u_v_eke(self, pad=2):
495499
self.upad = ma.concatenate((u_0, u_1), axis=1)
496500
else:
497501
self.upad = empty((j_size,
498-
self.slice_i_pad.stop - self.slice_i_pad.start))
502+
self.slice_i_pad.stop - self.slice_i_pad.start))
499503
self.vpad = empty(self.upad.shape)
500504

501505
def get_eke(self):
@@ -532,7 +536,7 @@ def create_index_inverse(slice_to_inverse, size):
532536
"""Return an array of index
533537
"""
534538
index = concatenate((arange(slice_to_inverse.stop, size),
535-
arange(slice_to_inverse.start)))
539+
arange(slice_to_inverse.start)))
536540
return index
537541

538542
def gaussian_resolution(self, zwl, mwl):

src/py_eddy_tracker/grid/aviso.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from dateutil import parser
3333
from numpy import meshgrid, zeros, array, where, ma, argmin, vstack, ones, \
3434
newaxis, sqrt, diff, r_, arange
35-
from scipy.interpolate import interp1d
35+
from scipy.interpolate import interp1d
3636
import logging
3737
from netCDF4 import Dataset
3838

@@ -45,9 +45,9 @@ class AvisoGrid(BaseData):
4545
to have a grid class
4646
"""
4747
KNOWN_UNITS = dict(
48-
m=100.,
49-
cm=1.,
50-
)
48+
m=100.,
49+
cm=1.,
50+
)
5151
__slots__ = (
5252
'lonmin',
5353
'lonmax',
@@ -69,11 +69,11 @@ class AvisoGrid(BaseData):
6969
'__lonpad',
7070
'__latpad',
7171
'labels',
72-
)
72+
)
7373

7474
def __init__(self, aviso_file, the_domain,
7575
lonmin, lonmax, latmin, latmax, grid_name, lon_name,
76-
lat_name,with_pad=True):
76+
lat_name, with_pad=True):
7777
"""
7878
Initialise the grid object
7979
"""
@@ -121,7 +121,7 @@ def __init__(self, aviso_file, the_domain,
121121
# zero_crossing, used for handling a longitude range that
122122
# crosses zero degree meridian
123123
if self.lonmin < 0 <= self.lonmax and 'MedSea' not in self.domain:
124-
if (self.lonmax < self._lon.max()) and (self.lonmax > self._lon.min()) and (self.lonmin < self._lon.max()) and (self.lonmin > self._lon.min()):
124+
if self._lon.min() < self.lonmax < self._lon.max() and self._lon.min() < self.lonmin < self._lon.max():
125125
pass
126126
else:
127127
self.zero_crossing = True
@@ -141,15 +141,17 @@ def __init__(self, aviso_file, the_domain,
141141
# self.init_pos_interpolator()
142142

143143
def init_pos_interpolator(self):
144-
self.xinterp = interp1d(self.lon[0].copy(), arange(self.lon.shape[1]), assume_sorted=True, copy=False, fill_value=(0, -1), bounds_error=False, kind='nearest')
145-
self.yinterp = interp1d(self.lat[:, 0].copy(), arange(self.lon.shape[0]), assume_sorted=True, copy=False, fill_value=(0, -1), bounds_error=False, kind='nearest')
144+
self.xinterp = interp1d(self.lon[0].copy(), arange(self.lon.shape[1]), assume_sorted=True, copy=False,
145+
fill_value=(0, -1), bounds_error=False, kind='nearest')
146+
self.yinterp = interp1d(self.lat[:, 0].copy(), arange(self.lon.shape[0]), assume_sorted=True, copy=False,
147+
fill_value=(0, -1), bounds_error=False, kind='nearest')
146148

147149
def nearest_indice(self, lon, lat):
148150
return self.xinterp(lon), self.yinterp(lat)
149151

150152
def set_filename(self, file_name):
151153
self.grid_filename = file_name
152-
154+
153155
def get_aviso_data(self, aviso_file, dimensions=None):
154156
"""
155157
Read nc data from AVISO file
@@ -160,7 +162,7 @@ def get_aviso_data(self, aviso_file, dimensions=None):
160162
units = self.read_nc_att(self.grid_name, 'units')
161163
if units not in self.KNOWN_UNITS:
162164
raise Exception('Unknown units : %s' % units)
163-
165+
164166
with Dataset(self.grid_filename.decode('utf-8')) as h_nc:
165167
grid_dims = array(h_nc.variables[self.grid_name].dimensions)
166168
lat_dim = h_nc.variables[self.lat_name].dimensions[0]
@@ -196,7 +198,6 @@ def set_mask(self, sla):
196198
else:
197199
self.mask = sla.mask.copy()
198200
if 'Global' in self.domain:
199-
200201
# Close Drake Passage
201202
minus70 = argmin(abs(self.lonpad[0] + 70))
202203
self.mask[:125, minus70] = True
@@ -232,7 +233,7 @@ def lonpad(self):
232233
self.__lonpad = self._lon[self.view_pad]
233234
if self.zero_crossing:
234235
self.__lonpad[:, :self._lon.shape[1] - self.slice_i_pad.stop
235-
] -= 360
236+
] -= 360
236237
return self.__lonpad
237238

238239
@property
@@ -280,7 +281,7 @@ def p_n(self): # Reciprocal of d_y
280281
@property
281282
def resolution(self):
282283
return sqrt(diff(self.lon[1:], axis=1) *
283-
diff(self.lat[:, 1:], axis=0)).mean()
284+
diff(self.lat[:, 1:], axis=0)).mean()
284285

285286
@property
286287
def boundary(self):
@@ -292,7 +293,7 @@ def boundary(self):
292293
lon/lat boundary points
293294
"""
294295
lon = r_[(self.lon[:, 0], self.lon[-1],
295-
self.lon[::-1, -1], self.lon[0, ::-1])]
296+
self.lon[::-1, -1], self.lon[0, ::-1])]
296297
lat = r_[(self.lat[:, 0], self.lat[-1],
297-
self.lat[::-1, -1], self.lat[0, ::-1])]
298+
self.lat[::-1, -1], self.lat[0, ::-1])]
298299
return lon, lat

0 commit comments

Comments
 (0)