@@ -361,32 +361,38 @@ def index(self, index):
361361 return eddies
362362
363363 @classmethod
364- def load_from_netcdf (cls , filename , raw_data = False ):
364+ def load_from_netcdf (cls , filename , raw_data = False , remove_vars = None ):
365365 array_dim = "NbSample"
366366 if not isinstance (filename , str ):
367367 filename = filename .astype (str )
368368 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+
369375 nb_obs = len (h_nc .dimensions [cls .obs_dimension (h_nc )])
370376 logging .debug ('%d observations will be load' , nb_obs )
371377 kwargs = dict ()
372378 if array_dim in h_nc .dimensions :
373379 kwargs ["track_array_variables" ] = len (h_nc .dimensions [array_dim ])
374380 kwargs ["array_variables" ] = list ()
375- for variable in h_nc . variables :
381+ for variable in var_list :
376382 if array_dim in h_nc .variables [variable ].dimensions :
377383 var_inv = VAR_DESCR_inv [variable ]
378384 kwargs ["array_variables" ].append (var_inv )
379385 array_variables = kwargs .get ("array_variables" , list ())
380386 kwargs ["track_extra_variables" ] = []
381- for variable in h_nc . variables :
387+ for variable in var_list :
382388 var_inv = VAR_DESCR_inv [variable ]
383389 if var_inv == "type_cyc" :
384390 continue
385391 if var_inv not in cls .ELEMENTS and var_inv not in array_variables :
386392 kwargs ["track_extra_variables" ].append (var_inv )
387393 kwargs ["raw_data" ] = raw_data
388394 eddies = cls (size = nb_obs , ** kwargs )
389- for variable in h_nc . variables :
395+ for variable in var_list :
390396 var_inv = VAR_DESCR_inv [variable ]
391397 if var_inv == "type_cyc" :
392398 continue
@@ -397,6 +403,8 @@ def load_from_netcdf(cls, filename, raw_data=False):
397403 factor = 1
398404 if not raw_data :
399405 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 )
400408 output_unit = VAR_DESCR [var_inv ]['nc_attr' ].get ('units' , None )
401409 if output_unit is not None and input_unit is not None and output_unit != input_unit :
402410 units = UnitRegistry ()
@@ -411,14 +419,14 @@ def load_from_netcdf(cls, filename, raw_data=False):
411419 factor = input_unit .to (output_unit ).to_tuple ()[0 ]
412420 # If we are able to find a conversion
413421 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 )
415424 if factor != 1 :
416425 eddies .obs [var_inv ] = h_nc .variables [variable ][:] * factor
417426 else :
418427 eddies .obs [var_inv ] = h_nc .variables [variable ][:]
419428
420-
421- for variable in h_nc .variables :
429+ for variable in var_list :
422430 var_inv = VAR_DESCR_inv [variable ]
423431 if var_inv == "type_cyc" :
424432 eddies .sign_type = h_nc .variables [variable ][0 ]
0 commit comments