Changeset 960 for trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py
- Timestamp:
- May 15, 2013, 8:29:27 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py
r942 r960 25 25 ################################### 26 26 # where settings files are located... 27 # ... this can be hardcoded here 27 28 whereset = None 28 29 whereset = ppcompute.findset(whereset) … … 39 40 for stuff in lines[17].strip().split(';'): glob_listarea.append(stuff) 40 41 except IOError: 41 print " warning: "+zefile+" not in "+whereset+" ; no presets."42 print "PPCLASS warning: "+zefile+" not in "+whereset+" ; no presets." 42 43 43 44 ################################## … … 135 136 stridez=1,stridet=1,\ 136 137 compute="mean",\ 137 verbose=False,noproj=False,\ 138 verbose=False,\ 139 quiet=False,\ 140 noproj=False,\ 138 141 superpose=False,\ 139 142 plotin=None,\ … … 154 157 label=None,\ 155 158 changetime=None,\ 159 units=None,\ 156 160 title=None): 157 161 self.request = None 162 self.nrequest = 0 158 163 self.nfin = 0 ; self.nvin = 0 159 164 self.nplotx = None ; self.nploty = None … … 165 170 self.p = None 166 171 self.customplot = False 167 self.allfield = None 172 self.f = None 173 self.l = None 168 174 ## what could be defined by the user 169 175 self.file = file … … 177 183 self.compute = compute 178 184 self.verbose = verbose 185 self.quiet = quiet 179 186 self.noproj = noproj 180 187 self.plotin = plotin … … 198 205 self.color = color 199 206 self.label = label 207 self.units = units 200 208 self.title = title 201 209 202 210 # print status 203 211 def printstatus(self): 212 if not self.quiet: 204 213 if self.filename == "THIS_IS_A_CLONE": 205 214 pass … … 243 252 self.color = other.color 244 253 self.label = other.label 254 self.units = other.units 245 255 self.title = other.title 246 256 self.includedate = other.includedate … … 319 329 if not isnum: 320 330 ope = other.request[i][j][t][z][y][x].field 321 if obj_ref.field.shape != ope.shape: 322 print "!! ERROR !! The two fields for operation do not have the same shape.",self.field.shape,other.field.shape 331 if ope.ndim == 0: 332 ope = float(ope) # if no dimension then this means that ope is a single value (not to be kept as an array) 333 elif obj_ref.field.shape != ope.shape: 334 print "!! ERROR !! The two fields for operation do not have the same shape.",obj_ref.field.shape,ope.shape 323 335 exit() 324 336 else: … … 347 359 if not isnum: 348 360 ope = other.request[i][j][t][z][y][x].field 349 if obj_ref.field.shape != ope.shape: 350 print "!! ERROR !! The two fields for operation do not have the same shape.",self.field.shape,other.field.shape 361 if ope.ndim == 0: 362 ope = float(ope) # if no dimension then this means that ope is a single value (not to be kept as an array) 363 elif obj_ref.field.shape != ope.shape: 364 print "!! ERROR !! The two fields for operation do not have the same shape.",obj_ref.field.shape,ope.shape 351 365 exit() 352 366 else: … … 375 389 if not isnum: 376 390 ope = other.request[i][j][t][z][y][x].field 377 if obj_ref.field.shape != ope.shape: 378 print "!! ERROR !! The two fields for operation do not have the same shape.",self.field.shape,other.field.shape 391 if ope.ndim == 0: 392 ope = float(ope) # if no dimension then this means that ope is a single value (not to be kept as an array) 393 elif obj_ref.field.shape != ope.shape: 394 print "!! ERROR !! The two fields for operation do not have the same shape.",obj_ref.field.shape,ope.shape 379 395 exit() 380 396 else: … … 403 419 if not isnum: 404 420 ope = other.request[i][j][t][z][y][x].field 405 if obj_ref.field.shape != ope.shape: 406 print "!! ERROR !! The two fields for operation do not have the same shape.",self.field.shape,other.field.shape 421 if ope.ndim == 0: 422 ope = float(ope) # if no dimension then this means that ope is a single value (not to be kept as an array) 423 elif obj_ref.field.shape != ope.shape: 424 print "!! ERROR !! The two fields for operation do not have the same shape.",obj_ref.field.shape,ope.shape 407 425 exit() 408 426 else: … … 526 544 for z in range(self.nplotz)] for t in range(self.nplott)] \ 527 545 for j in range(self.nvin)] for i in range(self.nfin)] 546 # store how many onerequest() objects are in self.request 547 self.nrequest = self.nfin*self.nvin*self.nplotx*self.nploty*self.nplotz*self.nplott 528 548 # loop on onerequest() objects 529 549 for i in range(self.nfin): … … 571 591 # check if things were done OK before 572 592 if self.status != "defined": print "!! ERROR !! Please use .define() to define your pp object." ; exit() 573 # create the list of allfield() objects 574 # --> so that the user can easily access values 575 self.allfield = [[[[[[ \ 576 [] \ 577 for x in range(self.nplotx)] for y in range(self.nploty)] \ 578 for z in range(self.nplotz)] for t in range(self.nplott)] \ 579 for j in range(self.nvin)] for i in range(self.nfin)] 593 ## create the list of f() and l() objects 594 ## --> so that the user can easily access values (and labels for easy exploration) 595 ## --> see example easy_get_field 596 self.f = [ [] for iii in range(self.nrequest) ] 597 self.l = [ [] for iii in range(self.nrequest) ] 598 count = 0 580 599 ## first get fields 581 600 ## ... only what is needed is extracted from the files … … 590 609 obj.getfield() 591 610 obj.computations() 592 self.allfield[i][j][t][z][y][x] = obj.field 611 # save fields in self.f for the user 612 self.f[count] = obj.field 613 # save a label in self.l for the user 614 self.l[count] = "_" 615 if self.nfin > 1: self.l[count] = self.l[count] + "f=#"+str(int(i+1))+'_' 616 if self.nvin > 1: self.l[count] = self.l[count] + "v="+obj.var+'_' 617 if self.nplotx > 1: self.l[count] = self.l[count] + "x="+str(self.x[x])+'_' 618 if self.nploty > 1: self.l[count] = self.l[count] + "y="+str(self.y[y])+'_' 619 if self.nplotz > 1: self.l[count] = self.l[count] + "z="+str(self.z[z])+'_' 620 if self.nplott > 1: self.l[count] = self.l[count] + "t="+str(self.t[t])+'_' 621 count = count + 1 622 ## make it simple: self.f is simply the data array if self.nrequest=1 623 if self.nrequest == 1: self.f = self.f[0] 593 624 # change status 594 625 self.status = "retrieved" … … 602 633 self.retrieve() 603 634 return self 635 636 ########################################################### 637 # getf: a shortcut method for the define + retrieve chain # 638 # ... in which the output is self.f # 639 # ... and the ppclass is kept quiet # 640 ########################################################### 641 def getf(self): 642 self.quiet = True 643 self.get() 644 return self.f 645 646 ############################################################ 647 # getfl: a shortcut method for the define + retrieve chain # 648 # ... in which the output is self.f, self.l # 649 # ... and the ppclass is kept quiet # 650 ############################################################ 651 def getfl(self): 652 self.quiet = True 653 self.get() 654 return self.f,self.l 604 655 605 656 ######################################## … … 730 781 if self.ycoeff is not None: plobj.ycoeff = self.ycoeff 731 782 if self.title is not None: plobj.title = self.title 783 if self.units is not None: plobj.units = self.units 732 784 # -- 1D specific 733 785 if dp == 1: … … 799 851 if self.verbose: print "**** OK. expect %i plots" % (self.howmanyplots) 800 852 else: 801 exit()# because this means that we only had 0D values !853 pass # because this means that we only had 0D values ! 802 854 # final status 803 855 self.status = "definedplot" … … 813 865 ############################################################################################## 814 866 def makeplot(self): 867 if self.howmanyplots > 0: 815 868 self.printstatus() 816 869 # a few initial operations … … 888 941 pickle.dump(self.p, filehandler) 889 942 except IOError: 890 print "!! WARNING !! Saved object file not written. Probably do not have permission to write here."943 if self.verbose: print "!! WARNING !! Saved object file not written. Probably do not have permission to write here." 891 944 return self 892 945 … … 915 968 return self 916 969 917 ############################################################## 918 # f : operation on two pp objects being on status 'definedplot'970 ################################################################# 971 # func: operation on two pp objects being on status 'definedplot' 919 972 # this allows for one field being function of another one 920 # e.g. u.f (v) means u will be displayed as a function of v921 # ... no need to do defineplot after u.f (v), makeplot directly922 ############################################################## 923 def f (self,other):973 # e.g. u.func(v) means u will be displayed as a function of v 974 # ... no need to do defineplot after u.func(v), makeplot directly 975 ################################################################# 976 def func(self,other): 924 977 # preamble: for this operation to work, defineplot() must have been done 925 978 if self.status != "definedplot": … … 1149 1202 if "grid points" not in self.name_x: 1150 1203 if self.field_x.all() == self.field_x[0,0]: 1151 print "!! WARNING !! xy axis look undefined. creating non-dummy ones."1204 if self.verbose: print "!! WARNING !! xy axis look undefined. creating non-dummy ones." 1152 1205 self.field_x = np.array(range(self.dim_x)) ; self.name_x = "x grid points" 1153 1206 self.field_y = np.array(range(self.dim_y)) ; self.name_y = "y grid points" … … 1242 1295 self.field_t = self.field_t % 24 # so that the user is not mistaken! 1243 1296 else: 1244 print "!! WARNING !! This time change is not implemented. Nothing is done."1297 if self.verbose: print "!! WARNING !! This time change is not implemented. Nothing is done." 1245 1298 if self.verbose: print "**** OK. new t axis values [%5.1f,%5.1f]" % (self.field_t.min(),self.field_t.max()) 1246 1299 … … 1396 1449 def getfield(self): 1397 1450 ## first tell what is to be done 1398 if self.dimplot > 2: print "**** !! ERROR !! "+str(self.dimplot)+"D plots not supported!" ; exit() 1399 elif self.dimplot == 0 and self.verbose: print "**** OK. 0D value requested." 1400 elif self.dimplot == 1 and self.verbose: print "**** OK. 1D plot requested." 1401 elif self.verbose: print "**** OK. 2D section requested." 1451 if self.verbose: 1452 if self.dimplot > 2: print "**** !! WARNING !! "+str(self.dimplot)+"D plots will not be supported!" 1453 elif self.dimplot == 0 and self.verbose: print "**** OK. 0D value requested." 1454 elif self.dimplot == 1 and self.verbose: print "**** OK. 1D plot requested." 1455 elif self.verbose: print "**** OK. 2D section requested." 1402 1456 # well, now get field from netcdf file 1403 1457 # part below is necessary otherwise there is an index error below
Note: See TracChangeset
for help on using the changeset viewer.