@@ -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