Changeset 25092


Ignore:
Timestamp:
06/22/20 00:55:16 (5 years ago)
Author:
bdef
Message:

CHG: taking care of single timestep result in NC export

Location:
issm/trunk-jpl/src/m/io
Files:
2 edited

Legend:

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

    r24213 r25092  
    1010
    1111
    12 def loadmodel(path):
     12def loadmodel(path, onlylast=False):
    1313    """
    1414    LOADMODEL - load a model using built - in load module
     
    3333    #       try:
    3434    #recover model on file and name it md
    35     struc = loadvars(path)
     35    struc = loadvars(path, OL=onlylast)
    3636    name = [key for key in list(struc.keys())]
    3737    if len(name) > 1:
  • issm/trunk-jpl/src/m/io/loadvars.py

    r25063 r25092  
    1414
    1515
    16 def loadvars(*args):
     16def loadvars(*args, OL):
    1717    """
    1818    LOADVARS - function to load variables to a file.
     
    116116                            nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [OrderedDict() for i in range(max(1, len(curclass.groups)))]
    117117                        else:
    118                             nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(curclass.groups)))]
    119                             Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
     118                            if OL:   #we load only the last result to save on time and memory
     119                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)()]
     120                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
     121                            else:
     122                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(curclass.groups)))]
     123                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
    120124                    else:
    121125                        #that is the current treatment
     
    125129                        indexlist = np.arange(0, len(NCFile.dimensions['Time']))
    126130                        AllHaveTime = np.all(['Time' in dimtuple for dimtuple in dimlist])
     131                        listtype = curclass.classtype
    127132                        if AllHaveTime:
    128133                            #Time dimension is in all the variables so we take that as stepnumber for the results
    129                             listtype = curclass.classtype
    130                             nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
    131                             Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
     134                            if OL:   #we load only the last result to save on time and memory
     135                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)()]
     136                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
     137                            else:
     138                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
     139                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
     140                        elif len(NCFile.dimensions['Time']) == 1:
     141                            nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = getattr(__import__(listtype), listtype)()
     142                            Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
    132143                        else:
     144
    133145                            print("ERROR: Time dimension is not in all results. That has been overlooked for now but your resulat are not saved.")
    134146
     
    160172                        NewFormat = 'Time' in NCFile.dimensions
    161173                        if type(Tree) == list and NewFormat:
    162                             for t in indexlist:
     174                            if OL:
    163175                                if vardim == 1:
    164                                     Tree[t].__dict__[str(var)] = varval[t].data
     176                                    Tree[0].__dict__[str(var)] = varval[-1].data
    165177                                elif vardim == 2:
    166                                     Tree[t].__dict__[str(var)] = varval[t, :].data
     178                                    Tree[0].__dict__[str(var)] = varval[-1, :].data
    167179                                elif vardim == 3:
    168                                     Tree[t].__dict__[str(var)] = varval[t, :, :].data
     180                                    Tree[0].__dict__[str(var)] = varval[-1, :, :].data
    169181                                else:
    170182                                    print('table dimension greater than 3 not implemented yet')
     183                            else:
     184                                for t in indexlist:
     185                                    if vardim == 0:
     186                                        Tree[t].__dict__[str(var)] = varval[:].data
     187                                    if vardim == 1:
     188                                        Tree[t].__dict__[str(var)] = varval[t].data
     189                                    elif vardim == 2:
     190                                        Tree[t].__dict__[str(var)] = varval[t, :].data
     191                                    elif vardim == 3:
     192                                        Tree[t].__dict__[str(var)] = varval[t, :, :].data
     193                                    else:
     194                                        print('table dimension greater than 3 not implemented yet')
    171195                        else:
    172196                            if vardim == 0:  #that is a scalar
Note: See TracChangeset for help on using the changeset viewer.