Changeset 27264 for issm/trunk-jpl/src/m/io/loadvars.py
- Timestamp:
- 09/05/22 02:05:50 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/io/loadvars.py
r26968 r27264 55 55 56 56 timeindex = False 57 SteadySols = ['ThermalSolution', 'HydrologySolution', 'StressbalanceSolution'] 57 58 58 59 for key, value in kwargs.items(): … … 105 106 #here we have a more NC approach with time being a dimension 106 107 listtype = split(r'\.', classtype[mod][0])[1] 107 print(listtype) 108 if len(NCFile.dimensions['Time']) == 1: 108 try: 109 soltype = str(getattr(curclass, 'SolutionType')) 110 except AttributeError: 111 #might be an older format try that instead : 112 soltype = str(getattr(curclass, 'sOLUTIONtYPE')) 113 if len(NCFile.dimensions['Time']) == 1 or soltype in SteadySols: 109 114 nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = getattr(classtype[mod][1], listtype)() 110 115 Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] … … 148 153 Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[defname][defindex - 1] 149 154 #}}} 155 elif classtype[mod][0] == 'collections.OrderedDict': #Treating multiple toolkits {{{ 156 nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = getattr(classtype[mod][1], 'OrderedDict') 157 Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] 150 158 else: 151 159 if verbose > 0: … … 184 192 else: 185 193 groupclass = [curclass] 186 #==== We deal with Variables {{{187 194 for groupindex, listclass in enumerate(groupclass): 195 try: 196 soltype = str(getattr(listclass, 'SolutionType')) 197 except AttributeError: 198 soltype = 'NoSol' 199 #==== We deal with Variables {{{ 188 200 for var in listclass.variables: 189 201 if not resname or var == resname: … … 217 229 else: 218 230 print('table dimension greater than 3 not implemented yet') 231 elif soltype in SteadySols: 232 Tree.__dict__[str(var)] = varval[:].data 219 233 else: #old format had step sorted in difeerent group so last group is last time 220 234 Tree[0].__dict__[str(var)] = varval[:].data 221 235 else: 222 236 if NewFormat: 223 incomplete = 'Time' not in varval.dimensions 237 incomplete = 'Time' not in varval.dimensions and soltype not in SteadySols 224 238 if incomplete: 225 239 try: … … 230 244 #just one step, so no dimension, we just put it on the first solutionstep 231 245 timelist = [0] 246 elif soltype in SteadySols: 247 timelist = [0] 232 248 else: 233 249 timelist = np.arange(0, len(NCFile.dimensions['Time'])) 234 for t in timelist: 235 if verbose > 5: 236 print("filing step {} for {}".format(t, var)) 237 if vardim == 0: 238 Tree[t].__dict__[str(var)] = varval[:].data 239 elif vardim == 1: 240 stepval = ma.masked_array(varval[t].data, mask=np.where(np.isnan(varval[t]), 1, 0)) 241 Tree[t].__dict__[str(var)] = ma.compressed(stepval) 242 elif vardim == 2: 243 stepval = ma.masked_array(varval[t, :].data, mask=np.where(np.isnan(varval[t, :]), 1, 0)) 244 Tree[t].__dict__[str(var)] = ma.compressed(stepval) 245 elif vardim == 3: 246 stepval = ma.masked_array(varval[t, :, :].data, mask=np.where(np.isnan(varval[t, :, :]), 1, 0)) 247 Tree[t].__dict__[str(var)] = ma.compressed(stepval).reshape((stepval.count(0)[0], stepval.count(1)[0])) 248 else: 249 print('table dimension greater than 3 not implemented yet') 250 if soltype in SteadySols: 251 Tree.__dict__[str(var)] = varval[:].data 252 else: 253 for t in timelist: 254 if verbose > 5: 255 print("filing step {} for {}".format(t, var)) 256 if vardim == 0: 257 Tree[t].__dict__[str(var)] = varval[:].data 258 elif vardim == 1: 259 stepval = ma.masked_array(varval[t].data, mask=np.where(np.isnan(varval[t]), 1, 0)) 260 Tree[t].__dict__[str(var)] = ma.compressed(stepval) 261 elif vardim == 2: 262 stepval = ma.masked_array(varval[t, :].data, mask=np.where(np.isnan(varval[t, :]), 1, 0)) 263 Tree[t].__dict__[str(var)] = ma.compressed(stepval) 264 elif vardim == 3: 265 stepval = ma.masked_array(varval[t, :, :].data, mask=np.where(np.isnan(varval[t, :, :]), 1, 0)) 266 Tree[t].__dict__[str(var)] = ma.compressed(stepval).reshape((stepval.count(0)[0], stepval.count(1)[0])) 267 else: 268 print('table dimension greater than 3 not implemented yet') 250 269 else: 251 270 if verbose > 0: … … 315 334 Tree.__dict__[str(var)] = varval[:, :].data 316 335 elif vardim == 3: 317 Tree.__dict__[str(var)] = varval[:, :, :].data 336 if varval.dtype == "|S1": #that is for matlab chararcter arrays 337 #most likely that is a toolkit dictionar so should be treated as such 338 #first we convert the character table to strings 339 stringtable = [] 340 for i in range(np.shape(varval)[0]): 341 stringtable.append([chartostring(varval[i, 0, :]), chartostring(varval[i, 1, :])]) 342 stringtable = np.asarray(stringtable, dtype=str) 343 Tree.__dict__[str(var)] = OrderedDict([('toolkit', str(varval[np.where(stringtable[:, 0] == 'toolkit')[0][0], 1]))]) 344 strings1 = [str(arg[0]) for arg in stringtable if arg[0] != 'toolkits'] 345 strings2 = [str(arg[1]) for arg in stringtable if arg[0] != 'toolkits'] 346 Tree.__dict__[str(var)].update(list(zip(strings1, strings2))) 347 else: 348 Tree.__dict__[str(var)] = varval[:, :, :].data 318 349 else: 319 350 print('table dimension greater than 3 not implemented yet') … … 387 418 if class_dict[classe][0] not in ['dict', 'list', 'cell']: 388 419 modulename = split(r'\.', class_dict[classe][0])[0] 389 if modulename == "giaivins": 390 print("WARNING: module {} does not exist anymore and is skipped".format(modulename)) 391 else: 420 try: 392 421 class_dict[classe].append(import_module(modulename)) 393 422 class_tree[classe] = [group, ] 423 except ModuleNotFoundError: 424 print("WARNING: module {} does not exist anymore and is skipped".format(modulename)) 425 394 426 except AttributeError: 395 427 print(('group {} is empty'.format(group)))
Note:
See TracChangeset
for help on using the changeset viewer.