Changeset 25092 for issm/trunk-jpl/src/m/io
- Timestamp:
- 06/22/20 00:55:16 (5 years ago)
- Location:
- issm/trunk-jpl/src/m/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/io/loadmodel.py
r24213 r25092 10 10 11 11 12 def loadmodel(path ):12 def loadmodel(path, onlylast=False): 13 13 """ 14 14 LOADMODEL - load a model using built - in load module … … 33 33 # try: 34 34 #recover model on file and name it md 35 struc = loadvars(path )35 struc = loadvars(path, OL=onlylast) 36 36 name = [key for key in list(struc.keys())] 37 37 if len(name) > 1: -
issm/trunk-jpl/src/m/io/loadvars.py
r25063 r25092 14 14 15 15 16 def loadvars(*args ):16 def loadvars(*args, OL): 17 17 """ 18 18 LOADVARS - function to load variables to a file. … … 116 116 nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [OrderedDict() for i in range(max(1, len(curclass.groups)))] 117 117 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]][:] 120 124 else: 121 125 #that is the current treatment … … 125 129 indexlist = np.arange(0, len(NCFile.dimensions['Time'])) 126 130 AllHaveTime = np.all(['Time' in dimtuple for dimtuple in dimlist]) 131 listtype = curclass.classtype 127 132 if AllHaveTime: 128 133 #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]] 132 143 else: 144 133 145 print("ERROR: Time dimension is not in all results. That has been overlooked for now but your resulat are not saved.") 134 146 … … 160 172 NewFormat = 'Time' in NCFile.dimensions 161 173 if type(Tree) == list and NewFormat: 162 for t in indexlist:174 if OL: 163 175 if vardim == 1: 164 Tree[ t].__dict__[str(var)] = varval[t].data176 Tree[0].__dict__[str(var)] = varval[-1].data 165 177 elif vardim == 2: 166 Tree[ t].__dict__[str(var)] = varval[t, :].data178 Tree[0].__dict__[str(var)] = varval[-1, :].data 167 179 elif vardim == 3: 168 Tree[ t].__dict__[str(var)] = varval[t, :, :].data180 Tree[0].__dict__[str(var)] = varval[-1, :, :].data 169 181 else: 170 182 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') 171 195 else: 172 196 if vardim == 0: #that is a scalar
Note:
See TracChangeset
for help on using the changeset viewer.