- Timestamp:
- Jul 13, 2018, 11:17:30 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1875 r1930 57 57 ## e.g. # drawing.py -o draw_multi_2D_shad -f '../PY/wrfout_d01_1995-01-01_00:00:00@T2@west_east|-1,south_north|-1,Time|0;../PY/wrfout_d01_1995-01-01_00:00:00@T2@west_east|-1,south_north|-1,Time|1;../PY/wrfout_d01_1995-01-01_00:00:00@T2@west_east|-1,south_north|-1,Time|2;../PY/wrfout_d01_1995-01-01_00:00:00@T2@west_east|-1,south_north|-1,Time|3' -S 'tas:XLONG:XLAT:auto:rainbow,auto,auto:Srange,Srange:png:None:cyl,l:0!UTC,1!UTC,2!UTC,3!UTC:2:2:tas!at!2001-11-11:True' 58 58 # 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 59 ## 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 59 60 60 61 ####### … … 85 86 # draw_points_lonlat: Function to plot a series of lon/lat points 86 87 # draw_ptZvals: Function to plot a given list of points by their Z value and a colorbar 88 # draw_SkewT: creation of a SkewT-logP diagram using matplotlib's API example 87 89 # draw_time_lag: Function to plot a time-lag figure with multiple sources (x, previous values; y, future values) 88 90 # draw_timeSeries: Function to draw a time-series … … 116 118 'draw_Neighbourghood_evol', \ 117 119 'draw_points', 'draw_points_lonlat', \ 118 'draw_ptZvals', 'draw_river_desc', 'draw_ subbasin', 'draw_Taylor',\120 'draw_ptZvals', 'draw_river_desc', 'draw_SkewT', 'draw_subbasin', 'draw_Taylor', \ 119 121 'draw_time_lag', 'draw_timeSeries', 'draw_topo_geogrid', \ 120 122 'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories', \ … … 8871 8873 #python drawing.py -o 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 8872 8874 8875 def draw_SkewT(ncfile, values, varname): 8876 """ creation of a SkewT-logP diagram using matplotlib's API example 8877 https://matplotlib.org/examples/api/skewt.html (skewt.py, included as external python) 8878 draw_SkewT(ncfile, values, varn) 8879 ncfile= file to use 8880 values = [dimvals]:[taminv],[tamaxv]:[presminv],[presmaxv]:[figt]:[kindfig]: 8881 [close] 8882 [dimvals]: ',' list of [dimname]|[value] telling at which dimension of the 8883 variable a given value is required: 8884 * [integer]: which value of the dimension 8885 * -1: all along the dimension 8886 * -9: last value of the dimension 8887 * [beg]@[end]@[inc] slice from [beg] to [end] every [inc] 8888 * NOTE, no dim name all the dimension size 8889 [taminv],[tamaxv]: minimum and maximum of temperatures to plot [C] 8890 ('auto' for -50,50) 8891 [presminv],[presmaxv]: minimum and maximum of pressures to plot [hPa] 8892 ('auto' for 100.,1020.) 8893 [figt]: title of figure ('!' for spaces) 8894 [kindfig]: kind of graphical output (ps, png, pdf) 8895 [close]: wether figure should be closed or not 8896 varn= [tavarn],[tdavarn],[presvarn] 8897 """ 8898 fname = 'draw_SkewT' 8899 8900 if values == 'h': 8901 print fname + '_____________________________________________________________' 8902 print draw_SkewT.__doc__ 8903 quit() 8904 8905 expectargs = '[dimvals]:[taminv],[tamaxv]:[presminv],[presmaxv]:[figt]:' + \ 8906 '[kindfig]:[close]' 8907 8908 drw.check_arguments(fname,values,expectargs,':') 8909 8910 # Variables 8911 varns = varname.split(',') 8912 if len(varns) != 3: 8913 print errormsg 8914 print ' ' +fname+ ": requires 3 name of variables as '[tavarn],[tdavarn]" + \ 8915 ",[tavarn]' !!" 8916 print " variables provided: '" + varname + "' " 8917 quit(-1) 8918 8919 dimvals= values.split(':')[0].replace('|',':') 8920 if values.split(':')[1] != 'auto': 8921 tanx = gen.str_list_k(values.split(':')[1], ',', 'np.float') 8922 else: 8923 tanx = [-50.,50.] 8924 if values.split(':')[2] != 'auto': 8925 presnx = gen.str_list_k(values.split(':')[2], ',', 'np.float') 8926 else: 8927 presnx = [100.,1020.] 8928 figt = values.split(':')[3].replace('!',' ') 8929 kindfig = values.split(':')[4] 8930 close = gen.Str_Bool(values.split(':')[5]) 8931 8932 onc = NetCDFFile(ncfile, 'r') 8933 for varn in varns: 8934 if not onc.variables.has_key(varn): 8935 print errormsg 8936 print ' ' + fname + ": file '" + ncfile + "' does not have variable '" + \ 8937 varn + "' !!" 8938 print ' available ones:', onc.variables-keys() 8939 quit(-1) 8940 8941 ota = onc.variables[varns[0]] 8942 otda = onc.variables[varns[1]] 8943 opres = onc.variables[varns[2]] 8944 8945 # Getting values 8946 tavals, tadims = drw.slice_variable(ota, dimvals.replace(',','|')) 8947 tdavals, tdadims = drw.slice_variable(otda, dimvals.replace(',','|')) 8948 presvals, presdims = drw.slice_variable(opres, dimvals.replace(',','|')) 8949 8950 # Expected masked values 8951 if type(tavals) != type(gen.mamat): 8952 tavals = ma.masked_array(tavals) 8953 if type(tdavals) != type(gen.mamat): 8954 tdavals = ma.masked_array(tdavals) 8955 if type(tavals) != type(gen.mamat): 8956 presvals = ma.masked_array(presvals) 8957 8958 drw.plot_SkewT(tavals, tdavals, presvals, tanx, presnx, figt, kindfig, close) 8959 8960 onc.close() 8961 8962 return 8963 8964 #filen='/home/lluis/estudios/ChemGBsAs/tests/199807/obs/snd/UWyoming_snd_87576.nc' 8965 #values='time|0:auto:auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes' 8966 #varn='ta,tda,pres' 8967 #draw_SkewT(filen, values, varn) 8968 8873 8969 #quit() 8874 8970 … … 8994 9090 elif oper == 'draw_subbasin': 8995 9091 draw_subbasin(opts.ncfile, opts.values) 9092 elif oper == 'draw_SkewT': 9093 draw_SkewT(opts.ncfile, opts.values, opts.varname) 8996 9094 elif oper == 'draw_Taylor': 8997 9095 draw_Taylor(opts.ncfile, opts.values, opts.varname) -
trunk/tools/drawing_tools.py
r1915 r1930 143 143 # plot_cycle: Function to plot a variale with a circular cycle 144 144 # plot_lines: Function to plot a collection of lines 145 # plot_SkewT: Function to plot a SkewT-logP diagram using matplotlib's API example 145 146 # plot_Taylor: Function to draw a Taylor diagram (Taylor 2001) 146 147 # plot_TimeEnsembles: Function to plot a of an Ensemble of values with a time-axis … … 11369 11370 return 11370 11371 11371 11372 def SaturationPressure(temp): 11373 """ Provides de saturation pressure at a given temperature following The August-Roche-Magnus equation 11374 temp: temperature [K] 11375 """ 11376 fname = 'SaturationPressure' 11377 11378 ARM1 = 6.1094 # hPa 11379 ARM2 = 17.625 # C 11380 ARM3 = 243.04 # C 11381 11382 tempC = temp - 273.15 11383 satpres = 100.*ARM1*(ARM2*tempC)/(tempC+ARM3) 11384 11385 return satpres 11386 11387 #print 'satpres:', SaturationPressure(293.15) 11388 11389 def SatMixingRatio(ta,pres): 11390 """ Provides de saturation mixing ratio 11391 ta: temperature [K] 11392 pres: pressure [Pa] 11393 """ 11394 fname = 'SatMixingRatio' 11395 11396 es = SaturationPressure(ta) 11397 rs = (0.6222*es)/(pres-es) 11398 11399 return rs 11400 11401 #print 'saturation mixing ratio:', SatMixingRatio(293.,101300.) 11402 11403 def ethetapotct(tsfc, dz=50, pmin=5000.): 11404 """ Provides the curve for a given constant equivalent potential temperature starting at surface 11405 After: 11406 http://www.atmo.arizona.edu/students/courselinks/fall14/atmo551a/Site/ATMO_451a_551a_files/WaterVapor2.pdf 11407 https://www.meteo.physik.uni-muenchen.de/~roger/Lectures/Moist%20Convection/Conv_L03_2005.pdf 11408 11409 tsfc= temperature at the surface (C) 11410 dz= number of points for the curve 11411 R = 287.058 (Jkg-1k-1) # 8.3144598 (Jmol-1K-1) 11412 Cp = 1.0035 (Jg-1K-1) # 29.07 (Jmol-1K-1) 11413 p0 = 100000 # (Pa) 11414 psfc = 101325 # (Pa) 11415 L = 2264.705 (kJkg-1) 11416 """ 11417 fname = 'ethetapotct' 11418 R = 287.058 # (Jkg1-K-1) 11419 Cp = 1003.5 # (Jkg1-K-1) 11420 psfc = 101325. # Pa 11421 p0 = 100000. # Pa 11422 L = 2264.705 # kJkg-1 11423 11424 ethetapotv = np.zeros((dz,2), dtype=np.float) 11425 11426 dp = (psfc-pmin)/(dz-1) 11427 11428 for iz in range(dz): 11429 ethetapotv[iz,0] = psfc-dp*iz 11430 thetapotv = (tsfc+273.15)*((psfc-dp*iz)/p0)**(R/Cp) 11431 # print iz,psfc-dp*iz,thetapotv,SatMixingRatio(tsfc+273.15,psfc),np.exp(L*1000.*SatMixingRatio(tsfc+273.15,psfc)/Cp*(tsfc+273.15)) 11432 ethetapotv[iz,1] = thetapotv*np.exp(L*1000.*SatMixingRatio(tsfc+273.15,psfc)/(Cp*(tsfc+273.15))) - 273.15 11433 11434 # quit() 11435 return ethetapotv 11436 11437 11438 def thetapotct(tsfc, dz=50, pmin=5000.): 11439 """ Provides the curve for a given constant potential temperature starting at surface 11440 tsfc= temperature at the surface (C) 11441 dz= number of points for the curve 11442 R = 287.058 (Jkg-1k-1) # 8.3144598 (Jmol-1K-1) 11443 Cp = 1.0035 (Jg-1K-1) # 29.07 (Jmol-1K-1) 11444 p0 = 100000 # (Pa) 11445 psfc = 101325 # (Pa) 11446 """ 11447 fname = 'thetapotct' 11448 R = 287.058 # (Jkg1-K-1) 11449 Cp = 1003.5 # (Jkg1-K-1) 11450 psfc = 101325. # Pa 11451 p0 = 100000. # Pa 11452 11453 thetapotv = np.zeros((dz,2), dtype=np.float) 11454 dp = (psfc-pmin)/(dz-1) 11455 11456 for iz in range(dz): 11457 thetapotv[iz,0] = psfc-dp*iz 11458 thetapotv[iz,1] = (tsfc+273.15)*((psfc-dp*iz)/p0)**(R/Cp) - 273.15 11459 11460 return thetapotv 11461 11462 def plot_SkewT(ta, tda, pres, taxtrm, presxtrm, figtitle, kfig, close): 11463 """ Function to plot a SkewT-logP diagram using matplotlib's API example 11464 ta: air temperature [K] 11465 tda: dew point air temperature [K] 11466 pres: pessures for ta and tda [Pa] 11467 figtitle: title of figure 11468 kfig: kind of graphical output (jpg, pdf, png) 11469 close: whether figure should be closed or not 11470 """ 11471 import skewt 11472 11473 fname = 'plot_SkewT' 11474 # Checking for variable consistency 11475 if len(ta.shape) != 1: 11476 print errormsg 11477 print ' ' + fname + ": values of 'ta' must have 1D-rank!!" 11478 print ' passed shape:', ta.shape 11479 quit(-1) 11480 if len(tda.shape) != 1: 11481 print errormsg 11482 print ' ' + fname + ": values of 'tda' must have 1D-rank!!" 11483 print ' passed shape:', tda.shape 11484 quit(-1) 11485 if len(pres.shape) != 1: 11486 print errormsg 11487 print ' ' + fname + ": values of 'pres' must have 1D-rank!!" 11488 print ' passed shape:', pres.shape 11489 quit(-1) 11490 11491 # Create a new figure. The dimensions here give a good aspect ratio 11492 fig = plt.figure(figsize=(6.5875, 6.2125)) 11493 ax = fig.add_subplot(111, projection='skewx') 11494 11495 plt.grid(True) 11496 11497 # Quantity of dryadiabats 11498 xmax = taxtrm[1] 11499 xmin = taxtrm[0] 11500 print 'len:', np.arange(xmin,xmax,10.) 11501 if len(np.arange(xmin,xmax,10.)) < 10: xfrqtk = 10. 11502 else: xfrqtk = 20. 11503 11504 # Including dry adiabats 11505 ddt = int((xmax+xfrqtk-xmin)/xfrqtk) 11506 for itt in range(ddt): 11507 dryt = thetapotct(xmin+itt*xfrqtk, pmin=10000.) 11508 ax.semilogy(dryt[:,1], dryt[:,0]/100., color='#FFCCCC', linewidth=0.75) 11509 11510 # Including moist- adiabats 11511 #for itt in range(ddt): 11512 # moist = ethetapotct(xmin+itt*xfrqtk, pmin=10000.) 11513 # if xmin+itt*xfrqtk == 10.: print moist[:,1], moist[:,0]/100. 11514 # ax.semilogy(moist[:,1], moist[:,0]/100., color='#CCFFCC', linewidth=0.75) 11515 11516 # Plot the data using normal plotting functions, in this case using 11517 # log scaling in Y, as dictated by the typical meteorological plot 11518 tamask = ta.mask 11519 tdamask = tda.mask 11520 11521 ax.semilogy(ta.compressed(), pres[~tamask], color='C3') 11522 ax.semilogy(tda.compressed(), pres[~tdamask], color='C2') 11523 11524 # An example of a slanted line at constant X 11525 l = ax.axvline(0, color='C0') 11526 11527 # Disables the log-formatting that comes with semilogy 11528 ax.yaxis.set_major_formatter(ScalarFormatter()) 11529 ax.yaxis.set_minor_formatter(NullFormatter()) 11530 ax.set_yticks(np.linspace(100, 1000, 10)) 11531 ax.set_ylim(presxtrm[1], presxtrm[0]) 11532 11533 ax.xaxis.set_major_locator(MultipleLocator(10)) 11534 ax.set_xlim(taxtrm[0], taxtrm[1]) 11535 11536 # Indices 11537 #plt.annotate('CAPE: ' + str(stvals['CAPE']), xy=(0.98,0.97), \ 11538 # xycoords='axes fraction', ha="right", backgroundcolor='#DDDDDD') 11539 #plt.annotate('CI: '+ str(stvals['CI']), xy=(0.98,0.93), xycoords='axes fraction', \ 11540 # ha='right', backgroundcolor='#DDDDDD') 11541 11542 ax.set_title(gen.latex_text(figtitle)) 11543 11544 figname = 'SkewT' 11545 output_kind(kfig, figname, close) 11546 11547 return
Note: See TracChangeset
for help on using the changeset viewer.