Changeset 960 for trunk/UTIL
- Timestamp:
- May 15, 2013, 8:29:27 PM (12 years ago)
- Location:
- trunk/UTIL/PYTHON/planetoplot_v2
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot_v2/examples/easy_get_field.py
r931 r960 1 1 #! /usr/bin/env python 2 2 from ppclass import pp 3 import numpy as np4 import matplotlib.pyplot as mpl5 3 4 ######## 5 ## ppclass allows for getting fields very easily from a netcdf file 6 ## ... this is contained in the "f" attributes of the pp object 7 ## ... and the "l" attributes of the pp object contains useful information 8 ## ... two methods getf() and getfl() are helpful shortcuts 9 ########################################### 10 11 ## 1 --> an unique and straightforward request 12 ## --> very easy ! see also minimal_field.py 13 ############################################## 14 icetot = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc",var="icetot",t=0.5).getf() 15 print "icetot", icetot[10,10] 16 17 ## 2 --> simple multiple request, no labelling 18 ############################################## 19 test = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc",t=0.5) 20 test.var = ["mtot","icetot"] 21 allf = test.getf() # or allf = test.get().f 22 ## 23 mtot = allf[0] 24 icetot = allf[1] 25 print "mtot", mtot[10,10] 26 print "icetot", icetot[10,10] 27 28 ## 3 --> complex multiple requests and labelling 29 ################################################ 30 test = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc") 31 test.var = ["mtot","icetot"] 32 test.t = [0.4,0.5] 33 allf,lab = test.getfl() 34 ## 35 icetot04 = allf[lab.index("_v=icetot_t=0.4_")] 36 mtot04 = allf[lab.index("_v=mtot_t=0.4_")] 37 icetot05 = allf[lab.index("_v=icetot_t=0.5_")] 38 mtot05 = allf[lab.index("_v=mtot_t=0.5_")] 39 print "mtot04", mtot04[10,10] 40 print "icetot04", icetot04[10,10] 41 print "mtot05", mtot05[10,10] 42 print "icetot05", icetot05[10,10] 43 44 ## 4 --> an example of complete labelling 45 ## .... a rather unlikely example .... 46 ## .... but shows label ordering .... 47 ######################################### 6 48 test = pp() 7 test.file = [ \ 8 "/planeto/jllmd/Earth/Nmix/F1525/output/diagfi4.nc", \ 9 "/planeto/jllmd/Earth/Nmix/F1550/output/diagfi4.nc", \ 10 "/planeto/jllmd/Earth/Nmix/F1500/output/diagfi4.nc" ] 11 test.var = ["tsurf","ASR"] 12 test.x = "-180.,175." 13 test.y = "-90.,90." 14 test.t = "0,1000" 15 #test.verbose = True 16 test.compute = "meanarea" 17 test.get() 18 19 # ----------------------------- 20 # self.allfield contains data ! 21 # ----------------------------- 22 # index ordering: 23 # - file 24 # - var 25 # - request t 26 # - request z 27 # - request y 28 # - request x 29 # - field dimensions 30 # ----------------------------- 31 32 33 for ii in range(test.nfin): 34 print "tsurf",test.allfield[ii][0][0][0][0][0] 35 print "asr",test.allfield[ii][1][0][0][0][0] 36 37 #mpl.plot(tsurf,asr) 38 #mpl.show() 49 test.file = ["/home/aymeric/Big_Data/DATAPLOT/diagfired.nc","/home/aymeric/Big_Data/DATAPLOT/diagfired.nc"] 50 test.var = ["u","v"] 51 test.x = [10.,20.] 52 test.y = [10.,20.] 53 test.z = [10.,20.] 54 test.t = [0.4,0.5] 55 print "... please wait. this one is a bit stupid..." 56 allf,lab = test.getfl() 57 ## note label ordering: file -- var -- x -- y -- z -- t 58 l1 = "_f=#2_v=u_x=10.0_y=10.0_z=20.0_t=0.4_" 59 l2 = "_f=#2_v=v_x=10.0_y=10.0_z=20.0_t=0.4_" 60 u_example = allf[lab.index(l1)] 61 v_example = allf[lab.index(l2)] 62 print l1, u_example 63 print l2, v_example -
trunk/UTIL/PYTHON/planetoplot_v2/examples/function.py
r933 r960 19 19 var2 = var2 / 3.72 20 20 21 S = var2.f (var1)21 S = var2.func(var1) 22 22 23 23 S.p[0].marker = 'o' -
trunk/UTIL/PYTHON/planetoplot_v2/examples/hodograph.py
r923 r960 16 16 17 17 # u as a function of v 18 hodo = u.f (v)18 hodo = u.func(v) 19 19 hodo.filename = "hodograph" 20 20 hodo.makeplot() 21 21 22 22 # v as a function of u 23 hodo2 = v.f (u)23 hodo2 = v.func(u) 24 24 hodo2.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/meso_profile.py
r923 r960 38 38 39 39 # define potential temperature as a function of height 40 S = tpot.f (z)40 S = tpot.func(z) 41 41 42 42 # change a few plot settings -
trunk/UTIL/PYTHON/planetoplot_v2/examples/scatter.py
r923 r960 15 15 ps.getdefineplot() 16 16 17 S = ps.f (tsurf)17 S = ps.func(tsurf) 18 18 S.p[0].lstyle="" 19 19 S.p[0].marker="h" … … 26 26 icetot.getdefineplot() 27 27 28 S2 = icetot.f (tsurf)28 S2 = icetot.func(tsurf) 29 29 S2.p[0].lstyle="" 30 30 S2.p[0].marker="D" … … 45 45 wind = u**2 + v**2 46 46 wind = wind**0.5 47 S3 = wind.f (ps)47 S3 = wind.func(ps) 48 48 S3.p[0].lstyle="" 49 49 S3.p[0].marker="o" … … 70 70 ps.getdefineplot() 71 71 72 S = ps.f (tsurf)72 S = ps.func(tsurf) 73 73 S.p[0].lstyle="" 74 74 S.p[0].marker="h" -
trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py
r942 r960 26 26 27 27 yeah = pp() 28 yeah.quiet = True 28 29 yeah.defineplot(loadfile=files) 29 30 yeah.out = opt.out -
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 -
trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py
r947 r960 534 534 print "!! WARNING !! Transposing axes" 535 535 self.field = np.transpose(self.field) 536 # set dummy xy axis if not defined 537 if self.absc is None: 538 self.absc = np.array(range(self.field.shape[0])) 539 self.mapmode = False 540 print "!! WARNING !! dummy coordinates on x axis" 541 if self.ordi is None: 542 self.ordi = np.array(range(self.field.shape[1])) 543 self.mapmode = False 544 print "!! WARNING !! dummy coordinates on y axis" 536 545 # bound field 537 546 zevmin, zevmax = calculate_bounds(self.field,vmin=self.vmin,vmax=self.vmax)
Note: See TracChangeset
for help on using the changeset viewer.