Changeset 27832


Ignore:
Timestamp:
07/18/23 13:07:22 (20 months ago)
Author:
musselman
Message:

CHG: updating to 07-11 versions of musselman netcdf.

Location:
issm/trunk-jpl/src/m/contrib/musselman
Files:
3 edited

Legend:

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

    r27831 r27832  
    7676
    7777def copy_variable_data_to_new_model(location_of_variable_in_file, location_of_variable_in_model, variable_name):
    78     # this should be as simple as navigating to the location_of_variable_in_model and setting it equal to the location_of_variable_in_file
    79     setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, eval(location_of_variable_in_file + '[:]'))
     78    # as simple as navigating to the location_of_variable_in_model and setting it equal to the location_of_variable_in_file
     79   
     80    # but there are a couple of cases we need to compensate for, like an arrary of a single integer should just be an integer and not an array
     81    if len(eval(location_of_variable_in_file))>1:
     82        setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, eval(location_of_variable_in_file + '[:]'))
     83    else:
     84        setattr(eval('model_copy.' + location_of_variable_in_model), variable_name, eval(location_of_variable_in_file + '[:][0]')) # note the [0] on the end
     85       
    8086    print('Successfully saved ' + location_of_variable_in_model + '.' + variable_name + ' to model.')
  • issm/trunk-jpl/src/m/contrib/musselman/write_netCDF_beta.py

    r27831 r27832  
    105105            adress_of_child_in_empty_class = 'empty_model' + adress_of_child.removeprefix(str(model_name))
    106106            print('adress_of_child_in_empty_class: '+ adress_of_child_in_empty_class + '\n')
    107             if type(child) == type(eval(adress_of_child_in_empty_class)):
    108                 print('passed a non-variable\n')
    109                 walk_through_subclasses(model_var, adress_of_child, model_name)
    110             # If it has been modified, record it in the NetCDF file
    111             else:
     107            # using try/except here because sometimes a model can have class instances/attributes that are not
     108            # in the framework of an empty model. If this is the case, we move to the except statement
     109            try:
     110                if type(child) == type(eval(adress_of_child_in_empty_class)):
     111                    print('passed a non-variable\n')
     112                    walk_through_subclasses(model_var, adress_of_child, model_name)
     113                # If it has been modified, record it in the NetCDF file
     114                else:
     115                    create_group(model_var, adress_of_child)
     116                    walk_through_subclasses(model_var, adress_of_child, model_name)
     117            except AttributeError:
    112118                create_group(model_var, adress_of_child)
    113119                walk_through_subclasses(model_var, adress_of_child, model_name)
  • issm/trunk-jpl/src/m/contrib/musselman/write_netCDF_commit.py

    r27831 r27832  
    8989            # If the attribute is unchanged, move onto the next layer
    9090            adress_of_child_in_empty_class = 'empty_model' + adress_of_child.removeprefix(str(model_name))
    91             # using try/except here because sometimes a model can have class instances/attributes that are not
    92             # in the framework of an empty model. If this is the case, we move to the except statement
    93             try:
    94                 if type(child) == type(eval(adress_of_child_in_empty_class)):
    95                     walk_through_subclasses(model_var, adress_of_child, model_name)
    96                 # If it has been modified, record it in the NetCDF file
    97                 else:
    98                     create_group(model_var, adress_of_child)
    99                     walk_through_subclasses(model_var, adress_of_child, model_name)
    100             except AttributeError:
     91            if type(child) == type(eval(adress_of_child_in_empty_class)):
     92                walk_through_subclasses(model_var, adress_of_child, model_name)
     93            # If it has been modified, record it in the NetCDF file
     94            else:
    10195                create_group(model_var, adress_of_child)
    10296                walk_through_subclasses(model_var, adress_of_child, model_name)
Note: See TracChangeset for help on using the changeset viewer.