Changeset 27859


Ignore:
Timestamp:
07/26/23 17:09:27 (20 months ago)
Author:
musselman
Message:

Added inversion/m1qn3inversion/taoinversion class compatibility to read/write_netCDF_commit.py files

Location:
issm/trunk/src/m/contrib/musselman
Files:
2 edited

Legend:

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

    r27858 r27859  
    77import re
    88from results import *
     9from m1qn3inversion import m1qn3inversion
     10from taoinversion import taoinversion
    911
    1012
     
    4244    except:
    4345        pass
     46
     47    # similarly, we need to check and see if we have an m1qn3inversion class instance
     48    try:
     49        NCData.groups['inversion']
     50        check_inversion_class()
     51    except:
     52        pass
    4453   
    4554    # walk through each group looking for subgroups and variables
     
    5665        class_instance = subclass + '()'
    5766        class_instance_name = NCData.groups['results'].variables[subclass][:][...].tobytes().decode()
    58         print(class_instance)
    59         print(class_instance_name)
    6067        setattr(model_copy.results, class_instance_name, eval(class_instance))
     68
     69
     70def check_inversion_class():
     71    # get the name of the inversion class: either inversion or m1qn3inversion or taoinversion
     72    inversion_class_is = NCData.groups['inversion'].variables['inversion_class_name'][:][...].tobytes().decode()
     73    if inversion_class_is == 'm1qn3inversion':
     74        # if it is m1qn3inversion we need to instantiate that class since it's not native to model()
     75        model_copy.inversion = m1qn3inversion(model_copy.inversion)
     76        print('Conversion successful')
     77    elif inversion_class_is == 'taoinversion':
     78        # if it is taoinversion we need to instantiate that class since it's not native to model()
     79        model_copy.inversion = taoinverion()
     80        print('Conversion successful')
     81    else: pass
     82
    6183
    6284
  • issm/trunk/src/m/contrib/musselman/write_netCDF_commit.py

    r27858 r27859  
    88from model import *
    99from results import *
     10from m1qn3inversion import m1qn3inversion
     11from taoinversion import taoinversion
    1012
    1113
     
    114116        # Recursively walk through subclasses
    115117        walk_through_subclasses(model_var, adress, model_name)       
    116        
     118
     119
    117120
    118121def walk_through_subclasses(model_var, adress: str, model_name: str):
     
    157160    group = NetCDF.createGroup(str(group_name))
    158161
     162    # need to check if inversion or m1qn3inversion class
     163    if group_name == 'inversion':
     164        check_inversion_class(model_var)
     165    else: pass
     166
    159167    # if the data is nested, create nested groups to match class structure
    160168    if len(levels_of_class) > 3:
     
    166174    variable_name = levels_of_class[-1]
    167175    create_var(variable_name, adress_of_child, group)
     176
     177
     178def check_inversion_class(model_var):
     179    # need to make sure that we have the right inversion class: inversion, m1qn3inversion, taoinversion
     180    if isinstance(model_var.__dict__['inversion'], m1qn3inversion):
     181        write_string_to_netcdf(variable_name=str('inversion_class_name'), adress_of_child=str('m1qn3inversion'), group=NetCDF.groups['inversion'])
     182        print('Successfully saved inversion class instance ' + 'm1qn3inversion')
     183    elif isinstance(model_var.__dict__['inversion'], taoinversion):
     184        write_string_to_netcdf(variable_name=str('inversion_class_name'), adress_of_child=str('taoinversion'), group=NetCDF.groups['inversion'])
     185        print('Successfully saved inversion class instance ' + 'taoinversion')
     186    else:
     187        write_string_to_netcdf(variable_name=str('inversion_class_name'), adress_of_child=str('inversion'), group=NetCDF.groups['inversion'])
     188        print('Successfully saved inversion class instance ' + 'inversion')
     189
     190       
    168191
    169192
Note: See TracChangeset for help on using the changeset viewer.