30
30
from matplotlib .dates import julian2num , num2date
31
31
32
32
from py_eddy_tracker .observations import EddiesObservations , VirtualEddiesObservations , TrackEddiesObservations
33
- from numpy import bool_ , array , arange , ones , setdiff1d , zeros , uint16 , where , empty , isin , unique , concatenate
33
+ from numpy import bool_ , array , arange , ones , setdiff1d , zeros , uint16 , where , empty , isin , unique , concatenate , ma
34
34
from netCDF4 import Dataset
35
35
import logging
36
36
@@ -377,6 +377,7 @@ def save(self, filename, dict_completion=None):
377
377
zlib = True , complevel = 1 ,
378
378
varname = 'nb_link' , datatype = 'u2' , dimensions = 'Nstep' )
379
379
380
+ datas = dict ()
380
381
for name , dtype in self .correspondance_dtype :
381
382
if dtype is bool_ :
382
383
dtype = 'u1'
@@ -390,12 +391,18 @@ def save(self, filename, dict_completion=None):
390
391
dimensions = ('Nstep' , 'Nlink' ),
391
392
** kwargs_cv
392
393
)
394
+ datas [name ] = ma .empty ((nb_step , self .nb_link_max ),dtype = dtype )
395
+ datas [name ].mask = datas [name ] == datas [name ]
393
396
394
397
for i , correspondance in enumerate (self ):
398
+ logging .debug ('correspondance %d' , i )
395
399
nb_elt = correspondance .shape [0 ]
396
400
var_nb_link [i ] = nb_elt
397
401
for name , _ in self .correspondance_dtype :
398
- h_nc .variables [name ][i , :nb_elt ] = correspondance [name ]
402
+ datas [name ][i , :nb_elt ] = correspondance [name ]
403
+ for name , data in datas .items ():
404
+ h_nc .variables [name ][:] = data
405
+
399
406
h_nc .virtual_use = str (self .virtual )
400
407
h_nc .virtual_max_segment = self .nb_virtual
401
408
h_nc .last_current_id = self .current_id
@@ -425,8 +432,10 @@ def load_compatible(self, filename):
425
432
def load (cls , filename ):
426
433
logging .info ('Try load %s' , filename )
427
434
with Dataset (filename , 'r' , format = 'NETCDF4' ) as h_nc :
428
- datasets = list (h_nc .variables ['FileIn' ][:])
429
- datasets .append (h_nc .variables ['FileOut' ][- 1 ])
435
+ datas = {varname : data [:] for varname , data in h_nc .variables .items ()}
436
+
437
+ datasets = list (datas ['FileIn' ])
438
+ datasets .append (datas ['FileOut' ][- 1 ])
430
439
431
440
if hasattr (h_nc , 'module' ):
432
441
class_method = getattr (__import__ (h_nc .module , globals (), locals (), h_nc .classname ), h_nc .classname )
@@ -435,19 +444,19 @@ def load(cls, filename):
435
444
obj = cls (datasets , h_nc .virtual_max_segment , class_method = class_method )
436
445
437
446
id_max = 0
438
- for i , nb_elt in enumerate (h_nc . variables ['nb_link' ][:]):
447
+ for i , nb_elt in enumerate (datas ['nb_link' ][:]):
439
448
logging .debug (
440
449
'Link between %s and %s' ,
441
- h_nc . variables ['FileIn' ][i ],
442
- h_nc . variables ['FileOut' ][i ])
443
- correspondance = array (h_nc . variables ['in' ][i , :nb_elt ],
450
+ datas ['FileIn' ][i ],
451
+ datas ['FileOut' ][i ])
452
+ correspondance = array (datas ['in' ][i , :nb_elt ],
444
453
dtype = obj .correspondance_dtype )
445
454
for name , _ in obj .correspondance_dtype :
446
455
if name == 'in' :
447
456
continue
448
457
if name == 'virtual_length' :
449
458
correspondance [name ] = 255
450
- correspondance [name ] = h_nc . variables [name ][i , :nb_elt ]
459
+ correspondance [name ] = datas [name ][i , :nb_elt ]
451
460
id_max = max (id_max , correspondance ['id' ].max ())
452
461
obj .append (correspondance )
453
462
obj .current_id = id_max + 1
@@ -551,7 +560,6 @@ def merge(self, until=-1):
551
560
# We select the list of id which are involve in the correspondance
552
561
i_id = self [i ]['id' ]
553
562
# Index where we will write in the final object
554
- print (i_id .max ())
555
563
index_final = self .i_current_by_tracks [i_id ]
556
564
557
565
# First obs of eddies
0 commit comments