Changeset 25532


Ignore:
Timestamp:
09/04/20 04:57:26 (5 years ago)
Author:
bdef
Message:

BUG:fixing netcdf load for ancient compatibility

File:
1 edited

Legend:

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

    r25478 r25532  
    3030    filename = ''
    3131    nvdict = {}
    32     debug = False  #print messages if true
     32    debug = True  #print messages if true
    3333
    3434    if len(args) >= 1 and isinstance(args[0], str):
     
    5252        raise TypeError("Unrecognized input arguments.")
    5353
    54     onlylast = False
     54    onlylast = True
    5555
    5656    for key, value in kwargs.items():
     
    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 
     135                elif classtype[mod][0] == 'list':  #Treating the old style of results
     136                    keylist = [key for key in curclass.groups]
     137                    # this is related to the old structure of NC files where every steps of results had its own group
     138                    if len(keylist) > 0:
     139                        #this is kept for compatibility
     140                        #and treatment of list of dicts??
     141                        try:
     142                            #group are named after their step
     143                            steplist = [int(key) for key in curclass.groups]
     144                        except ValueError:
     145                            #or a number is appended at the end of the name
     146                            steplist = [int(findall(r'\d + ', key)[0]) for key in keylist]
     147                        indexlist = [int(index * (len(curclass.groups) - 1) / max(1, max(steplist))) for index in steplist]
     148                        listtype = curclass.groups[keylist[0]].classtype
     149                        #discriminate between dict and results
     150                        if listtype == 'dict':
     151                            nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [OrderedDict() for i in range(max(1, len(curclass.groups)))]
     152                        else:
     153                            if onlylast:   #we load only the last result to save on time and memory
     154                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)()]
     155                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
     156                            else:
     157                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(curclass.groups)))]
     158                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
     159                    else:
     160                        print("WARNING: we don't get the expected format, there might be an issue somewhere")
    136161                elif classtype[mod][0] == 'massfluxatgate':  #this is for output definitions
    137162                    defname = split('Output|[0-9]+', classtree[mod][1])[1] + 's'
Note: See TracChangeset for help on using the changeset viewer.