Changeset 25591


Ignore:
Timestamp:
09/24/20 00:18:02 (4 years ago)
Author:
bdef
Message:

BUG: fix to nc loader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/io/loadvars.py

    r25532 r25591  
    3030    filename = ''
    3131    nvdict = {}
    32     debug = True  #print messages if true
     32    debug = False  #print messages if true
    3333
    3434    if len(args) >= 1 and isinstance(args[0], str):
     
    9494                if debug:
    9595                    print("===> {} is of class {}".format(mod, classtype[mod][0]))
    96                 if classtype[mod][0] == 'results' and 'Time' in NCFile.dimensions:  #Treating results
     96                if classtype[mod][0] == 'results' and 'Time' in NCFile.dimensions:  #Treating results {{{
    9797                    keylist = [key for key in curclass.groups]
    9898                    # this is related to the old structure of NC files where every steps of results had its own group
     
    133133                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
    134134                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
    135                 elif classtype[mod][0] == 'list':  #Treating the old style of results
     135                #}}}
     136                elif classtype[mod][0] == 'list':  #Treating the old style of results {{{
    136137                    keylist = [key for key in curclass.groups]
    137138                    # this is related to the old structure of NC files where every steps of results had its own group
     
    159160                    else:
    160161                        print("WARNING: we don't get the expected format, there might be an issue somewhere")
    161                 elif classtype[mod][0] == 'massfluxatgate':  #this is for output definitions
     162                # }}}
     163                elif classtype[mod][0] == 'massfluxatgate':  #this is for output definitions {{{
    162164                    defname = split('Output|[0-9]+', classtree[mod][1])[1] + 's'
    163165                    defindex = int(findall('[0-9]+', classtree[mod][1])[0])
    164166                    nvdict['md'].__dict__[classtree[mod][0]].__dict__[defname].append(getattr(classtype[mod][1], classtype[mod][0])())
    165167                    Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[defname][defindex - 1]
    166 
     168                #}}}
    167169                else:
    168170                    if debug:
     
    207209                                if incomplete:
    208210                                    chosendim = varval.dimensions[0]
    209                                     indexlist = np.arange(0, len(NCFile.dimensions[chosendim]))
     211                                    timelist = np.arange(0, len(NCFile.dimensions[chosendim]))
    210212                                    print('WARNING, {} is not present on every times, we chose {}({}) as the dimension to write it with'.format(var, chosendim, len(NCFile.dimensions[chosendim])))
    211213                                else:
    212                                     indexlist = np.arange(0, len(NCFile.dimensions['Time']))
    213                                 for t in indexlist:
     214                                    timelist = np.arange(0, len(NCFile.dimensions['Time']))
     215                                for t in timelist:
    214216                                    if vardim == 0:
    215217                                        Tree[t].__dict__[str(var)] = varval[:].data
     
    303305                        if attr == 'VARNAME':
    304306                            attribute = 'name'
    305                         if type(Tree) == list:
     307                        if type(Tree) == list and NewFormat:
     308                            if debug:
     309                                print("printing with index 0")
     310                            if listtype == 'dict':
     311                                Tree[0][attribute] = str(listclass.getncattr(attr))
     312                            else:
     313                                Tree[0].__dict__[attribute] = str(listclass.getncattr(attr))
     314                        elif type(Tree) == list:
    306315                            t = int(indexlist[i])
     316                            if debug:
     317                                print("printing with index {]".format(t))
    307318                            if listtype == 'dict':
    308319                                Tree[t][attribute] = str(listclass.getncattr(attr))
Note: See TracChangeset for help on using the changeset viewer.