@@ -361,32 +361,38 @@ def index(self, index):
361
361
return eddies
362
362
363
363
@classmethod
364
- def load_from_netcdf (cls , filename , raw_data = False ):
364
+ def load_from_netcdf (cls , filename , raw_data = False , remove_vars = None ):
365
365
array_dim = "NbSample"
366
366
if not isinstance (filename , str ):
367
367
filename = filename .astype (str )
368
368
with Dataset (filename ) as h_nc :
369
+ var_list = list (h_nc .variables .keys ())
370
+ if remove_vars is not None :
371
+ print (var_list )
372
+ print (remove_vars )
373
+ var_list = [i for i in var_list if i not in remove_vars ]
374
+
369
375
nb_obs = len (h_nc .dimensions [cls .obs_dimension (h_nc )])
370
376
logging .debug ('%d observations will be load' , nb_obs )
371
377
kwargs = dict ()
372
378
if array_dim in h_nc .dimensions :
373
379
kwargs ["track_array_variables" ] = len (h_nc .dimensions [array_dim ])
374
380
kwargs ["array_variables" ] = list ()
375
- for variable in h_nc . variables :
381
+ for variable in var_list :
376
382
if array_dim in h_nc .variables [variable ].dimensions :
377
383
var_inv = VAR_DESCR_inv [variable ]
378
384
kwargs ["array_variables" ].append (var_inv )
379
385
array_variables = kwargs .get ("array_variables" , list ())
380
386
kwargs ["track_extra_variables" ] = []
381
- for variable in h_nc . variables :
387
+ for variable in var_list :
382
388
var_inv = VAR_DESCR_inv [variable ]
383
389
if var_inv == "type_cyc" :
384
390
continue
385
391
if var_inv not in cls .ELEMENTS and var_inv not in array_variables :
386
392
kwargs ["track_extra_variables" ].append (var_inv )
387
393
kwargs ["raw_data" ] = raw_data
388
394
eddies = cls (size = nb_obs , ** kwargs )
389
- for variable in h_nc . variables :
395
+ for variable in var_list :
390
396
var_inv = VAR_DESCR_inv [variable ]
391
397
if var_inv == "type_cyc" :
392
398
continue
@@ -397,6 +403,8 @@ def load_from_netcdf(cls, filename, raw_data=False):
397
403
factor = 1
398
404
if not raw_data :
399
405
input_unit = getattr (h_nc .variables [variable ], 'unit' , None )
406
+ if input_unit is None :
407
+ input_unit = getattr (h_nc .variables [variable ], 'units' , None )
400
408
output_unit = VAR_DESCR [var_inv ]['nc_attr' ].get ('units' , None )
401
409
if output_unit is not None and input_unit is not None and output_unit != input_unit :
402
410
units = UnitRegistry ()
@@ -411,14 +419,14 @@ def load_from_netcdf(cls, filename, raw_data=False):
411
419
factor = input_unit .to (output_unit ).to_tuple ()[0 ]
412
420
# If we are able to find a conversion
413
421
if factor != 1 :
414
- logging .info ('%s will be multiply by %f to take care of units' , variable , factor )
422
+ logging .info ('%s will be multiply by %f to take care of units(%s->%s)' ,
423
+ variable , factor , input_unit , output_unit )
415
424
if factor != 1 :
416
425
eddies .obs [var_inv ] = h_nc .variables [variable ][:] * factor
417
426
else :
418
427
eddies .obs [var_inv ] = h_nc .variables [variable ][:]
419
428
420
-
421
- for variable in h_nc .variables :
429
+ for variable in var_list :
422
430
var_inv = VAR_DESCR_inv [variable ]
423
431
if var_inv == "type_cyc" :
424
432
eddies .sign_type = h_nc .variables [variable ][0 ]
0 commit comments