Changeset 27859
- Timestamp:
- 07/26/23 17:09:27 (20 months ago)
- 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 7 7 import re 8 8 from results import * 9 from m1qn3inversion import m1qn3inversion 10 from taoinversion import taoinversion 9 11 10 12 … … 42 44 except: 43 45 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 44 53 45 54 # walk through each group looking for subgroups and variables … … 56 65 class_instance = subclass + '()' 57 66 class_instance_name = NCData.groups['results'].variables[subclass][:][...].tobytes().decode() 58 print(class_instance)59 print(class_instance_name)60 67 setattr(model_copy.results, class_instance_name, eval(class_instance)) 68 69 70 def 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 61 83 62 84 -
issm/trunk/src/m/contrib/musselman/write_netCDF_commit.py
r27858 r27859 8 8 from model import * 9 9 from results import * 10 from m1qn3inversion import m1qn3inversion 11 from taoinversion import taoinversion 10 12 11 13 … … 114 116 # Recursively walk through subclasses 115 117 walk_through_subclasses(model_var, adress, model_name) 116 118 119 117 120 118 121 def walk_through_subclasses(model_var, adress: str, model_name: str): … … 157 160 group = NetCDF.createGroup(str(group_name)) 158 161 162 # need to check if inversion or m1qn3inversion class 163 if group_name == 'inversion': 164 check_inversion_class(model_var) 165 else: pass 166 159 167 # if the data is nested, create nested groups to match class structure 160 168 if len(levels_of_class) > 3: … … 166 174 variable_name = levels_of_class[-1] 167 175 create_var(variable_name, adress_of_child, group) 176 177 178 def 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 168 191 169 192
Note:
See TracChangeset
for help on using the changeset viewer.