- Timestamp:
- Jul 21, 2018, 3:14:01 AM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/create_OBSnetcdf.py
r648 r1948 41 41 return True 42 42 return False 43 44 45 def typemod(value, typeval): 46 """ Function to give back a value in a given dtype 47 >>> print(typemod(8.2223, 'np.float64')) 48 <type 'numpy.float64'> 49 >>> print(typemod(8.2223, 'tuple')) 50 <type 'tuple'> 51 """ 52 fname='typemod' 53 54 if typeval == 'int' or typeval == 'I': 55 return int(value) 56 elif typeval == 'long': 57 return long(value) 58 elif typeval == 'float' or typeval == 'F' or typeval == 'R': 59 return float(value) 60 elif typeval == 'complex': 61 return complex(value) 62 elif typeval == 'str' or typeval == 'S': 63 return str(value) 64 elif typeval == 'bool': 65 return bool(value) 66 elif typeval == 'B': 67 return Str_Bool(value) 68 elif typeval == 'list': 69 newval = [] 70 newval.append(value) 71 return newval 72 elif typeval == 'dic': 73 newval = {} 74 newval[value] = value 75 return newval 76 elif typeval == 'tuple': 77 newv = [] 78 newv.append(value) 79 newval = tuple(newv) 80 return newval 81 elif typeval == 'np.int8': 82 return np.int8(value) 83 elif typeval == 'np.int16': 84 return np.int16(value) 85 elif typeval == 'np.int32': 86 return np.int32(value) 87 elif typeval == 'np.int64': 88 return np.int64(value) 89 elif typeval == 'np.uint8': 90 return np.uint8(value) 91 elif typeval == 'np.uint16': 92 return np.uint16(value) 93 elif typeval == 'np.np.uint32': 94 return np.uint32(value) 95 elif typeval == 'np.uint64': 96 return np.uint64(value) 97 elif typeval == 'np.float' or typeval == 'R': 98 return np.float(value) 99 elif typeval == 'np.float16': 100 return np.float16(value) 101 elif typeval == 'np.float32': 102 return np.float32(value) 103 elif typeval == 'float32': 104 return np.float32(value) 105 elif typeval == 'np.float64' or typeval == 'D': 106 return np.float64(value) 107 elif typeval == 'float64': 108 return np.float64(value) 109 elif typeval == 'np.complex': 110 return np.complex(value) 111 elif typeval == 'np.complex64': 112 return np.complex64(value) 113 elif typeval == 'np.complex128': 114 return np.complex128(value) 115 else: 116 print errormsg 117 print fname + ': data type "' + typeval + '" is not ready !' 118 print errormsg 119 quit(-1) 120 121 return 122 123 def str_list_k(string, cdiv, kind): 124 """ Function to obtain a list of types of values from a string giving a split character 125 string= String from which to obtain a list ('None' for None) 126 cdiv= character to use to split the string 127 kind= kind of desired value (as string like: 'np.float', 'int', 'np.float64', ....) 128 >>> str_list_k('1:@#:$:56', ':', 'S') 129 ['1', '@#', '$', '56'] 130 >>> str_list_k('1:3.4:12.3', ':', 'np.float64') 131 [1.0, 3.3999999999999999, 12.300000000000001] 132 """ 133 fname = 'str_list' 134 135 if string.find(cdiv) != -1: 136 listv = string.split(cdiv) 137 else: 138 if string == 'None': 139 listv = None 140 else: 141 listv = [string] 142 143 if listv is not None: 144 finalist = [] 145 for lv in listv: 146 finalist.append(typemod(lv, kind)) 147 else: 148 finalist = None 149 150 return finalist 151 43 152 44 153 def set_attribute(ncvar, attrname, attrvalue): … … 227 336 else: 228 337 opern = 'sumc' 229 operv = '0 .'338 operv = '0' 230 339 231 340 if not searchInlist(fmts, fmt): … … 328 437 return newval 329 438 439 def getting_fixedline(line, cuts, types, dbg=False): 440 """ Function to get the values from a line of text with fixed lenght of different values 441 line: line with values 442 cuts: character number where a value ends 443 types: consecutive type of values 444 'I': integer 445 'R': real 446 'D': float64 447 'S': string 448 'B': boolean 449 dbg: debug mode (default False) 450 >>> Sline=' 87007 03012015 25.6 6.4 9.4 5 15' 451 >>> getting_fixedline(Sline, [8, 17, 23, 29, 36, 40, 45, 50], ['I', 'R', 'R', 'R', 'I', 'R', 'R', 'R']) 452 [87007, 3012015.0, 25.6, 6.4, -99999, -99999, 9.4, 5.0, 15.0] 453 """ 454 fname = 'getting_fixedline' 455 456 if len(cuts) + 1 != len(types): 457 print errormsg 458 print ' ' + fname + ': The number of types :', len(types), 'must be +1', \ 459 'number of cuts:', len(cuts) 460 quit(-1) 461 462 values = [] 463 val = line[0:cuts[0]] 464 if len(val.replace(' ','')) >= 1: 465 values.append(typemod(val, types[0])) 466 else: 467 if types[0] == 'I': values.append(fillValueI) 468 elif types[0] == 'R': values.append(fillValueF) 469 elif types[0] == 'D': values.append(fillValueF) 470 elif types[0] == 'S': values.append(fillValueS) 471 elif types[0] == 'B': values.append(fillValueB) 472 473 Ncuts = len(cuts) 474 for ic in range(1,Ncuts): 475 val = line[cuts[ic-1]:cuts[ic]] 476 if dbg: print ic, ':', val, '-->', types[ic] 477 if len(val.replace(' ','')) >= 1: 478 values.append(typemod(val, types[ic])) 479 else: 480 if types[ic] == 'I': values.append(fillValueI) 481 elif types[ic] == 'R': values.append(fillValueF) 482 elif types[ic] == 'D': values.append(fillValueF) 483 elif types[ic] == 'S': values.append(fillValueS) 484 elif types[ic] == 'B': values.append(fillValueB) 485 486 # Last value 487 Lline = len(line) 488 val = line[cuts[Ncuts-1]:Lline] 489 if len(val.replace(' ','')) >= 1: 490 values.append(typemod(val, types[Ncuts])) 491 else: 492 if types[Ncuts] == 'I': values.append(fillValueI) 493 elif types[Ncuts] == 'R': values.append(fillValueF) 494 elif types[Ncuts] == 'D': values.append(fillValueF) 495 elif types[Ncuts] == 'S': values.append(fillValueS) 496 elif types[Ncuts] == 'B': values.append(fillValueB) 497 498 return values 499 500 501 def getting_fixedline_NOk(line, cuts, miss, dbg=False): 502 """ Function to get the values from a line of text with fixed lenght of 503 different values without types 504 line: line with values 505 cuts: character number where a value ends 506 miss: character form issed values 507 dbg: debug mode (default False) 508 >>> Sline=' 87007 03012015 25.6 6.4 9.4 5 15' 509 >>> getting_fixedline_NOk(Sline, [8, 17, 23, 29, 36, 40, 45, 50], '#') 510 ['87007', '03012015', '25.6', '6.4', '#', '#', '9.4', '5', '15'] 511 """ 512 fname = 'getting_fixedline_NOk' 513 514 values = [] 515 val = line[0:cuts[0]] 516 if len(val.replace(' ','')) >= 1: 517 values.append(val.replace(' ','')) 518 else: 519 values.append(miss) 520 521 Ncuts = len(cuts) 522 for ic in range(1,Ncuts): 523 val = line[cuts[ic-1]:cuts[ic]] 524 if dbg: print ic, ':', val 525 if len(val.replace(' ','')) >= 1: 526 values.append(val.replace(' ','')) 527 else: 528 values.append(miss) 529 530 # Last value 531 Lline = len(line) 532 val = line[cuts[Ncuts-1]:Lline] 533 if len(val.replace(' ','')) >= 1: 534 values.append(val.replace(' ','')) 535 else: 536 values.append(miss) 537 538 return values 539 330 540 def read_datavalues(dataf, comchar, colchar, fmt, oper, miss, varns, dbg): 331 541 """ Function to read from an ASCII file values in column … … 358 568 line = line.replace('\n','').replace(chr(13),'') 359 569 if not searchInlist(comchar,line[0:1]) and len(line) > 1: 360 values0 = line.split(colchar) 570 # Getting values 571 if colchar[0:4] != 'None': 572 values0 = line.split(colchar) 573 else: 574 ltypes=str_list_k(colchar[5:len(colchar)+1],',','I') 575 values0 = getting_fixedline_NOk(line, ltypes, miss[0], dbg=dbg) 361 576 # Removing no-value columns 362 577 values = [] … … 826 1041 help="description file to use" + read_description.__doc__, metavar="FILE") 827 1042 parser.add_option("-e", "--end_column", dest="endcol", 828 help="character to indicate end of the column ('space', for ' ' )", metavar="VALUE")1043 help="character to indicate end of the column ('space', for ' ', or 'None,[fixcoljumps]' for fixed size columns with [fixcoljumps]: ',' separated list of positions of column ends within line)", metavar="VALUE") 829 1044 parser.add_option("-f", "--file", dest="obsfile", 830 1045 help="observational file to use", metavar="FILE") … … 1067 1282 basicvardef(newvar, timeCFname, 'time', tunits ) 1068 1283 else: 1069 newdim = objfile.createDimension('time',None) 1284 if searchInlist(objfile.dimensions, 'time'): 1285 print warnmsg 1286 print ' ' + main + ": dimension 'time' already exist !!" 1287 print " renaming it as 'CFtime'" 1288 tdimn = 'CFtime' 1289 newdim = objfile.renameDimension('time','CFtime') 1290 else: 1291 tdmin = 'time' 1292 newdim = objfile.createDimension(tdimn,None) 1070 1293 timeCFname = 'time' 1071 newvar = objfile.createVariable( timeCFname, 'f8', ('time')) 1294 newvar = objfile.createVariable( timeCFname, 'f8', (tdimn)) 1295 newvar[:] = np.zeros(timevals.shape[0]) 1072 1296 basicvardef(newvar, timeCFname, 'time', tunits ) 1073 1297 … … 1076 1300 newvar[:] = timevals[0] 1077 1301 else: 1302 print 'Lluis shapes: newvar:', newvar.shape, 'timevals:', timevals.shape 1078 1303 newvar[:] = timevals 1079 1304 -
trunk/tools/documentation/plotting/gallery.html
r1876 r1948 15 15 <A HREF="2Dshad_time.html"><IMG SRC="figs/ta_valley_fixpixel-grid.png" ALT="2D shadow time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 16 16 <A HREF="2Dshad_cont.html"><IMG SRC="figs/huss-tas_Blues_shad-cont.png" ALT="2D shadow contour" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 17 <A HREF="2Dshad_contdisc_time.html"><IMG SRC="figs/2Dshad_obs-sim_comparison_time.png" ALT="2D shadow continuous and discrete" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 17 18 <A HREF="2Dshad_2cont.html"><IMG SRC="figs/2Dfields_shadow-2contour.png" ALT="2D shadow 2 contour" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> 18 19 <A HREF="2Dshad_cont_time.html"><IMG SRC="figs/huss-tas_shad_cont_time_BuPu.png" ALT="2D shadow contour time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A> -
trunk/tools/documentation/plotting/intro.html
r1876 r1948 39 39 Available plots: 40 40 <UL> 41 <LI><SPAN CLASS="codetxt"> create_movie:</SPAN> Function to create a movie assuming ImageMagick installed! </LI> 42 <LI><SPAN CLASS="codetxt"> draw_2D_shad:</SPAN> plotting a fields with shading </LI> 43 <LI><SPAN CLASS="codetxt"> draw_2D_shad_cont:</SPAN> plotting two fields, one with shading and the other with contour lines </LI> 41 <LI><SPAN CLASS="codetxt">create_movie:</SPAN> Function to create a movie assuming ImageMagick installed! </LI> 42 <LI><SPAN CLASS="codetxt">draw_2D_shad:</SPAN> plotting a fields with shading </LI> 43 <LI><SPAN CLASS="codetxt">draw_2D_shad_cont:</SPAN> plotting two fields, one with shading and the other with contour lines </LI> 44 <LI><SPAN CLASS="codetxt">draw_2D_shad_contdisc_time:</SPAN> plotting one continuous fields with shading and another discrete one with points with a time-axis </LI> 44 45 <LI><SPAN CLASS="codetxt"> draw_2D_shad_cont_time:</SPAN> plotting two fields, one with shading and the other with contour lines being one of the dimensions of time characteristics </LI> 45 46 <LI><SPAN CLASS="codetxt">draw_2D_shad_line:</SPAN> plotting a fields with shading and another with line </LI> -
trunk/tools/documentation/plotting/plotting.html
r1875 r1948 10 10 <A CLASS="lc" HREF="2Dshad_time.html" TARGET="value">2D shadow time</A><BR> 11 11 <A CLASS="lc" HREF="2Dshad_cont.html" TARGET="value">2D shadow contour</A><BR> 12 <A CLASS="lc" HREF="2Dshad_contdisc_time.html" TARGET="value">2D shadow cont. & disc. time</A><BR> 12 13 <A CLASS="lc" HREF="2Dshad_2cont.html" TARGET="value">2D shadow 2 contour</A><BR> 13 14 <A CLASS="lc" HREF="2Dshad_cont_time.html" TARGET="value">2D shadow contour time</A><BR> -
trunk/tools/drawing.py
r1947 r1948 59 59 # movie_2D_shad -f '../PY/wrfout_d01_1995-01-01_00:00:00' -S 'tas:west_east|-1,south_north|-1,Time|-1:XLONG:XLAT:auto:rainbow,auto,auto:Srange,Srange:png:None:cyl,l:Time,Times:WRFdate,$%d^{%H}$:15:mp4' -v T2 60 60 ## e.g. # drawing.py -o draw_SkewT -f UWyoming_snd_87576.nc -S 'time|0:auto:auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes' -v ta,tda,pres 61 ## e.g. # drawing.py -o draw_multi_SkewT -f '/home/lluis/estudios/ChemGBsAs/tests/199807/obs/snd/UWyoming_snd_87576.nc:pres|-1,time|0:ta,pres;/home/lluis/estudios/ChemGBsAs/tests/199807/obs/snd/UWyoming_snd_87576.nc:pres|-1,time|0:tda,pres' -S 'auto:auto:multilines!ta,tda!#6464FF,#FF6464!-!,!2:0,auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes' 62 ## e.g. # drawing.py -o draw_2D_shad_contdisc -f '/home/lluis/estudios/ChemGBsAs/tests/199501/simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@/home/lluis/estudios/ChemGBsAs/tests/199501/obs/snd/UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta:time,bottom_top:Vfix,auto,3600.,auto,Vfix,auto,50.,auto:auto:Srange,Srange:auto:obs!&!sim!Ezeiza!airport!sounding:pdf:flip@y:None:yes' 61 ## e.g. # drawing.py -o draw_multi_SkewT -f 'UWyoming_snd_87576.nc:pres|-1,time|0:ta,pres;UWyoming_snd_87576.nc:pres|-1,time|0:tda,pres' -S 'auto:auto:multilines!ta,tda!#6464FF,#FF6464!-!,!2:0,auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes' 62 ## e.g. # drawing.py -o draw_2D_shad_contdisc -f 'simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta:time,bottom_top:Vfix,auto,3600.,auto,Vfix,auto,50.,auto:auto:Srange,Srange:auto:obs!&!sim!Ezeiza!airport!sounding:pdf:flip@y:None:yes' 63 ## e.g. # drawing.py -o draw_2D_shad_contdisc_time -f 'simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta;y;auto|exct,12,h|%d$^{%H}$|time!($[DD]^{[HH]}$);Vfix,auto,50.,auto;auto;Srange,Srange;auto;obs!&!sim!Ezeiza!airport!sounding;pdf;flip@y;None;yes' 63 64 64 65 ####### … … 67 68 # draw_2D_shad_cont: plotting two fields, one with shading and the other with contour lines 68 69 # draw_2D_shad_contdisc: plotting one continuous fields with shading and another discrete one with points 70 # draw_2D_shad_contdisc_time: plotting one continuous fields with shading and another discrete one with 71 # points with a time-axis 69 72 # draw_2D_shad_2cont: plotting three fields, one with shading and the other two with contour lines 70 73 # draw_2D_shad_cont_time: plotting two fields, one with shading and the other with contour lines being … … 115 118 116 119 namegraphics = ['create_movie', 'draw_2D_shad', 'draw_2D_shad_time', \ 117 'draw_2D_shad_cont', 'draw_2D_shad_contdisc', 'draw_2D_shad_ 2cont',\118 'draw_2D_shad_ cont_time',\120 'draw_2D_shad_cont', 'draw_2D_shad_contdisc', 'draw_2D_shad_contdisc_time', \ 121 'draw_2D_shad_2cont', 'draw_2D_shad_cont_time', \ 119 122 'draw_2D_shad_line', \ 120 123 'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', \ … … 9482 9485 9483 9486 def draw_2D_shad_contdisc_time(ncfiles, values, axfig=None, fig=None): 9484 """ plotting one continuous fields with shading and another discrete one with points 9485 draw_2D_shad_contdisc(ncfile, values) 9487 """ plotting one continuous fields with shading and another discrete one with 9488 points with a time-axis 9489 draw_2D_shad_contdisc_time(ncfile, values) 9486 9490 ncfiles= [contfilen];[contvarn];[dimtvarn];[dimvvarn];[dimvals]@[discfilen]; 9487 9491 [discvarn];[dimtvarn];[dimvvarn];[dimvals] files and variables to use … … 9499 9503 [discvarn]: name of the discrete variable 9500 9504 * NOTE: limits of the graph will be computed from the continuous variable 9501 values=[vnamefs];[varaxis];[timevals];[dim xyfmt];[colorbarvals];[sminv],[smaxv];9505 values=[vnamefs];[varaxis];[timevals];[dimvfmt];[colorbarvals];[sminv],[smaxv]; 9502 9506 [discvals];[figt];[kindfig];[reverse];[mapv];[close] 9503 9507 [vnamefs]: Name in the figure of the variable to be shaded 9504 9508 [varaxis]: axis in the figure for the variable-axis ('x' or 'y') 9505 [timevals]: [timen]|[units]|[kind]|[tfmt]|[label]|[timeaxis] time labels characteristics 9506 [timen]: name of the time variable ('WRFtime' for WRF times) 9509 [timevals]: [units]|[kind]|[tfmt]|[label] time labels characteristics 9507 9510 [units]: units string according to CF conventions ([tunits] since 9508 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) 9511 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces), 9512 'auto' for minutes!since!1949-12-01!00:00:00 9509 9513 [kind]: kind of output 9510 9514 'Nval': according to a given number of values as 'Nval',[Nval] … … 9513 9517 'w': week, 'd': day, 'h': hour, 'i': minute, 's': second, 9514 9518 'l': milisecond 9515 [tfmt]: desired format 9516 [label]: label at the graph ('!' for spaces) 9519 [tfmt]: desired format (combination of 'C'-style values and LaTeX) 9520 [label]: label at the graph ('!' for spaces, combination of 'C'-style 9521 values and LaTeX) 9517 9522 [dimvfmt]=[[dvs],[dvf],[Ndv],[ordv]: format of the values at variable-axis 9518 9523 (or 'auto') … … 9572 9577 quit() 9573 9578 9574 expectargs = '[vnamefs];[varaxis];[timevals];[dim xyfmt];[colorbarvals];' + \9575 '[sminv],[smaxv];[discvals];[figt];[kindfig];[reverse];[mapv];[close]' ;;;9579 expectargs = '[vnamefs];[varaxis];[timevals];[dimvfmt];[colorbarvals];' + \ 9580 '[sminv],[smaxv];[discvals];[figt];[kindfig];[reverse];[mapv];[close]' 9576 9581 9577 9582 drw.check_arguments(fname,values,expectargs,';') … … 9579 9584 vnamesfig = values.split(';')[0] 9580 9585 varaxis = values.split(';')[1] 9581 timevals = values.split(';')[2].split(',') 9582 colorbarvals = values.split(';')[3] 9583 shadminmax = values.split(';')[4] 9584 discvals = values.split(';')[5] 9585 figt = values.split(';')[6].replace('!',' ') 9586 kindfig = values.split(';')[7] 9587 revals = values.split(';')[8] 9588 mapvalue = values.split(';')[9] 9589 close = gen.Str_Bool(values.split(';')[10]) 9586 timevals = values.split(';')[2].split('|') 9587 dimvfmt = values.split(';')[3] 9588 colorbarvals = values.split(';')[4] 9589 shadminmax = values.split(';')[5] 9590 discvals = values.split(';')[6] 9591 figt = values.split(';')[7].replace('!',' ') 9592 kindfig = values.split(';')[8] 9593 revals = values.split(';')[9] 9594 mapvalue = values.split(';')[10] 9595 close = gen.Str_Bool(values.split(';')[11]) 9596 9597 if timevals[0] == 'auto': 9598 timevals[0] = 'minutes since 1949-12-01 00:00:00' 9599 else: 9600 timevals[0] = timevals[0].replace('!',' ') 9590 9601 9591 9602 ncs = ncfiles.split('@') … … 9614 9625 if not os.path.isfile(ncfilen): 9615 9626 print errormsg 9616 print ' ' + fname + ": '" + hfn + "' file '" + ncfile + "' does " +\9627 print ' ' + fname + ": '" + hfn + "' file '" + ncfilen + "' does " + \ 9617 9628 "not exist !!" 9618 9629 quit(-1) … … 9622 9633 if not onc.variables.has_key(varn): 9623 9634 print errormsg 9624 print ' ' + fname + ": '" + hfn + "' file '" + ncfile +\9635 print ' ' + fname + ": '" + hfn + "' file '" + ncfilen + \ 9625 9636 "' does not have variable '" + varn + "' !!" 9626 9637 varns = sorted(onc.variables.keys()) … … 9688 9699 objdimt.dimensions, objdimv.dimensions, dimvals.replace(':','|').split(','),\ 9689 9700 False) 9701 # Getting same times 9702 odimxv0 = gen.coincident_CFtimes(odimxv0, timevals[0], odimxu) 9690 9703 9691 9704 # Some statistics … … 9704 9717 9705 9718 if hfn == 'cont': 9706 timeinfo = [] 9707 9708 if varaxis == 'x': 9709 # Getting the right shape of dimensions 9710 if vals.shape[0] != odimxv0.shape[0]: gdimx = vals.shape[0] 9711 else: gdimx = vals.shape[1] 9712 gdimy = odimxv0.shape[0] 9713 else: 9714 if vals.shape[0] != odimxv0.shape[0]: gdimy = vals.shape[0] 9715 else: gdimy = vals.shape[1] 9716 gdimx = odimxv0.shape[0] 9719 9720 # Getting time initialy as x-axis the right shape of dimensions 9721 gdimx = odimxv0.shape[0] 9722 if vals.shape[0] != gdimx: gdimy = vals.shape[0] 9723 else: gdimy = vals.shape[1] 9717 9724 9718 9725 if vals.shape[1] == gdimx: contv = vals[:] … … 9737 9744 9738 9745 diminfo = {} 9739 diminfo['units'] = [ odimxu, odimyu]9740 diminfo['names'] = [gen.variables_values(vdim xn)[0], \9741 gen.variables_values(vdim yn)[1]]9746 diminfo['units'] = [timevals[0], odimvu] 9747 diminfo['names'] = [gen.variables_values(vdimtn)[0], \ 9748 gen.variables_values(vdimvn)[1]] 9742 9749 varinfo = {} 9743 9750 varinfo['units'] = varunits … … 9752 9759 else: 9753 9760 discvarv = [] 9754 discx 0= []9755 discy 0= []9761 discx = [] 9762 discy = [] 9756 9763 # Assuming that discrete values are masked 9757 9764 if type(vals) != type(gen.mamat): … … 9779 9786 discx.append(d2Dx[j,i]) 9780 9787 discy.append(d2Dy[j,i]) 9781 if varaxis == 'x':9782 discx = list(discy0)9783 # Getting same times9784 discy = gen.coincident_CFtimes(discx0, timeinfo[], varunits)9785 else:9786 discx = list(discx0)9787 discy = list(discy0)9788 9789 9788 9790 9789 Ndiscvals = len(discvarv) … … 9829 9828 colormapv = [colbarn, fmtcolbar, colbaror] 9830 9829 9831 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyf,',') 9832 xaxis = [xstyl, xaxf, Nxax, xaxor] 9833 yaxis = [ystyl, yaxf, Nyax, yaxor] 9830 # format axes 9831 if dimvfmt == 'auto': axfmt = 'auto,auto,auto,auto,auto,auto,auto,auto' 9832 else: axfmt = 'auto,auto,auto,auto,' + dimvfmt 9833 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(axfmt, ',') 9834 valaxis = [ystyl, yaxf, Nyax, yaxor] 9834 9835 9835 9836 if revals == 'None': 9836 9837 revals = None 9837 9838 9838 drw.plot_2Dshad_obssim_time(discv, contv, odxv, odyv, revals, diminfo, xaxis, \ 9839 yaxis, colormapv, shading_nx, varinfo, discinfo, mapvalue, graphnx, figt, \ 9840 kindfig, close) 9839 # time values 9840 timeinfo = {} 9841 timeinfo['units'] = timevals[0] 9842 timeinfo['name'] = timevals[3].replace('!', ' ') 9843 timeinfo['tpos'], timeinfo['tlabs'] = drw.CFtimes_plot([dxn, dxx], timevals[0], \ 9844 timevals[1], timevals[2]) 9845 9846 drw.plot_2Dshad_obssim_time(discv, contv, odxv, odyv, varaxis, revals, diminfo, \ 9847 valaxis, timeinfo, colormapv, shading_nx, varinfo, discinfo, mapvalue, graphnx,\ 9848 figt, kindfig, close) 9841 9849 9842 9850 return 9843 9851 9844 contfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/simout_snddiags.nc;ta;time;pres;time|-1,pres|-1' 9845 discfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/obs/snd/UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' 9846 9847 values = 'ta:time,bottom_top:Vfix,auto,3600.,auto,Vfix,auto,50.,auto:auto:Srange,Srange:o,5.:obs!&!sim!Ezeiza!airport!sounding:pdf:flip@y:None:yes' 9848 9849 draw_2D_shad_contdisc_time(contfilen+'@'+discfilen, values, axfig=None, fig=None) 9852 #contfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/simout_snddiags.nc;ta;time;pres;time|-1,pres|-1' 9853 #discfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/obs/snd/UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' 9854 #values = 'ta;y;auto|exct,12,h|%d$^{%H}$|time!($[DD]^{[HH]}$);Vfix,auto,50.,auto;auto;Srange,Srange;auto;obs!&!sim!Ezeiza!airport!sounding;pdf;flip@y;None;yes' 9855 9856 #draw_2D_shad_contdisc_time(contfilen+'@'+discfilen, values, axfig=None, fig=None) 9850 9857 9851 9858 … … 9870 9877 # Not checking file operation 9871 9878 Notcheckingfile = ['draw_2D_shad_cont', 'draw_2D_shad_contdisc', \ 9872 'draw_2D_shad_ 2cont', 'draw_2D_shad_cont_time',\9879 'draw_2D_shad_contdisc_time', 'draw_2D_shad_2cont', 'draw_2D_shad_cont_time', \ 9873 9880 'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time', \ 9874 9881 'draw_bar', 'draw_bar_line', 'draw_bar_line_time', 'draw_bar_time', \ … … 9930 9937 elif oper == 'draw_2D_shad_contdisc': 9931 9938 draw_2D_shad_contdisc(opts.ncfile, opts.values) 9939 elif oper == 'draw_2D_shad_contdisc_time': 9940 draw_2D_shad_contdisc_time(opts.ncfile, opts.values) 9932 9941 elif oper == 'draw_2D_shad_2cont': 9933 9942 draw_2D_shad_2cont(opts.ncfile, opts.values, opts.varname) -
trunk/tools/drawing_tools.py
r1947 r1948 165 165 # plot_time_lag: Function to plot a time-lag figure (x, previous values; y, future values) 166 166 # plot_Trajectories 167 # plot_2Dshad_obssim: Function to plot a 2D shadding plot with comparison 168 # between observations (as filled colored circles) and simulation (shadded 169 # continuous field) 170 # plot_2Dshad_obssim_time: Function to plot a 2D shadding plot with comparison 171 # between observations (as filled colored circles) and simulation (shadded 172 # continuous field) with a time-axis 167 173 # plot_2D_shadow_contour: 168 174 # plot_2D_shadow_2contour: Plotting 3 2D fields, 1 with shadow and two with contour lines … … 12036 12042 return 12037 12043 12038 def plot_2Dshad_obssim_time(obsv, varsv, dim vv, dimtv, dataxis, reva, diminf, vaxv, \12044 def plot_2Dshad_obssim_time(obsv, varsv, dimtv, dimvv, dataxis, reva, diminf, vaxv, \ 12039 12045 timeinf, cbarv, vs, varinf, discinf, mapv, gmaxmin, figtitle, kfig, close): 12040 12046 """ Function to plot a 2D shadding plot with comparison between observations (as 12041 filled colored circles) and simulation (shadded continuous field) 12047 filled colored circles) and simulation (shadded continuous field) with a time-axis 12042 12048 obsv= 3-column with observational values (x, y, value) 12043 12049 varsv= 2D matrix of simulation values 12050 dimtv= values for t-coordinate from simulation 12044 12051 dimvv= values for v-coordinate from simulation 12045 dimtv= values for t-coordinate from simulation12046 12052 dataxis= which axis 'x' or 'y' should be use for the non-temporal dimension 12047 12053 reva= in case of modification of the plotting of 2D variables ('|' can be used for combination) … … 12052 12058 diminf['names']= [dimxn, dimyn]: names of the dimension 12053 12059 vaxv= list with the v-axis paramteres [style, format, number and orientation] 12054 timeinf= list with information for the time-axis 12055 [timepos]: positions of the markers 12056 [timelabs]: labels of the markers 12057 [ttitle]: title in graphic 12060 timeinf= dictionary with information for the time-axis 12061 'tpos': positions of the markers 12062 'tlabs': labels of the markers 12063 'name': name in graphic 12064 'units': units 12058 12065 cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror] 12059 12066 colorbar: name of the color bar to use … … 12110 12117 # Usually axis > x must be the time, thus... 12111 12118 dimxv0 = dimtv.copy() 12112 dimyv0 = dim yv.copy()12119 dimyv0 = dimvv.copy() 12113 12120 12114 12121 dxn = dimtv.min() 12115 12122 dxx = dimtv.max() 12116 dyn = dim yv.min()12117 dyx = dim yv.max()12118 12119 dimxt0 = timeinf[ 0]12120 dimxl0 = timeinf[ 1]12123 dyn = dimvv.min() 12124 dyx = dimvv.max() 12125 12126 dimxt0 = timeinf['tpos'] 12127 dimxl0 = timeinf['tlabs'] 12121 12128 12122 12129 if vaxv[0] == 'pretty': … … 12128 12135 12129 12136 dimyl0 = [] 12130 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1])) 12131 12137 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], \ 12138 style=vaxv[1])) 12139 12140 dimn = diminf['names'] 12132 12141 dimyu = diminf['units'][1] 12133 12142 12134 dimxT0 = timeinf[ 2]12143 dimxT0 = timeinf['name'] 12135 12144 dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')' 12136 12145 … … 12310 12319 12311 12320 if signxl != signxt: 12312 plt.xticks(1.-dimxt, dimxl , rotation=xaxv[3])12321 plt.xticks(1.-dimxt, dimxl) 12313 12322 else: 12314 plt.xticks(dimxt, dimxl , rotation=xaxv[3])12323 plt.xticks(dimxt, dimxl) 12315 12324 if signyl != signyt: 12316 plt.yticks(1.-dimyt, dimyl, rotation= yaxv[3])12325 plt.yticks(1.-dimyt, dimyl, rotation=vaxv[3]) 12317 12326 else: 12318 plt.yticks(dimyt, dimyl, rotation= yaxv[3])12327 plt.yticks(dimyt, dimyl, rotation=vaxv[3]) 12319 12328 12320 12329 # Only if gmaxmin is used to compute limits of the figure !! … … 12342 12351 plt.title(gen.latex_text(figtitle)) 12343 12352 12344 figname = '2Dshad_obs-sim_comparison_time .png'12353 figname = '2Dshad_obs-sim_comparison_time' 12345 12354 output_kind(kfig, figname, close) 12346 12355 -
trunk/tools/nc_var_tools.py
r1939 r1948 14488 14488 14489 14489 arguments = '[longitude]:[latitude]:[dnames]:[vdnames]' 14490 check_arguments(fname, values, arguments, ':')14490 gen.check_arguments(fname, values, arguments, ':') 14491 14491 14492 14492 longitude = np.float(values.split(':')[0]) … … 14498 14498 14499 14499 for dn in dnames: 14500 if not searchInlist(onc.dimensions, dn):14500 if not gen.searchInlist(onc.dimensions, dn): 14501 14501 print errormsg 14502 14502 print ' ' + fname + ": file '" + ncfile + "' does not have dimension '"+\ … … 14505 14505 14506 14506 for vdn in dvnames: 14507 if not searchInlist(onc.variables, vdn):14507 if not gen.searchInlist(onc.variables, vdn): 14508 14508 print errormsg 14509 14509 print ' ' + fname + ": file '" + ncfile + "' does not have variable '"+ \ … … 14513 14513 # Getting grid point localization 14514 14514 ## 14515 lon2d, lat2d = lonlat2D(onc.variables[dvnames[0]], onc.variables[dvnames[1]])14515 lon2d, lat2d = gen.lonlat2D(onc.variables[dvnames[0]], onc.variables[dvnames[1]]) 14516 14516 14517 14517 dimx = lon2d.shape[1] … … 14521 14521 dist=np.sqrt((longitude - lon2d)**2. + (latitude - lat2d)**2.) 14522 14522 mindist = np.min(dist) 14523 minydist, minxdist = index_mat(dist,mindist)14523 minydist, minxdist = gen.index_mat(dist,mindist) 14524 14524 mappairs[:] = [minydist, minxdist] 14525 14525 … … 14531 14531 vals = vals + dnames[0] + ',' + str(mappairs[0]) + ',' + str(mappairs[0]) + ',1' 14532 14532 14533 DataSetSection_multidims(vals, ncfile )14533 DataSetSection_multidims(vals, ncfile, 'all') 14534 14534 of = ncfile.split('.')[0] + '_' + dnames[1] + '_B' + str(mappairs[1]) + '-E' + \ 14535 14535 str(mappairs[1]) + '-I1_' + dnames[0] + '_B' + str(mappairs[0]) + '-E' + \
Note: See TracChangeset
for help on using the changeset viewer.