@@ -46,10 +46,10 @@ class Correspondances(list):
46
46
# Track limit to 65535
47
47
N_DTYPE = 'u2'
48
48
49
-
50
49
def __init__ (self , datasets , virtual = 0 ):
51
50
"""Initiate tracking
52
51
"""
52
+ super (Correspondances , self ).__init__ ()
53
53
# Correspondance dtype
54
54
self .correspondance_dtype = [('in' , 'u2' ),
55
55
('out' , 'u2' ),
@@ -61,7 +61,7 @@ def __init__(self, datasets, virtual=0):
61
61
self .previous2_obs = None
62
62
self .previous_obs = None
63
63
self .current_obs = None
64
-
64
+
65
65
# To use virtual obs
66
66
# Number of obs which can prolongate real observations
67
67
self .nb_virtual = virtual
@@ -74,7 +74,7 @@ def __init__(self, datasets, virtual=0):
74
74
self .correspondance_dtype += [
75
75
('virtual' , bool_ ),
76
76
('virtual_length' , self .VIRTUAL_DTYPE )]
77
-
77
+
78
78
# Array to simply merged
79
79
self .nb_obs_by_tracks = None
80
80
self .i_current_by_tracks = None
@@ -87,12 +87,12 @@ def reset_dataset_cache(self):
87
87
self .current_obs = None
88
88
89
89
def swap_dataset (self , dataset ):
90
- """
90
+ """ Swap to next dataset
91
91
"""
92
92
self .previous2_obs = self .previous_obs
93
93
self .previous_obs = self .current_obs
94
94
self .current_obs = EddiesObservations .load_from_netcdf (dataset )
95
-
95
+
96
96
def store_correspondance (self , i_previous , i_current , nb_real_obs ):
97
97
"""Storing correspondance in an array
98
98
"""
@@ -105,7 +105,7 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
105
105
# if index in previous dataset is bigger than real obs number
106
106
# it's a virtual data
107
107
correspondance ['virtual' ] = i_previous >= nb_real_obs
108
-
108
+
109
109
if self .previous2_obs is None :
110
110
# First time we set ID (Program starting)
111
111
nb_match = i_previous .shape [0 ]
@@ -138,7 +138,7 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
138
138
self .virtual_obs ['track' ][i_virtual ]
139
139
correspondance ['virtual_length' ][m_virtual ] = \
140
140
self .virtual_obs ['segment_size' ][i_virtual ]
141
-
141
+
142
142
# new_id is equal to UINT32_MAX we must add a new ones
143
143
# we count the number of new
144
144
mask_new_id = correspondance ['id' ] == self .UINT32_MAX
@@ -148,16 +148,16 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
148
148
correspondance ['id' ][mask_new_id ] = self .id_generator (nb_new_tracks )
149
149
150
150
self .append (correspondance )
151
-
151
+
152
152
return False
153
-
153
+
154
154
def id_generator (self , nb_id ):
155
155
"""Generation id and incrementation
156
156
"""
157
157
values = arange (self .current_id , self .current_id + nb_id )
158
158
self .current_id += nb_id
159
159
return values
160
-
160
+
161
161
def recense_dead_id_to_extend (self ):
162
162
"""Recense dead id to extend in virtual observation
163
163
"""
@@ -176,15 +176,17 @@ def recense_dead_id_to_extend(self):
176
176
i_virtual_dead_id = [
177
177
list_previous_virtual_id .index (i ) for i in virtual_dead_id ]
178
178
# 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
180
181
nb_virtual_extend = alive_virtual_obs .sum ()
181
182
logging .debug ('%d virtual obs will be prolongate on the '
182
183
'next step' , nb_virtual_extend )
183
-
184
+
184
185
# Save previous state to count virtual obs
185
186
self .previous_virtual_obs = self .virtual_obs
186
187
# 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 )
188
190
189
191
# Find mask/index on previous correspondance to extrapolate
190
192
# position
@@ -208,42 +210,48 @@ def recense_dead_id_to_extend(self):
208
210
self .virtual_obs ['track' ][:nb_dead ] = dead_id
209
211
# Add previous virtual
210
212
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' ]
214
219
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' ]
216
222
# Count
217
223
self .virtual_obs ['segment_size' ][:] += 1
218
-
224
+
219
225
def track (self ):
220
226
"""Run tracking
221
227
"""
222
- FLG_VIRTUAL = False
228
+ flg_virtual = False
223
229
self .reset_dataset_cache ()
224
230
self .swap_dataset (self .datasets [0 ])
225
231
# We begin with second file, first one is in previous
226
232
for file_name in self .datasets [1 :]:
227
233
self .swap_dataset (file_name )
228
234
logging .debug ('%s match with previous state' , file_name )
229
235
logging .debug ('%d obs to match' , len (self .current_obs ))
230
-
236
+
231
237
nb_real_obs = len (self .previous_obs )
232
- if FLG_VIRTUAL :
238
+ if flg_virtual :
233
239
logging .debug ('%d virtual obs will be add to previous' ,
234
240
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
236
243
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 )
239
247
240
248
if self .store_correspondance (i_previous , i_current , nb_real_obs ):
241
249
continue
242
250
243
251
self .recense_dead_id_to_extend ()
244
252
245
253
if self .virtual :
246
- FLG_VIRTUAL = True
254
+ flg_virtual = True
247
255
248
256
def prepare_merging (self ):
249
257
# count obs by tracks (we add directly one, because correspondance
@@ -252,12 +260,16 @@ def prepare_merging(self):
252
260
for correspondance in self :
253
261
self .nb_obs_by_tracks [correspondance ['id' ]] += 1
254
262
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' ]]
258
269
259
270
# 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
261
273
# Number of global obs
262
274
self .nb_obs = self .nb_obs_by_tracks .sum ()
263
275
logging .info ('%d tracks identified' , self .current_id )
@@ -272,11 +284,12 @@ def merge(self):
272
284
# Calculate the index in each tracks, we compute in u4 and translate
273
285
# in u2 (which are limited to 65535)
274
286
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 ) )
278
290
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 )
280
293
281
294
# Start loading identification again to save in the finals tracks
282
295
# Load first file
@@ -312,7 +325,7 @@ def merge(self):
312
325
# Active this flag, we have only one first by tracks
313
326
first_obs_save_in_tracks [i_id ] = True
314
327
index_final = self .i_current_by_tracks [i_id ]
315
-
328
+
316
329
if self .virtual :
317
330
# If the flag virtual in correspondance is active,
318
331
# the previous is virtual
@@ -326,7 +339,7 @@ def merge(self):
326
339
327
340
# Index in the current file
328
341
index_current = self [i ]['out' ]
329
-
342
+
330
343
# Copy all variable
331
344
for var , _ in fields :
332
345
eddies [var ][index_final
0 commit comments