Changeset 23691
- Timestamp:
- 02/05/19 04:57:23 (6 years ago)
- Location:
- issm/trunk-jpl/src/py3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/py3/classes/plotoptions.py
r23670 r23691 42 42 #go through args and build list (like pairoptions) 43 43 rawoptions=pairoptions.pairoptions(*arg) 44 numoptions= len(arg)/244 numoptions=int(len(arg)/2) 45 45 rawlist=[] # cannot be a dict since they do not support duplicate keys 46 46 -
issm/trunk-jpl/src/py3/plot/plotmodel.py
r23670 r23691 52 52 #Go through plots 53 53 if numberofplots: 54 #if plt.fignum_exists(figurenumber): 54 #if plt.fignum_exists(figurenumber): 55 55 # plt.cla() 56 56 … … 72 72 # options needed to define plot grid 73 73 plotnum=options.numberofplots 74 if plotnum==1: 75 plotnum=None 74 76 direction=options.list[0].getfieldvalue('direction','row') # row,column 75 77 axes_pad=options.list[0].getfieldvalue('axes_pad',0.25) … … 81 83 cbar_location=options.list[0].getfieldvalue('colorbarpos','right') # right,top 82 84 cbar_size=options.list[0].getfieldvalue('colorbarsize','5%') 83 cbar_pad=options.list[0].getfieldvalue('colorbarpad', '2.5%') # None or %85 cbar_pad=options.list[0].getfieldvalue('colorbarpad',0.025) # None or % 84 86 85 87 axgrid=ImageGrid(fig,111, … … 97 99 98 100 if cbar_mode=='None': 99 for ax in axgrid.cbar_axes: 101 for ax in axgrid.cbar_axes: 100 102 fig._axstack.remove(ax) 101 103 -
issm/trunk-jpl/src/py3/solve/WriteData.py
r23689 r23691 1 1 import numpy as np 2 2 from struct import pack,unpack 3 from pairoptionsimport pairoptions3 import pairoptions 4 4 5 5 def WriteData(fid,prefix,*args): … … 12 12 13 13 #process options 14 options=pairoptions (*args)14 options=pairoptions.pairoptions(*args) 15 15 16 16 #Get data properties … … 55 55 56 56 #Step 1: write the enum to identify this record uniquely 57 fid.write(pack('>i',len(name))) 58 fid.write(pack('>{}s'.format(len(name)),name.encode())) 59 # print(name) 60 # print(pack('>{}s'.format(len(name)),name) 57 fid.write(pack('i',len(name))) 58 fid.write(pack('{}s'.format(len(name)),name.encode())) 59 61 60 62 61 #Step 2: write the data itself. 63 62 if datatype=='Boolean': # {{{ 64 63 # if len(data) !=1: 65 # raise ValueError('fi eld %s cannot be marshalled as it has more than one element!' % name[0])66 67 #first write length of record 68 fid.write(pack(' >i',4+4)) #1 bool (disguised as an int)+code69 70 #write data code: 71 fid.write(pack(' >i',FormatToCode(datatype)))64 # raise ValueError('fi eld %s cannot be marshalled as it has more than one element!' % name[0]) 65 66 #first write length of record 67 fid.write(pack('i',4+4)) #1 bool (disguised as an int)+code 68 69 #write data code: 70 fid.write(pack('i',FormatToCode(datatype))) 72 71 73 72 #now write integer 74 fid.write(pack(' >i',int(data))) #send an int, not easy to send a bool73 fid.write(pack('i',int(data))) #send an int, not easy to send a bool 75 74 # }}} 76 75 … … 80 79 81 80 #first write length of record 82 fid.write(pack(' >i',4+4)) #1 integer + code83 84 #write data code: 85 fid.write(pack(' >i',FormatToCode(datatype)))81 fid.write(pack('i',4+4)) #1 integer + code 82 83 #write data code: 84 fid.write(pack('i',FormatToCode(datatype))) 86 85 87 86 #now write integer 88 fid.write(pack(' >i',int(data))) #force an int,87 fid.write(pack('i',int(data))) #force an int, 89 88 # }}} 90 89 … … 94 93 95 94 #first write length of record 96 fid.write(pack(' >i',8+4)) #1 double+code97 98 #write data code: 99 fid.write(pack(' >i',FormatToCode(datatype)))95 fid.write(pack('i',8+4)) #1 double+code 96 97 #write data code: 98 fid.write(pack('i',FormatToCode(datatype))) 100 99 101 100 #now write double 102 fid.write(pack(' >d',data))101 fid.write(pack('d',data)) 103 102 # }}} 104 103 105 104 elif datatype=='String': # {{{ 106 105 #first write length of record 107 fid.write(pack(' >i',len(data)+4+4)) #string + string size + code108 109 #write data code: 110 fid.write(pack(' >i',FormatToCode(datatype)))106 fid.write(pack('i',len(data)+4+4)) #string + string size + code 107 108 #write data code: 109 fid.write(pack('i',FormatToCode(datatype))) 111 110 112 111 #now write string 113 fid.write(pack(' >i',len(data)))114 fid.write(pack(' >{}s'.format(len(data)),data.encode()))112 fid.write(pack('i',len(data))) 113 fid.write(pack('{}s'.format(len(data)),data.encode())) 115 114 # }}} 116 115 117 116 elif datatype in ['IntMat','BooleanMat']: # {{{ 118 117 119 if 118 if isinstance(data,(int,bool)): 120 119 data=np.array([data]) 121 120 elif isinstance(data,(list,tuple)): … … 134 133 135 134 #first write length of record 136 fid.write(pack(' >i',4+4+8*np.product(s)+4+4)) #2 integers (32 bits) + the double matrix + code + matrix type135 fid.write(pack('i',4+4+8*np.product(s)+4+4)) #2 integers (32 bits) + the double matrix + code + matrix type 137 136 138 137 #write data code and matrix type: 139 fid.write(pack(' >i',FormatToCode(datatype)))140 fid.write(pack(' >i',mattype))138 fid.write(pack('i',FormatToCode(datatype))) 139 fid.write(pack('i',mattype)) 141 140 142 141 #now write matrix 143 142 if np.ndim(data) == 1: 144 fid.write(pack(' >i',s[0]))145 fid.write(pack(' >i',1))143 fid.write(pack('i',s[0])) 144 fid.write(pack('i',1)) 146 145 for i in range(s[0]): 147 fid.write(pack(' >d',float(data[i]))) #get to the "c" convention, hence the transpose148 else: 149 fid.write(pack(' >i',s[0]))150 fid.write(pack(' >i',s[1]))146 fid.write(pack('d',float(data[i]))) #get to the "c" convention, hence the transpose 147 else: 148 fid.write(pack('i',s[0])) 149 fid.write(pack('i',s[1])) 151 150 for i in range(s[0]): 152 151 for j in range(s[1]): 153 fid.write(pack(' >d',float(data[i][j]))) #get to the "c" convention, hence the transpose152 fid.write(pack('d',float(data[i][j]))) #get to the "c" convention, hence the transpose 154 153 # }}} 155 154 … … 175 174 recordlength=4+4+8*np.product(s)+4+4; #2 integers (32 bits) + the double matrix + code + matrix type 176 175 if recordlength > 4**31 : 177 raise ValueError('field %s cannot be marshalled because it is larger than 4^31 bytes!' % enum)178 179 fid.write(pack(' >i',recordlength)) #2 integers (32 bits) + the double matrix + code + matrix type176 raise ValueError('field {} cannot be marshalled because it is larger than 4^31 bytes!'.format(enum)) 177 178 fid.write(pack('i',recordlength)) #2 integers (32 bits) + the double matrix + code + matrix type 180 179 181 180 #write data code and matrix type: 182 fid.write(pack(' >i',FormatToCode(datatype)))183 fid.write(pack(' >i',mattype))181 fid.write(pack('i',FormatToCode(datatype))) 182 fid.write(pack('i',mattype)) 184 183 185 184 #now write matrix 186 185 if np.ndim(data) == 1: 187 fid.write(pack(' >i',s[0]))188 fid.write(pack(' >i',1))186 fid.write(pack('i',s[0])) 187 fid.write(pack('i',1)) 189 188 for i in range(s[0]): 190 fid.write(pack(' >d',float(data[i]))) #get to the "c" convention, hence the transpose191 else: 192 fid.write(pack(' >i',s[0]))193 fid.write(pack(' >i',s[1]))189 fid.write(pack('d',float(data[i]))) #get to the "c" convention, hence the transpose 190 else: 191 fid.write(pack('i',s[0])) 192 fid.write(pack('i',s[1])) 194 193 for i in range(s[0]): 195 194 for j in range(s[1]): 196 fid.write(pack(' >d',float(data[i][j]))) #get to the "c" convention, hence the transpose195 fid.write(pack('d',float(data[i][j]))) #get to the "c" convention, hence the transpose 197 196 # }}} 198 197 … … 226 225 raise ValueError('field %s cannot be marshalled because it is larger than 4^31 bytes!' % enum) 227 226 228 fid.write(pack(' >i',recordlength)) #2 integers (32 bits) + the matrix + code + matrix type227 fid.write(pack('i',recordlength)) #2 integers (32 bits) + the matrix + code + matrix type 229 228 230 229 #write data code and matrix type: 231 fid.write(pack(' >i',FormatToCode(datatype)))232 fid.write(pack(' >i',mattype))230 fid.write(pack('i',FormatToCode(datatype))) 231 fid.write(pack('i',mattype)) 233 232 234 233 #Write offset and range … … 244 243 #now write matrix 245 244 if np.ndim(data) == 1: 246 fid.write(pack(' >i',s[0]))247 fid.write(pack(' >i',1))248 fid.write(pack(' >d',float(offsetA)))249 fid.write(pack(' >d',float(rangeA)))245 fid.write(pack('i',s[0])) 246 fid.write(pack('i',1)) 247 fid.write(pack('d',float(offsetA))) 248 fid.write(pack('d',float(rangeA))) 250 249 for i in range(s[0]-1): 251 fid.write(pack(' >B',int(A[i])))252 253 fid.write(pack(' >d',float(data[s[0]-1]))) #get to the "c" convention, hence the transpose250 fid.write(pack('B',int(A[i]))) 251 252 fid.write(pack('d',float(data[s[0]-1]))) #get to the "c" convention, hence the transpose 254 253 255 254 elif np.product(s) > 0: 256 fid.write(pack(' >i',s[0]))257 fid.write(pack(' >i',s[1]))258 fid.write(pack(' >d',float(offsetA)))259 fid.write(pack(' >d',float(rangeA)))255 fid.write(pack('i',s[0])) 256 fid.write(pack('i',s[1])) 257 fid.write(pack('d',float(offsetA))) 258 fid.write(pack('d',float(rangeA))) 260 259 for i in range(s[0]-1): 261 260 for j in range(s[1]): 262 fid.write(pack(' >B',int(A[i][j]))) #get to the "c" convention, hence the transpose261 fid.write(pack('B',int(A[i][j]))) #get to the "c" convention, hence the transpose 263 262 264 263 for j in range(s[1]): 265 fid.write(pack(' >d',float(data[s[0]-1][j])))264 fid.write(pack('d',float(data[s[0]-1][j]))) 266 265 267 266 # }}} … … 286 285 287 286 #write length of record 288 fid.write(pack(' >i',recordlength))289 290 #write data code: 291 fid.write(pack(' >i',FormatToCode(datatype)))287 fid.write(pack('i',recordlength)) 288 289 #write data code: 290 fid.write(pack('i',FormatToCode(datatype))) 292 291 293 292 #write data, first number of records 294 fid.write(pack(' >i',len(data)))293 fid.write(pack('i',len(data))) 295 294 296 295 for matrix in data: … … 305 304 306 305 if np.ndim(matrix) == 1: 307 fid.write(pack(' >i',s[0]))308 fid.write(pack(' >i',1))306 fid.write(pack('i',s[0])) 307 fid.write(pack('i',1)) 309 308 for i in range(s[0]): 310 fid.write(pack(' >d',float(matrix[i]))) #get to the "c" convention, hence the transpose309 fid.write(pack('d',float(matrix[i]))) #get to the "c" convention, hence the transpose 311 310 else: 312 fid.write(pack(' >i',s[0]))313 fid.write(pack(' >i',s[1]))311 fid.write(pack('i',s[0])) 312 fid.write(pack('i',s[1])) 314 313 for i in range(s[0]): 315 314 for j in range(s[1]): 316 fid.write(pack(' >d',float(matrix[i][j])))315 fid.write(pack('d',float(matrix[i][j]))) 317 316 # }}} 318 317 … … 325 324 326 325 #write length of record 327 fid.write(pack(' >i',recordlength))328 329 #write data code: 330 fid.write(pack(' >i',FormatToCode(datatype)))326 fid.write(pack('i',recordlength)) 327 328 #write data code: 329 fid.write(pack('i',FormatToCode(datatype))) 331 330 332 331 #now write length of string array 333 fid.write(pack(' >i',len(data)))332 fid.write(pack('i',len(data))) 334 333 335 334 #now write the strings 336 335 for string in data: 337 fid.write(pack(' >i',len(string)))338 fid.write(pack(' >{}s'.format(len(string)),string.encode()))336 fid.write(pack('i',len(string))) 337 fid.write(pack('{}s'.format(len(string)),string.encode())) 339 338 # }}} 340 339 -
issm/trunk-jpl/src/py3/solve/loadresultsfromdisk.py
r23670 r23691 2 2 from results import results 3 3 from parseresultsfromdisk import parseresultsfromdisk 4 import MatlabFuncs as m5 4 from postqmu import postqmu 6 5 7 6 def loadresultsfromdisk(md,filename): 8 7 """ 9 LOADRESULTSFROMDISK - load results of solution sequence from disk file "filename" 10 8 LOADRESULTSFROMDISK - load results of solution sequence from disk file "filename" 9 11 10 Usage: 12 11 md=loadresultsfromdisk(md=False,filename=False); … … 21 20 #Check that file exists 22 21 if not os.path.exists(filename): 23 raise OSError("binary file ' %s' not found." % filename)22 raise OSError("binary file '{}' not found.".format(filename)) 24 23 25 24 #initialize md.results if not a structure yet … … 30 29 structure=parseresultsfromdisk(md,filename,not md.settings.io_gather) 31 30 if not len(structure): 32 raise RuntimeError("No result found in binary file '%s'. Check for solution crash." % filename) 31 raise RuntimeError("No result found in binary file '{}'. Check for solution crash.".format(filename)) 32 33 33 setattr(md.results,structure[0].SolutionType,structure) 34 34 … … 53 53 54 54 #if only one solution, extract it from list for user friendliness 55 if len(structure) == 1 and not m.strcmp(structure[0].SolutionType,'TransientSolution'):55 if len(structure) == 1 and not structure[0].SolutionType=='TransientSolution': 56 56 setattr(md.results,structure[0].SolutionType,structure[0]) 57 57 -
issm/trunk-jpl/src/py3/solve/parseresultsfromdisk.py
r23677 r23691 9 9 else: 10 10 saveres=parseresultsfromdiskioserial(md,filename) 11 12 11 return saveres 13 12 … … 17 16 fid=open(filename,'rb') 18 17 except IOError as e: 19 raise IOError("loadresultsfromdisk error message: could not open ' %s' for binary reading." % filename)18 raise IOError("loadresultsfromdisk error message: could not open '{}' for binary reading.".format(filename)) 20 19 21 20 #initialize results: … … 79 78 fid=open(filename,'rb') 80 79 except IOError as e: 81 raise IOError("loadresultsfromdisk error message: could not open ' %s' for binary reading." % filename)80 raise IOError("loadresultsfromdisk error message: could not open '{}' for binary reading.".format(filename)) 82 81 83 82 saveres=[] … … 146 145 try: 147 146 length=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 148 149 fieldname=struct.unpack('%ds' % length,fid.read(length))[0][:-1] 147 fieldname=struct.unpack('{}s'.format(length),fid.read(length))[0][:-1] 150 148 time=struct.unpack('d',fid.read(struct.calcsize('d')))[0] 151 149 step=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 152 153 type=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 150 datatype=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 154 151 M=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 155 if type==1: 156 field=np.array(struct.unpack('%dd' % M,fid.read(M*struct.calcsize('d'))),dtype=float) 157 elif type==2: 158 field=struct.unpack('%ds' % M,fid.read(M))[0][:-1] 159 elif type==3: 152 if datatype==1: 153 field=np.array(struct.unpack('{}d'.format(M),fid.read(M*struct.calcsize('d'))),dtype=float) 154 155 elif datatype==2: 156 field=struct.unpack('{}s'.format(M),fid.read(M))[0][:-1] 157 field=field.decode() 158 159 elif datatype==3: 160 160 N=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 161 161 # field=transpose(fread(fid,[N M],'double')); 162 162 field=np.zeros(shape=(M,N),dtype=float) 163 163 for i in range(M): 164 field[i,:]=struct.unpack('%dd' % N,fid.read(N*struct.calcsize('d'))) 165 elif type==4: 164 field[i,:]=struct.unpack('{}d'.format(N),fid.read(N*struct.calcsize('d'))) 165 166 elif datatype==4: 166 167 N=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 167 168 # field=transpose(fread(fid,[N M],'int')); 168 169 field=np.zeros(shape=(M,N),dtype=int) 169 170 for i in range(M): 170 field[i,:]=struct.unpack('%ii' % N,fid.read(N*struct.calcsize('i'))) 171 field[i,:]=struct.unpack('{}i'.format(N),fid.read(N*struct.calcsize('i'))) 172 171 173 else: 172 raise TypeError("cannot read data of type %d" % type)174 raise TypeError("cannot read data of datatype {}".format(datatype)) 173 175 174 176 #Process units here FIXME: this should not be done here! … … 244 246 245 247 saveres=OrderedDict() 246 saveres['fieldname']=fieldname 248 saveres['fieldname']=fieldname.decode() 247 249 saveres['time']=time 248 250 saveres['step']=step … … 265 267 try: 266 268 length=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 267 fieldname=struct.unpack(' %ds' % length,fid.read(length))[0][:-1]269 fieldname=struct.unpack('{}s'.format(length),fid.read(length))[0][:-1] 268 270 time=struct.unpack('d',fid.read(struct.calcsize('d')))[0] 269 271 step=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 270 type=struct.unpack('i',fid.read(struct.calcsize('i')))[0]272 dtattype=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 271 273 M=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 272 274 N=1 #default 273 if type==1:275 if datatype==1: 274 276 fid.seek(M*8,1) 275 elif type==2:277 elif datatype==2: 276 278 fid.seek(M,1) 277 elif type==3:279 elif datatype==3: 278 280 N=struct.unpack('i',fid.read(struct.calcsize('i')))[0] 279 281 fid.seek(N*M*8,1) 280 282 else: 281 raise TypeError("cannot read data of type %d" % type)283 raise TypeError("cannot read data of datatype {}".format(datatype)) 282 284 283 285 saveres=OrderedDict()
Note:
See TracChangeset
for help on using the changeset viewer.