Changeset 27880


Ignore:
Timestamp:
08/17/23 10:06:39 (19 months ago)
Author:
musselman
Message:

Added type recognition for integers in read_netCDF_commit.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/contrib/musselman/read_netCDF_commit.py

    r27878 r27880  
    226226            try:
    227227                # this try block will only work on single ints/floats/doubles and will skip to the except block for all other cases
    228                 if FillValue == eval(location_of_variable_in_file + '[:][0]'):
     228                var_to_save = eval(location_of_variable_in_file + '[:][0]')  # note the [0] on the end
     229                if FillValue == var_to_save:
    229230                    setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, [])
    230231                else:
    231                     # we have to convert numpy datatypes to native python types with .item()
    232                     var_to_save = eval(location_of_variable_in_file + '[:][0]')  # note the [0] on the end
    233                     setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, var_to_save.item())
     232                    if var_to_save.is_integer():
     233                        setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, int(var_to_save))
     234                    else:
     235                        # we have to convert numpy datatypes to native python types with .item()
     236                        setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, var_to_save.item())                       
    234237            except:
    235                     setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, eval(location_of_variable_in_file + '[:]'))
     238                    setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, eval(location_of_variable_in_file + '[:].item()'))
    236239    except AttributeError:
    237240        copy_variable_data_to_new_model_dict(location_of_variable_in_file, location_of_variable_in_model)
Note: See TracChangeset for help on using the changeset viewer.