Skip to content

Commit ab8bba0

Browse files
author
adelepoulle
committed
Update pep8/pylint, read asked path
1 parent a44b2e1 commit ab8bba0

File tree

6 files changed

+125
-85
lines changed

6 files changed

+125
-85
lines changed

src/py_eddy_tracker/make_eddy_tracker_list_obj.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,12 @@ def create_variable(self, handler_nc, kwargs_variable,
765765
except ValueError:
766766
logging.warn('Data is empty')
767767

768-
def write_netcdf(self):
768+
def write_netcdf(self, path='./'):
769769
"""Write a netcdf with eddy obs
770770
"""
771771
eddy_size = len(self.observations)
772-
filename = '%s_%s.nc' % (self.sign_type, self.date.strftime('%Y%m%d'))
772+
filename = '%s/%s_%s.nc' % (
773+
path,self.sign_type, self.date.strftime('%Y%m%d'))
773774
with Dataset(filename, 'w', format='NETCDF4') as h_nc:
774775
logging.info('Create intermediary file %s', filename)
775776
# Create dimensions

src/py_eddy_tracker/observations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def tracking(self, other):
214214
"""
215215
cost = self.distance(other)
216216
# Links available which respect a maximal cost
217-
mask_accept_cost = cost < 75
217+
mask_accept_cost = cost < 40
218218
cost = ma.array(cost, mask=-mask_accept_cost, dtype='i2')
219219

220220
# Count number of link by self obs and other obs
@@ -351,12 +351,12 @@ def create_variable(handler_nc, kwargs_variable,
351351
except ValueError:
352352
logging.warn('Data is empty')
353353

354-
def write_netcdf(self):
354+
def write_netcdf(self, path='./'):
355355
"""Write a netcdf with eddy obs
356356
"""
357357
eddy_size = len(self.observations)
358358
sign_type = 'Cyclonic' if self.sign_type == -1 else 'Anticyclonic'
359-
filename = '%s.nc' % sign_type
359+
filename = '%s/%s.nc' % (path, sign_type)
360360
with Dataset(filename, 'w', format='NETCDF4') as h_nc:
361361
logging.info('Create file %s', filename)
362362
# Create dimensions

src/py_eddy_tracker/py_eddy_tracker_classes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def nearest_grd_indice(self, lon_value, lat_value, grid):
304304

305305
def fit_circle_path(self):
306306
if not hasattr(self, '_circle_params'):
307-
self._circle_params = self._fit_circle_path()
307+
self._fit_circle_path()
308308
return self._circle_params
309309

310310

@@ -326,11 +326,11 @@ def _fit_circle_path(self):
326326
logging.warning('An edge is only define in one position')
327327
logging.debug('%d coordinates %s,%s', len(self.lon), self.lon,
328328
self.lat)
329-
return 0, -90, np.nan, np.nan
329+
self._circle_params = 0, -90, np.nan, np.nan
330330

331331
centlon_e, centlat_e = proj(centlon_e, centlat_e, inverse=True)
332332
centlon_e = (centlon_e - lon_mean + 180) % 360 + lon_mean - 180
333-
return centlon_e, centlat_e, eddy_radius_e, aerr
333+
self._circle_params = centlon_e, centlat_e, eddy_radius_e, aerr
334334

335335
BasePath.fit_circle = fit_circle_path
336336
BasePath._fit_circle_path = _fit_circle_path

src/py_eddy_tracker/tracking.py

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class Correspondances(list):
4646
# Track limit to 65535
4747
N_DTYPE = 'u2'
4848

49-
5049
def __init__(self, datasets, virtual=0):
5150
"""Initiate tracking
5251
"""
52+
super(Correspondances, self).__init__()
5353
# Correspondance dtype
5454
self.correspondance_dtype = [('in', 'u2'),
5555
('out', 'u2'),
@@ -61,7 +61,7 @@ def __init__(self, datasets, virtual=0):
6161
self.previous2_obs = None
6262
self.previous_obs = None
6363
self.current_obs = None
64-
64+
6565
# To use virtual obs
6666
# Number of obs which can prolongate real observations
6767
self.nb_virtual = virtual
@@ -74,7 +74,7 @@ def __init__(self, datasets, virtual=0):
7474
self.correspondance_dtype += [
7575
('virtual', bool_),
7676
('virtual_length', self.VIRTUAL_DTYPE)]
77-
77+
7878
# Array to simply merged
7979
self.nb_obs_by_tracks = None
8080
self.i_current_by_tracks = None
@@ -87,12 +87,12 @@ def reset_dataset_cache(self):
8787
self.current_obs = None
8888

8989
def swap_dataset(self, dataset):
90-
"""
90+
""" Swap to next dataset
9191
"""
9292
self.previous2_obs = self.previous_obs
9393
self.previous_obs = self.current_obs
9494
self.current_obs = EddiesObservations.load_from_netcdf(dataset)
95-
95+
9696
def store_correspondance(self, i_previous, i_current, nb_real_obs):
9797
"""Storing correspondance in an array
9898
"""
@@ -105,7 +105,7 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
105105
# if index in previous dataset is bigger than real obs number
106106
# it's a virtual data
107107
correspondance['virtual'] = i_previous >= nb_real_obs
108-
108+
109109
if self.previous2_obs is None:
110110
# First time we set ID (Program starting)
111111
nb_match = i_previous.shape[0]
@@ -138,7 +138,7 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
138138
self.virtual_obs['track'][i_virtual]
139139
correspondance['virtual_length'][m_virtual] = \
140140
self.virtual_obs['segment_size'][i_virtual]
141-
141+
142142
# new_id is equal to UINT32_MAX we must add a new ones
143143
# we count the number of new
144144
mask_new_id = correspondance['id'] == self.UINT32_MAX
@@ -148,16 +148,16 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
148148
correspondance['id'][mask_new_id] = self.id_generator(nb_new_tracks)
149149

150150
self.append(correspondance)
151-
151+
152152
return False
153-
153+
154154
def id_generator(self, nb_id):
155155
"""Generation id and incrementation
156156
"""
157157
values = arange(self.current_id, self.current_id + nb_id)
158158
self.current_id += nb_id
159159
return values
160-
160+
161161
def recense_dead_id_to_extend(self):
162162
"""Recense dead id to extend in virtual observation
163163
"""
@@ -176,15 +176,17 @@ def recense_dead_id_to_extend(self):
176176
i_virtual_dead_id = [
177177
list_previous_virtual_id.index(i) for i in virtual_dead_id]
178178
# Virtual obs which can be prolongate
179-
alive_virtual_obs = self.virtual_obs['segment_size'][i_virtual_dead_id] < self.nb_virtual
179+
alive_virtual_obs = self.virtual_obs['segment_size'
180+
][i_virtual_dead_id] < self.nb_virtual
180181
nb_virtual_extend = alive_virtual_obs.sum()
181182
logging.debug('%d virtual obs will be prolongate on the '
182183
'next step', nb_virtual_extend)
183-
184+
184185
# Save previous state to count virtual obs
185186
self.previous_virtual_obs = self.virtual_obs
186187
# Creation of an virtual step for dead one
187-
self.virtual_obs = VirtualEddiesObservations(size=nb_dead + nb_virtual_extend)
188+
self.virtual_obs = VirtualEddiesObservations(
189+
size=nb_dead + nb_virtual_extend)
188190

189191
# Find mask/index on previous correspondance to extrapolate
190192
# position
@@ -208,42 +210,48 @@ def recense_dead_id_to_extend(self):
208210
self.virtual_obs['track'][:nb_dead] = dead_id
209211
# Add previous virtual
210212
if nb_virtual_extend > 0:
211-
obs_to_extend = self.previous_virtual_obs.obs[i_virtual_dead_id][alive_virtual_obs]
212-
self.virtual_obs['lon'][nb_dead:] = obs_to_extend['lon'] + obs_to_extend['dlon']
213-
self.virtual_obs['lat'][nb_dead:] = obs_to_extend['lat'] + obs_to_extend['dlat']
213+
obs_to_extend = self.previous_virtual_obs.obs[i_virtual_dead_id
214+
][alive_virtual_obs]
215+
self.virtual_obs['lon'][nb_dead:
216+
] = obs_to_extend['lon'] + obs_to_extend['dlon']
217+
self.virtual_obs['lat'][nb_dead:
218+
] = obs_to_extend['lat'] + obs_to_extend['dlat']
214219
self.virtual_obs['track'][nb_dead:] = obs_to_extend['track']
215-
self.virtual_obs['segment_size'][nb_dead:] = obs_to_extend['segment_size']
220+
self.virtual_obs['segment_size'][nb_dead:
221+
] = obs_to_extend['segment_size']
216222
# Count
217223
self.virtual_obs['segment_size'][:] += 1
218-
224+
219225
def track(self):
220226
"""Run tracking
221227
"""
222-
FLG_VIRTUAL = False
228+
flg_virtual = False
223229
self.reset_dataset_cache()
224230
self.swap_dataset(self.datasets[0])
225231
# We begin with second file, first one is in previous
226232
for file_name in self.datasets[1:]:
227233
self.swap_dataset(file_name)
228234
logging.debug('%s match with previous state', file_name)
229235
logging.debug('%d obs to match', len(self.current_obs))
230-
236+
231237
nb_real_obs = len(self.previous_obs)
232-
if FLG_VIRTUAL:
238+
if flg_virtual:
233239
logging.debug('%d virtual obs will be add to previous',
234240
len(self.virtual_obs))
235-
# If you comment this the virtual fonctionnality will be disable
241+
# If you comment this the virtual fonctionnality will be
242+
# disable
236243
self.previous_obs = self.previous_obs.merge(self.virtual_obs)
237-
238-
i_previous, i_current = self.previous_obs.tracking(self.current_obs)
244+
245+
i_previous, i_current = self.previous_obs.tracking(
246+
self.current_obs)
239247

240248
if self.store_correspondance(i_previous, i_current, nb_real_obs):
241249
continue
242250

243251
self.recense_dead_id_to_extend()
244252

245253
if self.virtual:
246-
FLG_VIRTUAL = True
254+
flg_virtual = True
247255

248256
def prepare_merging(self):
249257
# count obs by tracks (we add directly one, because correspondance
@@ -252,12 +260,16 @@ def prepare_merging(self):
252260
for correspondance in self:
253261
self.nb_obs_by_tracks[correspondance['id']] += 1
254262
if self.virtual:
255-
# When start is virtual, we don't have a previous correspondance
256-
self.nb_obs_by_tracks[correspondance['id'][correspondance['virtual']]
257-
] += correspondance['virtual_length'][correspondance['virtual']]
263+
# When start is virtual, we don't have a previous
264+
# correspondance
265+
self.nb_obs_by_tracks[
266+
correspondance['id'][correspondance['virtual']]
267+
] += correspondance['virtual_length'][
268+
correspondance['virtual']]
258269

259270
# Compute index of each tracks
260-
self.i_current_by_tracks = self.nb_obs_by_tracks.cumsum() - self.nb_obs_by_tracks
271+
self.i_current_by_tracks = \
272+
self.nb_obs_by_tracks.cumsum() - self.nb_obs_by_tracks
261273
# Number of global obs
262274
self.nb_obs = self.nb_obs_by_tracks.sum()
263275
logging.info('%d tracks identified', self.current_id)
@@ -272,11 +284,12 @@ def merge(self):
272284
# Calculate the index in each tracks, we compute in u4 and translate
273285
# in u2 (which are limited to 65535)
274286
logging.debug('Compute global index array (N)')
275-
n = arange(self.nb_obs,
276-
dtype='u4') - self.i_current_by_tracks.repeat(self.nb_obs_by_tracks)
277-
eddies['n'][:] = uint16(n)
287+
eddies['n'][:] = uint16(
288+
arange(self.nb_obs, dtype='u4')
289+
- self.i_current_by_tracks.repeat(self.nb_obs_by_tracks))
278290
logging.debug('Compute global track array')
279-
eddies['track'][:] = arange(self.current_id).repeat(self.nb_obs_by_tracks)
291+
eddies['track'][:] = arange(self.current_id
292+
).repeat(self.nb_obs_by_tracks)
280293

281294
# Start loading identification again to save in the finals tracks
282295
# Load first file
@@ -312,7 +325,7 @@ def merge(self):
312325
# Active this flag, we have only one first by tracks
313326
first_obs_save_in_tracks[i_id] = True
314327
index_final = self.i_current_by_tracks[i_id]
315-
328+
316329
if self.virtual:
317330
# If the flag virtual in correspondance is active,
318331
# the previous is virtual
@@ -326,7 +339,7 @@ def merge(self):
326339

327340
# Index in the current file
328341
index_current = self[i]['out']
329-
342+
330343
# Copy all variable
331344
for var, _ in fields:
332345
eddies[var][index_final

0 commit comments

Comments
 (0)