diff --git a/.gitignore b/.gitignore index df140b2..2079eae 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.ipynb -*.nc *.cdf *.png *.tar.gz @@ -7,3 +6,13 @@ *.pyc *.p *.npy +*.DS_Store +*pycache* +olym* +inputtxt/*.txt +configtxt/2* +logs/* +samples/* +outputfig/* +nexrad_obs_config.txt +nexrad_wrf_config.txt diff --git a/GeneralFunctions.py b/GeneralFunctions.py index ade2f0e..7667e84 100644 --- a/GeneralFunctions.py +++ b/GeneralFunctions.py @@ -35,7 +35,8 @@ #import analysis_tools as AT #import lightning_tools as LT -from CSU_RadarTools.csu_radartools import csu_fhc +#from CSU_RadarTools.csu_radartools import csu_fhc +import csu_fhc import general_tools as gentools import RadarConfig from matplotlib.colors import from_levels_and_colors @@ -118,7 +119,7 @@ def cfad(data = None,cfad =None,hts=None,value_bins=None, above=2.0, below=15.0, ############################################################################################################# def cfad_plot(var,data = None,cfad=None, hts=None, nbins=20, ax=None, maxval=10.0, above=2.0, below=15.0, bins=None, - log=False, pick=None, z_resolution=1.0,levels=None,tspan =None,cont = False, rconf = None,mask = None,**kwargs): + log=False, pick=None, ylim=None, xlim=None, xlab=None, cbyes=0, z_resolution=1.0,levels=None,tspan =None,cont = False, rconf = None,mask = None,**kwargs): if hts is None: print ('please provide nominal heights to cfad_plot') @@ -156,10 +157,10 @@ def cfad_plot(var,data = None,cfad=None, hts=None, nbins=20, ax=None, maxval=10. # plot the CFAD cfad_ma = np.ma.masked_where(cfad==0, cfad) - print(np.shape(cfad_ma),'cfad shape') + #print(np.shape(cfad_ma),'cfad shape') + levs = [0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.] + cols = ['lightgrey','silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet','thistle'] if cont is True: - levs = [0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.] - cols = ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet'] try: pc = ax.contourf(bins[:-1],reshts,cfad_ma,levs,colors=cols,extend = 'both') except TypeError as e: @@ -168,17 +169,33 @@ def cfad_plot(var,data = None,cfad=None, hts=None, nbins=20, ax=None, maxval=10. else: if levels is not None: - cmap, norm = from_levels_and_colors([0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.], ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet']) # mention levels and colors here + cmap, norm = from_levels_and_colors(levs,cols) # mention levels and colors here #print cmap pc = ax.pcolormesh(bins, reshts, cfad_ma, norm=norm, cmap=cmap) else: pc = ax.pcolormesh(bins, reshts, cfad_ma, vmin=0, vmax=maxval, norm=norm, **kwargs) - cb = fig.colorbar(pc, ax=ax) - cb.set_label('Frequency (%)') - ax.set_ylabel('Height (km MSL)') -# try: + ax.set_xlabel(xlab,fontsize=16) + ax.tick_params(axis='both', which='major', labelsize=16) + ax.set_xlim(xlim) + ax.set_ylim(ylim) + if cbyes == 1: + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.02,bur,0.02,hur] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(pc,cax=cbar_ax) + cbt.set_ticks(levs) + cbt.ax.tick_params(labelsize=16) + cbt.set_label('Frequency (%)', fontsize=16, rotation=270, labelpad=15) + + # cb = fig.colorbar(pc, ax=ax) + # cb.set_label('Frequency (%)',fontsize=16,rotation=270,labelpad=20) + # cb.ax.tick_params(labelsize=16) + ax.set_yticks([]) + ax.set_yticklabels([]) + ax.tick_params(axis='y', which='major', labelsize=0) + if rconf is not None: if var == 'DRC' or var == 'DRS': varn = rconf.zdr_name diff --git a/README b/README index 8adff29..b9a61e1 100644 --- a/README +++ b/README @@ -2,10 +2,18 @@ iPOLARRIS This is a complimentary program to POLARRIS-f, a forward model for producing polarimetric radar observations from model simulations. This suite of tools reads in gridded data (from radar or simulation), runs radar retrievals, and makes standardized plots. +***NOTE: ipol.sh only works for iMAC environment.*** + Written by Brenda Dolan Colorado State University, Dept. Atmos. Sci. bdolan@atmos.colostate.edu May 2017 +Contributions by Anthony Di Stefano +The University of British Columbia, Dept. EOAS +adistefa@eoas.ubc.ca +October 2020 - Present + based on code from Brody Fuchs +Last updated on August 16, 2021 diff --git a/RadarConfig.py b/RadarConfig.py index 401c3b1..f9eda01 100644 --- a/RadarConfig.py +++ b/RadarConfig.py @@ -6,13 +6,14 @@ import matplotlib.pyplot as plt from copy import deepcopy import datetime as dt - +import pyart class RadarConfig(object): - + def __init__(self, dz='DZ', zdr='DR', kdp='KD', ldr='LH', rho='RH', hid = 'HID',conv='Con', temp='T', x='x', y='y', z='z', u='U', v='V',rr='RR', w='Wvar',vr='VR',mphys='None',exper = 'Case', - band = 'C',lat_0 = 0,lon_0=90.0,lat_r=None,lon_r=None,lat=None,lon=None,tm = None,radar_name = None): + band = 'C',lat_0 = 0,lon_0=90.0,lat_r=None,lon_r=None,lat=None,lon=None,tm = None,radar_name = None, + color_blind = False): # ******** first the polarimetric stuff ************* self.dz_name = dz self.zdr_name = zdr @@ -20,6 +21,8 @@ def __init__(self, dz='DZ', zdr='DR', kdp='KD', ldr='LH', rho='RH', hid = 'HID', self.ldr_name = ldr self.rho_name = rho self.rr_name = rr + if self.rr_name == None: + self.rr_name = 'RR' self.temp_name = temp self.hid_name = hid self.vr_name = vr @@ -53,33 +56,39 @@ def __init__(self, dz='DZ', zdr='DR', kdp='KD', ldr='LH', rho='RH', hid = 'HID', self.date = tm self.radar_name = radar_name - - self.species = np.array(['DZ','RN','CR','AG','WS','VI','LDG','HDG','HA','BD']) - self.hid_colors = ['White','LightBlue','MediumBlue','Darkorange','LightPink','Cyan','DarkGray',\ - 'Lime','Yellow','Red','Fuchsia'] + self.species_long = np.array(['Drizzle','Rain','Ice\nCrystals','Snow\nAggre-\ngates','Wet\nSnow','Vertical\nIce','Low-\nDensity\nGraupel','High-\nDensity\nGraupel','Hail','Big\nDrops']) + #self.hid_colors = ['White','LightBlue','MediumBlue','Darkorange','LightPink','Cyan','DarkGray',\ + # 'Lime','Yellow','Red','Fuchsia'] + self.hid_colors = ['LightBlue','MediumBlue','Darkorange','Purple','Cyan','DarkGray',\ + 'Lime','Yellow','Red','Fuchsia'] self.pol_vars = np.array([self.dz_name, self.zdr_name, self.kdp_name, self.ldr_name, self.rho_name, self.hid_name]) self.cs_colors = ['#FFFFFF', 'DodgerBlue', 'Red', 'Khaki'] self.cs_labels = ['', 'Strat', 'Conv', 'Mixed'] - self.set_dbz_colorbar() + self.cfad_levs = [0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.] + self.cfad_cols = ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet'] + + self.set_dbz_colorbar(color_blind=color_blind) self.set_hid_colorbar() self.set_cs_colorbar() # Now just set some defaults - self.lims = {dz: [0,80], zdr: [-1, 3], kdp: [-0.5, 3], ldr: [-35, -20], rho: [0.95, 1.00], hid: [0, len(self.species)+1],w:[-25,25],vr:[-25,25],self.cs_name:[0,4],self.rr_name:[0.01,150]} - self.delta = {dz: 10, zdr: 1, kdp: 1, ldr: 5, rho: 0.005, hid: 1,w:5,vr:5,self.cs_name:1,self.rr_name:10} - self.units = {dz: '(dBZ)', zdr: '(dB)', kdp: '($^{\circ}$/km)', ldr: '(dB)', rho: '', hid: '',w:'m s$^{-1}$',vr:'m s$^{-1}$',self.cs_name:'',self.rr_name:'mm hr$^{-1}$'} - self.names = {dz: 'Z', zdr: 'Z$_{DR}$', kdp: 'K$_{dp}$', ldr: 'LDR', rho: r'$\rho_{hv}$', hid: '',w:'',vr:'V$_r$',self.cs_name:'',self.rr_name:'RR'} - self.longnames = {dz: 'Reflectivity', zdr: 'Differntial reflectivity', kdp: 'Specific differential phase',\ - ldr: 'Linear depolarization ratio', rho: 'Correlation coefficient', hid: 'Hydrometeor identification',w:'Vertical Velocity',vr:'Radial Velocity',\ - self.cs_name: 'Convective/Stratiform',self.rr_name:'Rain Rate'} - self.cmaps = {dz: self.temp_cmap, zdr: plt.cm.Spectral_r, kdp: plt.cm.gist_heat_r, \ - ldr: plt.cm.gist_rainbow_r, rho: plt.cm.jet, hid: self.hid_cmap,w:plt.cm.seismic,vr:plt.cm.bwr,self.cs_name: self.cs_cmap,self.rr_name:plt.cm.Spectral_r} + self.lims = {dz: [0,80], zdr: [-1, 3], kdp: [-0.5, 3], ldr: [-35, -20], rho: [0.95, 1.00], hid: [0,len(self.species)+1],w:[-25,25],vr:[-25,25],self.cs_name:[0,4],self.rr_name:[0,30],self.temp_name:[-30,30]} + self.cfbins = {dz: np.arange(-10,60.1,1), zdr: np.arange(-2,6.01,0.05), kdp: np.arange(-2,2.01,0.05), rho: np.arange(0.5,1.01,0.02), hid: '' , w: np.arange(-25,25.1,0.5), self.temp_name: np.arange(20,-60.1,-5)} + self.delta = {dz: 10, zdr: 1, kdp: 1, ldr: 5, rho: 0.005, hid: 1,w:5,vr:5,self.cs_name:1,self.rr_name:10,self.temp_name:5} + self.units = {dz: '(dBZ)', zdr: '(dB)', kdp: '($^{\circ}$ km$^{-1}$)', ldr: '(dB)', rho: '', hid: '',w:'(m s$^{-1}$)',vr:'(m s$^{-1}$)',self.cs_name:'',self.rr_name:'(mm hr$^{-1}$)',self.temp_name:'C'} + self.names = {dz: 'Z', zdr: 'Z$_{DR}$', kdp: 'K$_{dp}$', ldr: 'LDR', rho: r'$\rho_{hv}$', hid: '',w:'',vr:'V$_r$',self.cs_name:'',self.rr_name:'RR',self.temp_name:'T'} + self.names_uc = {dz: 'REF', zdr: 'ZDR', kdp: 'KDP', ldr: 'LDR', rho: 'RHO', hid: 'HID',w:'W',vr:'VRAD',self.cs_name:'',self.rr_name:'RR',self.temp_name:'T'} + self.longnames = {dz: 'Reflectivity', zdr: 'Differential Reflectivity', kdp: 'Specific Differential Phase',\ + ldr: 'Linear Depolarization Ratio', rho: 'Correlation Coefficient', hid: 'Hydrometeor Identification',w:'Vertical Velocity',vr:'Radial Velocity',\ + self.cs_name: 'Convective/Stratiform',self.rr_name:'Rain Rate',self.temp_name:'Temperature'} + #self.cmaps = {dz: self.temp_cmap, zdr: plt.cm.Spectral_r, kdp: plt.cm.gist_heat_r, ldr: plt.cm.gist_rainbow_r, rho: plt.cm.jet, hid: self.hid_cmap,w:plt.cm.seismic,vr:plt.cm.bwr,self.cs_name: self.cs_cmap,self.rr_name:plt.cm.Spectral_r,self.temp_name:'RdYlBu_r'} + self.cmaps = {dz: self.temp_cmap, zdr: plt.cm.Spectral_r, kdp: plt.cm.gist_heat_r, ldr: plt.cm.gist_rainbow_r, rho: plt.cm.jet, hid: self.hid_cmap,w:plt.cm.seismic,vr:plt.cm.bwr,self.cs_name: self.cs_cmap,self.rr_name:plt.get_cmap('pyart_HomeyerRainbow'),self.temp_name:'RdYlBu_r'} self.ticklabels = {dz: np.arange(0, 90, 10), zdr: np.arange(-1, 4, 1), kdp: np.arange(-0.5, 4.5, 1), ldr: np.arange(-35, -15, 5), rho: np.arange(0.95, 1.01, 0.005), hid: np.append('', self.species),w:np.arange(-25,30.0,5.0),vr:np.arange(-25,30.0,5.0), - self.cs_name: self.cs_labels,self.rr_name:[0.1,1,10,30,50,70,100,130,150]} + self.cs_name: self.cs_labels,self.rr_name:[0.1,1,10,30,50,70,100,130,150],self.temp_name:np.arange(-30,35,5)} ############################################################################################################# def print_date(self,tm=None, fmt='%Y-%m-%d %H:%M:%S %Z'): @@ -126,13 +135,19 @@ def sav_title(self,tm = None): return extra ############################################################################################################# - def set_dbz_colorbar(self, color_list=None): + def set_dbz_colorbar(self, color_list=None, color_blind=False): if color_list is None: # just use the default here - radarcbar = ['PeachPuff','Aqua','DodgerBlue','MediumBlue','Lime', \ - 'LimeGreen','Green','Yellow','Orange','OrangeRed', \ - 'Red', 'Crimson','Fuchsia','Indigo','DarkCyan','White'] - else: + if color_blind is not True: + radarcbar = ['PeachPuff','Aqua','DodgerBlue','Blue','Lime', \ + 'LimeGreen','Green','Yellow','Orange','DarkOrange','Red', \ + 'Crimson','Fuchsia','Purple','Indigo','MidnightBlue'] + #radarcbar = ['PeachPuff','Aqua','DodgerBlue','MediumBlue','Lime', \ + # 'LimeGreen','Green','Yellow','Orange','OrangeRed','Red', \ + # 'Crimson','Fuchsia','Indigo','DarkCyan','White'] + else: + radarcbar = ['Lavender', 'Thistle', 'Plum', 'MediumPurple', 'CornFlowerBlue', 'SkyBlue', 'PaleTurquoise', 'LightCyan', 'Yellow', 'Gold', 'Orange', 'DarkOrange', 'Chocolate', 'IndianRed', 'FireBrick', 'Maroon'] + else: radarcbar = deepcopy(color_list) temp_cmap = colors.ListedColormap(radarcbar) @@ -151,7 +166,8 @@ def set_hid_colorbar(self, color_list=None): hidcbar = deepcopy(color_list) self.hid_cmap = colors.ListedColormap(hidcbar) - self.boundshid = np.arange(0,12) + #self.boundshid = np.arange(0,12) + self.boundshid = np.arange(self.hid_cmap.N+1) self.normhid = colors.BoundaryNorm(self.boundshid, self.hid_cmap.N) ############################################################################################################# def set_cs_colorbar(self, color_list=None): diff --git a/RadarData.py b/RadarData.py index 1a3974a..ab2c5c9 100644 --- a/RadarData.py +++ b/RadarData.py @@ -20,6 +20,7 @@ import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt +#plt.style.use('./presentation.mplstyle') import os import sys #from pyhid import beta_functions, cdf_fhc, radar_calculations @@ -45,20 +46,15 @@ import csu_fhc import general_tools as gentools import RadarConfig - # Up here are just some general functions +np.set_printoptions(threshold=sys.maxsize) class RadarData(RadarConfig.RadarConfig): + def __init__(self, data,times, ddata = None,dz='DZ', zdr='DR', kdp='KD', ldr='LH', rho='RH', hid='HID',conv='Con',temp='T', x='x', y='y', z='z', u='U', v='V', w='Wvar', rr='RR',vr='VR',lat=None, lon=None, band='C',exper='CASE',lat_r=None,lon_r=None,mphys=None,dd_data = None,z_thresh=-10.0,cs_z = 2.0,zconv = 41.,zdr_offset=0, remove_diffatt = False,lat_0 = 0.0,lon_0=90.0,conv_types = ['CONVECTIVE'],strat_types = ['STRATIFORM'],mixed_types = ['UNCERTAIN'],mixr=['qr','qs','qc','qi','qh','qg'],return_scores=False,color_blind=False): - def __init__(self, data,times, ddata = None,dz='DZ', zdr='DR', kdp='KD', ldr='LH', rho='RH', hid='HID',conv='Con', - temp='T', x='x', y='y', z='z', u='U', v='V', w='Wvar', rr='RR',vr='VR',lat=None, lon=None, band='C',exper='CASE',lat_r=None,lon_r=None, - radar_name= None,mphys=None,dd_data = None,z_thresh=-10.0,cs_z = 2.0,zconv = 41.,zdr_offset=0, remove_diffatt = False,lat_0 = 0.0,lon_0=90.0, - conv_types = ['CONVECTIVE'],strat_types = ['STRATIFORM'],mixed_types = ['UNCERTAIN'],mixr=['qr','qs','qc','qi','qh','qg'],return_scores=False): - - super(RadarData, self).__init__(dz=dz, zdr=zdr, kdp=kdp, ldr=ldr, rho=rho, hid=hid, conv=conv,temp=temp, x=x, y=y,lat_0=lat_0,lon_0=lon_0,lat_r=lat_r,lon_r=lon_r, - z=z, u=u, v=v, w=w,rr=rr,vr=vr,mphys=mphys,exper=exper,lat=lat,lon=lon,tm = times,radar_name = radar_name) + super(RadarData, self).__init__(dz=dz, zdr=zdr, kdp=kdp, ldr=ldr, rho=rho, hid=hid, conv=conv,temp=temp, x=x, y=y,lat_0=lat_0,lon_0=lon_0,lat_r=lat_r,lon_r=lon_r, z=z, u=u, v=v, w=w,rr=rr,vr=vr,mphys=mphys,exper=exper,lat=lat,lon=lon,tm = times,color_blind=color_blind) # ********** initialize the data ********************* # self.data = {} @@ -95,18 +91,28 @@ def __init__(self, data,times, ddata = None,dz='DZ', zdr='DR', kdp='KD', ldr='LH self.yind = 2 self.xind = 3 self.ntimes =1 -# if 'd' in self.data[self.z_name].dims: -# self.nhgts = np.shape(self.data[self.z_name].values)[self.zind][0] -# except: -# self.nhgts = np.shape(self.data[self.z_name].values) - self.nhgts = self.data[self.dz_name].sizes['z'] + if 'd' in self.data[self.z_name].dims: + self.nhgts = len(self.data[self.z_name].values[0]) + else: + self.nhgts = len(self.data[self.z_name].values) + #self.data[self.z_name].values = self.data[self.z_name].values[0] +# if 'd' in self.data[self.z_name].dims: +# self.nhgts = np.shape(self.data[self.z_name].values)[self.zind][0] +# else: +# self.nhgts = np.shape(self.data[self.z_name].values) +# print(self.data[self.z_name].values) +# print(self.data[self.dz_name].sizes[self.z_name]) +# self.nhgts = self.data[self.dz_name].sizes[self.z_name] # self.read_data_from_nc(self.radar_file) print ('calculating deltas') self.calc_deltas() print ('calculating rain area') self.radar_area() self.rr_name = rr - #print 'masking data' + if self.rr_name == None: + self.rr_name = 'RR' + + #print 'masking data' #print('masking data') #self.mask_dat() if remove_diffatt == True: @@ -122,13 +128,13 @@ def __init__(self, data,times, ddata = None,dz='DZ', zdr='DR', kdp='KD', ldr='LH # down here goes some zdr checking self.zdr_offset = 0 # initialize as 0 try: - self.top_index = np.where(self.data[self.z_name]== np.max(self.data[self.z_name]))[self.zind] + self.top_index = np.where(self.data[self.z_name]== max(self.data[self.z_name]))[self.zind] except: - self.top_index = np.where(self.data[self.z_name]== np.max(self.data[self.z_name]))[0] + self.top_index = np.where(self.data[self.z_name]== max(self.data[self.z_name]))[0] try: - self.bot_index = np.where(self.data[self.z_name]== np.min(self.data[self.z_name]))[self.zind] + self.bot_index = np.where(self.data[self.z_name]== min(self.data[self.z_name]))[self.zind] except: - self.bot_index = np.where(self.data[self.z_name]== np.min(self.data[self.z_name]))[0] + self.bot_index = np.where(self.data[self.z_name]== min(self.data[self.z_name]))[0] # if hasattr(self.nc,'Latitude_deg') == True: # print 'Getting attribute!' @@ -323,8 +329,11 @@ def mask_dat(self): def convert_t(self): # if want to pass a dictionary already - self.T.values=np.ma.masked_less(self.T.values,0) - self.T.values = self.T.values-273.15 + #self.T = np.ma.masked_less(self.T, 0) + #self.T.values=np.ma.masked_less(self.T.values,0) + self.T = self.T #- 273.15 + + #self.T.values = self.T.values-273.15 ############################################################################################################# def set_masks(self): @@ -338,11 +347,18 @@ def radar_area(self): else: vrcomp = self.data[self.vr_name].sel(d=0).max(axis=0).values whmask = np.where(vrcomp > -50) - x,y = self.convert_ll_to_xy(self.data[self.y_name].sel(d=0),self.data[self.x_name].sel(d=0)) + + if 'd' in self.data[self.x_name].dims: + x,y = self.convert_ll_to_xy(self.data[self.lat_name].sel(d=0),self.data[self.lon_name].sel(d=0)) + dx = np.average(np.diff(x.sel(y=0))) + dy = np.average(np.diff(y.sel(x=0))) + else: + x,y = self.convert_ll_to_xy(self.data[self.lat_name],self.data[self.lon_name]) + dx = np.average(np.diff(x)) + dy = np.average(np.diff(y)) + self.x = x.values self.y = y.values - dx = np.average(np.diff(x.sel(y=0))) - dy = np.average(np.diff(y.sel(x=0))) self.dx = dx self.dy = dy dummy=np.zeros_like(vrcomp) @@ -373,15 +389,16 @@ def valid_vars(self): def calc_deltas(self): # get grid sizes for x, y, z + if 'd' in self.data[self.x_name].dims: print,'calc deltas' - self.dx = np.average(np.abs(np.diff(self.data[self.x_name].sel(d=0,y=0)))) - self.dy = np.average(np.abs(np.diff(self.data[self.y_name].sel(d=0,x=0)))) - self.dz = np.average(np.abs(np.diff(self.data[self.z_name].sel(d=0)))) + self.dx = np.average(abs(np.diff(self.data[self.x_name].sel(d=0,y=0)))) + self.dy = np.average(abs(np.diff(self.data[self.y_name].sel(d=0,x=0)))) + self.dz = np.average(abs(np.diff(self.data[self.z_name].sel(d=0)))) else: - self.dx = np.average(np.abs(np.diff(self.data[self.x_name].values))) - self.dy = np.average(np.abs(np.diff(self.data[self.y_name].values))) - self.dz = np.average(np.abs(np.diff(self.data[self.z_name].values))) + self.dx = np.average(abs(np.diff(self.data[self.x_name].values))) + self.dy = np.average(abs(np.diff(self.data[self.y_name].values))) + self.dz = np.average(abs(np.diff(self.data[self.z_name].values))) @@ -410,11 +427,11 @@ def get_names(self): def _get_ab_incides(self, above=None, below=None): if above is not None: - bot_index = np.argsort(np.abs(self.data[self.z_name].values - above))[0] + bot_index = np.argsort(abs(self.data[self.z_name].values - above))[0] else: bot_index = deepcopy(self.bot_index) if below is not None: - top_index = np.argsort(np.abs(self.data[self.z_name].values - below))[0] + top_index = np.argsort(abs(self.data[self.z_name].values - below))[0] else: top_index = deepcopy(self.top_index) @@ -469,7 +486,7 @@ def zdr_check(self, bins=np.arange(-3, 3, 0.15), thresh=0.3): offset = edges[maxarg]+dbin # print hist, edges self.zdr_offset = deepcopy(offset) - if np.abs(offset) >= thresh: + if abs(offset) >= thresh: self.zdr_correct() def zdr_correct(self): @@ -556,29 +573,35 @@ def interp_sounding(self): """This will take the sounding data and interpolate it to the radar coordinates""" self.gridded_height = np.zeros(self.data[self.dz_name].shape) #print(self.x) - for i in range(self.data[self.z_name].shape[0]): - self.gridded_height[:,:,i,...] = self.data[self.z_name][i] + if 'd' in self.data[self.z_name].dims: + for i in range(self.data[self.z_name].shape[1]): + self.gridded_height[:,i,:,:] = self.data[self.z_name][0,i] + else: + for i in range(self.data[self.z_name].shape[0]): + #self.gridded_height[:,:,i,...] = self.data[self.z_name][i] + self.gridded_height[:,i,:,:] = self.data[self.z_name][i] self.T = np.interp(self.gridded_height, self.snd_height, self.snd_temp) + self.add_field((self.data[self.dz_name].dims,self.T,), self.temp_name) ############################################################################################################# def get_T_height(self, temp, interp=False): - temp_index = np.argmin(np.abs(self.T[:,0,0] - temp)) + temp_index = np.argmin(abs(self.T[:,0,0] - temp)) return self.gridded_height[0,:,0,0][temp_index] ############################################################################################################# ############ Here is calling CSU radartools for HID, RR, etc... ############################ ############################################################################################################# - def calc_pol_analysis(self,**kwargs): + def calc_pol_analysis(self,tm,config,**kwargs): self.set_hid(use_temp = 'True',band=self.band,zthresh = self.z_thresh,return_scores=self.return_scores) print("running pol rain") - if self.mphys == 'obs': + #if self.mphys == 'obs': - self.calc_qr_pol() - self.calc_rr_pol(**kwargs) + self.calc_qr_pol() + self.calc_rr_pol(tm,config,**kwargs) ############################################################################################################# @@ -608,20 +631,21 @@ def set_hid(self, band=None, use_temp=False, name='HID',zthresh = -9999.0,return # print('shape holds',np.shape(dzhold)) if use_temp and hasattr(self, 'T'): #print ('Using T!') - tdum = self.T[v,...] -# print('shape tdum',type(tdum)) + #tdum = self.T[v,...] + tdum = self.T[v,:,:,:] #print(type(tdum),'tdum is') #print('T:',np.shape(tdum)) else: tdum = None - - hiddum = csu_fhc.csu_fhc_summer(dz=dzhold, zdr=np.squeeze(self.data[self.zdr_name].sel(d=v)).values, rho=np.squeeze(self.data[self.rho_name].sel(d=v)).values, - kdp=np.squeeze(self.data[self.kdp_name].sel(d=v)).values, band=self.hid_band, use_temp=True, T=tdum, return_scores=self.return_scores) + #print('You have entered hid band:',self.hid_band, 'ln 624 RadarData') + hiddum = csu_fhc.csu_fhc_summer(dz=dzhold, zdr=np.squeeze(self.data[self.zdr_name].sel(d=v)).values, rho=np.squeeze(self.data[self.rho_name].sel(d=v)).values, kdp=np.squeeze(self.data[self.kdp_name].sel(d=v)).values, band=self.hid_band, use_temp=True, T=tdum, return_scores=self.return_scores) # scores.append(scoresdum) #hiddum = np.argmax(scoresdum,axis=0)+1 # print(np.shape(tdum),'tdum') - whbad = np.where(np.logical_and(hiddum ==1,tdum <-5.0)) + #whbad = np.where(np.logical_and(hiddum ==1,tdum <-5.0)) + if tdum.any() == None: whbad = np.where(np.logical_and(hiddum == 1,tdum == None)) + else: whbad = np.where(np.logical_and(hiddum == 1,tdum < -5.0)) dzmask = np.where(np.isnan(dzhold)) hiddum[whbad] = -1 hiddum = np.array(hiddum,dtype='float64') @@ -757,7 +781,7 @@ def calc_qr_pol(self): self.add_field((self.data[self.dz_name].dims,qrr,), 'rqr') print('saved data') - def calc_rr_pol(self,band=None): + def calc_rr_pol(self,tm,config,band=None): # import pydisdrometer as pyd # import pytmatrix as pyt @@ -845,19 +869,25 @@ def calc_rr_pol(self,band=None): print ('Sorry, your wavelength has not been run yet! Return to first principles!') return - rr,rm = csu_blended_rain_julie.csu_hidro_rain(self.data[self.dz_name].values,self.data[self.zdr_name].values,self.data[self.kdp_name].values,z_c,z_m,k_c,k_m,azdrk_coeff,bzdrk_coeff, - czdrk_coeff,azzdr_coeff,bzzdr_coeff,czzdr_coeff,band=band,fhc=self.hid) + rr_arr,rm = csu_blended_rain_julie.csu_hidro_rain(self.data[self.dz_name].values,self.data[self.zdr_name].values,self.data[self.kdp_name].values,z_c,z_m,k_c,k_m,azdrk_coeff,bzdrk_coeff, czdrk_coeff,azzdr_coeff,bzzdr_coeff,czzdr_coeff,band=band,fhc=self.hid) + #rr_arr,rm = csu_blended_rain_julie.calc_blended_rain(self.data[self.dz_name].values,self.data[self.zdr_name].values,self.data[self.kdp_name].values,z_c,z_m,k_c,k_m,None,None,azdrk_coeff,bzdrk_coeff, czdrk_coeff,azzdr_coeff,bzzdr_coeff,czzdr_coeff,band=band) # mask=np.where(np.isnan(self.data[self.dz_name].values)) # rr[mask]=np.nan # rm[mask]=-1 - self.add_field((self.data[self.dz_name].dims,rr,), 'RRP') - self.add_field((self.data[self.dz_name].dims,rm,), 'RRM') - if self.rr_name ==None: - self.rr_name ='RRP' + self.add_field((self.data[self.dz_name].dims,rr_arr,),self.rr_name) + self.add_field((self.data[self.dz_name].dims,rm,),'RRM') whbad = np.where(np.isnan(self.data[self.dz_name])) - self.data['RRP'].values[whbad]=np.nan + self.data[self.rr_name].values[whbad]=np.nan self.data['RRM'].values[whbad]=-1 + + it = self.data[self.rr_name].shape[0] + print('\nSaving RR to files...') + for ii in tqdm(range(it)): + filepath = config['rr_dir']+'/RR_hidro_'+config['exper']+'_'+str(tm[ii].strftime('%Y%m%d_%H%M%S'))+'.nc' + if not os.path.isfile(filepath): self.data[self.rr_name].sel(d=ii).to_netcdf(path=filepath, mode='w') + print('') + return ############################################################################################################# @@ -868,7 +898,7 @@ def score_xsec_plot(self, y=None, title_flag=False, *args, **kwargs): if y is None: y_ind = int(len(self.data[self.y_name])/2.0) else: - y_ind = np.argmin(np.abs(y - self.data[self.y_name])) + y_ind = np.argmin(abs(y - self.data[self.y_name])) fig, ax = plt.subplots(5,2, figsize = (9,9)) @@ -885,10 +915,10 @@ def score_xsec_plot(self, y=None, title_flag=False, *args, **kwargs): cbar_ax = fig.add_axes([0.15, 0.06, 0.7, 0.03]) cb = fig.colorbar(dummy, cax = cbar_ax, orientation = 'horizontal') - cb.set_label('$\mu$ score') + cb.set_label(r'$\mu$'+' score') if title_flag: - fig.suptitle('%s %s Cross Section HID scores' %(self.print_date(), self.radar_name), fontsize = 14) + fig.suptitle('%s %s Cross Section HID scores' %(self.print_date(), self.band+'-band'), fontsize = 14) return fig, ax @@ -900,8 +930,7 @@ def score_cappi_plot(self, z=1.0, title_flag=False, *args, **kwargs): "CAPPI plot showing scores for all species, used as HID analysis tool" # first, get the appropriate z index from the z that's wanted in altitude - z_ind = np.argmin(np.abs(z - self.data[self.z_name])) - + z_ind = np.argmin(abs(z - self.data[self.z_name])) fig, ax = plt.subplots(5,2, figsize = (9,9)) @@ -917,330 +946,208 @@ def score_cappi_plot(self, z=1.0, title_flag=False, *args, **kwargs): cbar_ax = fig.add_axes([0.15, 0.06, 0.7, 0.03]) cb = fig.colorbar(dummy, cax = cbar_ax, orientation = 'horizontal') - cb.set_label('$\mu$ score') + cb.set_label(r'$\mu$'+' score') if title_flag: - fig.suptitle('%s %s CAPPI HID scores' %(self.print_date(), self.radar_name), fontsize = 14) + fig.suptitle('%s %s CAPPI HID scores' %(self.print_date(), self.band+'-band'), fontsize = 14) return fig, ax + def xsec(self, var, y=None, xlim=None, zmax=None, cbar=1, ts = None,varlist=None, ax=None, title_flag=False, vectors=None, cblabel=None, res=2.0,cbpad=0.03, labels=True, xlab=False, ylab=False, latlon=False, lblsz=16, lblpad=15, **kwargs): + + if ts is not None: + try: + tmind = np.where(np.array(self.date) == ts)[0][0] + except IndexError as e: + tmind = np.where(np.array(self.date) == ts)[0] + + if not xlim: + xmin, xmax = np.floor(self.data[self.x_name].values.min()), np.ceil(self.data[self.x_name].values.max()) + else: + xmin, xmax = xlim[0], xlim[1] + if not zmax: + zmax = self.data[self.z_name].values.max() + if 'y' in self.data[self.x_name]: + xdataset = self.data[self.x_name].sel(x=slice(xmin,xmax),y=slice(ymin,ymax)) + else: + xdataset = self.data[self.x_name].sel(x=slice(xmin,xmax)) -### NOW WE GET DOWN TO THE PLOTTING FUNCTIONS HERE + zdataset = self.data[self.z_name].sel(z=slice(0,zmax)) + if 'd' in xdataset: + xdat = np.squeeze(xdataset.sel(d=tmind).values) + zdat = np.squeeze(zdataset.sel(d=tmind).values) + else: + xdat = np.squeeze(xdataset.values) + zdat = np.squeeze(zdataset.values) -########### STARTING WITH CROSS SECTIONS ################ + dataset = self.data[var].sel(z=slice(0,zmax),y=y,x=slice(xmin,xmax)) + data = np.squeeze(dataset.sel(d=tmind).values) + data = np.ma.masked_where(~np.isfinite(data),data) + + if var.startswith('HID'): + data = np.ma.masked_where(data < 1,data) - def xsec(self, var, y=None, xlim=None, zlim=None, ts = None,varlist=None, ax=None, title_flag=False, - vectors=None, cblabel=None, res=2.0,cbpad=0.03, **kwargs): - "Just one axis cross-section plot of a variable" - # first, get the appropriate y index from the y that's wanted - if ts is None: - ts=self.date[0] - tmind = np.where(np.array(self.date) == ts)[0][0] - #print(tmind,'tmind in xsec') - tsi = 0 -# print('ts in xsec is ',type(np.array(ts))) if ax is None: - fig, ax = plt.subplots() + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(111) else: - # ax has been passed in, do nothing to ax, but need to get the parent fig fig = ax.get_figure() - if var in self.data.variables.keys(): -# print('952',y,self.y_name,self.data[self.y_name].dims) - if y is None: - y_ind = int(len(self.data[self.y_name].values)/2.0) - else: - if self.y_name == 'latitude': - y_ind = self.get_ind(y,np.squeeze(self.data[self.y_name].sel(x=0,d=tmind).values)) - #print('trying to find', y,y_ind) - #print('yind',y_ind,y,self.data[self.y_name].sel(x=0,d=0).values) - else: - y_ind = y - - if y is None: - y_ind = int(((self.data[self.y_name].min().values)-self.data[self.y_name].max())/2.0) - y = self.data[self.y_name][y_ind] - - else: - if 'd' in self.data[self.y_name].dims: - y_ind = self.get_ind(y,self.data[self.y_name].sel(d=tmind).values) - if 'x' in self.data[self.y_name].dims: - y_ind = self.get_ind(y,self.data[self.y_name].sel(d=tmind,x=0).values) - else: - y_ind = self.get_ind(y,self.data[self.y_name].sel(d=tmind).values) - else: - y_ind = self.get_ind(y,self.data[self.y_name].values) - if xlim is None: - xmini, xmaxi = self.data[self.x_name].data.min(), self.data[self.x_name].data.max() + if var in self.lims.keys(): + dummy = ax.pcolormesh(xdat, zdat, data, vmin = self.lims[var][0], vmax = self.lims[var][1], cmap = self.cmaps[var], **kwargs) + else: + dat = self.data[var].values + dat[dat<-900.0]=np.nan + range_lim = np.nanmax(dat) - np.nanmin(dat) + dummy = ax.pcolormesh(xdat,zdat, data, + vmin = np.nanmin(dat), vmax = np.nanmax(dat),cmap = plt.cm.gist_ncar, **kwargs) + + ####### plotting limits getting set here ###### + if self.x_name == 'longitude': + if labels: + ax.set_xlabel('Distance E of Radar (km)', fontsize=lblsz) + ax.set_ylabel('Altitude (km MSL)', fontsize=lblsz) + ax.set_xlim([xmin,xmax]) + ax.tick_params(axis='both', which='major', labelsize=lblsz) else: - if self.x_name == 'longitude': - if 'd' in self.data[self.x_name].dims: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind,y=0).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind,y=0).values) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind).values) - - else: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(y=0).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(y=0).values) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].values) - else: - xmini, xmaxi = xlim - - - - if zlim is None: - zmin, zmax = self.data[self.z_name].values.min(), self.data[self.z_name].values.max() - zlim = [zmin,zmax] - if 'd' in self.data[self.z_name].dims: - print('getting z mini, zmaxi') - zmini = self.get_ind(zlim[0],self.data[self.z_name].sel(d=tmind).values) - zmaxi = self.get_ind(zlim[1],self.data[self.z_name].sel(d=tmind).values) + if xlab: + ax.set_xlabel('Distance E of Radar (km)', fontsize=lblsz) + ax.tick_params(axis='x', which='major', labelsize=lblsz) else: - print('d is not in dims') - zmini = self.get_ind(zlim[0],self.data[self.z_name].values) - zmaxi = self.get_ind(zlim[1],self.data[self.z_name].values) - else: - zmini = zlim[0] - zmaxi = zlim[1] - xmin, xmax = xlim - zmin, zmax = zlim - # now actually doing the plotting - ##Adding this here because if the x and y are in reverse order, the indices do not work with the slice. -# ylimtest = [ymin,ymax] -# #when these are negative latitudes, then the 0th value is > the 1st value -# ymin,ymax = [np.min(ylimtest),np.max(ylimtest)] - - ##Adding this here because if the x and y are in reverse order, the indices do not work with the slice. - xlimtest = [xmini,xmaxi] - #when these are negative latitudes, then the 0th value is > the 1st value - xmini,xmaxi = [np.min(xlimtest),np.max(xlimtest)] - - #print self.data[self.x_name].shape, self.data[self.z_name].shape, self.data[var][:,y_ind,:].shape - #print self.data[self.z_name] - - #print xmini,xmaxi,zmini,zmaxi - # if this variable is already included in the defaults, then this is straightforward -# print (tsi, tmind, zmini,zmaxi,xmini,xmaxi,y_ind,var) - # print zmini,zmaxi,y_ind,xmini,xmaxi -# print('ts is ',ts) - if self.y_name == 'latitude': - #print(y_ind,xmini,xmaxi,'lats and lons') -# print('yind is ',y_ind,tmind,zmini,zmaxi,xmini,xmaxi) - data = np.squeeze(self.data[var].sel(d=tmind,z=slice(zmini,zmaxi),y=y_ind,x=slice(xmini,xmaxi))) - else: - data = (self.data[var].sel(d=tmind,z=slice(zmini,zmaxi),y=y,x=slice(xlim[0],xlim[1])).values) - # if np.shape(data) > 2: - # data = np.squeeze(self.data[var].sel(z=slice(zmini,zmaxi),x=slice(xmini,xmaxi)).data) - - - if 'y' in self.data[self.x_name].dims: - if 'd' in self.data[self.x_name].dims: - xdat = np.squeeze(self.data[self.x_name].sel(d=tmind,x=slice(xmini,xmaxi),y=slice(y_ind,y_ind+1))) + ax.set_xticklabels([]) + ax.xaxis.set_ticks_position('none') + if ylab: + ax.set_ylabel('Altitude (km MSL)', fontsize=lblsz) + ax.tick_params(axis='y', which='major', labelsize=lblsz) else: - xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi),y=slice(y_ind,y_ind+1))) - + ax.set_yticklabels([]) + ax.yaxis.set_ticks_position('none') + + else: + if labels: + ax.set_xlabel('Distance E of radar (km)',fontsize=lblsz) + ax.set_ylabel('Altitude (km MSL)',fontsize=lblsz) + ax.tick_params(axis='both', which='major', labelsize=lblsz) else: - if 'd' in self.data[self.x_name].dims: - xdat = np.squeeze(self.data[self.x_name].sel(d=tmind,x=slice(xmini,xmaxi))) + if xlab: + ax.set_xlabel('Distance E of radar (km)',fontsize=lblsz) + ax.tick_params(axis='x', which='major', labelsize=lblsz) + else: + ax.set_xticklabels([]) + ax.xaxis.set_ticks_position('none') + if ylab: + ax.set_ylabel('Altitude (km MSL)',fontsize=lblsz) + ax.tick_params(axis='y', which='major', labelsize=lblsz) else: - xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi))) -# print ('zmini,zmaxi',zmini,zmaxi) - - if 'd' in self.data[self.z_name].dims: - zdat = np.squeeze(self.data[self.z_name].sel(d=tmind,z=slice(zmini,zmaxi))) - else: - zdat = np.squeeze(self.data[self.z_name].sel(z=slice(zmini,zmaxi))) - data = np.ma.masked_less(data,-900.0) - data = np.ma.masked_where(~np.isfinite(data),data) - print (np.shape(data),np.shape(xdat),np.shape(zdat),'ln 1053') - #print np.shape(xdat),np.shape(zdat) - # print 'data',np.shape(data),'zdat',np.shape(zdat),'xdat',np.shape(xdat) - if var in self.lims.keys(): - range_lim = self.lims[var][1] - self.lims[var][0] - - dummy = ax.pcolormesh(xdat,zdat, data, - vmin = self.lims[var][0], vmax = self.lims[var][1], cmap = self.cmaps[var], **kwargs) - else: - dat = self.data[var].values - dat[dat<-900.0]=np.nan - range_lim = np.nanmax(dat) - np.nanmin(dat) -# print('workign on {v}, sizes:'.format(v=var),np.nanmin(dat),np.nanmax(dat)) - - dummy = ax.pcolormesh(xdat,zdat, data, - vmin = np.nanmin(dat), vmax = np.nanmax(dat),cmap = plt.cm.gist_ncar, **kwargs) - if range_lim < 1: - cb_format = '%.2f' - if range_lim >= 1: - cb_format = '%.1f' - if range_lim >= 10: - cb_format = '%d' - - cb = fig.colorbar(dummy, ax=ax, fraction=0.03, format=cb_format, pad=cbpad) - if var in self.lims.keys(): - cb.set_label(' '.join([self.names[var], self.units[var]]).strip()) - if var != 'w' and var != self.vr_name: - cb.set_ticks(np.arange(self.lims[var][0], self.lims[var][1]+self.delta[var], self.delta[var])) - cb.set_ticklabels(self.ticklabels[var]) - else: - cb.set_label(var) - - - - ###### this sets the limits ####### - # print zmin, zmax - if self.x_name == 'longitude': - ax.axis([xmin, xmax, zmin, zmax]) - # ax.set_xlabel('Longitude') + ax.set_yticklabels([]) + ax.yaxis.set_ticks_position('none') + + ax.set_xlim([xmin,xmax]) + ax.set_xticks(np.linspace(xmin,xmax,5)) + ax.set_ylim([0,zmax]) + ax.set_yticks(np.linspace(0,zmax,6)) + ax.grid(color='grey', linestyle='-', linewidth=1) + + if cbar == 1: # call separate HID colorbar function for bar plots + if var.startswith('HID'): + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.015,bur,0.03,hur] + cbt = self.HID_barplot_colorbar(fig,cbar_ax_dims) + cbt.ax.tick_params(labelsize=16) + cbt.set_label(self.names_uc[var]+' '+self.units[var], fontsize=16, rotation=270, labelpad=20) else: - ax.axis([xmin, xmax, zmin, zmax]) - ax.set_xlabel('Distance E of radar (km)') - ax.set_ylabel('Altitude (km MSL)') - - - if vectors: + self.mycbar(fig,ax,dummy,self.longnames[var]+' '+self.units[var]) + + if cbar == 2 and var.startswith('HID'): + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur,bur-0.125,wur,0.03] + self.HID_barplot_colorbar(fig,cbar_ax_dims,orientation='horizontal',names='longnames', lblsz=12) + + if vectors: # try: -# print( zlim,xlim,ts,res) - self.xsec_vector(ax=ax, y=y,zlim=zlim,xlim=xlim,ts=ts,res=res) +# print( zmax,xlim,ts,res) + self.xsec_vector(ax=ax, y=y,zmax=zmax,xlim=xlim,ts=ts,res=res) # except Exception as e: # print ('Error trying to plot xsec vectors: {}'.format(e)) - if title_flag: - ax.set_title('%s %s Cross Section' %(ts, self.radar_name), fontsize = 14) + if title_flag: + ax.set_title('%s %s Cross Section' %(ts, self.band+'-band'), fontsize = 14) else: - print ('No data for this variable!') dummy = fig # print type(dummy),dummy - return dummy - -############################################################################################################# - - def xsec_multiplot(self, y=None, xlim=None, zlim=None, ts=None,varlist=None, vectors=None,res=2.0, **kwargs): - "multipanel cross-section plot showing all available polarimetric variables and HID, if available" - - # first, get the appropriate y index from the y that's wanted + return dummy, ax - if ts is None: - print('Recieved no time. Using 1st time') - ts=np.array(self.date)[0] - tmind = np.where(np.array(self.date) == ts)[0] - #print('tmind in xsec_multiplod',tmind) - - tsi = 0 - if y is None: - y_ind = int(((self.data[self.y_name].min().values)-self.data[self.y_name].max())/2.0) - y = self.data[self.y_name][y_ind] - - else: - if 'd' in self.data[self.y_name].dims: - y_ind = self.get_ind(y,self.data[self.y_name].sel(d=tmind).values) - if 'x' in self.data[self.y_name].dims: - y_ind = self.get_ind(y,self.data[self.y_name].sel(d=tmind,x=0).values) - else: - y_ind = self.get_ind(y,self.data[self.y_name].sel(d=tmind).values) - else: - y_ind = self.get_ind(y,self.data[self.y_name].values) - if xlim is None: - xmini, xmaxi = self.data[self.x_name].data.min(), self.data[self.x_name].data.max() - else: - if self.x_name == 'longitude': - if 'd' in self.data[self.x_name].dims: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind,y=0).values[0,:]) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind,y=0).values[0,:]) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind).values[0,:]) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind).values[0,:]) - - else: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(y=0).values[0,:]) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(y=0).values[0,:]) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].values[0,:]) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].values[0,:]) - else: - xmini, xmaxi = xlim - if zlim is None: - print("trying to get Z limits",self.data[self.z_name].values.min(),self.data[self.z_name].values.max()) - zmini = 0 - zmaxi = -1 - - # zmini, zmaxi = self.data[self.z_name].values.min(), self.data[self.z_name].values.max() - zlim = [zmini,zmaxi] - else: - zmini = zlim[0] - zmaxi = zlim[1] + + def xsec_multiplot(self, y=0.5, xlim=[], zmax=[], ts=None, res = 2.0, varlist=None, vectors=None, latlon=False, **kwargs): + + if ts is not None: + try: + tmind = np.where(np.array(self.date)==ts)[0][0] + except: + tmind = np.where(np.array(self.date)==ts)[0] -# if 'd' in self.data[self.z_name].dims: -# zmini = self.get_ind(zlim[0],self.data[self.z_name].sel(d=tmind).values) -# zmaxi = self.get_ind(zlim[1],self.data[self.z_name].sel(d=tmind).values) -# else: -# zmini = self.get_ind(zlim[0],self.data[self.z_name].values) -# zmaxi = self.get_ind(zlim[1],self.data[self.z_name].values) -# - # first get how many varialbes there are? if varlist is not None: good_vars = varlist else: good_vars = self.valid_vars() + nvars = len(good_vars) if 'scores' in good_vars: + print('needing to add + to HID, ln 1257 RadarData') if hasattr(self, 'scores'): nvars += 1 if nvars <= 3: ncols = 1 nrows = deepcopy(nvars) - figx = 7 - figy = 4*nrows + figx = 5 + figy = 3*nrows elif (nvars > 3 and nvars < 7): - ncols = 2 - nrows = int(np.ceil(nvars/2)) - figx = 12 - figy = 4*nrows + nrows = 2 + ncols = int(np.ceil(nvars/2)) else: ncols = 2 nrows = int(np.ceil(nvars/2)) - figx=16 - figy = 4*nrows - - fig, ax = plt.subplots(nrows, ncols, figsize = (figx, figy), sharex = True, sharey = True) - if not isinstance(ax, np.ndarray) or not isinstance(ax, list): ax = np.array([ax]) - axf = ax.flatten() + figx= 18 + figy = 18 + fig, ax = plt.subplots(nrows,ncols,figsize=(16,8),gridspec_kw={'wspace': 0.45, 'hspace': 0.07, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + + if not isinstance(ax, np.ndarray) or not isinstance(ax, list): + ax = np.array([ax]) + axf = ax.flatten() - # BF 3/30/16: TAKING OUT IMSHOW AND PUTTING IN PCOLORMESH for i, var in enumerate(good_vars): - if vectors is not None: - vect = vectors[i] -# print 'RadarData ln 992 vectors', vectors,vect + if var is None: + fig.delaxes(axf[i]) + continue else: - vect = None - dummy = self.xsec(var, ts=ts, y=y, vectors=vect, xlim=xlim, zlim=zlim, ax=axf[i],res=res, **kwargs) - # now do the HID plot, call previously defined functions - - -# fig.tight_layout() - fig.tight_layout() - fig.subplots_adjust(top = 0.94) + if vectors is not None: + vect = vectors[i] + else: + vect = None + botpanels = np.arange(nvars-ncols,nvars) + xlabbool = True if i in botpanels else False + lspanels = [ncols*n for n in range(0,nrows)] + ylabbool = True if i in lspanels else False + #dummy = self.xsec(var, ts=ts, y=y, vectors=vect, xlim=xlim, zmax=zmax, ax=axf[i],res=res,xlab=xlabbool,ylab=ylabbool,labels=False,lblsz=28,lblpad=28,**kwargs) + dummy = self.xsec(var, ts=ts, y=y, xlim=xlim, zmax=zmax, ax=axf[i],res=res,xlab=xlabbool,ylab=ylabbool,labels=False,latlon=latlon,**kwargs) - fig.suptitle('%s %s Cross Section y = %s' %(ts, self.radar_name,y), fontsize = 18) + axf[0].text(0, 1, '{e} {r}'.format(e=self.exper,r=self.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=20, color='k', zorder=10, weight='bold', transform=axf[0].transAxes) # (a) Top-left - return fig #, ax + axf[ncols-1].text(1, 1, '{d:%Y-%m-%d %H:%M:%S} UTC'.format(d=ts), horizontalalignment='right', verticalalignment='bottom', size=20, color='k', zorder=10, weight='bold', transform=axf[ncols-1].transAxes) # (a) Top-left + + axf[ncols-1].text(0.99, 0.99, 'y = {a} km'.format(a=y), horizontalalignment='right',verticalalignment='top', size=20, color='k', zorder=10, weight='bold', transform=axf[ncols-1].transAxes, bbox=dict(facecolor='w', edgecolor='none', pad=0.0)) + + return fig def get_ind(self,val,dat): - dum = np.abs(val - dat) - wh_t = np.squeeze(np.where(dum == np.min(dum))) + dum = abs(val - dat) + wh_t = np.squeeze(np.where(dum == min(dum))) try: t = (len(wh_t)) if t==1: @@ -1259,248 +1166,175 @@ def get_ind(self,val,dat): ######################### Here is the 4 stuff ############################## - def cappi(self, var, z=1.0, xlim=None, ylim=None, ax=None,ts = None, title_flag=False, vectors=None, cblabel=None, - labels=True, res = 2.0, thresh_dz=False,contour = None,**kwargs): - "Just make a Constant Altitude Plan Position Indicator plot of a given variable" + def cappi(self, var, z=1.0, xlim=[], ylim=[], latlon=False, ax=None, ts = None, title_flag=False, vectors=None, cblabel=None, labels=True, xlab=1, ylab=1, cbar=1, res = 2.0, thresh_dz=False,contours = None,statpt=False, dattype='obs', **kwargs): + + from copy import deepcopy + import cartopy.crs as ccrs + import xarray as xr - # first, get the appropriate z index from the z that's wanted in altitude - #z_ind = np.argmin(np.abs(z - self.data[self.z_name].data)) -# z_ind = self.get_ind(z,self.data[self.z_name].values) - if ts is not None: try: tmind = np.where(np.array(self.date)==ts)[0][0] except IndexError as e: tmind = np.where(np.array(self.date)==ts)[0] + + if latlon: - if z is None: - print('zin in 1258 is None. assuming 2') - z_ind = 2 + if 'd' in self.data[self.lon_name].dims: + lons = self.data[self.lon_name].sel(d=tmind).values + lats = self.data[self.lat_name].sel(d=tmind).values + else: + lons = self.data[self.lon_name].values + lats = self.data[self.lat_name].values - else: - z_ind = z -# if 'd' in self.data[self.z_name].dims: -# print('getting z-ind') -# z_ind = self.get_ind(z,np.squeeze(self.data[self.z_name].sel(d=tmind).values)) -# else: -# print('no d, getting z_ind 1266, z ',z) -# z_ind = self.get_ind(z,self.data[self.z_name].values) -# print('got z index for z:',z, z_ind) -# print('xlims 1203',xlim,tmind) - # print('xlim is',xlim) - if xlim is None: - xmint, xmaxt = self.data[self.x_name].values.min(), self.data[self.x_name].values.max() - xlimtest = [xmint,xmaxt] - #when these are negative latitudes, then the 0th value is > the 1st value - xlim = [np.min(xlimtest),np.max(xlimtest)] - if self.x_name == 'longitude': - if 'd' in self.data[self.x_name].dims: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind,y=0).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind,y=0).values) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind).values) + if not xlim: + xmin, xmax = lons[(0,0)], lons[(0,-1)] + ymin, ymax = lats[(0,0)], lats[(-1,0)] + else: + xmin, xmax = min(xlim), max(xlim) + ymin, ymax = min(ylim), max(ylim) - else: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(y=0).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(y=0).values) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].values) - else: - xmini = np.min(xlim) - xmaxi = np.max(xlim) + xshift = 0.5*(self.data[self.x_name].shape[0]-1) + xmin = np.where(lons[0,:] >= xmin)[0][0]-xshift + xmax = np.where(lons[0,:] <= xmax)[0][-1]-xshift + + yshift = 0.5*(self.data[self.y_name].shape[0]-1) + ymin = np.where(lats[:,0] >= ymin)[0][0]-yshift + ymax = np.where(lats[:,0] <= ymax)[0][-1]-yshift + + xdataset = self.data[self.lon_name].sel(x=slice(xmin,xmax),y=slice(ymin,ymax)) + ydataset = self.data[self.lat_name].sel(x=slice(xmin,xmax),y=slice(ymin,ymax)) - xmin, xmax = xlim + else: - if ylim is None: - ymint, ymaxt = self.data[self.y_name].values.min(), self.data[self.y_name].values.max() - ylimtest = [ymint,ymaxt] - #when these are negative latitudes, then the 0th value is > the 1st value - ylim = [np.min(ylimtest),np.max(ylimtest)] - # print 'ylim is None!' - if self.y_name == 'latitude': - ymint, ymaxt = self.data[self.y_name].values.min(), self.data[self.y_name].values.max() - ymini = self.get_ind(ymint,self.data[self.y_name].sel(d=tmind).values[:,0]) - ymaxi = self.get_ind(ymaxt,self.data[self.y_name].sel(d=tmind).values[:,0]) - ymin =ymint - ymax = ymaxt + if not xlim: xmin, xmax = self.data[self.x_name].values.min(), self.data[self.x_name].values.max() + else: xmin, xmax = min(xlim), max(xlim) + + if not ylim: ymin, ymax = self.data[self.x_name].values.min(), self.data[self.x_name].values.max() + else: ymin, ymax = min(ylim), max(ylim) - else: - ymini, ymaxi = self.data[self.y_name].values.min(), self.data[self.y_name].values.max() - else: - ymini = self.get_ind(ylim[0],self.data[self.y_name].sel(d=tmind).values[:,0]) - ymaxi = self.get_ind(ylim[1],self.data[self.y_name].sel(d=tmind).values[:,0]) - ymin = ylim[0] - ymax = ylim[1] + if 'y' in self.data[self.x_name].dims: xdataset = self.data[self.x_name].sel(x=slice(xmin,xmax),y=slice(ymin,ymax)) + else: xdataset = self.data[self.x_name].sel(x=slice(xmin,xmax)) - # else: -# -# ymini, ymaxi = ylim -# ymin = ylim[0] -# ymax = ylim[1] -# - ##Adding this here because if the x and y are in reverse order, the indices do not work with the slice. - ylimtest = [ymini,ymaxi] - #when these are negative latitudes, then the 0th value is > the 1st value - ymini,ymaxi = [np.min(ylimtest),np.max(ylimtest)] - - ##Adding this here because if the x and y are in reverse order, the indices do not work with the slice. - xlimtest = [xmini,xmaxi] - #when these are negative latitudes, then the 0th value is > the 1st value - xmini,xmaxi = [np.min(xlimtest),np.max(xlimtest)] -# ts=self.date - tsi = 0 + if 'x' in self.data[self.y_name].dims: ydataset = self.data[self.y_name].sel(x=slice(xmin,xmax),y=slice(ymin,ymax)) + else: ydataset = self.data[self.y_name].sel(y=slice(ymin,ymax)) + + if 'd' in xdataset.dims: + xdat = np.squeeze(xdataset.sel(d=tmind).values) + ydat = np.squeeze(ydataset.sel(d=tmind).values) + else: + xdat = np.squeeze(xdataset.values) + ydat = np.squeeze(ydataset.values) + + dataset = self.data[var].sel(z=z,x=slice(xmin,xmax),y=slice(ymin,ymax)) + + data = np.squeeze(dataset.sel(d=tmind).values) + data = np.ma.masked_where(~np.isfinite(data),data) + if var.startswith('HID'): + data = np.ma.masked_where(data < 1,data) + elif var.startswith('RR'): + data = np.ma.masked_where(data < 0.5,data) - # If ax is not given, open a fig and ax object. This is not advisable if ax is None: - fig, ax = plt.subplots() + if latlon: + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(111, projection=ccrs.Mercator()) + else: + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(111) else: - # ax has been passed in, do nothing to ax, but need to get the parent fig fig = ax.get_figure() - - #print np.shape(self.data[var]) -## try: -# print(xmini,xmaxi,ymini,ymaxi) -# print('tmind 1264',tmind,z_ind) -# print('1325',self.data.keys(),var) - - ###COMMENTING OUT FOR GCE. LET'S SEE WHAT HAPPENS. BD 1/11/2021 - #z_ind=self.get_ind(z,self.data[self.z_name]) - data = np.squeeze(self.data[var].sel(d=tmind,z=slice(z_ind,z_ind+1),x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values) - if np.ndim(data) == 3: - data = np.squeeze(self.data[var].sel(d=tmind,z=slice(z_ind,z_ind),x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values) - -# print("changing shape",np.shape(data)) - #print('lims',self.lims[var]) -## except: -# print 'ln1033',z_ind,ymini,ymaxi,xmini,xmaxi,var -# print np.shape(self.data[var].data) - -## data = np.squeeze(self.data[var].data[z_ind,ymini:ymaxi,xmini:xmaxi]) -# if len(np.shape(data)) > 2: -# # print 'data shape is wrong!',np.shape(data) -# data = data[0,...] - if 'd' in self.data[self.x_name].dims: - xdat = np.squeeze(self.data[self.x_name].sel(d=tmind,x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values) - ydat = np.squeeze(self.data[self.y_name].sel(d=tmind,x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values) - else: - xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi)).values)#,y=slice(ymini,ymaxi)).values) - ydat = np.squeeze(self.data[self.y_name].sel(y=slice(ymini,ymaxi)).values) - -# print 'xmini, xmaxi, xmin,xmax',xmini,xmaxi,xmin,xmax,ymini,ymaxi -# print xdat[xmax] -# data[dzmask] =np.nan - data = np.ma.masked_where(~np.isfinite(data),data) - #print(np.max(data)) -# print 'about to do plotting, ln 1113' if var in self.lims.keys(): - range_lim = self.lims[var][1] - self.lims[var][0] -# print 'in var',var - #print **kwargs - #print(np.min(xdat),np.min(ydat),np.shape(data),np.max(data)) - dummy = ax.pcolormesh(xdat,ydat, data, - vmin = self.lims[var][0], vmax = self.lims[var][1], cmap = self.cmaps[var])#, **kwargs) + if latlon: + dummy = ax.pcolormesh(xdat,ydat, data, vmin = self.lims[var][0], vmax = self.lims[var][1], cmap = self.cmaps[var], transform=ccrs.PlateCarree(), **kwargs) + else: + dummy = ax.pcolormesh(xdat,ydat, data, vmin = self.lims[var][0], vmax = self.lims[var][1], cmap = self.cmaps[var], **kwargs) + else: -# print ('unrecognized var',var) dat = self.data[var].data dat[dat<-900.0]=np.nan range_lim = np.nanmax(dat) - np.nanmin(dat) dummy = ax.pcolormesh(xdat,ydat, data, vmin = np.nanmin(dat), vmax = np.nanmax(dat), cmap = plt.cm.gist_ncar,**kwargs) -# print 'success in plotting. Ln 1126 returned ', type(dummy) -# print 'contour is:', contour - - if contour is not None: -# print 'Contour is not none',contour - if contour == 'CS': -# print 'contours!' - #print(np.shape(self.data[self.cs_name].sel(d=ts,z=z_ind,x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values)) -# print('CS keys',self.cs_name,tmind,z_ind,xmini,xmaxi,ymini,ymaxi) - - -# z_ind=1 -# print(z_ind,z,type(z_ind)) - - - csvals =np.squeeze(self.data[self.cs_name].sel(d=tmind,z=slice(z_ind,z_ind+1),x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values) -# csvals = deepcopy(self.data[var].sel(d=slice(ts,ts+1),z=slice(z_ind,z_ind)).values) -# csdats = deepcopy((self.data[self.cs_name].sel(d=slice(ts,ts+1),z=slice(z_ind,z_ind)))) -# #print(np.ndim(np.squeeze(csvals.values))) -# if np.ndim(np.squeeze(csvals)) == 3: -# csvals = deepcopy((self.data[var].sel(d=slice(ts,ts+1),z=slice(z_ind,z_ind+1)))) -# csdats = deepcopy((self.data[self.cs_name].sel(d=slice(ts,ts+1),z=slice(z_ind,z_ind+1)))) -# -# print(type(csvals),'csvals') -# mask = np.where(csdats.values >= 2) -# strat = np.where(csdats.values == 1) -# csvals[:] = 0 -# csvals[mask]=2 -# csvals[strat] = 1 -# print z_ind, z_ind+1 - #Note: CS is the same at every level so we don't need to slice along z at the exact vert height.... -# print('csvals shape',np.shape(csvals)) -# try: -# cs = np.squeeze(csdats.sel(x=slice(xmini,xmaxi),y=slice(ymini,ymaxi)).values) -# print('cs shape',np.shape(cs)) - ax.contour(xdat, ydat, csvals, levels=[1,2], colors=['k'], linewidths=[3], alpha=0.8,zorder=10) -# except: -# cs = np.squeeze(csdats.sel(x=slice(xmini, xmaxi), y=slice(ymini, ymaxi)).values) -# ax.contour(xdat,ydat,csvals,levels = [0,2],colors=['blue','k'],linewidths = [2],alpha = 0.8) - - - - if range_lim < 1: - cb_format = '%.2f' - if range_lim >= 1: - cb_format = '%.1f' - if range_lim >= 10: - cb_format = '%d' - - - if labels: - cb = fig.colorbar(dummy, ax=ax, fraction=0.03, pad=0.03, format=cb_format) - if var in self.lims.keys(): - #print('in the var lims loop') - cb.set_label(' '.join([self.names[var], self.units[var]]).strip()) - if var != self.vr_name: - #cb.set_ticks(np.arange(self.lims[var][0], self.lims[var][1]+self.delta[var], self.delta[var])) - cb.set_ticklabels(self.ticklabels[var]) - - else: - cb.set_label(var) -# cb.set_ticks(np.arange(self.lims[var][0], self.lims[var][1]+self.delta[var], self.delta[var])) -# cb.set_ticklabels(self.ticklabels[var]) - + if contours is not None: + if contours == 'CS': + csvals = np.squeeze(self.data[self.cs_name].sel(d=tmind,z=z,x=slice(xmin,xmax),y=slice(ymin,ymax)).values) + if latlon: + cb = ax.contour(xdat, ydat, csvals, levels=[1,2], colors=['k'], linewidths=[3], alpha=0.8, zorder=10, transform=ccrs.PlateCarree()) + else: + cb = ax.contour(xdat, ydat, csvals, levels=[1,2], colors=['k'], linewidths=[3], alpha=0.8, zorder=10) + + if not xlim: + + maxxs = [] + minxs = [] + maxys = [] + minys = [] - else: # if this variable is not included in the defaults, have a lot less customization - # can get around this with the **kwargs - dummy = ax.pcolormesh(self.data[self.x_name], self.data[self.y_name], self.data[var][z_ind,:,:], **kwargs) - - cb = fig.colorbar(dummy, ax=ax, fraction=0.03, pad=0.03) - if cblabel is not None: - cb.set_label(cblabel) + for ii in range(dataset.shape[0]): + if 'd' in xdataset.dims: + xdat_masked = deepcopy(xdataset.sel(d=ii).values) + ydat_masked = deepcopy(ydataset.sel(d=ii).values) + else: + xdat_masked = deepcopy(xdataset.values) + ydat_masked = deepcopy(ydataset.values) + if not latlon and xdat_masked.ndim == 1: xdat_masked,ydat_masked = np.meshgrid(xdat_masked,ydat_masked) + + xdat_masked = np.where(np.isnan(dataset.sel(d=ii).values),np.nan,xdat_masked) + ydat_masked = np.where(np.isnan(dataset.sel(d=ii).values),np.nan,ydat_masked) - ####### plotting limits getting set here ###### - if self.x_name == 'longitude': - #print('setting min and max',xmin,xmax,ymin,ymax) - ax.axis([xmin, xmax, ymin, ymax]) -# if labels: -# ax.set_xlabel('Longitude') -# ax.set_ylabel('Latitude') + minxs.append(np.nanmin(xdat_masked)) + maxxs.append(np.nanmax(xdat_masked)) + minys.append(np.nanmin(ydat_masked)) + maxys.append(np.nanmax(ydat_masked)) + + if latlon: + + minx = np.round(min(minxs)-0.1,1) + maxx = np.round(self.lon_0+(self.lon_0-min(minxs))+0.1,1) + miny = np.round(min(minys)-0.1,1) + maxy = np.round(max(maxys)+0.1,1) + + else: + + minx = np.round(min(minxs),1) + maxx = np.round(abs(min(minxs)),1) + miny = np.round(min(minys),1) + maxy = np.round(max(maxys),1) + else: - ax.axis([xmini, xmaxi, ymini, ymaxi]) - if labels: - ax.set_xlabel('Distance E of radar (km)') - ax.set_ylabel('Distance N of radar (km)') - + minx = min(xlim) + maxx = max(xlim) + miny = min(ylim) + maxy = max(ylim) + + self.co_gridlines(fig,ax,latlonyn=latlon,minx=minx,maxx=maxx,miny=miny,maxy=maxy,xlab=xlab,ylab=ylab) + + if statpt: + if latlon: ax.plot(self.lon_0,self.lat_0,markersize=16,marker='^',color='k',transform=ccrs.PlateCarree()) + else: ax.plot(0,0,markersize=16,marker='^',color='k') + + if cbar == 1: + if var.startswith('HID'): + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.015,bur,0.03,hur] + cbt = self.HID_barplot_colorbar(fig,cbar_ax_dims) + cbt.ax.tick_params(labelsize=16) + cbt.set_label(self.names_uc[var]+' '+self.units[var], fontsize=16, rotation=270, labelpad=20) + else: + self.mycbar(fig,ax,dummy,self.longnames[var]+' '+self.units[var]) + + elif cbar == 2 and var.startswith('HID'): + lur,bur,wur,hur = ax.get_position().bounds + if latlon: cbar_ax_dims = [lur,bur-0.075,wur,0.03] + else: cbar_ax_dims = [lur,bur-0.125,wur,0.03] + self.HID_barplot_colorbar(fig,cbar_ax_dims,orientation='horizontal',names='longnames', lblsz=14) + # Now check for the vectors flag, if it's there then plot it over the radar stuff if vectors is not None: # try: @@ -1513,86 +1347,24 @@ def cappi(self, var, z=1.0, xlim=None, ylim=None, ax=None,ts = None, title_flag= else: hts = self.data[self.z_name].values - if title_flag: - ax.set_title('%s %s CAPPI %.1f km MSL' %(ts, self.radar_name, \ + ax.set_title('%s %s CAPPI %.1f km MSL' %(ts, self.band+'-band', \ hts[z_ind]), fontsize = 14) # print type(dummy),dummy - return dummy,xdat,ydat,data + return dummy,ax ############################################################################################################# - def cappi_multiplot(self, z=1.0, xlim=None, ylim=None, ts=None,res = 2, varlist=None, vectors=None, - contours = None,thresh_dz = False, **kwargs): - "6 panel CAPPI plot showing all the polarimetric variables and HID" - - # first, get the appropriate z index from the z that's wanted in altitude + def cappi_multiplot(self, z=1.0, xlim=[], ylim=[], ts=None,res = 2, varlist=None, vectors=None, contours = None,thresh_dz = False, latlon=False, statpt=False, dattype='obs', **kwargs): + + import cartopy.crs as ccrs + if ts is not None: try: tmind = np.where(np.array(self.date)==ts)[0][0] except: tmind = np.where(np.array(self.date)==ts)[0] - # print('tmind in cappi-multi',tmind) - if z is None: - z_ind = 2 - - else: - if 'd' in self.data[self.z_name].dims: -# print('getting z-ind') - z_ind = self.get_ind(z,np.squeeze(self.data[self.z_name].sel(d=tmind).values)) - else: - z_ind = self.get_ind(z,self.data[self.z_name].values) - -# print('xlims 1203',xlim,tmind) - if self.x_name == 'longitude': - if 'd' in self.data[self.x_name].dims: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind,y=0).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind,y=0).values) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(d=tmind).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(d=tmind).values) - - else: - if 'y' in self.data[self.x_name].dims: - xmini = self.get_ind(xlim[0],self.data[self.x_name].sel(y=0).values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].sel(y=0).values) - else: - xmini = self.get_ind(xlim[0],self.data[self.x_name].values) - xmaxi = self.get_ind(xlim[1],self.data[self.x_name].values) - else: - xmini, xmaxi = xlim - - xmin, xmax = xlim - - if ylim is None: - # print 'ylim is None!' - if self.y_name == 'latitude': - ymint, ymaxt = self.data[self.y_name].values.min(), self.data[self.y_name].values.max() - ymini = self.get_ind(ymint,self.data[self.y_name].sel(d=tmind).values[:,0]) - ymaxi = self.get_ind(ymaxt,self.data[self.y_name].sel(d=tmind).values[:,0]) - ymin =ymint - ymax = ymaxt - - else: - ymini, ymaxi = self.data[self.y_name].values.min(), self.data[self.y_name].values.max() - else: - if self.y_name == 'latitude': -# print 'trying to get indices' - ymini = self.get_ind(ylim[0],self.data[self.y_name].sel(d=tmind).values[:,0]) - ymaxi = self.get_ind(ylim[1],self.data[self.y_name].sel(d=tmind).values[:,0]) - ymin = ylim[0] - ymax = ylim[1] - - else: - ymini, ymaxi = ylim - ymin = ylim[0] - ymax = ylim[1] - tsi = 0 - - - if varlist is not None: good_vars = varlist else: @@ -1608,53 +1380,51 @@ def cappi_multiplot(self, z=1.0, xlim=None, ylim=None, ts=None,res = 2, varlist= figx = 5 figy = 3*nrows else: - ncols = 2 - nrows = int(np.ceil(nvars/2)) - figx = 12 - figy = 4*nrows + nrows = 2 + ncols = int(np.ceil(nvars/2)) - fig, ax = plt.subplots(nrows, ncols, figsize = (figx, figy), sharex = True, sharey = True) - if not isinstance(ax, np.ndarray) or not isinstance(ax, list): ax = np.array([ax], **kwargs) + if latlon: + fig, ax = plt.subplots(nrows,ncols,figsize=(16,8),subplot_kw={'projection': ccrs.Mercator()},gridspec_kw={'wspace': 0.45, 'hspace': 0.075, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + else: + fig, ax = plt.subplots(nrows,ncols,figsize=(16,8),gridspec_kw={'wspace': 0.45, 'hspace': 0.07, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + + if not isinstance(ax, np.ndarray) or not isinstance(ax, list): + ax = np.array([ax], **kwargs) axf = ax.flatten() for i, var in enumerate((good_vars)): -# print var - if contours is not None: - vcont = contours[i] + if var is None: + fig.delaxes(axf[i]) + continue else: - vcont = None - if vectors is not None: - vect = vectors[i] - else: - vect = None -# print 'RadarDAta 1258:',axf[i],xlim,ylim,var,vect,res,vcont - dummy = self.cappi(var, z=z, ax=axf[i], xlim=xlim, ylim=ylim,ts = ts, vectors=vect,res=res,contour=vcont,thresh_dz =thresh_dz) - # now do the HID plot, call previously defined functions - # try: - # dummy_hid = self.HID_plot(self.HID_from_scores(self.scores, rank = 1)[z_ind,:,:], - # axis = axf[-1],extent=ext) - # self.HID_colorbar(dummy_hid, axis = axf[-1], figure = fig, fraction = 0.03, pad = 0.03) - # except AttributeError: - # print 'No HID scores, not plotting' - # pass - - fig.tight_layout() - fig.subplots_adjust(top = 0.94) - if 'd' in self.data[self.z_name].dims: - hts = self.data[self.z_name].sel(d=tmind).values - else: - hts = self.data[self.z_name].values - fig.suptitle('%s %s CAPPI %.1f km MSL' %(ts, self.radar_name, \ - hts[z_ind]), fontsize = 18) - - - return fig #, ax + if contours is not None: + vcont = contours[i] + else: + vcont = None + if vectors is not None: + vect = vectors[i] + else: + vect = None + botpanels = np.arange(nvars-ncols,nvars) + xlabbool = True if i in botpanels else False + lspanels = [ncols*n for n in range(0,nrows)] + ylabbool = True if i in lspanels else False + #dummy = self.cappi(var, z=z, ax=axf[i], xlim=xlim, ylim=ylim,ts = ts, vectors=vect,res=res,contour=vcont,thresh_dz =thresh_dz,xlab=xlabbool,ylab=ylabbool,cbar=1,labels=False,statpt=statpt,latlon=False) + dummy = self.cappi(var, z=z, ax=axf[i], xlim=xlim, ylim=ylim,ts = ts, res=res, thresh_dz=thresh_dz,xlab=xlabbool,ylab=ylabbool,cbar=1,labels=False,statpt=statpt,latlon=latlon,dattype=dattype) + + axf[0].text(0, 1, '{e} {r}'.format(e=self.exper,r=self.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=20, color='k', zorder=10, weight='bold', transform=axf[0].transAxes) # (a) Top-left + + axf[ncols-1].text(1, 1, '{d:%Y-%m-%d %H:%M:%S} UTC'.format(d=ts), horizontalalignment='right', verticalalignment='bottom', size=20, color='k', zorder=10, weight='bold', transform=axf[ncols-1].transAxes) # (a) Top-left + + axf[ncols-1].text(0.99, 0.99, 'z = {a} km'.format(a=z), horizontalalignment='right',verticalalignment='top', size=20, color='k', zorder=10, weight='bold', transform=axf[ncols-1].transAxes,bbox=dict(facecolor='w', edgecolor='none', pad=0.0)) + + return fig ############################################################################################################# # Down here is dual doppler plotting stuff - def xsec_vector(self, y=None, xlim=None,zlim=None,ts=None,ax=None, res=2.0, ht_offset=0.2, **kwargs): + def xsec_vector(self, y=None, xlim=None,zmax=None,ts=None,ax=None, res=2.0, ht_offset=0.2, **kwargs): if ts is None: print('xsec_vector got no time') ts=self.date[0] @@ -1667,24 +1437,18 @@ def xsec_vector(self, y=None, xlim=None,zlim=None,ts=None,ax=None, res=2.0, ht_o # print 'Check your dates!', ts # print 'ts:',ts - if zlim is None: - zmin=0 + if zmax is None: if 'd' in self.data[self.z_name].dims: zmax=len(self.data[self.z_name].sel(d=0)) else: zmax=len(self.data[self.z_name]) - zlim=[zmin,zmax] - - else: - - zmin, zmax = zlim if 'd' in self.data[self.z_name].dims: # print('getting z-ind') - zmini = self.get_ind(zmin,np.squeeze(self.data[self.z_name].sel(d=tmind).values)) + zmini = self.get_ind(0,np.squeeze(self.data[self.z_name].sel(d=tmind).values)) zmaxi = self.get_ind(zmax,np.squeeze(self.data[self.z_name].sel(d=tmind).values)) else: - zmini = self.get_ind(zmin,np.squeeze(self.data[self.z_name].values)) + zmini = self.get_ind(0,np.squeeze(self.data[self.z_name].values)) zmaxi = self.get_ind(zmax,np.squeeze(self.data[self.z_name].values)) # print('xlims 1203',xlim,tmind) @@ -1759,6 +1523,7 @@ def xsec_vector(self, y=None, xlim=None,zlim=None,ts=None,ax=None, res=2.0, ht_o fig = ax.get_figure() # print 'ln 1274', xmini,xmaxi,y_ind,zmini,zmaxi,skip,xlim,y + if self.u_name in self.data.variables.keys(): try: @@ -1766,7 +1531,7 @@ def xsec_vector(self, y=None, xlim=None,zlim=None,ts=None,ax=None, res=2.0, ht_o if 'd' in self.data[self.u_name].dims: udat= np.squeeze(np.squeeze(self.data[self.u_name]).sel(d=tmind,x=slice(xmini,xmaxi),y=y_ind,z=slice(zmini,zmaxi)).values) wdat= np.squeeze(np.squeeze(self.data[self.w_name]).sel(d=tmind,x=slice(xmini,xmaxi),y=y_ind,z=slice(zmini,zmaxi)).values) - xdat= np.squeeze(np.squeeze(self.data[self.x_name]).sel(d=tmind,x=slice(xmini,xmaxi),y=y_ind).values) + xdat= np.squeeze(np.squeeze(self.data[self.x_name]).sel(d=tmind,x=slice(xmini,xmaxi)).values) if 'y' in self.data[self.z_name].dims: @@ -1776,11 +1541,10 @@ def xsec_vector(self, y=None, xlim=None,zlim=None,ts=None,ax=None, res=2.0, ht_o zdat= np.squeeze(np.squeeze(self.data[self.z_name]).sel(d=tmind,z=slice(zmini,zmaxi)).values) else: - udat= np.squeeze(np.squeeze(self.data[self.u_name]).sel(x=slice(xmini,xmaxi),y=y_ind,z=slice(zmini,zmaxi)).values) - wdat= np.squeeze(np.squeeze(self.data[self.w_name]).sel(x=slice(xmini,xmaxi),y=y_ind,z=slice(zmini,zmaxi)).values) - xdat= np.squeeze(np.squeeze(self.data[self.x_name]).sel(x=slice(xmini,xmaxi),y=slice(y_ind,y_ind+1)).values) + udat= np.squeeze(np.squeeze(self.data[self.u_name]).sel(x=slice(xmini,xmaxi),y=slice(y,y+1),z=slice(zmini,zmaxi)).values) + wdat= np.squeeze(np.squeeze(self.data[self.w_name]).sel(x=slice(xmini,xmaxi),y=slice(y,y+1),z=slice(zmini,zmaxi)).values) + xdat= np.squeeze(np.squeeze(self.data[self.x_name]).sel(x=slice(xmini,xmaxi)).values) if 'y' in self.data[self.z_name].dims: - zdat= np.squeeze(np.squeeze(self.data[self.z_name]).sel(z=slice(zmini,zmaxi),y=y_ind).values) else: zdat= np.squeeze(np.squeeze(self.data[self.z_name]).sel(z=slice(zmini,zmaxi)).values) @@ -1789,22 +1553,46 @@ def xsec_vector(self, y=None, xlim=None,zlim=None,ts=None,ax=None, res=2.0, ht_o else: # print np.shape(xdat), np.shape(zdat) - xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1),y=y_ind).values) - zdat = np.squeeze(self.data[self.z_name].sel(z=slice(zmini,zmaxi+1)).values) - udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) - wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + #xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1),y=y_ind).values) + if 'd' in self.data[self.u_name].dims: +# print('made line 1936') + xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1)).values) + zdat = np.squeeze(self.data[self.z_name].sel(z=slice(zmini,zmaxi+1)).values) + #udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + udat = np.squeeze(self.data[self.u_name].sel(d=tmind,z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y+1)).values) + #wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + wdat = np.squeeze(self.data[self.w_name].sel(d=tmind,z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y+1)).values) + if len(np.shape(udat))>2: +# print('Udat shape is too many!') + udat = np.squeeze(self.data[self.u_name].sel(d=tmind,z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y)).values) + #wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + wdat = np.squeeze(self.data[self.w_name].sel(d=tmind,z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y)).values) + else: +# print('made 1949') + xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1)).values) + zdat = np.squeeze(self.data[self.z_name].sel(z=slice(zmini,zmaxi+1)).values) + #udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y+1)).values) + #wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y+1)).values) except: # print 'uh-oh, exception' xdat = np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1)).values) zdat = np.squeeze(self.data[self.z_name].sel(z=slice(zmini,zmaxi+1)).values) # print np.shape(xdat),np.shape(zdat),np.shape(self.data[self.u_name].data) - udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) - wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) - + #udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y+1)).values) + #wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y+1)).values) + if len(np.shape(udat))>2: + # print('Udat shape is too many!') + udat = np.squeeze(self.data[self.u_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y)).values) + #wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=y_ind).values) + wdat = np.squeeze(self.data[self.w_name].sel(z=slice(zmini,zmaxi+1),x=slice(xmini,xmaxi+1),y=slice(y,y)).values) + # print('w is',np.nanmax(wdat[::zskip,::xskip])) - if self.y_name == 'latitude': q_handle = ax.quiver(xdat[::xskip], zdat[::zskip]+ht_offset, \ udat[::zskip, ::xskip], wdat[::zskip, ::xskip], \ @@ -1876,6 +1664,7 @@ def plan_vector(self, z=1.0, ax=None, xlim=None,ylim = None,ts=None,res=2.0, ht_ xmini = self.get_ind(xlim[0],self.data[self.x_name].values) xmaxi = self.get_ind(xlim[1],self.data[self.x_name].values) else: + xmini, xmaxi = xlim xmin, xmax = xlim @@ -1925,18 +1714,30 @@ def plan_vector(self, z=1.0, ax=None, xlim=None,ylim = None,ts=None,res=2.0, ht_ xdat = np.squeeze(np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).data)) ydat = np.squeeze(np.squeeze(self.data[self.y_name].sel(y=slice(ymini,ymaxi+1),x=slice(xmini,xmaxi+1)).data)) else: +# print(np.shape(self.data['x']), self.data['x'].dims) +# print(np.shape(self.data['y'])) xdat = np.squeeze(np.squeeze(self.data[self.x_name].sel(x=slice(xmini,xmaxi+1)).data)) ydat = np.squeeze(np.squeeze(self.data[self.y_name].sel(y=slice(ymini,ymaxi+1)).data)) - +# print(np.shape(xdat),np.shape(ydat)) if 'd' in self.data[self.u_name].dims: - udat = np.squeeze(np.squeeze(self.data[self.u_name].sel(d=tmind,z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) - vdat = np.squeeze(np.squeeze(self.data[self.v_name].sel(d=tmind,z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) - else: - udat = np.squeeze(np.squeeze(self.data[self.u_name].sel(z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) - vdat = np.squeeze(np.squeeze(self.data[self.v_name].sel(z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + #udat = np.squeeze(np.squeeze(self.data[self.u_name].sel(d=tmind,z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + #vdat = np.squeeze(np.squeeze(self.data[self.v_name].sel(d=tmind,z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + udat = np.squeeze(np.squeeze(self.data[self.u_name].sel(d=tmind,z=slice(z_ind,z_ind+1),x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + vdat = np.squeeze(np.squeeze(self.data[self.v_name].sel(d=tmind,z=slice(z_ind,z_ind+1),x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + if np.shape(udat)[0] == 2: + udat = udat[0] + vdat = vdat[0] + + #print(np.shape(udat),np.shape(vdat)) - z_ind = self.get_ind(z_ind,self.data[self.z_name].data) - # + else: + #udat = np.squeeze(np.squeeze(self.data[self.u_name].sel(z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + #vdat = np.squeeze(np.squeeze(self.data[self.v_name].sel(z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + udat = np.squeeze(np.squeeze(self.data[self.u_name].sel(z=slice(z_ind,z_ind+1),x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + vdat = np.squeeze(np.squeeze(self.data[self.v_name].sel(z=slice(z_ind,z_ind+1),x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values)) + + #z_ind = self.get_ind(z_ind,self.data[self.z_name].data) + if thresh_dz == True: dzdat = np.squeeze(self.data[self.dz_name].sel(d=tmind,z=z_ind,x=slice(xmini,xmaxi+1),y=slice(ymini,ymaxi+1)).values) print ('trying to threshold...',np.shape(vdat),np.shape(dzdat)) @@ -1950,8 +1751,8 @@ def plan_vector(self, z=1.0, ax=None, xlim=None,ylim = None,ts=None,res=2.0, ht_ udat[msk2] = np.nan # ydat= np.ma.masked_where(msk,ydat) #print type(vdat) - #print np.max(vdat) - #print 'vect shp',np.shape(udat),np.shape(vdat),np.shape(xdat),np.min(ydat),np.max(ydat) + #print max(vdat) + #print 'vect shp',np.shape(udat),np.shape(vdat),np.shape(xdat),min(ydat),max(ydat) # print type(xdat),type(ydat),type(udat) # print('yskip','xskip',yskip,xskip) if xdat.ndim > 1: @@ -1971,11 +1772,13 @@ def plan_vector(self, z=1.0, ax=None, xlim=None,ylim = None,ts=None,res=2.0, ht_ else: xdatskip = xdat[::yskip]#,::xskip] ydatskip = ydat[::yskip]#,::xskip] - udatskip = udat[::yskip,::xskip] - vdatskip = vdat[::yskip,::xskip] + udatskip = np.squeeze(udat[::yskip,::xskip]) + vdatskip = np.squeeze(vdat[::yskip,::xskip]) + xdatskipmesh,ydatskipmesh = np.meshgrid(xdatskip,ydatskip) # print np.shape(xdatskip),np.shape(ydatskip),np.shape(udatskip),np.shape(vdatskip) # print ('RadarData 1516:', xskip, yskip,np.shape(xdat),np.shape(ydat),np.shape(udat),np.shape(vdat)) - q_handle = ax.quiver(xdatskip, ydatskip, \ +# print('RadarData line 2111',np.shape(xdatskipmesh),np.shape(ydatskipmesh),np.shape(udatskip),np.shape(vdatskip)) + q_handle = ax.quiver(xdatskipmesh, ydatskipmesh, \ udatskip, vdatskip, \ scale=100, scale_units='inches', pivot='middle', width=0.0025, headwidth=4, **kwargs) @@ -1988,7 +1791,7 @@ def plan_vector(self, z=1.0, ax=None, xlim=None,ylim = None,ts=None,res=2.0, ht_ ############################################################################################################# - def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=None, ret_z=0,z_resolution=1.0,cscfad = None): + def cfad(self, var, value_bins=None, above=None, below=15.0, pick=None, ret_z=0,z_resolution=1.0,cscfad = None): # pick a variable and do a CFAD for the cell if value_bins is None: # set a default if nothing is there @@ -1996,7 +1799,6 @@ def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=Non else: pass #print('value bins',value_bins) - nbins = value_bins.shape[0] if above is not None: bot_index, top_index = self._get_ab_incides(above=above, below=below) @@ -2008,20 +1810,20 @@ def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=Non # print np.shape(data),type(data) if np.mod(z_resolution, self.dz) != 0: - print('Need even multiple of vertical resolution: %.1f'%self.dz) - return + print('Need even multiple of vertical resolution: %.1f'%self.dz) + return # print('ln 1592') - multiple = np.int(z_resolution/self.dz) + multiple = int(z_resolution/self.dz) if 'd' in self.data[self.z_name].dims: sz=np.shape(self.data[self.z_name].sel(d=0).values)[0] hts = np.squeeze(self.data[self.z_name].sel(d=0).values) else: sz=np.shape(self.data[self.z_name].values)[0] hts=np.squeeze(self.data[self.z_name].values) - #print( np.shape(sz),sz, multiple) looped = np.arange(0, sz, multiple) - cfad_out = np.zeros((sz//multiple, nbins-1)) + #cfad_out = np.zeros((sz//multiple, nbins-1)) + cfad_out = np.zeros((len(looped), nbins-1)) #print (np.shape(cfad_out),'cfad shape') #print looped #print cfad_out.shape, multiple @@ -2035,12 +1837,13 @@ def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=Non # tei = self.get_ind(te,np.array(self.date)) # # print 'cscfad',cscfad + if cscfad == 'convective': #mask = np.where(self.raintype != 2) mask= np.where(self.raintype != 2) holddat = deepcopy(self.data[var].values) self.data[var].values[mask] = np.nan -# print ('in conv') +# print ('in conv' elif cscfad == 'stratiform': mask = np.where(self.raintype != 1) holddat = deepcopy(self.data[var].values) @@ -2050,9 +1853,14 @@ def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=Non mask = np.where(self.raintype > 100) # print('entering deep copy') holddat = deepcopy(self.data[var].values) - self.data[var].values[mask] = np.nan + holddat2 = deepcopy(self.data[var].values) + holddat2[mask] = np.nan + #self.data[var].values[mask] = np.nan + self.data[var].values = holddat2 #print('ready to go in loop!') # if left blank, check the whole thing + + for ivl, vl in (enumerate(tqdm(looped[:-1]))): #print ivl, vl # try: @@ -2068,20 +1876,38 @@ def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=Non # v2 = self.get_ind(vl+multiple,self.data[self.z_name].data]) # print v,v2 dum = self.data[var].sel(z=slice(vl,vl+multiple)).where(np.isfinite) - #print np.max(dum) + #print max(dum) # dum2 = np.ma.masked_less(dum,-900.0) # dum2 = np.where(np.isfinite(dum)) # print(type(dum[dum2])) #print dum[dum2] lev_hist, edges = np.histogram(dum, bins=value_bins, density=True) -# except: + ''' + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist(dum.values.flatten(), bins=value_bins, density=True) + if self.mphys.startswith('obs'): + plt.savefig('hist1x_'+var+'_'+str(ivl).zfill(2)+'.png') + else: + plt.savefig('hist2x_'+var+'_'+str(ivl).zfill(2)+'.png') + plt.close() + ''' +# except: # lev_hist, edges = np.histogram(data[vl:vl+multiple].ravel(), bins=value_bins, density=True) #print lev_hist, edges # this keeps it general, can make more elaborate calls in other functions #print(np.shape(lev_hist)) + lev_hist = 100.0*lev_hist/np.sum(lev_hist) - if np.max(lev_hist) > 0: + if max(lev_hist) > 0: + #print(looped[ivl]) + #print('Hello') + #print(max(lev_hist)) cfad_out[ivl, :] = lev_hist + #else: + # print('Negative!') + # print(looped[ivl]) + # print(max(lev_hist)) #print np.shape(cfad_out) # if cscfad == 'convective' or cscfad == 'stratiform': # print 'setting data back' @@ -2095,74 +1921,115 @@ def cfad(self, var, value_bins=None, above=None, below=15.0,tspan=None, pick=Non ############################################################################################################# - def cfad_plot(self, var, nbins=20, ax=None, maxval=10.0, above=None, below=15.0, bins=None, - log=False, pick=None, z_resolution=1.0,levels=None,tspan =None,cont = False,cscfad = False, **kwargs): + def cfad_multiplot(self, varlist=None, z_resolution=1.0, zmax=None, **kwargs): + + if varlist is not None: + good_vars = varlist + else: + good_vars = self.valid_vars() + + nvars = len(good_vars) + if 'scores' in good_vars: + if hasattr(self, 'scores'): + nvars += 1 + if nvars <= 3: + ncols = 1 + nrows = deepcopy(nvars) + figx = 5 + figy = 3*nrows + else: + nrows = 2 + ncols = int(np.ceil(nvars/2)) + + fig, ax = plt.subplots(nrows,ncols,figsize=(14,8),gridspec_kw={'wspace': 0.1, 'hspace': 0.2, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + + if not isinstance(ax, np.ndarray) or not isinstance(ax, list): + ax = np.array([ax], **kwargs) + axf = ax.flatten() + + for i, var in enumerate((good_vars)): + if var is None: + fig.delaxes(axf[i]) + continue + else: + print(var) + lspanels = [ncols*n for n in range(0,nrows)] + ylabbool = True if i in lspanels else False + cbpanels = [ncols*n+2 for n in range(0,nrows)] + cbbool = True if i in cbpanels else False + if not var.startswith('HID'): + self.cfad_plot(var,ax=axf[i],ylab=ylabbool,cbar=cbbool,bins=self.cfbins[var],levels=1,zmax=zmax,z_resolution=z_resolution) + else: + self.plot_hid_cdf(ax=axf[i],ylab=ylabbool,zmax=zmax,z_resolution=z_resolution) + + return fig, ax + +############################################################################################################# + + def cfad_plot(self, var, cfad=None, hts=None, nbins=20, ax=None, maxval=10.0, above=None, below=15.0, bins=None, log=False, diff=False, pick=None, z_resolution=1.0, levels=None, cont=False, cscfad=False, cbar=1, xlab=1, ylab=1, zmax=8,**kwargs): from matplotlib.colors import from_levels_and_colors + if bins is None: bins = np.linspace(self.lims[var][0], self.lims[var][1], nbins) else: pass + multiple = int(z_resolution/self.dz) - multiple = np.int(z_resolution/self.dz) -# print self.dz -# print 'multiple: {}'.format(multiple) + if np.nanstd(self.data[var].values) < abs(bins[0]-bins[-1]): + if self.names_uc[var].startswith('RHO'): + bins = np.arange(0.95,bins[-1],0.001) + + if not diff: + cfad,value_bins,hts = self.cfad(var, value_bins=bins, above=above, below=below, pick=pick, z_resolution=z_resolution,cscfad=cscfad,ret_z=1) - cfad,value_bins,hts = self.cfad(var, value_bins=bins, above=above, below=below, pick=pick, z_resolution=z_resolution,tspan=tspan,cscfad=cscfad,ret_z=1) - #print cfad.sum(axis=1) if above is not None: bot_index, top_index = self._get_ab_incides(above=above, below=below) if ax is None: - fig, ax = plt.subplots() + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(111) else: - # ax has been passed in, do nothing to ax, but need to get the parent fig fig = ax.get_figure() + cfad_ma = np.ma.masked_where(cfad==0,cfad) if log: norm = colors.LogNorm(vmin=1e-5, vmax=1e2) + elif diff: + cmap = plt.set_cmap('bwr') + vmin,vmax = -np.nanmax(cfad_ma),np.nanmax(cfad_ma) + norm = colors.Normalize(vmin=vmin,vmax=vmax) else: - norm = None - - - # plot the CFAD - cfad_ma = np.ma.masked_where(cfad==0, cfad) -# print np.max(cfad_ma),var - #print np.shape(cfad_ma) -# print multiple, self.data[self.z_name].data[::multiple] + cmap, norm = from_levels_and_colors(self.cfad_levs,self.cfad_cols) + if cont is True: - cmap, norm = from_levels_and_colors([0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.], ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet']) # mention levels and colors here - levs = [0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.] - cols = ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet'] - #pc = ax.contourf(bins[0:-1],self.data[self.z_name].data[::multiple],(cfad_ma/np.sum(cfad_ma))*100.,levs,color=cols) - pc = ax.contourf(bins[0:-1],hts,(cfad_ma),levs,color=cols,cmap=cmap,norm=norm,extend='both') + pc = ax.contourf(bins[0:-1],hts,(cfad_ma),levels=self.cfad_levs,color=self.cfad_cols,cmap=cmap,norm=norm,extend='both') else: - if levels is not None: - cmap, norm = from_levels_and_colors([0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.], ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet']) # mention levels and colors here - #print cmap - pc = ax.pcolormesh(bins, hts, cfad_ma, norm=norm, cmap=cmap) + pc = ax.pcolormesh(bins[0:-1], hts, cfad_ma, norm=norm, cmap=cmap) else: - cmap, norm = from_levels_and_colors([0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.], ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet']) # mention levels and colors here pc = ax.pcolormesh(bins, hts, cfad_ma, vmin=0, vmax=maxval, norm=norm,cmap=cmap, **kwargs) + + if xlab: + ax.set_xlabel('%s %s' %(self.names_uc[var], self.units[var]),fontsize=16) + ax.tick_params(axis='x',labelsize=16) + else: + ax.tick_params(axis='x',labelsize=0,left=False) + if cbar: + cbar = self.mycbar(fig,ax,pc,'Frequency (%)') + cbar.set_ticks(self.cfad_levs) + if ylab: + ax.set_ylabel('Height (km MSL)',fontsize=16) + ax.tick_params(axis='y',labelsize=16) + else: + ax.tick_params(axis='y',labelsize=0,left=False) + + ax.set_xlim(min(bins),max(bins)) + ax.set_ylim(0,zmax) + ax.grid(color='grey', linestyle='-', linewidth=1) -# print np.shape(cfad_ma) - - cb = fig.colorbar(pc, ax=ax) - cb.set_label('Frequency (%)') - ax.set_ylabel('Height (km MSL)') -# # try: - ax.set_xlabel('%s %s' %(var, self.units[var])) -# ax.set_title("{d} {r} {v}".format(d=self.date,r=self.radar_name,v=self.longnames[var])) -# ax.set_title('%s %s %s CFAD' % (self.print_date(), self.radar_name, self.longnames[var])) -# except: -# pass - - return fig, ax - - -############################################################################################################# + return cfad_ma, hts, pc, fig, ax ############################################################################################################# @@ -2203,12 +2070,14 @@ def plot_2dhist(self, hist,edge,ax=None,cbon = True): # ax has been passed in, do nothing to ax, but need to get the parent fig fig = ax.get_figure() - cb = ax.contourf(edge[0][:-1],edge[1][:-1],hist.T,norm=colors.Normalize(vmin=0, vmax=np.max(hist)),levels=np.arange(0.01,np.max(hist),0.01)) + cb = ax.contourf(edge[0][:-1],edge[1][:-1],hist.T,norm=colors.Normalize(vmin=0, vmax=max(hist)),levels=np.arange(0.01,max(hist),0.01)) if cbon == True: #print ' making colorbar' - plt.colorbar(cb,ax=ax) - + col = plt.colorbar(cb,ax=ax) + col.ax.tick_params(labelsize=24) + ax.tick_params(axis='both',labelsize=24) + # This will just look at the whole volume # if above is None: return fig, ax @@ -2392,7 +2261,7 @@ def vertical_hid_volume(self, hid_nums, z_resolution=1.0, above=None, below=None print ('Need even multiple of vertical resolution: %.1f'%self.dz) return - multiple = np.int(z_resolution/self.dz) + multiple = int(z_resolution/self.dz) vol = np.zeros(int(self.data[self.z_name].values.shape[0]/multiple)) hts = np.zeros(int(self.data[self.z_name].values.shape[0]/multiple)) #print np.shape(vol) @@ -2401,14 +2270,12 @@ def vertical_hid_volume(self, hid_nums, z_resolution=1.0, above=None, below=None # print('in d version of looped') looped = np.arange(0, int(self.data[self.z_name].values.shape[1]), multiple) # print('looped',looped) - vol = np.zeros(int(self.data[self.z_name].values.shape[1]/multiple)) - hts = np.zeros(int(self.data[self.z_name].values.shape[1]/multiple)) + vol = np.zeros(int(self.data[self.z_name].values.shape[1]/multiple)+1) + hts = np.zeros(int(self.data[self.z_name].values.shape[1]/multiple)+1) else: looped = np.arange(0, int(self.data[self.z_name].values.shape[0]), multiple) vol = np.zeros(int(self.data[self.z_name].values.shape[0]/multiple)) hts = np.zeros(int(self.data[self.z_name].values.shape[0]/multiple)) - -# print (looped,multiple) for vi,vl in enumerate(looped): lev_hid = data[:,vl:vl+multiple,...] # go to vl+multiple cuz not inclusive #print 'lev_hid',np.shape(lev_hid) @@ -2426,7 +2293,7 @@ def vertical_hid_volume(self, hid_nums, z_resolution=1.0, above=None, below=None if cscfad == 'convective' or cscfad == 'stratiform': self.data[self.hid_name].values = holddat - #print np.shape(vol), np.max(vol) + #print np.shape(vol), max(vol) #print hts # print self.data[self.z_name].data[0] # print self.data[self.z_name].data[0][::looped] @@ -2501,65 +2368,75 @@ def hid_cdf(self, z_resolution=1.0, pick=None,cscfad = None): ############################################################################################################# - def HID_barplot_colorbar(self, figure, location = [0.9, 0.1, 0.03, 0.8]): + def HID_barplot_colorbar(self, figure, location = [0.9, 0.1, 0.03, 0.8], orientation='vertical', names='shortnames', lblsz=16): scalarMap = plt.cm.ScalarMappable(norm=self.normhid,cmap=self.hid_cmap) - axcb = figure.add_axes(location) # x pos, y pos, x width, y width - cb = mpl.colorbar.ColorbarBase(axcb, cmap=self.hid_cmap, norm=self.normhid, boundaries=self.boundshid,\ - orientation = 'vertical') - cb.set_ticks(np.arange(0,11)) - # need to add a blank at the beginning of species to align labels correctly - labs = np.concatenate((np.array(['']), np.array(self.species))) - cb.set_ticklabels(labs) + axcb = figure.add_axes(location) + cb = mpl.colorbar.ColorbarBase(axcb, cmap=self.hid_cmap, norm=self.normhid, boundaries=self.boundshid, orientation = orientation) + cb.set_ticks(np.arange(len(self.species))+0.5) + + if names.startswith('long'): + labs = np.array(self.species_long) + cb.set_ticklabels(labs) + cb.ax.tick_params(labelsize=lblsz) + else: + labs = np.array(self.species) + cb.set_ticklabels(labs) + cb.ax.tick_params(labelsize=lblsz) + return cb - def plot_hid_cdf(self, data=None, z_resolution=1.0, ax=None, pick=None,cscfad = None): - # this will just plot it + def plot_hid_cdf(self, ax=None, xlab=1, ylab=1, zmax=None, cbar=1, data=None, z_resolution=1.0, pick=None,cscfad = None): + ts=np.array(self.date)[0] if data is not None: pass else: - pass # will call the hid_cdf function here + pass data,hgt = self.hid_cdf(z_resolution=z_resolution, pick=pick,cscfad = cscfad) - #print np.shape(data) if ax is None: - fig, ax = plt.subplots(1,1) + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(111) else: - fig = ax.get_figure() + fig = ax.get_figure() - fig.subplots_adjust(left = 0.07, top = 0.93, right = 0.87, bottom = 0.1) - multiple = np.int(z_resolution/self.dz) -# if 'd' in self.data[self.z_name].dims: -# hgt = self.data[self.z_name].sel(d=0).values -# else: -# hgt = self.data[self.z_name].valeus - print(len(hgt),'heights!') - for i, vl in enumerate(np.arange(0, len(hgt), multiple)): - #print vl,i -# print self.data[self.z_name].data[vl] - #print data[0,:] -# print('in plotting cfad',i, vl,np.shape(data),hgt[i])#,np.shape(data[0,:])) - ax.barh(hgt[i], data[0, i], left = 0., edgecolor = 'none', color = self.hid_colors[1]) - for spec in range(1, len(self.species)): # now looping thru the species to make bar plot - #print spec, np.max(data[spec,i]) - - ax.barh(vl, data[spec, i], left = data[spec-1, i], \ - color = self.hid_colors[spec+1], edgecolor = 'none') - ax.set_xlim(0,100) - ax.set_xlabel('Cumulative frequency (%)') - ax.set_ylabel('Height (km MSL)') - # now have to do a custom colorbar? - self.HID_barplot_colorbar(fig) # call separate HID colorbar function for bar plots + multiple = int(z_resolution/self.dz) + + for i in tqdm(np.arange(0,len(hgt),multiple)): + ax.barh(hgt[i],data[0,i],left=0.,align='center',height=z_resolution,color=self.hid_colors[0],edgecolor='k') + for spec in range(1, len(self.species)): + ax.barh(hgt[i],data[spec,i],left=data[spec-1,i],align='center',height=z_resolution,color=self.hid_colors[spec],edgecolor='k') - #fig.suptitle('%04d/%02d/%02d - %02d:%02d:%02d %s, cell %d, HID CDF' \ - # %(self.year,self.month,self.date,self.hour,self.minute,self.second, \ - # self.radar, self.cell_num), fontsize = 14) - ax.set_title('%s %s HID CDF' % (self.print_date(), self.radar_name)) + ax.set_xlim(0,100) + if xlab == 1: + ax.set_xlabel('Cumulative Frequency (%)',fontsize=16) + ax.tick_params(axis='x',which='major',labelsize=16) + else: + ax.tick_params(axis='x',which='major',labelsize=0) + ax.set_xticks([]) + ax.set_xticklabels([]) + + ax.set_ylim(0,zmax) + if ylab == 1: + ax.set_ylabel('Height (km MSL)',fontsize=16) + ax.tick_params(axis='y',which='major',labelsize=16) + else: + ax.tick_params(axis='y',which='major',labelsize=0) + ax.set_yticks([]) + ax.set_yticklabels([]) + + if cbar == 1: + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.015,bur,0.03,hur] + self.HID_barplot_colorbar(fig,cbar_ax_dims) + + if cbar == 2: + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur,bur-0.125,wur,0.03] + self.HID_barplot_colorbar(fig,cbar_ax_dims,orientation='horizontal',names='longnames') return fig, ax - -############################################################################################################# ############################################################################################################# def vertical_profile(self, var, rep_func=np.average, above=None, below=None, pick=None): @@ -2704,7 +2581,7 @@ def plot_w_profile(self, rep_func=np.average, masked=True, ax=None): u = ax.plot(wprof['up'], self.data[self.z_name], color='red', linewidth=2, label='updrafts') d = ax.plot(wprof['down'], self.data[self.z_name], color='blue', linewidth=2, label='downdrafts') - max_abs = np.abs(np.array(ax.get_xlim())).max() + max_abs = abs(np.array(ax.get_xlim())).max() ax.set_xlim(-1*max_abs, max_abs) #ax.set_xlim() @@ -2713,7 +2590,7 @@ def plot_w_profile(self, rep_func=np.average, masked=True, ax=None): ax.set_ylabel('Altitude (km MSL)') ax.grid(True) ax.legend(loc='best') - ax.set_title('%s %s Vertical motion profile' % (self.print_date(), self.radar_name)) + ax.set_title('%s %s Vertical motion profile' % (self.print_date(), self.band+'-band')) return fig, ax @@ -2730,21 +2607,27 @@ def updraft_width_profile(self, thresh=5.0, temps=np.arange(20,-60,-5),thresh_dz #temps = self.data[self.z_name].data[0,:] # basically just loop thru the Z and get the associated temperature and area - data = self.data[self.w_name].data + #data = self.data[self.w_name].data + #data_dz = self.data[self.dz_name].data + data = self.data[self.w_name].values + data_dz = self.data[self.dz_name].values if thresh_dz == True: - data[self.data[self.dz_name].data < self.z_thresh]=np.nan + data[data_dz < self.z_thresh] = np.nan # print np.shape(data),'ln2075' for iz, z in enumerate(self.data[self.z_name].data): - values_above = np.where(data[iz,...] >= thresh)[0] + #values_above = np.where(data[iz,...] >= thresh)[0] + values_above = np.where(data[:,iz,:,:] >= thresh)[0] num_above = len(values_above) uw[iz] = num_above*self.dx*self.dy/self.ntimes if self.data[self.x_name].units == "[deg]": # print 'changing units' uw[iz]=uw[iz]*110.*110. - #print np.shape(uw),np.max(uw),self.data[self.x_name].units + #print np.shape(uw),max(uw),self.data[self.x_name].units #print np.shape(uw) #print np.shape(self.T[0,:,0,0]) # now inerpolate this to the temps listed + self.T = xr.DataArray(data=self.T,dims=['d','z','y','x']) + if 'd' in self.T.dims: print('shapes in updraft width',np.shape(uw),np.shape(self.T.sel(x=0,y=0))) f_temp_u = sint.interp1d(self.T.sel(d=0,x=0,y=0), uw, bounds_error=False) @@ -2772,8 +2655,8 @@ def def_convstrat(self): def calc_timeseries_stats(self,var,ht_lev = 3,thresh=-99.,cs_flag=False,make_zeros=False,areas=False): #First calculate the domain averaged rain rates at a given level. #if self.rr_name is not None: - # rr_timeseries_uncond = rr.mean(dim=['x','y','z'],skipna=True) - data = deepcopy(self.data[var].sel(z=slice(ht_lev,ht_lev+1))) + # rr_timeseries_uncond = rr.mean(dim=['x','y','z'],skipna=True) + data = deepcopy(self.data[var].sel(z=slice(int(ht_lev),int(ht_lev)+1))) whbad= np.where(data.values0) - if areas==False: + if areas==False: datstrat_ts= datstrat.mean(dim=['z','y','x'],skipna=True) datconv_ts= datconv.mean(dim=['z','y','x'],skipna=True) datall_ts= datall.mean(dim=['z','y','x'],skipna=True) @@ -2798,7 +2681,6 @@ def calc_timeseries_stats(self,var,ht_lev = 3,thresh=-99.,cs_flag=False,make_zer datstrat_ts = cssum.where(cssum==1).count(dim=['y','x']) datconv_ts = cssum.where(cssum==2).count(dim=['y','x']) datall_ts = cssum.where(cssum>0).count(dim=['y','x']) - return datstrat_ts,datconv_ts,datall_ts else: @@ -2855,7 +2737,7 @@ def get_latlon_fromxy(self): # p = Proj('+proj=lcc +a=6370000.0m +lon_0={n}e +lon_1 = {n}e +lat_1={t}n +lat_2=60n +lat_0={t}n'.format(t=self.lat_0,n=self.lon_0)) # else: # print('trying lat lon') -# lon_0 = np.abs(self.lon_0) +# lon_0 = abs(self.lon_0) # p = Proj('+proj=lcc +a=6370000.0m +lon_0={n}w +lon_1 = {n}w +lat_1={t}n +lat_2=60n +lat_0={t}n'.format(t=self.lat_0,n=lon_0)) # else: # if self.lon_0 > 0: @@ -2872,32 +2754,31 @@ def get_latlon_fromxy(self): ############################################################################################################# def calc_cs_shy(self,cs_z=2.0): - print ('Unfortunatley have to run the convective stratiform per timestep. Might take a minute....{n}'.format(n=self.data.dims['d'])) + print ('Unfortunately have to run the convective stratiform per timestep. Might take a minute....{n}'.format(n=self.data.dims['d'])) rntypetot = [] # print(cs_z,'cs_z in 2424') for q in tqdm(range(self.data.dims['d'])): if self.lat_name in self.data.keys(): # lat = self.data[self.lat_name].sel(d=q).values # lon = self.data[self.lon_name].sel(d=q).values - if 'd' in self.data[self.lat_name].dims: - lat = self.data[self.lat_name].sel(d=q).values - lon = self.data[self.lon_name].sel(d=q).values - zlev = np.where(self.data[self.z_name].sel(d=q).values ==cs_z)[0] - nlevs = np.shape(self.data[self.z_name].sel(d=q).values)[0] - else: - lat = self.data[self.lat_name].values - lon = self.data[self.lon_name].values - zlev = np.where(self.data[self.z_name].values ==cs_z)[0] - nlevs = np.shape(self.data[self.z_name].values)[0] - - + if 'd' in self.data[self.lat_name].dims: + lat = self.data[self.lat_name].sel(d=q).values + lon = self.data[self.lon_name].sel(d=q).values + else: + lat = self.data[self.lat_name].values + lon = self.data[self.lon_name].values + if 'd' in self.data[self.z_name].dims: + zlev = np.where(self.data[self.z_name].sel(d=q).values ==cs_z)[0] + nlevs = np.shape(self.data[self.z_name].sel(d=q).values)[0] + else: + zlev = np.where(self.data[self.z_name].values ==cs_z)[0] + nlevs = np.shape(self.data[self.z_name].values)[0] else: - self.get_latlon_fromxy() - lat = self.data[self.lat_name].values - lon = self.data[self.lon_name].values - zlev = np.where(self.data[self.z_name].values ==cs_z)[0] - nlevs = np.shape(self.data[self.z_name].values)[0] - + self.get_latlon_fromxy() + lat = self.data[self.lat_name].values + lon = self.data[self.lon_name].values + zlev = np.where(self.data[self.z_name].values ==cs_z)[0] + nlevs = np.shape(self.data[self.z_name].values)[0] # print (np.shape(self.data[self.lat_name])) # print 'q is ' #print np.shape(self.data[self.z_name].sel(d=q)) @@ -3005,7 +2886,7 @@ def composite(self, var,ts=0,map_on = True,res='10m'): vmax=np.nanmax(dat) cmap = plt.cm.gist_ncar - ax.set_extent([np.min(self.lons), np.max(lons), np.min(lats), np.max(lats)]) + ax.set_extent([min(self.lons), max(lons), min(lats), max(lats)]) lon_formatter = LongitudeFormatter(number_format='.1f') lat_formatter = LatitudeFormatter(number_format='.1f') ax.xaxis.set_major_formatter(lon_formatter) @@ -3021,4 +2902,127 @@ def composite(self, var,ts=0,map_on = True,res='10m'): gl.xlabels_top = False gl.ylabels_right = False - # ax.set_title('MC3E CSAPR {d: \ No newline at end of file + # ax.set_title('MC3E CSAPR {d: + + ###################################### + ##### plot_driver.PLOT_COMPOSITE ##### + ###################################### + + # Description: plot_composite overlays a Cartopy basemap with a colormesh plot of a given variable. + + def plot_composite(self,var,time,resolution='10m',cs_over=False,statpt=False): + + import cartopy.crs as ccrs + + dat = deepcopy(self.data[var].sel(d=time)) + whbad = np.where(self.data['CSS'].sel(d=time).values<0) + dat.values[whbad] = np.nan + dat = np.squeeze(dat.values) + dzcomp = np.nanmax(dat,axis=0) + + if not self.lat_name in self.data.keys(): + print('No latitude. Calculating....') + self.get_latlon_fromxy() + lats = self.data['lat'] + lons = self.data['lon'] + else: + if 'd' in self.data[self.lat_name].dims: + lats = self.data[self.lat_name].sel(d=time).values + lons = self.data[self.lon_name].sel(d=time).values + else: + lats = self.data[self.lat_name].values + lons = self.data[self.lon_name].values + + minlon,maxlon,minlat,maxlat = lons[(0,0)],lons[(0,-1)],lats[(0,0)],lats[(-1,0)] + + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(111, projection=ccrs.Mercator()) + + cb = ax.pcolormesh(lons,lats,dzcomp,vmin=self.lims[var][0],vmax=self.lims[var][1],cmap=self.cmaps[var],transform=ccrs.PlateCarree()) + + if cs_over == True: + cs_arr = np.squeeze(np.nanmax(np.squeeze(self.data['CSS'].sel(d=time).values),axis=0)) + ax.contour(lons,lats,cs_arr,levels=[0,1,2,3],linewidths=3,colors=['black','black'],transform=ccrs.PlateCarree()) + + if statpt: ax.plot(self.lon_0,self.lat_0,markersize=12,marker='^',color='k',transform=ccrs.PlateCarree()) + + self.co_gridlines(fig,ax,latlonyn=True,minx=minlon,maxx=maxlon,miny=minlat,maxy=maxlat) + self.mycbar(fig,ax,cb,'Composite '+self.longnames[var]+' '+self.units[var]) + + return fig, ax + + + def co_gridlines(self,fig,ax,latlonyn=False,minx=-200,maxx=200,miny=-200,maxy=200,xlab=True,ylab=True,lnspc=2,ltspc=2,resolution='10m'): + + if latlonyn == True: + + import cartopy.crs as ccrs + import matplotlib.ticker as ticker + + ax.coastlines(resolution=resolution) + lur,bur,wur,hur = ax.get_position().bounds + + gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1.5, alpha=0.75, linestyle='--') + gl.xlocator = ticker.MultipleLocator(base=lnspc) + gl.ylocator = ticker.MultipleLocator(base=ltspc) + gl.xlabels_top = False + gl.ylabels_right = False + gl.x_inline = False + gl.y_inline = False + + if xlab: + gl.xlabel_style = {'size': 16, 'color': 'black'} + #ax.text(0.5,bur-0.15,'Longitude',fontsize=16,ha='center',va='bottom',rotation_mode='anchor',transform=ax.transAxes) + else: + gl.xlabels_bottom = False + if ylab: + gl.ylabel_style = {'size': 16, 'color': 'black'} #, 'rotation': 90} + #ax.text(lur-0.15,0.5,'Latitude',fontsize=16,ha='center',va='bottom',rotation_mode='anchor',rotation=90,transform=ax.transAxes) + else: + gl.xlabels_left = False + gl.ylabel_style = {'size': 0} + + #newax = fig.add_axes(ax.get_position(), frameon=False) + #newax.tick_params(axis='x', labelsize=0, length=0, pad=15) + #newax.tick_params(axis='y', labelsize=0, length=0, pad=45) + #if xlab: newax.set_xlabel('Longitude',fontsize=16) + #if ylab: newax.set_ylabel('Latitude',fontsize=16) + + ax.set_extent([minx,maxx,miny,maxy],crs=ccrs.PlateCarree()) + ax.set_aspect('auto') + + else: + + import numpy as np + + ax.set_xlim([minx,maxx]) + ax.set_xticks(np.linspace(minx,maxx,5)) + ax.set_ylim([miny,maxy]) + ax.set_yticks(np.linspace(miny,maxy,5)) + + ax.grid(axis='both',c='grey',linewidth=1.5, alpha=0.75, linestyle='--') + + if xlab: + ax.set_xlabel('Distance E of radar (km)',fontsize=16) + ax.tick_params(axis='x', which='major', labelsize=16) + else: + ax.set_xticklabels([]) + ax.xaxis.set_ticks_position('none') + if ylab: + ax.set_ylabel('Distance N of radar (km)',fontsize=16) + ax.tick_params(axis='y', which='major', labelsize=16) + else: + ax.set_yticklabels([]) + ax.yaxis.set_ticks_position('none') + + + def mycbar(self,fig,ax,cb,labtxt): + + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.015,bur,0.03,hur] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(cb,cax=cbar_ax) + cbt.ax.tick_params(labelsize=16) + cbt.set_label(labtxt, fontsize=16, rotation=270, labelpad=20) + + return cbt diff --git a/beta_functions.py b/beta_functions.py index f9fc087..39e56e2 100755 --- a/beta_functions.py +++ b/beta_functions.py @@ -77,7 +77,7 @@ #Beta function parameters stored in individual CSVs in separate directory CSV_DIR = os.sep.join([os.path.dirname(__file__), 'beta_function_parameters'])+'/' -print('CSV_DIR',CSV_DIR) +#print('CSV_DIR',CSV_DIR) ################################ #Helper Functions Below ################################ diff --git a/calc_kdp_ray_fir.cpython-39-darwin.so b/calc_kdp_ray_fir.cpython-39-darwin.so new file mode 100755 index 0000000..f3345c9 Binary files /dev/null and b/calc_kdp_ray_fir.cpython-39-darwin.so differ diff --git a/calc_kdp_ray_fir.cpython-39-x86_64-linux-gnu.so b/calc_kdp_ray_fir.cpython-39-x86_64-linux-gnu.so new file mode 100755 index 0000000..3a3c698 Binary files /dev/null and b/calc_kdp_ray_fir.cpython-39-x86_64-linux-gnu.so differ diff --git a/calc_kdp_ray_fir.so b/calc_kdp_ray_fir.so index 2622771..907725e 100755 Binary files a/calc_kdp_ray_fir.so and b/calc_kdp_ray_fir.so differ diff --git a/configtxt/testing/MC3E_config.txt b/configtxt/testing/MC3E_config.txt new file mode 100644 index 0000000..f97ecf6 --- /dev/null +++ b/configtxt/testing/MC3E_config.txt @@ -0,0 +1,207 @@ +#################################################### +#################### MY_CONFIG.TXT ################# +#################################################### + +type == obs == # Type of input data: 'obs' OR 'wrf' (obs + simulated) +mphys == obs == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf' + + +#============== +#### INPUT #### +#============== + +#----------------------------------------------- +#------ Radar File Reading (NOT OPTIONAL) ------ +#----------------------------------------------- + +# Args +sdatetime == '20110523_200000' == # Start time of analysis of interest +sdatetime_format == %Y%m%d_%H%M%S == # Start time format +edatetime == '20110523_235710' == # End time of analysis of interest +edatetime_format == %Y%m%d_%H%M%S == # End time format + +date == '20110523' == # Date of the case +rfiles == './obs_mc3e_csapr_20110523_all.txt' == # Input directory of radar files to read in +rdate_format == %Y%m%d_%H%M%S == # Format for the radar file date +rdend == 13 == # End of date timestamp in radar filename +rdstart == 0 == # Start of date timestamp in radar filename + +# Variables (NOTE: use NCDUMP to locate variable names of radar observables and info) +dz_name == DBZCS == # Name of the reflectivity field +dr_name == ZDRCS == # Name of the differential reflectivity field +kd_name == KDPCS == # Name of the Kdp field +rh_name == RHOCS == # Name of the RhoHV field +rr_name == None == # Name of the Rain rate / precipitation field +vr_name == VELCS == # Name of radial velocity field +band == C == # Radar band: X, C OR S. Note: needs to be capital letter. +exper == MC3E == # Radar location +lat == 36.79616 == # Latitude of the radar station +lon == -97.450546 == # Longitude of the radar station +radarname == C-band == # + +# Other (NOTE: use the internet to find these - not ideal) +alt ==0.327 == # Altitude of the radar in km + +#--------------------------------------------------- +#------ Doppler Radar File Reading (Optional) ------ +#--------------------------------------------------- + +dd_on == True == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +dfiles == './obs_mc3e_dd_20110523.txt' == # Location of dual-Doppler files +ddate_format == %Y%m%d_%H%M%S == # Format for the dual-Doppler file date +ddstart == 0 == # Offset for dual-Doppler timestamp in filename +ddend == 13 == # Offset for dual-Doppler timestamp in filename + +# Variables (NOTE: use NCDUMP to locate variable names of Doppler radar fields and info) +convname == None == # Name of +uname == U == # Name of the zonal wind field +vname == V == # Name of the meridional wind field +wname == Wvar == # Name of the vertical wind field +xname == x == # Name of the zonal directional variable +yname == y == # Name of the meridional directional variables +zname == z == # Name of the vertical level field + +#---------------------------------------------- +#------ Sounding File Reading (Optional) ------ +#---------------------------------------------- + +snd_on == True == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +sdate_format == %Y%m%d%H == # Sounding file date format +sfiles == './MC3E_sounding_files.txt' == # Sounding file directory +sdstart == 13 == # Offset for date timestamp in sounding filename +sdend == 23 == # Number of characters in timestamp on sounding file +sstat == LMN == # Sounding station identification + +# Variables +t_name == T == # Name of the temperature field + + +#=============== +#### OUTPUT #### +#=============== + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'obs' ------ +#---------------------------------------------------------- + +# SET 1) Plots created in run_ipolarris_new.py +all1 == False == # Set to True to output ALL figures in SET 1 below +compo_ref == False == # 1) Set to True to plot for spatial composite reflectivity plotting (1 figure per timestep) +cappi_ref == False == # 2) Set to True to plot reflectivity CAPPI at some altitude z (set z below) +cappi_rr == False == # 3) Set to True to plot rain rate CAPPI at some altitude z (set z below) +rr_timeseries == False == # 4) Set to True to plot a time series of convective and stratiform rain rate +vv_profiles == False == # 5) Set to True to plot vertical profiles of the 50th, 90th and 99th percentile of updraft, downdrafts and overall vertical velocity +vert_ref == False == # 5) Set to True to plot vertical profile of reflectivity with height +refcfad == False == # 6) Set to True to plot CFAD of reflectivity with height + +# Text files created in run_ipolarris_new.py +all2 == False == # Set to True to output ALL text files in SET 2 below +rrstats_txt == False == # 7) +rrhist_txt == False == # 8) +rrstats_areas_txt == False == # 9) +percentiles_txt == False == # 10) + +# Plots created in plot_driver.py +all3 == False == Set to True to output ALL figures in SET 3 below +plot_int == False == # 11) Set to True to plot integrated parameters over the whole time frame +plot_cs == False == # 12) Set to True to plot separate convective and stratiform CFADs +cfad_mpanel_flag == False == # 13) Set to True to plot 4-panel of CFADs of Z, ZDR, KDP and W +hid_cfad_flag == False == # 14) Set to True to plot CFAD of HID +joint_flag == False == # 15) Set to True to plot 4-panel of comparison figures between various polarimetric vars +cfad_individ_flag == False == # 16) Set to True to plot separate images for Z, ZDR, KDP, W and RHO +hid_prof == False == # 17) Set to True to plot vertical profile of grouped HID species with height +up_width == False == # 18) Set to True to plot vertical profile of updraft width with temperature. +cappi_multi == True == # 19) Set to True to plot x-panel of CAPPIs for x polarimetric variables at some altitude z (set z below; 1 figure per timestep) +cappi_individ == False == # 20) Set to True to plot a CAPPI for x individual polarimetric variables at some altitude z (set z below; 1 figure per timestep) +rhi_multi == True == # 21) Set to True to plot x-panel of RHIs for x polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) +rhi_individ == False == # 22) Set to True to plot an RHI for x individual polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) + +# Model Only +qr_cappi == False == # FK) Make cappi cross section of mixing ratios. change parameters in plot_driver.py (only valid for model) +qr_rhi == False == # FL) Make rhis of the mixing ratios (only valid for model) + + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'wrf' ------ +#---------------------------------------------------------- + +convert_Tk_Tc == False == # Convert temperature in K to deg C + +#----------------------------- +#------ Output Settings ------ +#----------------------------- + +# Args +image_dir == './outputfig/' == # Output figure directory +ptype == 'png' == # Output figure file extenstion (i.e. .png, .jpg, ...) +cb_friendly == True == # Use color-blindness palette for output (i.e. reflectivity) + +# Constant-Altitude Plan-Position Indicator (CAPPI) +xlim == [-200,200] ==#lat / lon zoom for CAPPIS +ylim == [-200,200] ==# lat / lon zoom for CAPPIS +y == 20 ==#Lat of the y cross-section for RHI +#xlim == [-127.0,-121.0] ==#lat / lon zoom for CAPPIS +#ylim == [45.0,49.0] ==# lat / lon zoom for CAPPIS +#y==35.7 ==#Lat of the y cross-section for RHI +z == 2.0 ==#Height of the CAPPIs +zlim == [0,12] == + +# Histogram Bins for Radar Observables +wbins == np.arange(-25,26,0.5) == # Histogram bins for vertical velocity +dzbins == np.arange(-10,60,1) == # Histogram bins for reflectivity +drbins == np.arange(-2,6,0.05) == # Histogram bins for differential reflectivity +kdbins == np.arange(-2,6,0.05) == # Histogram bins for specific differential phase +rrbins == np.logspace(0.01,100.01,30) == # Histogram bins for rain rates + +# Grouping of HID Variables for Vertical Profiling +hidwater == [1,2,10] == # Group drizzle, rain and big drops +hidgraup == [7,8] == # Group low and high density graupel +hidhail == [9] == # Hail +hidsnow == [3,4,5,6] == # Group ice crystals, snow, wet snow and VI + + +#========================================================= +#### UNCLASSIFIED (from old version of my_config.txt) #### +#========================================================= + +###############Set up variable names and how to read the data############### +latname == lat == +lonname == lon == +pol_on == True ==#Calculate the pol data such as HID and RR +z_resolution == 1.0 ==#Vertical resolution for CFADs. If comparing 2, they need to be the same. +zthresh == -10. ==#Threshold for good data +wthresh == 5. ==#Threshold for 'updraft' statistics. +trange == np.arange(20,-60,-5) ==#Range of thresholds for plotting temperatures. +cs_z == 2.0 ==#Level to determine Convective / stratiform designation. +zconv == 40 ==#Zconv threshold in raintyping algorithm. +conv_types == ['ISO_CONV_CORE','CONVECTIVE','ISO_CS_CORE'] ==#Which Powell et al. types to consider in convective CFADS +strat_types == ['WEAK_ECHO','STRATIFORM','ISO_CONV_FRINGE'] ==#Which Powell et al. types to consider in stratiform CFADS +mixed_types == ['UNCERTAIN'] ==#Which types to not include in either convective or stratiform but will be considered in totals). +zdr_offset == 0.6 ==#Add any Zdr offset here. Value will be SUBTRACTED from the zdr values. +mask_model == False == +drop_vars == False == +# +#######Set up some variables related to the observations ################### +removediffatt == True ==#Remove differential attenuation by Zdr < -1 and dBZ < 35. +# +############Select the types of plots to see on the output########################## +#############Set up some plotting configurations ######################### +# +# +####Set up some specifics for the cross-sections.#################### +cvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +rvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +skip == 2 ==#Number of vectors to skip for the vector plots. +mix_vars ==['qc','qr','qg','qi','qh',config['rr_name'],config['vr_name'],'HID'] ==#Mixing ratios from model to plot. +rhi_vars ==['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['wname']] == #Names of vars for RHI plots +cappi_vars == ['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['vr_name']] == #Names of vars for CAPPI plots +comb_vicr == True ==# Combine VI with CR for plotting. +cappi_contours == ['CS',None,None,None,None,None] ==#What contours to apply to the CAPPI images. +cappi_vectres == 5 ==#Defined the vector skip for cappi plots. +rhi_vectres == [6,2] ==#Defines the [x,z] skip for rhi plots +# diff --git a/configtxt/testing/OBS_CONFIG.txt b/configtxt/testing/OBS_CONFIG.txt new file mode 100644 index 0000000..d2bce0a --- /dev/null +++ b/configtxt/testing/OBS_CONFIG.txt @@ -0,0 +1,219 @@ +#################################################### +#################### MY_CONFIG.TXT ################# +#################################################### + +type == obs == # Type of input data: 'obs' OR 'wrf' (obs + simulated) +mphys == obs == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf' + + +#============== +#### INPUT #### +#============== + +#----------------------------------------------- +#------ Variables Affected by Wrapper ---------- +#----------------------------------------------- + +sdatetime == '20220302-0600' == # Start time of analysis of interest +edatetime == '20220302-0700' == # End time of analysis of interest +rfiles == 'inputtxt/testing/test_radfiles.txt' == # Input directory of radar files to read in +sfiles == ./inputtxt/testing/test_soundfiles.txt == # Sounding file directory +wfiles == ./inputtxt/testing/test_modpolfiles.txt == # Sounding file directory +dfiles == ./inputtxt/testing/test_doppfiles.txt == # Location of dual-Doppler files + + +#----------------------------------------------- +#------ Radar File Reading (NOT OPTIONAL) ------ +#----------------------------------------------- + +# Args +sdtime_format == %Y%m%d-%H%M == # Start time format +edtime_format == %Y%m%d-%H%M == # End time format + +date == '20151203' == # Date of the case +rdate_format == %Y%m%d_%H%M%S == # Format for the radar file date +rdend == 20 == # End of date timestamp in radar filename +rdstart == 5 == # Start of date timestamp in radar filename + +# Variables (NOTE: use NCDUMP to locate variable names of radar observables and info) +dz_name == REF == # Name of the reflectivity field +dr_name == ZDR == # Name of the differential reflectivity field +kd_name == KDP == # Name of the Kdp field +rh_name == RHO == # Name of the RhoHV field +rr_name == None == # Name of the Rain rate / precipitation field +vr_name == VEL == # Name of radial velocity field +t_name == T == # Name of the temperature field +uname == eastward_wind == # Name of the zonal wind field +vname == northward_wind == # Name of the meridional wind field +wname == upward_air_velocity == # Name of the vertical wind field +xname == x == # Name of the zonal directional variable +yname == y == # Name of the meridional directional variables +zname == z == # Name of the vertical level field +latname == lat == +lonname == lon == +band == S == # Radar band: X, C OR S. Note: needs to be capital letter. +exper == KLGX == # Radar location +lat == 47.116806 == # Latitude of the radar station +lon == -124.10625 == # Longitude of the radar station +radarname == S-band == # + +# Other (NOTE: use the internet to find these - not ideal) +alt == 354 == # Altitude of the radar + +#--------------------------------------------------- +#------ Doppler Radar File Reading (Optional) ------ +#--------------------------------------------------- + +dd_on == False == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ddate_format == %Y%m%d_%H%M%S == # Format for the dual-Doppler file date +ddstart == 10 == # Offset for dual-Doppler timestamp in filename +ddend == 25 == # Offset for dual-Doppler timestamp in filename + +# Variables (NOTE: use NCDUMP to locate variable names of Doppler radar fields and info) +convname == None == # Name of + +#---------------------------------------------- +#------ Sounding File Reading (Optional) ------ +#---------------------------------------------- + +snd_on == False == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +sdate_format == %Y%m%d_%H%M%S == # Sounding file date format +sdstart == 4 == # Offset for date timestamp in radar filename +sdend == 19 == # Number of characters in timestamp on radar file +sstat == UIL == # Sounding station identification + +#------------------------------------------- +#------ POL-f File Reading (Optional) ------ +#------------------------------------------- + +wrft_on == True == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +wdate_format == %Y-%m-%d_%H:%M:%S == # Sounding file date format +wdstart == 14 == # Offset for date timestamp in radar filename +wdend == 33 == # Number of characters in timestamp on radar file + +#=============== +#### OUTPUT #### +#=============== + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'obs' ------ +#---------------------------------------------------------- + +# SET 1) Plots created in run_ipolarris_new.py +all1 == False == # Set to True to output ALL figures in SET 1 below +compo_ref == False == # 1) Set to True to plot for spatial composite reflectivity plotting (1 figure per timestep) +cappi_rr == False == # 3) Set to True to plot rain rate CAPPI at some altitude z (set z below) +rr_timeseries == False == # 4) Set to True to plot a time series of convective and stratiform rain rate +vv_profiles == False == # 5) Set to True to plot vertical profiles of the 50th, 90th and 99th percentile of updraft, downdrafts and overall vertical velocity +vert_ref == False == # 5) Set to True to plot vertical profile of reflectivity with height +refcfad == False == # 6) Set to True to plot CFAD of reflectivity with height + +# Text files created in run_ipolarris_new.py +all2 == False == # Set to TRUE to output ALL text files in SET 2 below +rrstats_txt == False == # 7) +rrhist_txt == False == # 8) +rrstats_areas_txt == False == # 9) +percentiles_txt == False == # 10) + +# Plots created in plot_driver.py +all3 == False == Set to TRUE to output ALL figures in SET 3 below +cfad_multi == False == # 13) Set to True to plot 4-panel of CFADs of Z, ZDR, KDP and W +hist_multi == False == # 15) Set to True to plot 4-panel of comparison figures between various polarimetric vars +cfad_individ == False == # 16) Set to True to plot separate images for Z, ZDR, KDP, W, RHO and HID +hid_prof == False == # 17) Set to True to plot vertical profile of grouped HID species with height +up_width == False == # 18) Set to True to plot vertical profile of updraft width with temperature. +cappi_multi == False == # 19) Set to True to plot x-panel of CAPPIs for x polarimetric variables at some altitude z (set z below; 1 figure per timestep) +cappi_individ == False == # 20) Set to True to plot a CAPPI for x individual polarimetric variables at some altitude z (set z below; 1 figure per timestep) +rhi_multi == False == # 21) Set to True to plot x-panel of RHIs for x polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) +rhi_individ == True == # 22) Set to True to plot an RHI for x individual polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) + +# Model Only +qr_cappi == False == # FK) Make cappi cross section of mixing ratios. change parameters in plot_driver.py (only valid for model) +qr_rhi == False == # FL) Make rhis of the mixing ratios (only valid for model) + + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'wrf' ------ +#---------------------------------------------------------- + +convert_Tk_Tc == False == # Convert temperature in K to deg C + +#----------------------------- +#------ Output Settings ------ +#----------------------------- + +# Args +image_dir == './outputfig/' == # Output figure directory +ptype == 'png' == # Output figure file extenstion (i.e. .png, .jpg, .mp4, ...) +cb_friendly == True == # Use color-blindness palette for output (i.e. reflectivity) + +# Constant-Altitude Plan-Position Indicator (CAPPI) +xlim == [-200,200] ==#lat / lon zoom for CAPPIS +ylim == [-200,200] ==# lat / lon zoom for CAPPIS +y == 0 ==#Lat of the y cross-section for RHI +#xlim == [-127.0,-121.0] ==#lat / lon zoom for CAPPIS +#ylim == [45.0,49.0] ==# lat / lon zoom for CAPPIS +#y==35.7 ==#Lat of the y cross-section for RHI +z == 2.5 ==#Height of the CAPPIs +zlim == [0,12] == + +# Histogram Bins for Radar Observables +wbins == np.arange(-25,26,0.5) == # Histogram bins for vertical velocity +dzbins == np.arange(-10,60,1) == # Histogram bins for reflectivity +drbins == np.arange(-2,6,0.05) == # Histogram bins for differential reflectivity +kdbins == np.arange(-2,2,0.05) == # Histogram bins for specific differential phase +rrbins == np.logspace(0.01,100.01,30) == # Histogram bins for rain rates + +# Grouping of HID Variables for Vertical Profiling +hidwater == [1,2,10] == # Group drizzle, rain and big drops +hidgraup == [7,8] == # Group low and high density graupel +hidhail == [9] == # Hail +hidsnow == [3,4,5,6] == # Group ice crystals, snow, wet snow and VI + + +#========================================================= +#### UNCLASSIFIED (from old version of my_config.txt) #### +#========================================================= + +###############Set up variable names and how to read the data############### +pol_on == True ==#Calculate the pol data such as HID and RR +z_resolution == 1.0 ==#Vertical resolution for CFADs. If comparing 2, they need to be the same. +zthresh == -10. ==#Threshold for good data +wthresh == 5. ==#Threshold for 'updraft' statistics. +trange == np.arange(20,-60,-5) ==#Range of thresholds for plotting temperatures. +cs_z == 2.0 ==#Level to determine Convective / stratiform designation. +zconv == 40 ==#Zconv threshold in raintyping algorithm. +conv_types == ['ISO_CONV_CORE','CONVECTIVE','ISO_CS_CORE'] ==#Which Powell et al. types to consider in convective CFADS +strat_types == ['WEAK_ECHO','STRATIFORM','ISO_CONV_FRINGE'] ==#Which Powell et al. types to consider in stratiform CFADS +mixed_types == ['UNCERTAIN'] ==#Which types to not include in either convective or stratiform but will be considered in totals). +zdr_offset == 0.6 ==#Add any Zdr offset here. Value will be SUBTRACTED from the zdr values. +mask_model == False == +drop_vars == False == +# +#######Set up some variables related to the observations ################### +removediffatt == True ==#Remove differential attenuation by Zdr < -1 and dBZ < 35. +# +############Select the types of plots to see on the output########################## +#############Set up some plotting configurations ######################### +# +# +####Set up some specifics for the cross-sections.#################### +cvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +rvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +skip == 2 ==#Number of vectors to skip for the vector plots. +mix_vars ==['qc','qr','qg','qi','qh',config['rr_name'],config['vr_name'],'HID'] ==#Mixing ratios from model to plot. +rhi_vars ==['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['wname']] == #Names of vars for RHI plots +cappi_vars == ['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['vr_name']] == #Names of vars for CAPPI plots +comb_vicr == True ==# Combine VI with CR for plotting. +cappi_contours == ['CS',None,None,None,None,None] ==#What contours to apply to the CAPPI images. +cappi_vectres == 5 ==#Defined the vector skip for cappi plots. +rhi_vectres == [6,2] ==#Defines the [x,z] skip for rhi plots +# diff --git a/configtxt/testing/SIM_CONFIG.txt b/configtxt/testing/SIM_CONFIG.txt new file mode 100644 index 0000000..0c983bc --- /dev/null +++ b/configtxt/testing/SIM_CONFIG.txt @@ -0,0 +1,214 @@ +#################################################### +#################### MY_CONFIG.TXT ################# +#################################################### + +type == wrf == # Type of input data: 'obs' OR 'wrf' (obs + simulated) +mphys == wdm6 == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf' + + +#============== +#### INPUT #### +#============== + +#----------------------------------------------- +#------ Radar File Reading (NOT OPTIONAL) ------ +#----------------------------------------------- + +# Args +sdatetime == '20151203-2100' == # Start time of analysis of interest +sdatetime_format == %Y%m%d-%H%M == # Start time format +edatetime == '20151203-2200' == # End time of analysis of interest +edatetime_format == %Y%m%d-%H%M == # End time format + +date == '20151203' == # Date of the case +rfiles == './inputtxt/testing/test_modpolfiles.txt' == # Input directory of radar files to read in +rdate_format == %Y-%m-%d_%H:%M:%S == # Format for the radar file date +rdend == 33 == # End of date timestamp in radar filename +rdstart == 14 == # Start of date timestamp in radar filename + +# Variables (NOTE: use NCDUMP to locate variable names of radar observables and info) +dz_name == zhh01 == # Name of the reflectivity field +dr_name == zdr01 == # Name of the differential reflectivity field +kd_name == kdp01 == # Name of the Kdp field +rh_name == rhohv01 == # Name of the RhoHV field +rr_name == precip == # Name of the Rain rate / precipitation field +vr_name == vrad01 == # Name of radial velocity field +t_name == t_air == # Name of the temperature field +vdop_name == vdop01 == # Name of Doppler velocity +uname == u == # Name of the zonal wind field +vname == v == # Name of the meridional wind field +wname == w == # Name of the vertical wind field +xname == longitude == # Name of the zonal directional variable +yname == latitude == # Name of the meridional directional variables +zname == hgt == # Name of the vertical level field +latname == latitude == +lonname == longitude == +band == S == # Radar band: X, C OR S. Note: needs to be capital letter. +exper == WDM6 == # Radar location +lat == 47.116806 == # Latitude of the radar station +lon == -124.10625 == # Longitude of the radar station +radarname == S-band == # + +# Other (NOTE: use the internet to find these - not ideal) +alt == 354 == # Altitude of the radar + +#--------------------------------------------------- +#------ Doppler Radar File Reading (Optional) ------ +#--------------------------------------------------- + +dd_on == False == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +dfiles == ./inputtxt/testing/test_doppfiles.txt == # Location of dual-Doppler files +ddate_format == %Y%m%d_%H%M%S == # Format for the dual-Doppler file date +ddstart == 10 == # Offset for dual-Doppler timestamp in filename +ddend == 25 == # Offset for dual-Doppler timestamp in filename + +# Variables (NOTE: use NCDUMP to locate variable names of Doppler radar fields and info) +convname == None == # Name of + +#---------------------------------------------- +#------ Sounding File Reading (Optional) ------ +#---------------------------------------------- + +snd_on == False == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +sdate_format == %Y%m%d_%H%M%S == # Sounding file date format +sfiles == ./inputtxt/testing/test_soundfiles.txt == # Sounding file directory +sdstart == 4 == # Offset for date timestamp in radar filename +sdend == 19 == # Number of characters in timestamp on radar file +sstat == UIL == # Sounding station identification + +#------------------------------------------- +#------ POL-f File Reading (Optional) ------ +#------------------------------------------- + +wrft_on == True == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +wdate_format == %Y-%m-%d_%H:%M:%S == # Sounding file date format +wfiles == ./inputtxt/testing/test_modpolfiles.txt == # Sounding file directory +wdstart == 14 == # Offset for date timestamp in radar filename +wdend == 33 == # Number of characters in timestamp on radar file + +#=============== +#### OUTPUT #### +#=============== + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'obs' ------ +#---------------------------------------------------------- + +# SET 1) Plots created in run_ipolarris_new.py +all1 == False == # Set to True to output ALL figures in SET 1 below +compo_ref == False == # 1) Set to True to plot for spatial composite reflectivity plotting (1 figure per timestep) +cappi_rr == False == # 3) Set to True to plot rain rate CAPPI at some altitude z (set z below) +rr_timeseries == False == # 4) Set to True to plot a time series of convective and stratiform rain rate +vv_profiles == False == # 5) Set to True to plot vertical profiles of the 50th, 90th and 99th percentile of updraft, downdrafts and overall vertical velocity +vert_ref == False == # 5) Set to True to plot vertical profile of reflectivity with height +refcfad == False == # 6) Set to True to plot CFAD of reflectivity with height + +# Text files created in run_ipolarris_new.py +all2 == False == # Set to TRUE to output ALL text files in SET 2 below +rrstats_txt == False == # 7) +rrhist_txt == False == # 8) +rrstats_areas_txt == False == # 9) +percentiles_txt == False == # 10) + +# Plots created in plot_driver.py +all3 == False == Set to TRUE to output ALL figures in SET 3 below +cfad_multi == False == # 13) Set to True to plot 4-panel of CFADs of Z, ZDR, KDP and W +hist_multi == False == # 15) Set to True to plot 4-panel of comparison figures between various polarimetric vars +cfad_individ == False == # 16) Set to True to plot separate images for Z, ZDR, KDP, W, RHO and HID +hid_prof == False == # 17) Set to True to plot vertical profile of grouped HID species with height +up_width == False == # 18) Set to True to plot vertical profile of updraft width with temperature. +cappi_multi == False == # 19) Set to True to plot x-panel of CAPPIs for x polarimetric variables at some altitude z (set z below; 1 figure per timestep) +cappi_individ == False == # 20) Set to True to plot a CAPPI for x individual polarimetric variables at some altitude z (set z below; 1 figure per timestep) +rhi_multi == True == # 21) Set to True to plot x-panel of RHIs for x polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) +rhi_individ == False == # 22) Set to True to plot an RHI for x individual polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) + +# Model Only +qr_cappi == False == # FK) Make cappi cross section of mixing ratios. change parameters in plot_driver.py (only valid for model) +qr_rhi == False == # FL) Make rhis of the mixing ratios (only valid for model) + + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'wrf' ------ +#---------------------------------------------------------- + +convert_Tk_Tc == True == # Convert temperature in K to deg C + +#----------------------------- +#------ Output Settings ------ +#----------------------------- + +# Args +image_dir == './outputfig/' == # Output figure directory +ptype == 'png' == # Output figure file extenstion (i.e. .png, .jpg, .mp4, ...) +cb_friendly == True == # Use color-blindness palette for output (i.e. reflectivity) + +# Constant-Altitude Plan-Position Indicator (CAPPI) +xlim == [-200,200] ==#lat / lon zoom for CAPPIS +ylim == [-200,200] ==# lat / lon zoom for CAPPIS +y == 0 ==#Lat of the y cross-section for RHI +#xlim == [-127.0,-121.0] ==#lat / lon zoom for CAPPIS +#ylim == [45.0,49.0] ==# lat / lon zoom for CAPPIS +#y==35.7 ==#Lat of the y cross-section for RHI +z == 3.0 ==#Height of the CAPPIs +zlim == [0,10] == + +# Histogram Bins for Radar Observables +wbins == np.arange(-25,26,0.5) == # Histogram bins for vertical velocity +dzbins == np.arange(-10,60,1) == # Histogram bins for reflectivity +drbins == np.arange(-2,6,0.05) == # Histogram bins for differential reflectivity +kdbins == np.arange(-2,6,0.05) == # Histogram bins for specific differential phase +rrbins == np.logspace(0.01,100.01,30) == # Histogram bins for rain rates + +# Grouping of HID Variables for Vertical Profiling +hidwater == [1,2,10] == # Group drizzle, rain and big drops +hidgraup == [7,8] == # Group low and high density graupel +hidhail == [9] == # Hail +hidsnow == [3,4,5,6] == # Group ice crystals, snow, wet snow and VI + + +#========================================================= +#### UNCLASSIFIED (from old version of my_config.txt) #### +#========================================================= + +###############Set up variable names and how to read the data############### +pol_on == True ==#Calculate the pol data such as HID and RR +z_resolution == 1.0 ==#Vertical resolution for CFADs. If comparing 2, they need to be the same. +zthresh == -10. ==#Threshold for good data +wthresh == 5. ==#Threshold for 'updraft' statistics. +trange == np.arange(20,-60,-5) ==#Range of thresholds for plotting temperatures. +cs_z == 2.0 ==#Level to determine Convective / stratiform designation. +zconv == 40 ==#Zconv threshold in raintyping algorithm. +conv_types == ['ISO_CONV_CORE','CONVECTIVE','ISO_CS_CORE'] ==#Which Powell et al. types to consider in convective CFADS +strat_types == ['WEAK_ECHO','STRATIFORM','ISO_CONV_FRINGE'] ==#Which Powell et al. types to consider in stratiform CFADS +mixed_types == ['UNCERTAIN'] ==#Which types to not include in either convective or stratiform but will be considered in totals). +zdr_offset == 0.6 ==#Add any Zdr offset here. Value will be SUBTRACTED from the zdr values. +mask_model == False == +drop_vars == False == +# +#######Set up some variables related to the observations ################### +removediffatt == True ==#Remove differential attenuation by Zdr < -1 and dBZ < 35. +# +############Select the types of plots to see on the output########################## +#############Set up some plotting configurations ######################### +# +# +####Set up some specifics for the cross-sections.#################### +cvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +rvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +skip == 2 ==#Number of vectors to skip for the vector plots. +mix_vars ==['qc','qr','qg','qi','qh',config['rr_name'],config['vr_name'],'HID'] ==#Mixing ratios from model to plot. +rhi_vars ==['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['wname']] == #Names of vars for RHI plots +cappi_vars == ['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['vr_name']] == #Names of vars for CAPPI plots +comb_vicr == True ==# Combine VI with CR for plotting. +cappi_contours == ['CS',None,None,None,None,None] ==#What contours to apply to the CAPPI images. +cappi_vectres == 5 ==#Defined the vector skip for cappi plots. +rhi_vectres == [6,2] ==#Defines the [x,z] skip for rhi plots +# diff --git a/configtxt/testing/cwr_obs_config_template.txt b/configtxt/testing/cwr_obs_config_template.txt new file mode 100644 index 0000000..4f3e452 --- /dev/null +++ b/configtxt/testing/cwr_obs_config_template.txt @@ -0,0 +1,216 @@ +#################################################### +#################### MY_CONFIG.TXT ################# +#################################################### + +type == == # Type of input data: 'obs' OR 'wrf' (obs + simulated) +mphys == == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf' + + +#============== +#### INPUT #### +#============== + +#----------------------------------------------- +#------ Variables Affected by Wrapper ---------- +#----------------------------------------------- + +sdatetime == == # Start time of analysis of interest +edatetime == == # End time of analysis of interest +rfiles == == # Input directory of radar files to read in +sfiles == == # Sounding file directory +wfiles == == # Sounding file directory +dfiles == == # Location of dual-Doppler files +image_dir == == # Output figure directory +ptype == == # Output figure file extenstion (i.e. .png, .jpg, .mp4, ...) +exper == == # Radar location +lat == == # Latitude of the radar station +lon == == # Longitude of the radar station + +#----------------------------------------------- +#------ Radar File Reading (NOT OPTIONAL) ------ +#----------------------------------------------- + +# Args +sdatetime_format == %Y%m%d-%H%M == # Start time format +edatetime_format == %Y%m%d-%H%M == # End time format + +rdate_format == %Y%m%d_%H%M%S == # Format for the radar file date +rdend == 21 == # End of date timestamp in radar filename +rdstart == 6 == # Start of date timestamp in radar filename + +# Variables (NOTE: use NCDUMP to locate variable names of radar observables and info) +dz_name == DBZH == # Name of the reflectivity field +dr_name == ZDR == # Name of the differential reflectivity field +kd_name == KDP == # Name of the Kdp field +rh_name == RHOHV == # Name of the RhoHV field +rr_name == None == # Name of the Rain rate / precipitation field +vr_name == VRADH == # Name of radial velocity field +t_name == T == # Name of the temperature field +uname == eastward_wind == # Name of the zonal wind field +vname == northward_wind == # Name of the meridional wind field +wname == upward_air_velocity == # Name of the vertical wind field +xname == x == # Name of the zonal directional variable +yname == y == # Name of the meridional directional variables +zname == z == # Name of the vertical level field +latname == lat == +lonname == lon == +band == S == # Radar band: X, C OR S. Note: needs to be capital letter. +radarname == S-band == # + +# Other (NOTE: use the internet to find these - not ideal) + +#--------------------------------------------------- +#------ Doppler Radar File Reading (Optional) ------ +#--------------------------------------------------- + +dd_on == False == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ddate_format == %Y%m%d_%H%M%S == # Format for the dual-Doppler file date +ddstart == 10 == # Offset for dual-Doppler timestamp in filename +ddend == 25 == # Offset for dual-Doppler timestamp in filename + +# Variables (NOTE: use NCDUMP to locate variable names of Doppler radar fields and info) +convname == None == # Name of + +#---------------------------------------------- +#------ Sounding File Reading (Optional) ------ +#---------------------------------------------- + +snd_on == False == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +sdate_format == %Y%m%d_%H%M%S == # Sounding file date format +sdstart == 4 == # Offset for date timestamp in radar filename +sdend == 19 == # Number of characters in timestamp on radar file +sstat == UIL == # Sounding station identification + +#------------------------------------------- +#------ POL-f File Reading (Optional) ------ +#------------------------------------------- + +wrft_on == True == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ad == config['date']+'_' == # Extra characters +wdate_format == %Y-%m-%d_%H:%M:%S == # Sounding file date format +wdstart == 16 == # Offset for date timestamp in radar filename +wdend == 35 == # Number of characters in timestamp on radar file + +#=============== +#### OUTPUT #### +#=============== + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'obs' ------ +#---------------------------------------------------------- + +# SET 1) Plots created in run_ipolarris_new.py +all1 == False == # Set to True to output ALL figures in SET 1 below +compo_ref == False == # 1) Set to True to plot for spatial composite reflectivity plotting (1 figure per timestep) +cappi_rr == False == # 3) Set to True to plot rain rate CAPPI at some altitude z (set z below) +rr_timeseries == False == # 4) Set to True to plot a time series of convective and stratiform rain rate +vv_profiles == False == # 5) Set to True to plot vertical profiles of the 50th, 90th and 99th percentile of updraft, downdrafts and overall vertical velocity +vert_ref == False == # 5) Set to True to plot vertical profile of reflectivity with height +refcfad == False == # 6) Set to True to plot CFAD of reflectivity with height + +# Text files created in run_ipolarris_new.py +all2 == False == # Set to TRUE to output ALL text files in SET 2 below +rrstats_txt == False == # 7) +rrhist_txt == False == # 8) +rrstats_areas_txt == False == # 9) +percentiles_txt == False == # 10) + +# Plots created in plot_driver.py +all3 == False == Set to TRUE to output ALL figures in SET 3 below +cfad_multi == False == # 13) Set to True to plot 4-panel of CFADs of Z, ZDR, KDP and W +hist_multi == False == # 15) Set to True to plot 4-panel of comparison figures between various polarimetric vars +cfad_individ == False == # 16) Set to True to plot separate images for Z, ZDR, KDP, W, RHO and HID +hid_prof == False == # 17) Set to True to plot vertical profile of grouped HID species with height +up_width == False == # 18) Set to True to plot vertical profile of updraft width with temperature. +cappi_multi == True == # 19) Set to True to plot x-panel of CAPPIs for x polarimetric variables at some altitude z (set z below; 1 figure per timestep) +cappi_individ == False == # 20) Set to True to plot a CAPPI for x individual polarimetric variables at some altitude z (set z below; 1 figure per timestep) +rhi_multi == False == # 21) Set to True to plot x-panel of RHIs for x polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) +rhi_individ == False == # 22) Set to True to plot an RHI for x individual polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) + +# Model Only +qr_cappi == False == # FK) Make cappi cross section of mixing ratios. change parameters in plot_driver.py (only valid for model) +qr_rhi == False == # FL) Make rhis of the mixing ratios (only valid for model) + + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'wrf' ------ +#---------------------------------------------------------- + +convert_Tk_Tc == False == # Convert temperature in K to deg C + +#----------------------------- +#------ Output Settings ------ +#----------------------------- + +# Args +cb_friendly == True == # Use color-blindness palette for output (i.e. reflectivity) + +# Constant-Altitude Plan-Position Indicator (CAPPI) +xlim == [-200,200] ==#lat / lon zoom for CAPPIS +ylim == [-200,200] ==# lat / lon zoom for CAPPIS +y == 0 ==#Lat of the y cross-section for RHI +#xlim == [-127.0,-121.0] ==#lat / lon zoom for CAPPIS +#ylim == [45.0,49.0] ==# lat / lon zoom for CAPPIS +#y==35.7 ==#Lat of the y cross-section for RHI +z == 2.0 ==#Height of the CAPPIs +zlim == [0,12] == + +# Histogram Bins for Radar Observables +wbins == np.arange(-25,26,0.5) == # Histogram bins for vertical velocity +dzbins == np.arange(-10,60,1) == # Histogram bins for reflectivity +drbins == np.arange(-2,6,0.05) == # Histogram bins for differential reflectivity +kdbins == np.arange(-2,2,0.05) == # Histogram bins for specific differential phase +rrbins == np.logspace(0.01,100.01,30) == # Histogram bins for rain rates + +# Grouping of HID Variables for Vertical Profiling +hidwater == [1,2,10] == # Group drizzle, rain and big drops +hidgraup == [7,8] == # Group low and high density graupel +hidhail == [9] == # Hail +hidsnow == [3,4,5,6] == # Group ice crystals, snow, wet snow and VI + + +#========================================================= +#### UNCLASSIFIED (from old version of my_config.txt) #### +#========================================================= + +###############Set up variable names and how to read the data############### +pol_on == True ==#Calculate the pol data such as HID and RR +z_resolution == 1.0 ==#Vertical resolution for CFADs. If comparing 2, they need to be the same. +zthresh == -10. ==#Threshold for good data +wthresh == 5. ==#Threshold for 'updraft' statistics. +trange == np.arange(20,-60,-5) ==#Range of thresholds for plotting temperatures. +cs_z == 2.0 ==#Level to determine Convective / stratiform designation. +zconv == 40 ==#Zconv threshold in raintyping algorithm. +conv_types == ['ISO_CONV_CORE','CONVECTIVE','ISO_CS_CORE'] ==#Which Powell et al. types to consider in convective CFADS +strat_types == ['WEAK_ECHO','STRATIFORM','ISO_CONV_FRINGE'] ==#Which Powell et al. types to consider in stratiform CFADS +mixed_types == ['UNCERTAIN'] ==#Which types to not include in either convective or stratiform but will be considered in totals). +zdr_offset == 0.6 ==#Add any Zdr offset here. Value will be SUBTRACTED from the zdr values. +mask_model == False == +drop_vars == False == +# +#######Set up some variables related to the observations ################### +removediffatt == True ==#Remove differential attenuation by Zdr < -1 and dBZ < 35. +# +############Select the types of plots to see on the output########################## +#############Set up some plotting configurations ######################### +# +# +####Set up some specifics for the cross-sections.#################### +cvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +rvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +skip == 2 ==#Number of vectors to skip for the vector plots. +mix_vars ==['qc','qr','qg','qi','qh',config['rr_name'],config['vr_name'],'HID'] ==#Mixing ratios from model to plot. +rhi_vars ==['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['wname']] == #Names of vars for RHI plots +cappi_vars == ['HID',config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],config['vr_name']] == #Names of vars for CAPPI plots +comb_vicr == True ==# Combine VI with CR for plotting. +cappi_contours == ['CS',None,None,None,None,None] ==#What contours to apply to the CAPPI images. +cappi_vectres == 5 ==#Defined the vector skip for cappi plots. +rhi_vectres == [6,2] ==#Defines the [x,z] skip for rhi plots +# diff --git a/configtxt/testing/nexrad_obs_config_template.txt b/configtxt/testing/nexrad_obs_config_template.txt new file mode 100644 index 0000000..7c25a99 --- /dev/null +++ b/configtxt/testing/nexrad_obs_config_template.txt @@ -0,0 +1,211 @@ +#################################################### +#################### MY_CONFIG.TXT ################# +#################################################### + +type == == # Type of input data: 'obs' OR 'wrf' (obs + simulated) +mphys == == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf' + + +#=============== +#### OUTPUT #### +#=============== + +# Args +cb_friendly == True == # Use color-blindness palette for output (i.e. reflectivity) +latlon == True == # Output plots on Cartopy basemap if True + +xlim == == #lat / lon zoom for CAPPIS +#xlim == [-200,200] == +#xlim == [-126.0,-122.0] == #lat / lon zoom for CAPPIS +ylim == == #lat / lon zoom for CAPPIS +#ylim == [-200,200] == +#ylim == [46.0,48.5] == #lat / lon zoom for CAPPIS +zmax == 10 == + +y == == # Lat of the y cross-section for RHI +#y == 0.5 == # Lat of the y cross-section for RHI +#z == 0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0 == # Height of the CAPPIs +z == 2.0 == # Height of the CAPPIs +z_resolution == 0.5 == # Vertical resolution for CFADs. + + +#============== +#### INPUT #### +#============== + +#----------------------------------------------- +#------ Variables Affected by Wrapper ---------- +#----------------------------------------------- + +sdatetime == == # Start time of analysis of interest +edatetime == == # End time of analysis of interest +rfiles == == # Input directory of radar files to read in +sfiles == == # Sounding file directory +wfiles == == # Sounding file directory +dfiles == == # Location of dual-Doppler files +image_dir == == # Output figure directory +rr_dir == == # Output rain rate netcdf directory +ptype == == # Output figure file extenstion (i.e. png, jpg, mp4, ...) +exper == == # Radar location +lat == == # Latitude of the radar station +lon == == # Longitude of the radar station + +#------------------------------------------------------------------ +#------ Sounding File Reading (REQUIRED if wfrt_on == False) ------ +#------------------------------------------------------------------ + +snd_on == == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +sdate_format == %Y%m%d_%H%M%S == # Sounding file date format +sdstart == 4 == # Offset for date timestamp in radar filename +sdend == 19 == # Number of characters in timestamp on radar file +sstat == UIL == # Sounding station identification + +#-------------------------------------------------------------- +#------ POL-f File Reading (REQUIRED if snd_on == False) ------ +#-------------------------------------------------------------- + +wrft_on == == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +wdate_format == %Y-%m-%d_%H:%M:%S == # Sounding file date format +wdstart == 16 == # Offset for date timestamp in radar filename +wdend == 35 == # Number of characters in timestamp on radar file + +#--------------------------------------------------- +#------ Doppler Radar File Reading (Optional) ------ +#--------------------------------------------------- + +dd_on == == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ddate_format == %Y%m%d_%H%M%S == # Format for the dual-Doppler file date +ddstart == 10 == # Offset for dual-Doppler timestamp in filename +ddend == 25 == # Offset for dual-Doppler timestamp in filename + +# Variables (NOTE: use NCDUMP to locate variable names of Doppler radar fields and info) +convname == None == # Name of + +#---------------------------------------------------------------------------------------------------------------- +#------ Radar File Reading (DEFAULT - Change only if radar .nc conventions have changed - use ncdump) ----------- +#---------------------------------------------------------------------------------------------------------------- + +# Args +sdatetime_format == %Y%m%d-%H%M == # Start time format +edatetime_format == %Y%m%d-%H%M == # End time format + +rdate_format == %Y%m%d_%H%M%S == # Format for the radar file date +rdend == 20 == # End of date timestamp in radar filename +rdstart == 5 == # Start of date timestamp in radar filename + +# Variables (NOTE: use NCDUMP to locate variable names of radar observables and info) +dz_name == REF == # Name of the reflectivity field +dr_name == ZDR == # Name of the differential reflectivity field +kd_name == KDP == # Name of the Kdp field +rh_name == RHO == # Name of the RhoHV field +rr_name == None == # Name of the Rain rate / precipitation field +vr_name == VEL == # Name of radial velocity field +t_name == T == # Name of the temperature field +uname == eastward_wind == # Name of the zonal wind field +vname == northward_wind == # Name of the meridional wind field +wname == upward_air_velocity == # Name of the vertical wind field +xname == x0 == # File naming of the zonal directional variable +yname == y0 == # File naming of the meridional directional variables +zname == z0 == # File naming of the vertical level field +lonname == lon0 == # File naming of the longitude variable +latname == lat0 == # File naming of the latitude variable +band == S == # Radar band: X, C OR S. Note: needs to be capital letter. + + +#============== +#### OTHER #### +#============== + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'obs' ------ +#---------------------------------------------------------- + +# SET 1) Plots created in run_ipolarris.py +all1 == False == # Set to True to output ALL figures in SET 1 below +compo_ref == False == # 1) Set to True to plot for spatial composite reflectivity plotting (1 figure per timestep) +cappi_rr == False == # 3) Set to True to plot rain rate CAPPI at some altitude z (set z below) +rr_timeseries == False == # 4) Set to True to plot a time series of convective and stratiform rain rate +vv_profiles == False == # 5) Set to True to plot vertical profiles of the 50th, 90th and 99th percentile of updraft, downdrafts and overall vertical velocity +vert_ref == False == # 5) Set to True to plot vertical profile of reflectivity with height +refcfad == False == # 6) Set to True to plot CFAD of reflectivity with height + +# Text files created in run_ipolarris.py +all2 == False == # Set to TRUE to output ALL text files in SET 2 below +rrstats_txt == False == # 7) +rrhist_txt == False == # 8) +rrstats_areas_txt == False == # 9) +percentiles_txt == False == # 10) + +# Plots created in plot_driver.py +all3 == False == Set to TRUE to output ALL figures in SET 3 below +pol_compare == False == # 13) Set to True to plot 4-panel of CFADs of Z, ZDR, KDP and W +hist_multi == False == # 15) Set to True to plot 4-panel of comparison figures between various polarimetric vars +cfad_multi == True == # 13) Set to True to plot x-panel of CFADs for x polarimetric variables +cfad_individ == True == # 16) Set to True to plot separate images for Z, ZDR, KDP, W, RHO and HID +hid_prof == False == # 17) Set to True to plot vertical profile of grouped HID species with height +up_width == False == # 18) Set to True to plot vertical profile of updraft width with temperature. +cappi_multi == True == # 19) Set to True to plot x-panel of CAPPIs for x polarimetric variables at some altitude z (set z below; 1 figure per timestep) +cappi_individ == True == # 20) Set to True to plot a CAPPI for x individual polarimetric variables at some altitude z (set z below; 1 figure per timestep) +rhi_multi == True == # 21) Set to True to plot x-panel of RHIs for x polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) +rhi_individ == True == # 22) Set to True to plot an RHI for x individual polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) + +# Model Only +qr_cappi == False == # FK) Make cappi cross section of mixing ratios. change parameters in plot_driver.py (only valid for model) +qr_rhi == False == # FL) Make rhis of the mixing ratios (only valid for model) + + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'wrf' ------ +#---------------------------------------------------------- + +convert_Tk_Tc == False == # Convert temperature in K to deg C + +# Grouping of HID Variables for Vertical Profiling +hidwater == [1,2,10] == # Group drizzle, rain and big drops +hidgraup == [7,8] == # Group low and high density graupel +hidhail == [9] == # Hail +hidsnow == [3,4,5,6] == # Group ice crystals, snow, wet snow and VI + + +#========================================================= +#### UNCLASSIFIED (from old version of my_config.txt) #### +#========================================================= + +###############Set up variable names and how to read the data############### +refthresh == -10. ==#Threshold for good data +wthresh == 5. ==#Threshold for 'updraft' statistics. +cs_z == 2.0 ==#Level to determine Convective / stratiform designation. +zconv == 40 ==#Zconv threshold in raintyping algorithm. +conv_types == ['ISO_CONV_CORE','CONVECTIVE','ISO_CS_CORE'] ==#Which Powell et al. types to consider in convective CFADS +strat_types == ['WEAK_ECHO','STRATIFORM','ISO_CONV_FRINGE'] ==#Which Powell et al. types to consider in stratiform CFADS +mixed_types == ['UNCERTAIN'] ==#Which types to not include in either convective or stratiform but will be considered in totals). +zdr_offset == 0.6 ==#Add any Zdr offset here. Value will be SUBTRACTED from the zdr values. +mask_model == False == +drop_vars == False == +# +#######Set up some variables related to the observations ################### +removediffatt == True ==#Remove differential attenuation by Zdr < -1 and dBZ < 35. +# +############Select the types of plots to see on the output########################## +#############Set up some plotting configurations ######################### +# +# +####Set up some specifics for the cross-sections.#################### +cvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +rvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +skip == 2 ==#Number of vectors to skip for the vector plots. +mix_vars ==['qc','qr','qg','qi','qh',config['rr_name'],config['vr_name'],'HID'] ==#Mixing ratios from model to plot. +rhi_vars ==[config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],'HID',config['wname']] == #Names of vars for RHI plots +cfad_vars == [config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],'HID',config['wname']] == #Names of vars for CFAD plots +cfad_compare_vars == ['dz_name','dr_name','kd_name','rh_name','HID','wname'] == #Names of vars for CFAD plots +#cfad_vars == ['HID'] == #Names of vars for CAPPI plots +cappi_vars == [config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],'HID',config['vr_name']] == #Names of vars for CAPPI plots +comb_vicr == True ==# Combine VI with CR for plotting. +cappi_contours == ['CS',None,None,None,None,None] ==#What contours to apply to the CAPPI images. +cappi_vectres == 5 ==#Defined the vector skip for cappi plots. +rhi_vectres == [6,2] ==#Defines the [x,z] skip for rhi plots +# diff --git a/configtxt/testing/nexrad_wrf_config_template.txt b/configtxt/testing/nexrad_wrf_config_template.txt new file mode 100644 index 0000000..cd68823 --- /dev/null +++ b/configtxt/testing/nexrad_wrf_config_template.txt @@ -0,0 +1,212 @@ +#################################################### +#################### MY_CONFIG.TXT ################# +#################################################### + +type == == # Type of input data: 'obs' OR 'wrf' (obs + simulated) +mphys == == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf' + + +#=============== +#### OUTPUT #### +#=============== + +# Args +cb_friendly == True == # Use color-blindness palette for output (i.e. reflectivity) +latlon == True == # Output plots on Cartopy basemap if True + +xlim == == #lat / lon zoom for CAPPIS +#xlim == [-200,200] == +#xlim == [-126.0,-122.0] == #lat / lon zoom for CAPPIS +ylim == == #lat / lon zoom for CAPPIS +#ylim == [-200,200] == +#ylim == [46.0,48.5] == #lat / lon zoom for CAPPIS +zmax == 10 == + +y == == # Lat of the y cross-section for RHI +#y == 0.5 == # Lat of the y cross-section for RHI +#z == 0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0 == # Height of the CAPPIs +z == 2.0 == # Height of the CAPPIs + + +#============== +#### INPUT #### +#============== + +#----------------------------------------------- +#------ Variables Affected by Wrapper ---------- +#----------------------------------------------- + +sdatetime == == # Start time of analysis of interest +edatetime == == # End time of analysis of interest +rfiles == == # Input directory of radar files to read in +sfiles == == # Sounding file directory +wfiles == == # Sounding file directory +dfiles == == # Location of dual-Doppler files +image_dir == == # Output figure directory +rr_dir == == # Output rain rate netcdf directory +ptype == == # Output figure file extenstion (i.e. png, jpg, mp4, ...) +exper == == # Radar location +lat == == # Latitude of the radar station +lon == == # Longitude of the radar station + +#------------------------------------------------------------------ +#------ Sounding File Reading (REQUIRED if wfrt_on == False) ------ +#------------------------------------------------------------------ + +snd_on == == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +sdate_format == %Y%m%d_%H%M%S == # Sounding file date format +sdstart == 4 == # Offset for date timestamp in radar filename +sdend == 19 == # Number of characters in timestamp on radar file +sstat == UIL == # Sounding station identification + +#-------------------------------------------------------------- +#------ POL-f File Reading (REQUIRED if snd_on == False) ------ +#-------------------------------------------------------------- + +wrft_on == == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +wdate_format == %Y-%m-%d_%H:%M:%S == # Sounding file date format +wdstart == 16 == # Offset for date timestamp in radar filename +wdend == 35 == # Number of characters in timestamp on radar file + +#--------------------------------------------------- +#------ Doppler Radar File Reading (Optional) ------ +#--------------------------------------------------- + +dd_on == == # Set this to loop through separate dual-Doppler files (e.g. for obs) + +# Args +ddate_format == %Y%m%d_%H%M%S == # Format for the dual-Doppler file date +ddstart == 10 == # Offset for dual-Doppler timestamp in filename +ddend == 25 == # Offset for dual-Doppler timestamp in filename + +# Variables (NOTE: use NCDUMP to locate variable names of Doppler radar fields and info) +convname == None == # Name of + +#---------------------------------------------------------------------------------------------------------------- +#------ Radar File Reading (DEFAULT - Change only if radar .nc conventions have changed - use ncdump) ----------- +#---------------------------------------------------------------------------------------------------------------- + +# Args +sdatetime_format == %Y%m%d-%H%M == # Start time format +edatetime_format == %Y%m%d-%H%M == # End time format + +rdate_format == %Y-%m-%d_%H:%M:%S == # Format for the radar file date +rdend == 35 == # End of date timestamp in radar filename +rdstart == 16 == # Start of date timestamp in radar filename + +# Variables (NOTE: use NCDUMP to locate variable names of radar observables and info) +dz_name == zhh01 == # Name of the reflectivity field +dr_name == zdr01 == # Name of the differential reflectivity field +kd_name == kdp01 == # Name of the Kdp field +rh_name == rhohv01 == # Name of the RhoHV field +rr_name == None == # Name of the Rain rate / precipitation field +vr_name == vrad01 == # Name of radial velocity field +t_name == t_air == # Name of the temperature field +uname == u == # Name of the zonal wind field +vname == v == # Name of the meridional wind field +wname == w == # Name of the vertical wind field +xname == x == # File naming of the zonal directional variable +yname == y == # File naming of the meridional directional variables +zname == hgt == # File naming of the vertical level field +lonname == longitude == # File naming of the longitude variable +latname == latitude == # File naming of the latitude variable +band == S == # Radar band: X, C OR S. Note: needs to be capital letter. + + +#============== +#### OTHER #### +#============== + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'obs' ------ +#---------------------------------------------------------- + +# SET 1) Plots created in run_ipolarris.py +all1 == False == # Set to True to output ALL figures in SET 1 below +compo_ref == False == # 1) Set to True to plot for spatial composite reflectivity plotting (1 figure per timestep) +cappi_rr == False == # 3) Set to True to plot rain rate CAPPI at some altitude z (set z below) +rr_timeseries == False == # 4) Set to True to plot a time series of convective and stratiform rain rate +vv_profiles == False == # 5) Set to True to plot vertical profiles of the 50th, 90th and 99th percentile of updraft, downdrafts and overall vertical velocity +vert_ref == False == # 5) Set to True to plot vertical profile of reflectivity with height +refcfad == False == # 6) Set to True to plot CFAD of reflectivity with height + +# Text files created in run_ipolarris.py +all2 == False == # Set to TRUE to output ALL text files in SET 2 below +rrstats_txt == False == # 7) +rrhist_txt == False == # 8) +rrstats_areas_txt == False == # 9) +percentiles_txt == False == # 10) + +# Plots created in plot_driver.py +all3 == False == Set to TRUE to output ALL figures in SET 3 below +pol_compare == False == # 13) Set to True to plot 4-panel of CFADs of Z, ZDR, KDP and W +hist_multi == False == # 15) Set to True to plot 4-panel of comparison figures between various polarimetric vars +cfad_multi == True == # 13) Set to True to plot x-panel of CFADs for x polarimetric variables +cfad_individ == True == # 16) Set to True to plot separate images for Z, ZDR, KDP, W, RHO and HID +cfad_compare == True == # 16) Set to True to plot separate images for Z, ZDR, KDP, W, RHO and HID +hid_prof == False == # 17) Set to True to plot vertical profile of grouped HID species with height +up_width == False == # 18) Set to True to plot vertical profile of updraft width with temperature. +cappi_multi == True == # 19) Set to True to plot x-panel of CAPPIs for x polarimetric variables at some altitude z (set z below; 1 figure per timestep) +cappi_individ == True == # 20) Set to True to plot a CAPPI for x individual polarimetric variables at some altitude z (set z below; 1 figure per timestep) +rhi_multi == True == # 21) Set to True to plot x-panel of RHIs for x polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) +rhi_individ == True == # 22) Set to True to plot an RHI for x individual polarimetric variables at some latitude/N-S distance from the radar y (set y below; 1 figure per timestep) + +# Model Only +qr_cappi == False == # FK) Make cappi cross section of mixing ratios. change parameters in plot_driver.py (only valid for model) +qr_rhi == False == # FL) Make rhis of the mixing ratios (only valid for model) + + +#---------------------------------------------------------- +#------ Output Flags (what to print) if type = 'wrf' ------ +#---------------------------------------------------------- + +convert_Tk_Tc == False == # Convert temperature in K to deg C + +# Grouping of HID Variables for Vertical Profiling +hidwater == [1,2,10] == # Group drizzle, rain and big drops +hidgraup == [7,8] == # Group low and high density graupel +hidhail == [9] == # Hail +hidsnow == [3,4,5,6] == # Group ice crystals, snow, wet snow and VI + + +#========================================================= +#### UNCLASSIFIED (from old version of my_config.txt) #### +#========================================================= + +###############Set up variable names and how to read the data############### +z_resolution == 0.5 ==#Vertical resolution for CFADs. If comparing 2, they need to be the same. +refthresh == -10. ==#Threshold for good data +wthresh == 5. ==#Threshold for 'updraft' statistics. +cs_z == 2.0 ==#Level to determine Convective / stratiform designation. +zconv == 40 ==#Zconv threshold in raintyping algorithm. +conv_types == ['ISO_CONV_CORE','CONVECTIVE','ISO_CS_CORE'] ==#Which Powell et al. types to consider in convective CFADS +strat_types == ['WEAK_ECHO','STRATIFORM','ISO_CONV_FRINGE'] ==#Which Powell et al. types to consider in stratiform CFADS +mixed_types == ['UNCERTAIN'] ==#Which types to not include in either convective or stratiform but will be considered in totals). +zdr_offset == 0.6 ==#Add any Zdr offset here. Value will be SUBTRACTED from the zdr values. +mask_model == False == +drop_vars == False == +# +#######Set up some variables related to the observations ################### +removediffatt == True ==#Remove differential attenuation by Zdr < -1 and dBZ < 35. +# +############Select the types of plots to see on the output########################## +#############Set up some plotting configurations ######################### +# +# +####Set up some specifics for the cross-sections.#################### +cvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +rvectors == [None,None,None,None,None,True] ==#Turn on vectors in the plots. +skip == 2 ==#Number of vectors to skip for the vector plots. +mix_vars ==['qc','qr','qg','qi','qh',config['rr_name'],config['vr_name'],'HID'] ==#Mixing ratios from model to plot. +rhi_vars ==[config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],'HID',config['wname']] == #Names of vars for RHI plots +cfad_vars == [config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],'HID',config['wname']] == #Names of vars for CAPPI plots +cfad_compare_vars == ['dz_name','dr_name','kd_name','rh_name','HID','wname'] == #Names of vars for CFAD plots +#cfad_vars == [config['rh_name']] == #Names of vars for CAPPI plots +cappi_vars == [config['dz_name'],config['dr_name'],config['kd_name'],config['rh_name'],'HID',config['vr_name']] == #Names of vars for CAPPI plots +comb_vicr == True ==# Combine VI with CR for plotting. +cappi_contours == ['CS',None,None,None,None,None] ==#What contours to apply to the CAPPI images. +cappi_vectres == 5 ==#Defined the vector skip for cappi plots. +rhi_vectres == [6,2] ==#Defines the [x,z] skip for rhi plots +# diff --git a/polarris_config_mc3e_obs.txt b/configtxt/testing/polarris_config_mc3e_obs.txt similarity index 100% rename from polarris_config_mc3e_obs.txt rename to configtxt/testing/polarris_config_mc3e_obs.txt diff --git a/polarris_config_mc3e_wrf.txt b/configtxt/testing/polarris_config_mc3e_wrf.txt similarity index 100% rename from polarris_config_mc3e_wrf.txt rename to configtxt/testing/polarris_config_mc3e_wrf.txt diff --git a/polarris_config_twp_obs.txt b/configtxt/testing/polarris_config_twp_obs.txt similarity index 100% rename from polarris_config_twp_obs.txt rename to configtxt/testing/polarris_config_twp_obs.txt diff --git a/polarris_config_twp_wrf.txt b/configtxt/testing/polarris_config_twp_wrf.txt similarity index 100% rename from polarris_config_twp_wrf.txt rename to configtxt/testing/polarris_config_twp_wrf.txt diff --git a/csu_blended_rain_julie.py b/csu_blended_rain_julie.py index d635681..97623bc 100644 --- a/csu_blended_rain_julie.py +++ b/csu_blended_rain_julie.py @@ -149,8 +149,8 @@ def calc_blended_rain(dz, zdr, kdp, r_z_a, r_z_b, r_kdp_a, r_kdp_b, zdp = calc_zdp(zhor, zvert) # calculate contribution to Zh from pure rain - #if fit_a is None: - # fit_a, fit_b = get_linear_fits(method=method) + if fit_a is None: + fit_a, fit_b = get_linear_fits(method=method) zrain = 10.0**((fit_a * zdp + fit_b)/10.0) dzrain = 10.0 * np.log10(zrain) fi = 1.0 - (zrain / zhor) diff --git a/env.yml b/env.yml new file mode 100644 index 0000000..2b691c4 --- /dev/null +++ b/env.yml @@ -0,0 +1,22 @@ +name: pol +channels: +- defaults +- conda-forge +dependencies: +- pandas +- dill +- netcdf4 +- xarray=0.18.0 +- python +- matplotlib +- pyproj +- tqdm +- libgfortran +- cartopy +- pip +- toolz +- ffmpeg +- pip: + - dask + - click + - scipy diff --git a/ipol_imac.sh b/ipol_imac.sh new file mode 100755 index 0000000..cd43fba --- /dev/null +++ b/ipol_imac.sh @@ -0,0 +1,288 @@ +#!/bin/bash + +echo + +realpath() { + echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" +} + +ipoldir="$(realpath )" + +ptype=$1 +starg=$2 +enarg=$3 +raddir="$(realpath $4)" +tempdir="$(realpath $5)" +simdir=$6 +doppdir=$7 + +mkdir -p $raddir $tempdir +if [ ! -z $simdir ]; then + mkdir -p $simdir +fi +if [ ! -z $doppdir ]; then + mkdir -p $doppdir +fi + +declare -a mpopts=( "mp06" "mp08" "mp10" "mp16" "mp51" ) +declare -a mpnames=( "wsm6" "thom" "morr" "wdm6" "p3" ) + +st=$(echo $starg | sed 's/[^0-9]*//g') +stdate=${st:0:8} +sttime=${st:8:4} +en=$(echo $enarg | sed 's/[^0-9]*//g') +endate=${en:0:8} +entime=${en:8:4} +stt=${stdate}_${sttime} +edt=${endate}_${entime} + +configdir=$ipoldir/configtxt/${stt}_${edt} +mkdir -p $configdir + +echo Determining data agency and type... +echo +sleep 3 + +station=$(basename $raddir) +if [[ "$station" == "CASAG" ]]; then + agency='cwr' +elif [[ "$station" == "NPOL" ]]; then + agency='olympex' +else + agency='nexrad' +fi +echo $agency + +if [[ "$(ls $raddir/* | head -n 1 | xargs basename)" == "wrfout"* ]]; then + data='wrf' + mp=$(ls $raddir/* | head -n 1 | xargs basename | cut -d '_' -f2) + for ((ii=0;ii<${#mpopts[@]};ii++)); do + [[ "${mpopts[ii]}" = "$mp" ]] && break + done + inputfile=input_${mpnames[ii]}_${stt}_${edt}.txt + configfile=config_${mpnames[ii]}_${stt}_${edt}.txt + echo $data +else + if [ -z $simdir ]; then + data='obs' + inputfile=input_${data}_${stt}_${edt}.txt + configfile=config_${data}_${stt}_${edt}.txt + echo $data + else + inputfile=input_obs_${stt}_${edt}.txt + configfile=config_obs_${stt}_${edt}.txt + echo "obs vs wrf" + fi +fi + +echo +echo Selecting radar files for analysis in range $stt to $edt... +echo +sleep 3 + +tfile=input_${stt}_${edt}.txt + +for filepath in $(ls $raddir/* | sort); do + file=$(basename $filepath) + if [[ "$(ls $raddir/* | head -n 1 | xargs basename)" == "wrfout"* ]]; then + filedt=$(echo $file | cut -d '_' -f4 | tr -d '-')$(echo $file | cut -d '_' -f5 | cut -d '.' -f1 | tr -d ':') + else + filedt=$(echo $file | cut -d '_' -f2)$(echo $file | cut -d '_' -f3) + fi + if [ "$filedt" -ge "$(echo $stt | tr -d '_')00" ] && [ "$filedt" -lt "$(echo $edt | tr -d '_')00" ]; then + echo $filepath >> $configdir/$tfile + echo $(basename $filepath) + fi + if [ "$filedt" -ge "$(echo $edt | tr -d '_')00" ]; then + break + fi +done + +mv $configdir/$tfile $configdir/$inputfile + +#latcen=$(ncdump $indir/$headfile | grep "latitude =" | cut -d '=' -f2 | cut -d ';' -f1 | xargs) +#loncen=$(ncdump $indir/$headfile | grep "longitude =" | cut -d '=' -f2 | cut -d ';' -f1 | xargs) +latcen=47.116943359375 +loncen=-124.106666564941 +#latcen=49.0164413452148 +#loncen=-122.487358093262 + +echo +echo Selecting temperature files for analysis in range $stt to $edt... +echo +sleep 3 + +tfile=tmp_${stt}_${edt}.txt + +for filepath in $(ls $tempdir/* | sort); do + file=$(basename $filepath) + filedt=$(echo $file | cut -d '_' -f4 | tr -d '-')$(echo $file | cut -d '_' -f5 | cut -d '.' -f1 | tr -d ':') + if [ "$filedt" -ge "$(echo $stt | tr -d '_')00" ] && [ "$filedt" -le "$(echo $edt | tr -d '_')00" ]; then + echo $filepath >> $configdir/$tfile + echo $(basename $filepath) + fi + if [ "$filedt" -gt "$(echo $edt | tr -d '_')00" ]; then + break + fi +done + +if [[ "$(head -n 1 $configdir/$tfile | xargs basename)" == "wrfout"* ]]; then + mp=$(head -n 1 $configdir/$tfile | xargs basename | cut -d '_' -f2) + for ((ii=0;ii<${#mpopts[@]};ii++)); do + [[ "${mpopts[ii]}" = "$mp" ]] && break + done + mpname=$(echo "${mpnames[ii]}") + tempsrc=$mpname + tempfile=temp_${tempsrc}_${stt}_${edt}.txt + snd_on='False' + wrft_on='True' +else + tempsrc='uwyo' + tempfile=temp_${tempsrc}_${stt}_${edt}.txt + snd_on='True' + wrft_on='False' +fi +mv $configdir/$tfile $configdir/$tempfile + +if [ -z $simdir ]; then + if [[ "$data" == "obs" ]]; then + fold="obs" + else + fold=$mpname + fi + +else + + echo + echo Selecting wrfout files for analysis in range $stt to $edt... + echo + sleep 3 + + fold='obsvwrf' + mp2=$(ls $simdir/* | head -n 1 | xargs basename | cut -d '_' -f2) + for ((ii=0;ii<${#mpopts[@]};ii++)); do + [[ "${mpopts[ii]}" = "$mp2" ]] && break + done + mpname2=$(echo ${mpnames[ii]}) + + inputfile2=input_${mpname2}_${stt}_${edt}.txt + configfile2=config_${mpname2}_${stt}_${edt}.txt + + tfile=input_${stt}_${edt}.txt + + for filepath in $(ls $simdir/* | sort); do + file=$(basename $filepath) + filedt=$(echo $file | cut -d '_' -f4 | tr -d '-')$(echo $file | cut -d '_' -f5 | cut -d '.' -f1 | tr -d ':') + if [ "$filedt" -ge "$(echo $stt | tr -d '_')00" ] && [ "$filedt" -lt "$(echo $edt | tr -d '_')00" ]; then + echo $filepath >> $configdir/$tfile + echo $(basename $filepath) + fi + if [ "$filedt" -ge "$(echo $edt | tr -d '_')00" ]; then + break + fi + done + + mv $configdir/$tfile $configdir/$inputfile2 + +fi + +if [ -z $doppdir ]; then + dd_on='False' +else + dd_on='True' +fi + +outfigdir=outputfig/${fold}_temp${tempsrc}_${station}_${stt}_${edt} +outrrdir=$(cd $raddir/../../ && pwd)/radar_rainrates/$station +mkdir -p $outfigdir $outrrdir + +if [ -z $simdir ]; then + + echo + echo Creating config file for iPOLARRIS... + echo + sleep 3 + + template=$ipoldir/${agency}_${data}_config.txt + cp $template $configdir/$configfile + + sed -i '' "s/^type ==.*/type == $data == # Type of input data: 'obs' OR 'wrf' (obs + simulated)/g" $configdir/$configfile + if [[ "$data" == "obs" ]]; then + sed -i '' "s/.*mphys ==.*/mphys == $data == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf'/g" $configdir/$configfile + else + sed -i '' "s/.*mphys ==.*/mphys == $mpname == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf'/g" $configdir/$configfile + fi + sed -i '' "s/.*ptype ==.*/ptype == '$ptype' == # Output figure file extenstion (i.e. png, jpg, mp4, ...)/g" $configdir/$configfile + sed -i '' "s/.*sdatetime ==.*/sdatetime == '$(echo $stt | tr '_' '-')' == # Start time of analysis of interest/g" $configdir/$configfile + sed -i '' "s/.*edatetime ==.*/edatetime == '$(echo $edt | tr '_' '-')' == # End time of analysis of interest/g" $configdir/$configfile + sed -i '' "s%.*rfiles ==.*%rfiles == '$configdir/$inputfile' == # Path to list of radar files to read in%g" $configdir/$configfile + sed -i '' "s%.*wfiles ==.*%wfiles == '$configdir/$tempfile' == # Path to list of WRF temperature files to read in%g" $configdir/$configfile + if [[ "$data" == "obs" ]]; then + sed -i '' "s/.*exper ==.*/exper == $station == # Radar location/g" $configdir/$configfile + else + sed -i '' "s/.*exper ==.*/exper == $station-$(echo $mpname | tr '[:lower:]' '[:upper:]') == # Radar location/g" $configdir/$configfile + fi + sed -i '' "s/lat == == #.*/lat == $latcen == # Latitude of the radar station/g" $configdir/$configfile + sed -i '' "s/lon == == #.*/lon == $loncen == # Longitude of the radar station/g" $configdir/$configfile + sed -i '' "s%.*image_dir ==.*%image_dir == '$outfigdir/' == # Output figure directory%g" $configdir/$configfile + sed -i '' "s%.*rr_dir ==.*%rr_dir == '$outrrdir/' == # Output rain rate netcdf directory%g" $configdir/$configfile + sed -i '' "s/.*dd_on ==.*/dd_on == $dd_on == # Doppler gridded velocity on/g" $configdir/$configfile + sed -i '' "s/.*snd_on ==.*/snd_on == $snd_on == # Sounding temperature on/g" $configdir/$configfile + sed -i '' "s/.*wrft_on ==.*/wrft_on == $wrft_on == # WRF temperature on/g" $configdir/$configfile + + echo Running iPOLARRIS... + sleep 3 + + python run_ipolarris.py $configdir/$configfile + +else + + echo + echo Creating OBS and SIM config files for iPOLARRIS... + echo + sleep 3 + + template=$ipoldir/${agency}_obs_config.txt + cp $template $configdir/$configfile + + sed -i '' "s/^type ==.*/type == obs == # Type of input data: 'obs' OR 'wrf' (obs + simulated)/g" $configdir/$configfile + sed -i '' "s/.*mphys ==.*/mphys == obs == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf'/g" $configdir/$configfile + sed -i '' "s/.*ptype ==.*/ptype == '$ptype' == # Output figure file extenstion (i.e. png, jpg, mp4, ...)/g" $configdir/$configfile + sed -i '' "s/.*sdatetime ==.*/sdatetime == '$(echo $stt | tr '_' '-')' == # Start time of analysis of interest/g" $configdir/$configfile + sed -i '' "s/.*edatetime ==.*/edatetime == '$(echo $edt | tr '_' '-')' == # End time of analysis of interest/g" $configdir/$configfile + sed -i '' "s%.*rfiles ==.*%rfiles == '$configdir/$inputfile' == # Path to list of radar files to read in%g" $configdir/$configfile + sed -i '' "s%.*wfiles ==.*%wfiles == '$configdir/$tempfile' == # Path to list of WRF temperature files to read in%g" $configdir/$configfile + sed -i '' "s/.*exper ==.*/exper == $station == # Radar location/g" $configdir/$configfile + sed -i '' "s/lat == == #.*/lat == $latcen == # Latitude of the radar station/g" $configdir/$configfile + sed -i '' "s/lon == == #.*/lon == $loncen == # Longitude of the radar station/g" $configdir/$configfile + sed -i '' "s%.*image_dir ==.*%image_dir == '$outfigdir/' == # Output figure directory%g" $configdir/$configfile + sed -i '' "s%.*rr_dir ==.*%rr_dir == '$outrrdir/' == # Output rain rate netcdf directory%g" $configdir/$configfile + sed -i '' "s/.*dd_on ==.*/dd_on == $dd_on == # Doppler gridded velocity on/g" $configdir/$configfile + sed -i '' "s/.*snd_on ==.*/snd_on == $snd_on == # Sounding temperature on/g" $configdir/$configfile + sed -i '' "s/.*wrft_on ==.*/wrft_on == $wrft_on == # WRF temperature on/g" $configdir/$configfile + + template2=$ipoldir/${agency}_wrf_config.txt + cp $template2 $configdir/$configfile2 + + sed -i '' "s/^type ==.*/type == wrf == # Type of input data: 'obs' OR 'wrf' (obs + simulated)/g" $configdir/$configfile2 + sed -i '' "s/.*mphys ==.*/mphys == $mpname2 == # Type of microphysics used in model: 'obs' OR '' if type = 'wrf'/g" $configdir/$configfile2 + sed -i '' "s/.*ptype ==.*/ptype == '$ptype' == # Output figure file extenstion (i.e. png, jpg, mp4, ...)/g" $configdir/$configfile2 + sed -i '' "s/.*sdatetime ==.*/sdatetime == '$(echo $stt | tr '_' '-')' == # Start time of analysis of interest/g" $configdir/$configfile2 + sed -i '' "s/.*edatetime ==.*/edatetime == '$(echo $edt | tr '_' '-')' == # End time of analysis of interest/g" $configdir/$configfile2 + sed -i '' "s%.*rfiles ==.*%rfiles == '$configdir/$inputfile2' == # Path to list of radar files to read in%g" $configdir/$configfile2 + sed -i '' "s%.*wfiles ==.*%wfiles == '$configdir/$tempfile' == # Path to list of WRF temperature files to read in%g" $configdir/$configfile2 + sed -i '' "s/.*exper ==.*/exper == $station-$(echo $mpname2 | tr '[:lower:]' '[:upper:]') == # Radar location/g" $configdir/$configfile2 + sed -i '' "s/lat == == #.*/lat == $latcen == # Latitude of the radar station/g" $configdir/$configfile2 + sed -i '' "s/lon == == #.*/lon == $loncen == # Longitude of the radar station/g" $configdir/$configfile2 + sed -i '' "s%.*image_dir ==.*%image_dir == '$outfigdir/' == # Output figure directory%g" $configdir/$configfile2 + sed -i '' "s%.*rr_dir ==.*%rr_dir == '$outrrdir/' == # Output rain rate netcdf directory%g" $configdir/$configfile2 + sed -i '' "s/.*dd_on ==.*/dd_on == $dd_on == # Doppler gridded velocity on/g" $configdir/$configfile2 + sed -i '' "s/.*snd_on ==.*/snd_on == $snd_on == # Sounding temperature on/g" $configdir/$configfile2 + sed -i '' "s/.*wrft_on ==.*/wrft_on == $wrft_on == # WRF temperature on/g" $configdir/$configfile2 + + echo Running iPOLARRIS... + sleep 3 + + python run_ipolarris.py $configdir/$configfile $configdir/$configfile2 + +fi diff --git a/old_csu_fhc.py b/old_csu_fhc.py new file mode 100644 index 0000000..a451dd1 --- /dev/null +++ b/old_csu_fhc.py @@ -0,0 +1,276 @@ +""" +csu_fhc.py + +Brody Fuchs, CSU, Sept 2014 +brfuchs@atmos.colostate.edu + +Porting over Brenda Dolan's HID code from IDL +(apparently originally from Kyle Wiens) + +Modifications by Timothy Lang +tjlangoc@gmail.com +01/21/2015 +08/05/2015 - Python 3 +11/20/2015 - Sped up hid_beta by using f2py + working w/ 1-D flattened arrays + that are later reshaped to the necessary shape. +05/03/2016 - Cython now an option for speeding up the hid_beta routines. + +""" + +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function +import numpy as np +from beta_functions import get_mbf_sets_summer +from calc_kdp_ray_fir import hid_beta_f + +DEFAULT_WEIGHTS = {'DZ': 1.5, 'DR': 0.8, 'KD': 1.0, 'RH': 0.8, 'LD': 0.5, + 'T': 0.4} + + +def hid_beta(x_arr, a, b, m): + """Beta function calculator""" + return 1.0/(1.0 + (((x_arr - m)/a)**2)**b) + + +def csu_fhc_summer(use_temp=True, weights=DEFAULT_WEIGHTS, method='hybrid', + dz=None, zdr=None, ldr=None, kdp=None, rho=None, T=None, + verbose=False, plot_flag=False, n_types=10, temp_factor=1, + band='S',return_scores=False): + """ + Does FHC for warm-season precip. + + Arguments: + use_temp = Set to False to not use T in HID + weights = Dict that contains relative weights for every variable; see + DEFAULT_WEIGHTS for expected stucture + method = Currently support 'hybrid' or 'linear' methods; hybrid preferred + verbose = Set to True to get text updates + plot_flag = Flag to turn on optional beta function plots + band = 'X', 'C', or 'S' + temp_factor = Factor to modify depth of T effects; > 1 will broaden the + slopes of T MBFs + n_types = Number of hydrometeor species + verbose = Set to True to get text updates + + Input measurands (if not None, all must match in shape/size): + dz = Input reflectivity scalar/array + zdr = Input reflectivity scalar/array + ldr = Input reflectivity scalar/array + kdp = Input reflectivity scalar/array + rho = Input reflectivity scalar/array + T = Input temperature scalar/array + + Returns: + mu = Input array + addtl dimension containing weights for each HID species + To get dominant species number: fh = np.argmax(mu, axis=0) + 1 + + HID types: Species #: + ------------------------------- + Drizzle 1 + Rain 2 + Ice Crystals 3 + Aggregates 4 + Wet Snow 5 + Vertical Ice 6 + Low-Density Graupel 7 + High-Density Graupel 8 + Hail 9 + Big Drops 10 + + """ + + if dz is None: + print('FHC fail, no reflectivity field') + return None + if T is None: + use_temp = False + + # Populate fhc_vars and radar_data based on what was passed to function + radar_data, fhc_vars, shp, sz = \ + _populate_vars(dz, zdr, kdp, rho, ldr, T, verbose) + + # Now grab the membership beta function parameters + mbf_sets = get_mbf_sets_summer( + use_temp=use_temp, plot_flag=plot_flag, n_types=n_types, + temp_factor=temp_factor, band=band, verbose=verbose) + sets = _convert_mbf_sets(mbf_sets) + + # Check for presence of polarimetric variables + pol_flag = _get_pol_flag(fhc_vars) + + # Check for presence of temperature + if use_temp: + if verbose: + print('Using T in FHC') + else: + fhc_vars['T'] = 0 + if verbose: + print('Not using T in FHC') + + # Get weighted sums + weight_sum, varlist = _get_weight_sum(fhc_vars, weights, method, verbose) + if weight_sum is None: + return None + + # Now loop over every hydrometeor class + test_list = _get_test_list(fhc_vars, weights, radar_data, sets, varlist, + weight_sum, pol_flag, use_temp, method, sz) + if test_list is None: + return None + + # Finish up + mu = np.array(test_list) + shp = np.concatenate([[n_types], shp]) + if verbose: + print(mu.shape) + print('mu max: ', mu.max()) + # return mu but make sure the shape is an int array + if return_scores: + return mu.reshape(shp.astype(np.int32)) + else: + hid = np.argmax(mu.reshape(shp.astype(np.int32)), axis=0) + 1 + return hid + +########################## +# Private Functions Below# +########################## + + +def _convert_mbf_sets(mbf_sets): + """Gets mbf_sets dict into form that matches labels used in csu_fhc""" + sets = {} + sets['DZ'] = mbf_sets['Zh_set'] + sets['DR'] = mbf_sets['Zdr_set'] + sets['KD'] = mbf_sets['Kdp_set'] + sets['LD'] = mbf_sets['LDR_set'] + sets['RH'] = mbf_sets['rho_set'] + sets['T'] = mbf_sets['T_set'] + return sets + + +def _get_pol_flag(fhc_vars): + """Check for presence of polarimetric variables""" + if fhc_vars['DR'] or fhc_vars['KD'] or fhc_vars['LD'] or fhc_vars['RH']: + pol_flag = True + else: + pol_flag = False + return pol_flag + + +def _populate_vars(dz, zdr, kdp, rho, ldr, T, verbose): + + """ + Check for presence of each var, and update dicts as needed. + Flattens multi-dimensional arrays to optimize processing. + The output array from csu_fhc_summer() will be re-dimensionalized later. + """ + varlist = [dz, zdr, kdp, rho, ldr, T] + keylist = ['DZ', 'DR', 'KD', 'RH', 'LD', 'T'] + fhc_vars = {} + radar_data = {} + for i, key in enumerate(keylist): + var = varlist[i] + if var is not None: + if key == 'DZ': + shp = np.shape(var) + sz = np.size(var) + if np.ndim(var) > 1: + radar_data[key] = np.array(var).ravel().astype('float32') + elif np.ndim(var) == 1: + radar_data[key] = np.array(var).astype('float32') + else: + radar_data[key] = np.array([var]).astype('float32') + fhc_vars[key] = 1 + else: + fhc_vars[key] = 0 + if verbose: + print('USING VARIABLES: ', fhc_vars) + return radar_data, fhc_vars, shp, sz + + +def _get_weight_sum(fhc_vars, weights, method, verbose): + """Gets sum of weights and varlist used, which depend on method""" + if 'hybrid' in method: + if verbose: + print('Using hybrid HID method. Pol vars weighted,', + 'Z and T (if used) are multiplied') + varlist = ['DR', 'KD', 'RH', 'LD'] + elif 'linear' in method: + if verbose: + print('NOT using hybrid, all variables treated as weighted sum') + varlist = ['DR', 'KD', 'RH', 'LD', 'T', 'DZ'] + else: + print('No weighting method defined, use hybrid or linear') + return None, None + weight_sum = np.sum(np.array([fhc_vars[key]*weights[key] + for key in varlist])) + if verbose: + print('weight_sum: ', weight_sum) + return weight_sum, varlist + + +def _calculate_test(fhc_vars, weights, radar_data, sets, + varlist, weight_sum, c, sz): + """Loop over every var to get initial value for each HID species 'test'""" +# test = (np.sum(np.array([fhc_vars[key] * weights[key] * +# hid_beta(radar_data[key], sets[key]['a'][c], +# sets[key]['b'][c], sets[key]['m'][c]) + test = (np.sum(np.array([fhc_vars[key] * weights[key] * + hid_beta_f(sz, radar_data[key], sets[key]['a'][c], + sets[key]['b'][c], sets[key]['m'][c]) + for key in varlist if key in radar_data.keys()]), + axis=0))/weight_sum + return test + + +def _get_test_list(fhc_vars, weights, radar_data, sets, varlist, weight_sum, + pol_flag, use_temp, method, sz): + """ + Master loop to compute HID values for each species ('test' & 'test_list'). + Depending on method used, approach is modfied. + Currently disabling testing as it gets spoofed by bad data. Letting the + calculations continue then mask out the bad data using other methods. + TO DO: Change poor naming scheme for variables 'test' and 'test_list'] + """ + # TJL - Check order of if statements + test_list = [] + #print('Using fortran hid_beta!') + for c in range(len(sets['DZ']['m'])): + if 'hybrid' in method: # Hybrid emphasizes Z and T extra HARD + if pol_flag: + test = _calculate_test(fhc_vars, weights, radar_data, sets, + varlist, weight_sum, c, sz) + # if test.max() > 1: # Max of test should never be > 1 + # print 'Fail loc 1, test.max() =', test.max() + # return None + if use_temp: + if pol_flag: + # *= multiplies by new value and stores in test + mdum= hid_beta_f(sz, radar_data['T'], sets['T']['a'][c], + sets['T']['b'][c], sets['T']['m'][c]) + test=mdum*test + # print 'in loc 2' + # if test.max() > 1: #Maximum of test should never be > 1 + # print 'Fail loc 2, test.max() =', test.max() + # return None + else: + test = hid_beta_f(sz, radar_data['T'], sets['T']['a'][c], + sets['T']['b'][c], sets['T']['m'][c]) + if fhc_vars['DZ']: + if pol_flag or use_temp: + test *= hid_beta_f( + sz, radar_data['DZ'], sets['DZ']['a'][c], + sets['DZ']['b'][c], sets['DZ']['m'][c]) + # if test.max() > 1: # Max of test should never be > 1 + # print 'Fail loc 3, test.max() =', test.max() + # return None + else: + test = hid_beta_f(sz, radar_data['DZ'], sets['DZ']['a'][c], + sets['DZ']['b'][c], sets['DZ']['m'][c]) + elif 'linear' in method: # Just a giant weighted sum + if pol_flag: + test = _calculate_test(fhc_vars, weights, radar_data, sets, + varlist, weight_sum, c, sz) + test_list.append(test) + return test_list diff --git a/plot_driver.py b/plot_driver.py index 0c8b010..dc545c8 100644 --- a/plot_driver.py +++ b/plot_driver.py @@ -6,18 +6,16 @@ import pandas as pd import xarray as xr import numpy as np -#import RadarData import datetime import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from copy import deepcopy - -#from polarris_config import get_data import RadarData import GeneralFunctions as GF from matplotlib import colors -plt.style.use('presentation') +#plt.style.use('./presentation.mplstyle') +#plt.style.use('default') from matplotlib.dates import DateFormatter,HourLocator dayFormatter = DateFormatter('%H%M') # e.g., 12 @@ -38,8 +36,7 @@ def label_subplots(fig, xoff = 0.0, yoff = 0.02, nlabels = None,**kwargs): xmin, ymax = xbox.xmin, xbox.ymax # this is the position I want if letters[fa] != '-': - fig.text(xmin+xoff, ymax+yoff, '({})'.format(letters[fa]),**kwargs) - + fig.text(xmin+xoff, ymax+yoff, '({})'.format(letters[fa]),**kwargs) #,transform=figaxes[fa].transAxes) @@ -47,7 +44,7 @@ def plot_cfad_int(dat1,config,typ='dz',n1=None): fig, ax = plt.subplots(1,1,figsize=(8,6)) # axf = ax.flatten() if n1 is None: - n1 = '{e}_{x}_{t}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys,t=config['extrax']) + n1 = '{e}_{x}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys) dat1cnt = np.shape(dat1['{t}cfad'.format(t=typ)])[0] @@ -65,7 +62,7 @@ def plot_cfad_int(dat1,config,typ='dz',n1=None): plt.tight_layout() - plt.savefig('{id}CFAD_{tp}_{s}_int.{t}'.format(id=config['image_dir'],s=n1,t=config['ptype'],tp=typ.upper()),dpi=200) + plt.savefig('{id}CFAD_{tp}_{s}_int.{t}'.format(id=outdir,s=n1,t=config['ptype'],tp=typ.upper()),dpi=200) plt.clf() def plot_hid_int(dat1,config,typ='hid',n1 = None): @@ -73,7 +70,7 @@ def plot_hid_int(dat1,config,typ='hid',n1 = None): ht1sum = np.nansum(dat1['{t}cfad'.format(t=typ)], axis=0) dat1cnt = np.nanmax(ht1sum, axis=0) / 100. if n1 is None: - n1 = '{e}_{x}_{t}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys,t=config['extrax']) + n1 = '{e}_{x}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys) fig, ax = GF.plot_hid_cdf(np.nansum(dat1['{t}cfad'.format(t=typ)], axis=0) / dat1cnt, dat1['hidhts'][0], ax=ax, rconf=dat1['rconf']) @@ -87,13 +84,13 @@ def plot_hid_int(dat1,config,typ='hid',n1 = None): plt.tight_layout() - plt.savefig('{id}CFAD_{h}_{s}_int.{t}'.format(id=config['image_dir'],h=typ.upper(),s=n1,t=config['ptype']),bbox_inches='tight', pad_inches=0.01,dpi=200) + plt.savefig('{id}CFAD_{h}_{s}_int.{t}'.format(id=outdir,h=typ.upper(),s=n1,t=config['ptype']),bbox_inches='tight', pad_inches=0.01,dpi=200) plt.clf() def plot_hid_prof_int(dat1,config,typ='hid',n1 = None,n2 = None): fig, ax = plt.subplots(1,1,figsize=(12,8)) if n1 is None: - n1 = '{e}_{x}_{t}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys,t=config['extrax']) + n1 = '{e}_{x}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys) tw_water_vert1 = np.nansum(dat1['water_vert'],axis=0) tw_graup_vert1 = np.nansum(dat1['graup_vert'],axis=0) @@ -113,7 +110,7 @@ def plot_hid_prof_int(dat1,config,typ='hid',n1 = None,n2 = None): ax.set_ylabel('Height (km)',fontsize=18) ax.set_ylim(0,20) plt.tight_layout() - plt.savefig('{d}{e1}_hid_vert_int.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_hid_vert_int.{t}'.format(d=outdir,e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() def plot_joint_int(dat1,config,typ='zzdr',n1= None,n2=None): @@ -125,27 +122,27 @@ def plot_joint_int(dat1,config,typ='zzdr',n1= None,n2=None): cb6 = ax.contourf(dat1['edgzzdr'][0][1][:-1],dat1['edgzzdr'][0][0][:-1],np.nansum(dat1['histzzdr'],axis=0)) ax.set_xlabel('Zdr') ax.set_ylabel('dBZ') - ax.set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + ax.set_title('{e} {m}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=ax) - plt.savefig('{d}{e1}_zzdr_int_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_zzdr_int.{t}'.format(d=outdir,e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() if typ == 'zkdp': cb6 = ax.contourf(dat1['edgkdz'][0][1][:-1],dat1['edgkdz'][0][0][:-1],np.nansum(dat1['histkdz'],axis=0)) ax.set_xlabel('Kdp') ax.set_ylabel('dBZ') - ax.set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + ax.set_title('{e} {m}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=ax) - plt.savefig('{d}{e1}_zkdp_int_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_zkdp_int.{t}'.format(d=outdir,e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() if typ == 'zw': cb6 = ax.contourf(dat1['edgzw'][0][1][:-1],dat1['edgzw'][0][0][:-1],np.nansum(dat1['histzw'],axis=0)) ax.set_xlabel('W (m/s)') ax.set_ylabel('dBZ') - ax.set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + ax.set_title('{e} {m}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=ax) - plt.savefig('{d}{e1}_zw_int_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_zw_int.{t}'.format(d=outdir,e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() if typ == 'wr': @@ -153,18 +150,18 @@ def plot_joint_int(dat1,config,typ='zzdr',n1= None,n2=None): cb6 = ax.contourf(dat1['edgwr'][0][0][:-1],dat1['edgwr'][0][1][:-1],np.nansum(dat1['histwr'],axis=0).T) ax.set_ylabel('RR (mm/hr)') ax.set_xlabel('W (M/s)') - ax.set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + ax.set_title('{e} {m}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=ax) - plt.savefig('{d}{e1}_wr_int_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_wr_int.{t}'.format(d=outdir,e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() def plot_upwidth_int(dat1,config,n1= None): - #print np.max(m_warea_wrf) + #print max(m_warea_wrf) plt.plot(np.nanmean(dat1['warea'],axis=0),dat1['wareat'][0],color='k',lw=5) plt.ylim(20,-60) plt.xlabel('Updraft Width (km$^2$)') plt.ylabel('Temperature (deg C)') - plt.savefig('{d}{e1}_upwidth_int_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_upwidth_int.{t}'.format(d=outdir,e1=dat1['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() def plot_uppercent_compare(dat1,dat2,config,n1= None,n2=None): @@ -194,7 +191,7 @@ def plot_uppercent_compare(dat1,dat2,config,n1= None,n2=None): plt.tight_layout() st_diff = '{e1}-{e2}'.format(e1=dat1['rconf'].exper,e2=dat2['rconf'].exper) - plt.savefig('{id}{e1}_{e2}_wpercent_compare_{s}_{x}.{t}'.format(id=config['image_dir'],e2=dat1['rconf'].exper,e1=dat2['rconf'].exper,s=st_diff,x=config['extrax'],t=config['ptype']),dpi=200) + plt.savefig('{id}{e1}_{e2}_wpercent_compare_{s}.{t}'.format(id=outdir,e2=dat1['rconf'].exper,e1=dat2['rconf'].exper,s=st_diff,t=config['ptype']),dpi=200) plt.clf() def plot_uppercent_compare_updn(dat1, dat2, config, n1=None, n2=None): @@ -260,7 +257,7 @@ def plot_uppercent_compare_updn(dat1, dat2, config, n1=None, n2=None): st_diff = '{e1}-{e2}'.format(e1=dat1['rconf'].exper,e2=dat2['rconf'].exper) print (st_diff) # plt.savefig('test.png') - plt.savefig('{id}{s}_updownstats_{x}.{t}'.format(id=config['image_dir'],s=st_diff,t=config['ptype'],x=config['extrax']),dpi=200) + plt.savefig('{id}{s}_updownstats.{t}'.format(id=outdir,s=st_diff,t=config['ptype']),dpi=200) # def plot_uppercent(dat1,config,n1= None): fig, ax = plt.subplots(1,2,figsize=(18,8)) @@ -293,7 +290,7 @@ def plot_uppercent(dat1,config,n1= None): plt.tight_layout() - plt.savefig('{id}{e}_vvelstats_{x}.{t}'.format(id=config['image_dir'],e=dat1['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=200) + plt.savefig('{id}{e}_vvelstats.{t}'.format(id=outdir,e=dat1['rconf'].exper,t=config['ptype']),dpi=200) # plt.clf() @@ -319,7 +316,7 @@ def plot_upwidth(dat1,dat2,config,n1= None,n2=None): plt.tight_layout() st_diff = '{e1}-{e2}'.format(e1=dat1['rconf'].exper,e2=dat2['rconf'].exper) - plt.savefig('{id}{e1}_{e2}_wpwidth_compare_{s}_{x}.{t}'.format(id=config['image_dir'],e2=dat1['rconf'].exper,e1=dat2['rconf'].exper,s=st_diff,x=config['extrax'],t=config['ptype']),dpi=200) + plt.savefig('{id}{e1}_{e2}_wpwidth_compare_{s}.{t}'.format(id=outdir,e2=dat1['rconf'].exper,e1=dat2['rconf'].exper,s=st_diff,t=config['ptype']),dpi=200) plt.clf() def plot_joint_comp(dat1,dat2,config,typ='zzdr',n1= None,n2=None): @@ -336,13 +333,13 @@ def plot_joint_comp(dat1,dat2,config,typ='zzdr',n1= None,n2=None): cb6 = axf[0].contourf(dat1['edgzzdr'][0][1][:-1],dat1['edgzzdr'][0][0][:-1],np.nansum(dat1['histzzdr'],axis=0)) axf[0].set_xlabel('Zdr') axf[0].set_ylabel('dBZ') - axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=axf[0]) cb6 = axf[1].contourf(dat2['edgzzdr'][0][1][:-1],dat2['edgzzdr'][0][0][:-1],np.nansum(dat2['histzzdr'],axis=0)) axf[1].set_xlabel('Zdr') axf[1].set_ylabel('dBZ') - axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,x=config['extrax'],m=dat2['rconf'].mphys)) + axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,m=dat2['rconf'].mphys)) plt.colorbar(cb6,ax=axf[1]) diffdat = np.nansum(dat1['histzzdr'],axis=0)-np.nansum(dat2['histzzdr'],axis=0) @@ -353,20 +350,20 @@ def plot_joint_comp(dat1,dat2,config,typ='zzdr',n1= None,n2=None): axf[2].set_ylabel('dBZ',fontsize=18) axf[2].set_xlabel('Zdr',fontsize = 18) axf[2].set_title('{d}-{v}'.format(d=n1,v=n2)) - plt.savefig('{d}{e1}_{e2}_zzdr_comp_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_{e2}_zzdr_comp.{t}'.format(d=outdir,e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() if typ == 'zkdp': cb6 = axf[0].contourf(dat1['edgkdz'][0][1][:-1],dat1['edgkdz'][0][0][:-1],np.nansum(dat1['histkdz'],axis=0)) axf[0].set_xlabel('Kdp') axf[0].set_ylabel('dBZ') - axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=ax[0]) cb6 = axf[1].contourf(dat2['edgkdz'][0][1][:-1],dat2['edgkdz'][0][0][:-1],np.nansum(dat2['histkdz'],axis=0)) axf[1].set_xlabel('Kdp') axf[1].set_ylabel('dBZ') - axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,x=config['extrax'],m=dat2['rconf'].mphys)) + axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,m=dat2['rconf'].mphys)) plt.colorbar(cb6,ax=axf[1]) diffdat = np.nansum(dat1['histkdz'],axis=0)-np.nansum(dat2['histkdz'],axis=0) @@ -377,20 +374,20 @@ def plot_joint_comp(dat1,dat2,config,typ='zzdr',n1= None,n2=None): axf[2].set_title('{d}-{v}'.format(d=n1,v=n2)) plt.colorbar(cb,ax=axf[2]) - plt.savefig('{d}{e1}_{e2}_zkdp_comp_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_{e2}_zkdp_comp.{t}'.format(d=outdir,e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() if typ == 'zw': cb6 = axf[0].contourf(dat1['edgzw'][0][1][:-1],dat1['edgzw'][0][0][:-1],np.nansum(dat1['histzw'],axis=0)) axf[0].set_xlabel('W (m/s)') axf[0].set_ylabel('dBZ') - axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=config['extrax'],m=dat1['rconf'].mphys)) + axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=axf[0]) cb6 = axf[1].contourf(dat2['edgzw'][0][1][:-1],dat2['edgzw'][0][0][:-1],np.nansum(dat2['histzw'],axis=0)) axf[1].set_xlabel('W (m/s)') axf[1].set_ylabel('dBZ') - axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,x=config['extrax'],m=dat2['rconf'].mphys)) + axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,m=dat2['rconf'].mphys)) plt.colorbar(cb6,ax=axf[1]) diffdat = np.nansum(dat1['histzw'],axis=0)-np.nansum(dat2['histzw'],axis=0) @@ -401,20 +398,20 @@ def plot_joint_comp(dat1,dat2,config,typ='zzdr',n1= None,n2=None): axf[2].set_title('{d}-{v}'.format(d=n1,v=n2)) plt.colorbar(cb,ax=axf[2]) - plt.savefig('{d}{e1}_{e2}_zw_comp_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_{e2}_zw_comp.{t}'.format(d=outdir,e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() if typ == 'wr': cb6 = axf[0].contourf(dat1['edgwr'][0][0][:-1],dat1['edgwr'][0][1][:-1],np.nansum(dat1['histwr'],axis=0).T) axf[0].set_ylabel('RR (mm/hr)') axf[0].set_xlabel('W (M/s)') - axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,x=extra,m=dat1['rconf'].mphys)) + axf[0].set_title('{e} {m} {x}'.format(e=dat1['rconf'].exper,m=dat1['rconf'].mphys)) plt.colorbar(cb6,ax=axf[0]) cb6 = axf[1].contourf(dat2['edgwr'][0][0][:-1],dat2['edgwr'][0][1][:-1],np.nansum(dat2['histwr'],axis=0).T) axf[1].set_ylabel('RR (mm/hr)') axf[1].set_xlabel('W (M/s)') - axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,x=extra,m=dat2['rconf'].mphys)) + axf[1].set_title('{e} {m} {x}'.format(e=dat2['rconf'].exper,m=dat2['rconf'].mphys)) plt.colorbar(cb6,ax=axf[1]) diffdat = np.nansum(dat1['histwr'],axis=0)-np.nansum(dat2['histwr'],axis=0) @@ -425,51 +422,51 @@ def plot_joint_comp(dat1,dat2,config,typ='zzdr',n1= None,n2=None): axf[2].set_title('{d}-{v}'.format(d=n1,v=n2)) plt.colorbar(cb,ax=axf[2]) - plt.savefig('{d}{e1}_{e2}_wr_comp_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_{e2}_wr_comp.{t}'.format(d=outdir,e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() -def plot_difference_cfad(rdata1,rdata2,var1,var2,lonvar,config1,config2,bins=np.arange(0,82,2),savefig=True,n1=None,n2=None,n3=None,cscfad=None, nor=False): +def plot_difference_cfad(rdat1,rdat2,var1,var2,config1,bins=np.arange(0,82,2),xlab=None,savefig=True,n1=None,n2=None,n3=None,cscfad=None, nor=False,ylim=None,xlim=None): ###Pass a value for nor in order to normalize the colorbar over a standard range rather than normalization across values within the data. To normalize within the data, pass a value of False - r1cdf,r1bins,r1ht = rdata1.cfad(var1,ret_z=1,z_resolution=1.0,value_bins=bins,cscfad=cscfad) - r2cdf,r2bins,r2ht = rdata2.cfad(var2,ret_z=1,z_resolution=1.0,value_bins=bins,cscfad=cscfad) + r1cdf,r1bins,r1ht = rdat1.cfad(var1,ret_z=1,z_resolution=1.0,value_bins=bins,cscfad=cscfad) + r2cdf,r2bins,r2ht = rdat2.cfad(var2,ret_z=1,z_resolution=1.0,value_bins=bins,cscfad=cscfad) print('In plot_driver, csfad is ',cscfad) if n1 is None: - n1 = rdata1.exper + n1 = rdat1.exper if n2 is None: - n2 = rdata2.exper + n2 = rdat2.exper if n3 is None: - n3 = '{a}-{b}'.format(a=rdata1.exper,b=rdata2.exper) - - - fig, axf = plot_cfad_compare(r1cdf,r2cdf,r1ht,r2ht,r1bins,r2bins,config1,n1=n1,n2=n2,n3=n3,typ='dz',nor=nor) - if cscfad is not False: - plt.suptitle('{c} {l}'.format(c=cscfad,l=lonvar),y=1.05,fontsize=30) - else: - plt.suptitle('{l}'.format(l=lonvar),y=1.05,fontsize=30) - - axf[0].set_xlabel('{l} bin'.format(l=lonvar)) - axf[1].set_xlabel('{l} bin'.format(l=lonvar)) - axf[2].set_xlabel('{l} bin'.format(l=lonvar)) - if savefig == True: - if cscfad is not False: - plt.savefig('{d}CFAD_diff_{e1}_{e2}_{c}{l}_{x}.{p}'.format(p=config['ptype'],d=config1['image_dir'],c=cscfad,x=config1['extrax'],e1=rdata1.exper,e2=rdata2.exper,l=var1),dpi=400,bbox_inches='tight') - else: - plt.savefig('{d}CFAD_diff_{e1}_{e2}_{l}_{x}.{p}'.format(p=config['ptype'],d=config1['image_dir'],x=config1['extrax'],e1=rdata1.exper,e2=rdata2.exper,l=var1),dpi=400,bbox_inches='tight') - return fig, axf - else: - return fig,axf + n3 = '{a}-{b}'.format(a=rdat1.exper,b=rdat2.exper) -def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',n1 = None,n2 = None,n3= None,savefig=False,nor=False): + fig, axf = plot_cfad_compare(r1cdf,r2cdf,r1ht,r2ht,r1bins,r2bins,config1,xlab=xlab,n1=n1,n2=n2,n3=n3,typ='dz',nor=nor,ylim=ylim,xlim=xlim) + #if cscfad is not False: + # plt.suptitle('{c} {l}'.format(c=cscfad,l=lonvar),y=1.05,fontsize=30) + #else: + # plt.suptitle('{l}'.format(l=lonvar),y=1.05,fontsize=30) + + #axf[0].set_xlabel('{l} bin'.format(l=lonvar)) + #axf[1].set_xlabel('{l} bin'.format(l=lonvar)) + #axf[2].set_xlabel('{l} bin'.format(l=lonvar)) + #if savefig == True: + # if cscfad is not False: + # plt.savefig('{d}CFAD_diff_{e1}_{e2}_{c}{l}.{p}'.format(p=config['ptype'],d=config1['image_dir'],c=cscfad,e1=rdat1.exper,e2=rdat2.exper,l=var1),dpi=400,bbox_inches='tight') + # else: + # plt.savefig('{d}CFAD_diff_{e1}_{e2}_{l}.{p}'.format(p=config['ptype'],d=config1['image_dir'],e1=rdat1.exper,e2=rdat2.exper,l=var1),dpi=400,bbox_inches='tight') + # return fig, axf + #else: + # + return fig,axf + +def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',xlab = None, n1 = None,n2 = None,n3= None,savefig=False,nor=False,ylim=False,xlim=False): ###Pass a value for nor in order to normalize the colorbar over a standard range rather than normalization across values within the data. To normalize within the data, pass a value of False - fig, ax = plt.subplots(1,3,figsize=(18,8)) + fig, ax = plt.subplots(1,4,figsize=(14,8),gridspec_kw={'wspace': 0.1,'hspace': 0.05,'width_ratios': [4,4,1.2,4],\ + 'top':1., 'bottom':0., 'left':0., 'right':1.}) axf = ax.flatten() - dat1cnt = np.shape(dat1)[0] - dat2cnt = np.shape(dat2)[0] -# + #dat1cnt = np.shape(dat1)[0] + #dat2cnt = np.shape(dat2)[0] - cfad1_all = np.sum(dat1,axis=0)/dat1cnt - cfad2_all = np.sum(dat2,axis=0)/dat2cnt + #cfad1_all = np.sum(dat1,axis=0)/dat1cnt + #cfad2_all = np.sum(dat2,axis=0)/dat2cnt cfad1_all = dat1 cfad2_all = dat2 @@ -479,20 +476,21 @@ def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',n1 = None,n2 = # print np.nanmax(cfad2_all) if typ == 'w': - fig, ax = GF.cfad_plot('{t}var'.format(t=typ.upper()),data = cfad1_all, hts = ht1, bins = bin1,ax=axf[0],cfad_on = 0,rconf =config,tspan = dat1['time'],maxval=20,cont=True,levels = True) + fig, ax = GF.cfad_plot('{t}var'.format(t=typ.upper()),data = cfad1_all, hts = ht1, bins = bin1,ax=axf[0],cfad_on = 0,rconf =config,tspan = dat1['time'],maxval=20,cont=True,levels = True,cbyes=0, xlim=xlim, ylim=ylim, xlab=xlab) - fig, ax = GF.cfad_plot('{t}var'.format(t=typ.upper()),cfad = cfad2_all, hts =ht2, bins = bin2,ax=axf[1],cfad_on = 0,rconf = confing,tspan = dat2['time'],maxval=20,cont=True,levels = True) + fig, ax = GF.cfad_plot('{t}var'.format(t=typ.upper()),cfad = cfad2_all, hts =ht2, bins = bin2,ax=axf[1],cfad_on = 0,rconf = confing,tspan = dat2['time'],maxval=20,cont=True,levels = True,cbyes=1, xlim=xlim, ylim=ylim, xlab=xlab) else: - fig, ax = GF.cfad_plot(typ.upper(),cfad = cfad1_all, hts = ht1, bins = bin1,ax=axf[0],cfad_on = 0,rconf = config,tspan = config['date'],maxval=20,cont=True,levels = True) + fig, ax = GF.cfad_plot(typ.upper(),cfad = cfad1_all, hts = ht1, bins = bin1,ax=axf[0],cfad_on = 0,rconf = config,tspan = config['sdatetime']+'_'+config['edatetime'],maxval=20,cont=True,levels = True,cbyes=0, xlim=xlim, ylim=ylim, xlab=xlab) - fig, ax = GF.cfad_plot(typ.upper(),cfad = cfad2_all, hts = ht2, bins = bin2,ax=axf[1],cfad_on = 0,rconf = config,tspan = config['date'],maxval=20,cont=True,levels = True) - axf[0].set_title('{n}'.format(n=n1)) - axf[1].set_title('{n}'.format(n=n2)) + fig, ax = GF.cfad_plot(typ.upper(),cfad = cfad2_all, hts = ht2, bins = bin2,ax=axf[1],cfad_on = 0,rconf = config,tspan = config['sdatetime']+'_'+config['edatetime'],maxval=20,cont=True,levels = True,cbyes=1, xlim=xlim, ylim=ylim, xlab=xlab) + + #axf[0].set_title('{n}'.format(n=n1)) + #axf[1].set_title('{n}'.format(n=n2)) - axf[0].set_ylim(0,18) - axf[1].set_ylim(0,18) - axf[2].set_ylim(0,18) + #axf[0].set_ylim(0,18) + #axf[1].set_ylim(0,18) + #axf[2].set_ylim(0,18) if len(ht1) != len(ht2): print('fixing heights') @@ -500,7 +498,7 @@ def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',n1 = None,n2 = vals = np.array([cfad1_all, cfad2_all]) lens = [len(ht1),len(ht2)] - sz = np.max(lens) + sz = max(lens) arg = np.argmax(lens) cfad_new1=np.zeros_like(vals[arg]) cfad_new2=np.zeros_like(vals[arg]) @@ -518,12 +516,13 @@ def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',n1 = None,n2 = else: diff_cfad = cfad1_all - cfad2_all hts = ht1 - cfad_ma = np.ma.masked_where(diff_cfad == 0, diff_cfad) maxa = np.nanpercentile(np.abs(cfad_ma),98) levels=np.linspace(-1*maxa,maxa,50) + axf[2].remove() + if nor is False: # print typ, maxa if typ=='w': @@ -532,22 +531,37 @@ def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',n1 = None,n2 = delt = np.around((maxa+maxa)/50,decimals=2) print( maxa,nor,delt) levels = np.arange(-1 * maxa, maxa+delt, delt) - cb=axf[2].contourf(bin1[:-1],hts,cfad_ma,levels=levels,norm=colors.Normalize(vmin=-1*nor,vmax=nor),cmap='bwr',extend='both') + cb=axf[3].contourf(bin1[:-1],hts,cfad_ma,levels=levels,norm=colors.Normalize(vmin=-1*nor,vmax=nor),cmap='bwr',extend='both') else: nor = np.around(np.nanpercentile(np.abs(cfad_ma),98),decimals=1) - cb=axf[2].contourf(bin1[:-1],hts,cfad_ma,levels,cmap='bwr',norm=colors.Normalize(vmin=-1.*nor,vmax=nor),extend='both') + cb=axf[3].contourf(bin1[:-1],hts,cfad_ma,levels,cmap='bwr',norm=colors.Normalize(vmin=-1.*nor,vmax=nor),extend='both') else: nor=nor - cb=axf[2].contourf(bin1[:-1],hts,cfad_ma,levels,cmap='bwr',norm=colors.Normalize(vmin=-1.*nor,vmax=nor),extend='both') - - + cb=axf[3].contourf(bin1[:-1],hts,cfad_ma,levels,cmap='bwr',norm=colors.Normalize(vmin=-1.*nor,vmax=nor),extend='both') - cb3= plt.colorbar(cb,ax=axf[2]) - cb3.set_label('Relative difference (%)') - cb3.set_ticks(np.linspace(-1.*nor,nor,9)) + axf[3].set_xlim(xlim) + axf[3].set_ylim(ylim) + axf[3].set_xlabel(xlab,fontsize=16) + axf[3].set_yticks([]) + axf[3].set_yticklabels([]) + axf[3].tick_params(axis='x', which='major', labelsize=16) + axf[3].tick_params(axis='y', which='major', labelsize=0) + + lur,bur,wur,hur = axf[3].get_position().bounds + cbar_ax_dims = [lur+wur+0.02,bur,0.02,hur] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(cb,cax=cbar_ax) + cbt.set_ticks(np.arange(-1*nor,nor+1,0.5*nor)) + cbt.ax.tick_params(labelsize=16) + cbt.set_label('Relative Difference (%)', fontsize=16, rotation=270, labelpad=15) + + #cb3 = plt.colorbar(cb,ax=axf[2]) + #cb3.set_label('Relative difference (%)',fontsize=16,rotation=270,labelpad=20) + #cb3.ax.tick_params(labelsize=16) + #cb3.set_ticks(np.linspace(-1.*nor,nor,9)) # print('nor',nor) - axf[2].set_ylabel('Height (km MSL)',fontsize=18) + #axf[2].set_ylabel('Height (km MSL)',fontsize=18) if typ == 'drc' or typ == 'drs' or typ == 'dr': varn = 'DR' @@ -559,32 +573,33 @@ def plot_cfad_compare(dat1,dat2,ht1,ht2,bin1,bin2,config,typ='dz',n1 = None,n2 = varn = 'Wvar' else: varn = typ - try: + #try: - axf[2].set_xlabel('{n} {u}'.format(n=dat1['rconf'].names[varn],u=dat1['rconf'].units[varn]),fontsize = 18) - except: + # axf[2].set_xlabel('{n} {u}'.format(n=dat1['rconf'].names[varn],u=dat1['rconf'].units[varn]),fontsize = 18) + #except: # print 'Exception!' - axf[2].set_xlabel('{tp}'.format(tp=typ.upper()),fontsize = 18) - axf[2].set_title('{v}'.format(v=n3)) - - - plt.tight_layout() - if savefig==True: - - st_diff = '{e1}-{e2}'.format(e1=dat1['rconf'].exper,e2=dat2['rconf'].exper) - - plt.savefig('{id}CFAD_{tp}_{s}_{x}.{t}'.format(id=config['image_dir'],s=st_diff,t=config['ptype'],x=config['extrax'],tp=typ.upper()),dpi=200) - else: - return fig, axf + #axf[2].set_xlabel('{tp}'.format(tp=typ.upper()),fontsize = 18) + #axf[2].set_title('{v}'.format(v=n3)) + + + #plt.tight_layout() + #if savefig==True: + # + # st_diff = '{e1}-{e2}'.format(e1=dat1['rconf'].exper,e2=dat2['rconf'].exper) + # + # plt.savefig('{id}CFAD_{tp}_{s}.{t}'.format(id=outdir,s=st_diff,t=config['ptype'],tp=typ.upper()),dpi=200) + #else: + + return fig, axf # plt.clf() def plot_hid_2panel(dat1,dat2,config,typ='hid',n1 = None,n2 = None,): dat1cnt = np.shape(dat1['hts'])[0] dat2cnt = np.shape(dat2['hts'])[0] if n1 is None: - n1 = '{e}_{k}_{x}_{t}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys,k=typ,t=config['extrax']) + n1 = '{e}_{k}_{x}'.format(e=dat1['rconf'].exper,x=dat1['rconf'].mphys,k=typ) if n2 is None: - n2 = '{e}_{k}_{x}_{t}'.format(e=dat2['rconf'].exper,x=dat2['rconf'].mphys,k=typ,t=config['extrax']) + n2 = '{e}_{k}_{x}'.format(e=dat2['rconf'].exper,x=dat2['rconf'].mphys,k=typ) fig, ax = plt.subplots(1,2,figsize=(18,8)) axf = ax.flatten() @@ -609,7 +624,7 @@ def plot_hid_2panel(dat1,dat2,config,typ='hid',n1 = None,n2 = None,): plt.tight_layout() st_diff = '{e1}-{e2}'.format(e1=dat1['rconf'].exper,e2=dat2['rconf'].exper) - plt.savefig('{id}CFAD_{h}_{s}_{x}.{t}'.format(id=config['image_dir'],h=typ.upper(),s=st_diff,x=config['extrax'],t=config['ptype']),bbox_inches='tight',dpi=200) + plt.savefig('{id}CFAD_{h}_{s}.{t}'.format(id=outdir,h=typ.upper(),s=st_diff,t=config['ptype']),bbox_inches='tight',dpi=200) plt.clf() @@ -664,7 +679,7 @@ def plot_hid_profile(dat1,dat2,config,typ='hid',n1 = None,n2 = None): svals = np.array([tw_snow_vert1,tw_snow_vert2]) lens = [len(dat1['hts'][0]),len(dat2['hts'][0])] - sz = np.max(lens) + sz = max(lens) arg = np.argmax(lens) wvals_new1=np.zeros_like(wvals[arg]) wvals_new2=np.zeros_like(wvals[arg]) @@ -729,7 +744,7 @@ def plot_hid_profile(dat1,dat2,config,typ='hid',n1 = None,n2 = None): axf[2].set_ylabel('Height (km)',fontsize=18) axf[2].set_ylim(0,20) - plt.savefig('{d}{e1}_{e2}_hid_vert_compare_{x}.{t}'.format(d=config['image_dir'],e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,x=config['extrax'],t=config['ptype']),dpi=300) + plt.savefig('{d}{e1}_{e2}_hid_vert_compare.{t}'.format(d=outdir,e1=dat1['rconf'].exper,e2=dat2['rconf'].exper,t=config['ptype']),dpi=300) plt.clf() @@ -759,147 +774,304 @@ def plot_upstat(dat1,dat2,config,typ='hid',n1 = None,n2 = None): axf[2].set_ylabel('Height (km MSL)',fontsize=18) -def make_single_pplots(rdat,flags,config,y=None): - print ('in make_singl_pplots') +def make_single_pplots(rdat,config,y=None): + tspan= [rdat.date[0],rdat.date[-1]] tms = np.array(rdat.date) - #print('DATES',np.array(rdat.date)) - tstart = tspan[0] -# print ts -# print rdat.exper - tend = tspan[1] -# print ts, te - xlim = config['xlim'] - ylim = config['ylim'] - y = config['y'] - z = config['z'] - - title_string = '{e} {t} {d1:%Y%m%d-%H%M%S} {x}'.format(e=rdat.exper,t=rdat.mphys,d1=tstart,x=config['extrax']) - - if flags['cfad_mpanel_flag'] == True: - print ('Working on Cfad mpanel') + outpath = config['image_dir'] + + if (config['pol_compare'] | config['all3']): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel CFADs for various polarimetric vars.\n') + + outdir = outpath+'pol_compare/' + os.makedirs(outdir,exist_ok=True) + + if config['wname'] in rdat.data.variables.keys(): + numr,numc = 2,2 + figsize=(16,12) + else: + numr,numc = 1,3 + figsize=(16,8) + + fig, ax = plt.subplots(numr,numc,figsize=figsize,gridspec_kw={'wspace': 0.05, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + axf = ax.flatten() + + if config['wname'] in rdat.data.variables.keys(): + dum =rdat.cfad_plot(rdat.w_name,ax = axf[0],bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,ylab=True) + print('Panel 1: '+rdat.w_name) + + dum =rdat.cfad_plot(rdat.dz_name,ax = axf[numr*numc-3],bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,ylab=True if numr==1 else False) + print('Panel '+str(numr*numc-2)+': '+rdat.dz_name) + + dum =rdat.cfad_plot(rdat.zdr_name,ax= axf[numr*numc-2],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,ylab=True if numr==2 else False) + print('Panel '+str(numr*numc-1)+': '+rdat.zdr_name) + + dum =rdat.cfad_plot(rdat.kdp_name,ax = axf[numr*numc-1],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan) + print('Panel '+str(numr*numc)+': '+rdat.kdp_name) + + lur1,bur1,wur1,hur1 = axf[1].get_position().bounds + lur2,bur2,wur2,hur2 = axf[-1].get_position().bounds + cbar_ax_dims = [lur2+wur2+0.02,bur2-0.001,0.03,bur1+hur1] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(dum[-2],cax=cbar_ax) + cbt.ax.tick_params(labelsize=20) + cbt.set_label('Frequency (%)', fontsize=22, rotation=270, labelpad=20) + cbt.set_ticks(dum[-1]) + cbt.set_ticklabels(dum[-1]) + + axf[0].text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=24, color='k', zorder=10, weight='bold', transform=axf[0].transAxes) # (a) Top-left + + plt.savefig('{d}{p}_CFAD_4panel.{t}'.format(d=outdir,p=rdat.exper,t=config['ptype']),dpi=400,bbox_inches='tight') + plt.clf() + + print('\nDone! Saved to '+outdir) + print('\nIN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel CONVECTIVE CFADs for various polarimetric vars.\n') + + if config['wname'] in rdat.data.variables.keys(): + numr,numc = 2,2 + figsize=(16,12) + else: + numr,numc = 1,3 + figsize=(16,8) + + fig, ax = plt.subplots(2,2,figsize=(18,12),constrained_layout=True) + axf = ax.flatten() + + if config['wname'] in rdat.data.variables.keys(): + dum =rdat.cfad_plot(rdat.w_name,ax = axf[0],bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='convective',cont=True) + print('Panel 1: '+rdat.w_name) + + dum =rdat.cfad_plot(rdat.dz_name,ax = axf[numr*numc-3],bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='convective',cont=True) + print('Panel '+str(numr*numc-2)+': '+rdat.dz_name) + + dum =rdat.cfad_plot(rdat.zdr_name,ax = axf[numr*numc-2],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='convective',cont=True) + print('Panel '+str(numr*numc-1)+': '+rdat.zdr_name) + + dum =rdat.cfad_plot(rdat.kdp_name,ax = axf[numr*numc-1],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='convective',cont=True) + print('Panel '+str(numr*numc)+': '+rdat.kdp_name) + + extrax ='conv' + #plt.tight_layout() +# print "{s:%Y%m%d%H%M%S}".format(s=ts[0]) + plt.savefig('{d}{p}_CFAD_4panel_{x}.{t}'.format(d=outdir,p=rdat.exper,x=extrax,t=config['ptype']),dpi=400,bbox_inches='tight') + plt.clf() + + print('\nDone! Saved to '+outdir) + print('\nIN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel STRATIFORM CFADs for various polarimetric vars.\n') + fig, ax = plt.subplots(2,2,figsize=(18,12)) axf = ax.flatten() if config['wname'] in rdat.data.variables.keys(): - dum =rdat.cfad_plot(rdat.w_name,ax = axf[0],bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan) - dum =rdat.cfad_plot(rdat.dz_name,ax = axf[1],bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan) - dum =rdat.cfad_plot(rdat.zdr_name,ax= axf[2],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan) - dum =rdat.cfad_plot(rdat.kdp_name,ax = axf[3],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan) - plt.tight_layout() + dum =rdat.cfad_plot(rdat.w_name,ax = axf[0],bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='stratiform') + print('Panel 1: '+rdat.w_name) + + dum =rdat.cfad_plot(rdat.dz_name,ax = axf[numr*numc-3],bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='stratiform') + print('Panel '+str(numr*numc-2)+': '+rdat.dz_name) + + dum =rdat.cfad_plot(rdat.zdr_name,ax= axf[numr*numc-2],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='stratiform') + print('Panel '+str(numr*numc-1)+': '+rdat.zdr_name) + + dum =rdat.cfad_plot(rdat.kdp_name,ax = axf[numr*numc-1],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='stratiform') + print('Panel '+str(numr*numc)+': '+rdat.kdp_name) + + extrax ='strat' + #plt.tight_layout() # print "{s:%Y%m%d%H%M%S}".format(s=ts[0]) - plt.savefig('{d}{p}_CFAD_4panel_{s:%Y%m%d%H%M%S}_{r}_{m}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,m=rdat.mphys,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) + #plt.savefig('{d}{p}_CFAD_4panel_{s:%Y%m%d%H%M%S}_{r}_{m}_{x}.{t}'.format(d=outdir,p=rdat.exper,s=tstart,m=rdat.mphys,r=rdat.band+'-band',t=config['ptype'],x=extrax),dpi=300) + plt.savefig('{d}{p}_CFAD_4panel_{x}.{t}'.format(d=outdir,p=rdat.exper,x=extrax,t=config['ptype']),dpi=400,bbox_inches='tight') plt.clf() - if config['plot_cs'] == True: - fig, ax = plt.subplots(2,2,figsize=(18,12)) - axf = ax.flatten() - - if config['wname'] in rdat.data.variables.keys(): - dum =rdat.cfad_plot(rdat.w_name,ax = axf[0],bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='convective',cont=True) - dum =rdat.cfad_plot(rdat.dz_name,ax = axf[1],bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='convective',cont=True) - dum =rdat.cfad_plot(rdat.zdr_name,ax= axf[2],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='convective',cont=True) - dum =rdat.cfad_plot(rdat.kdp_name,ax = axf[3],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='convective',cont=True) - extrahold = config['extrax'] - config['extrax']='{e}_convective'.format(e=extrahold) - plt.tight_layout() - # print "{s:%Y%m%d%H%M%S}".format(s=ts[0]) - plt.savefig('{d}{p}_CFAD_4panel_{s:%Y%m%d%H%M%S}_{r}_{m}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,m=rdat.mphys,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - config['extrax']=extrahold - plt.clf() + print('Done! Saved to '+outdir) + print('Moving on.\n') + - fig, ax = plt.subplots(2,2,figsize=(18,12)) - axf = ax.flatten() - if config['wname'] in rdat.data.variables.keys(): - dum =rdat.cfad_plot(rdat.w_name,ax = axf[0],bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='stratiform') - dum =rdat.cfad_plot(rdat.dz_name,ax = axf[1],bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='stratiform') - dum =rdat.cfad_plot(rdat.zdr_name,ax= axf[2],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan,cscfad='stratiform') - dum =rdat.cfad_plot(rdat.kdp_name,ax = axf[3],bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan,cscfad='stratiform') - extrahold = config['extrax'] - config['extrax']='{e}_stratiform'.format(e=extrahold) - plt.tight_layout() - # print "{s:%Y%m%d%H%M%S}".format(s=ts[0]) - plt.savefig('{d}{p}_CFAD_4panel_{s:%Y%m%d%H%M%S}_{r}_{m}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,m=rdat.mphys,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - config['extrax']=extrahold - plt.clf() + if (config['cfad_multi'] | config['all3']): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel CFADs for various polarimetric vars.\n') + + outdir = outpath+'cfad_multi/' + os.makedirs(outdir,exist_ok=True) + + zmax = config['zmax'] + st = rdat.date[0].strftime('%Y%m%d_%H%M%S') + en = rdat.date[-1].strftime('%Y%m%d_%H%M%S') + if st.startswith(en): dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+' UTC' + else: + if st[0:8].startswith(en[0:8]): dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+'-'+en[9:11]+':'+en[11:13]+' UTC' + else: dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+' - '+en[0:4]+'-'+en[4:6]+'-'+en[6:8]+' '+en[9:11]+':'+en[11:13]+' UTC' - if flags['cfad_individ_flag'] == True: - fig, ax = plt.subplots(1,1,figsize=(18,12)) - # axf = ax.flatten() - if config['wname'] in rdat.data.variables.keys(): + if not zmax == '': + fig, ax = rdat.cfad_multiplot(varlist = eval(config['cfad_vars']),z_resolution=config['z_resolution'],zmax=zmax) + else: + fig, ax = rdat.cfad_multiplot(varlist = eval(config['cfad_vars']),z_resolution=config['z_resolution']) + + nvars=0 + for var in eval(config['cfad_vars']): + if var in rdat.data.variables.keys(): + nvars+=1 + + if nvars <=6: + yof = 0.01 + else: + yof = -0.02 + yof = -0.01 + xof = 0.01 + + label_subplots(fig,yoff=yof,xoff=xof,size=16,nlabels=nvars,horizontalalignment='left',verticalalignment='top',color='k',bbox=dict(facecolor='w', edgecolor='w', pad=2.0),weight='bold') - rdat.cfad_plot(rdat.w_name,ax = ax,bins=config['wbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan) - plt.tight_layout() - plt.savefig('{d}{p}_CFAD_W_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - plt.clf() + axf = ax.flatten() + axf[0].text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=20, color='k', zorder=10, weight='bold', transform=axf[0].transAxes) # (a) Top-left + axf[2].text(1, 1, dtlab, horizontalalignment='right', verticalalignment='bottom', size=20, color='k', zorder=10, weight='bold', transform=axf[2].transAxes) # (a) Top-left + + if config['ptype'].startswith('mp4'): + plt.savefig('{d}{p}_CFAD_{t1}-{t2}.png'.format(d=outdir,p=rdat.exper,t1=st,t2=en),dpi=400,bbox_inches='tight') + else: + plt.savefig('{d}{p}_CFAD_{t1}-{t2}.{t}'.format(d=outdir,p=rdat.exper,t=config['ptype'],t1=st,t2=en),dpi=400,bbox_inches='tight') + plt.close() - fig, ax = plt.subplots(1,1,figsize=(18,12)) - rdat.cfad_plot(rdat.dz_name,ax = ax,bins=config['dzbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan) - plt.tight_layout() - plt.savefig('{d}{p}_CFAD_dBZ_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - plt.clf() + print('\nDone! Saved to '+outdir) + print('Moving on.\n') - fig, ax = plt.subplots(1,1,figsize=(18,12)) - rdat.cfad_plot(rdat.zdr_name,ax= ax,bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan= tspan) - plt.tight_layout() - plt.savefig('{d}{p}_CFAD_Zdr_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - plt.clf() - fig, ax = plt.subplots(1,1,figsize=(18,12)) - rdat.cfad_plot(rdat.kdp_name,ax = ax,bins=config['drbins'],z_resolution=config['z_resolution'],levels='levs',tspan = tspan) - plt.savefig('{d}{p}_CFAD_Kdp_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - plt.tight_layout() - plt.clf() + if (config['cfad_individ'] | config['all3']): - fig, ax = plt.subplots(1,1,figsize=(18,12)) - rdat.cfad_plot(rdat.rho_name,ax = ax,z_resolution=config['z_resolution'],levels='levs',tspan = tspan) - plt.tight_layout() - plt.savefig('{d}{p}_CFAD_RHO_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) - plt.clf() - - if flags['hid_cfad_flag'] == True: - fig, ax = rdat.plot_hid_cdf() - plt.savefig('{d}{p}_CFAD_HID_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating individual CFADs for various polarimetric vars.\n') + outdir = outpath+'cfad_individ/' + os.makedirs(outdir,exist_ok=True) - plt.clf() + allvars = eval(config['cfad_vars']) + + zmax = config['zmax'] + st = rdat.date[0].strftime('%Y%m%d_%H%M%S') + en = rdat.date[-1].strftime('%Y%m%d_%H%M%S') + + if st.startswith(en): dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+' UTC' + else: + if st[0:8].startswith(en[0:8]): dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+'-'+en[9:11]+':'+en[11:13]+' UTC' + else: dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+' - '+en[0:4]+'-'+en[4:6]+'-'+en[6:8]+' '+en[9:11]+':'+en[11:13]+' UTC' - if flags['joint_flag'] == True: + for i,v in enumerate(eval(config['cfad_vars'])): + + if v is None: + continue + else: + + if v.startswith('HID'): + + print(v) + + if not zmax == '': + fig, ax = rdat.plot_hid_cdf(cbar=2,z_resolution=config['z_resolution'],zmax=zmax+0.5) + else: + fig, ax = rdat.plot_hid_cdf(cbar=2,z_resolution=config['z_resolution']) + + ax.text(0,1,'{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=ax.transAxes) + ax.text(1,1, dtlab, horizontalalignment='right', verticalalignment='bottom', size=18, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + + if config['ptype'].startswith('mp4'): + plt.savefig('{d}{p}_HID_CFAD_{t1}-{t2}.png'.format(d=outdir,p=rdat.exper,t1=st,t2=en),dpi=400,bbox_inches='tight') + else: + plt.savefig('{d}{p}_HID_CFAD_{t1}-{t2}.{t}'.format(d=outdir,p=rdat.exper,t=config['ptype'],t1=st,t2=en),dpi=400,bbox_inches='tight') + + plt.close() + + else: - fig, ax = plt.subplots(2,2,figsize=(12,12)) + if not rdat.cfbins[v] is '': # and v in rdat.data.variables.keys(): + + print(v) + + if not zmax == '': + cfad, hts, pl, fig, ax = rdat.cfad_plot(v,bins=rdat.cfbins[v],z_resolution=config['z_resolution'],levels=1,zmax=zmax) + else: + cfad, hts, pl, fig, ax = rdat.cfad_plot(v,bins=rdat.cfbins[v],z_resolution=config['z_resolution'],levels=1) + + ax.text(0,1,'{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=ax.transAxes) + ax.text(1,1, dtlab, horizontalalignment='right', verticalalignment='bottom', size=18, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + + if config['ptype'].startswith('mp4'): + plt.savefig('{d}{p}_{v}_CFAD_{t1}-{t2}.png'.format(d=outdir,p=rdat.exper,v=rdat.names_uc[v],t1=st,t2=en),dpi=400,bbox_inches='tight') + else: + plt.savefig('{d}{p}_{v}_CFAD_{t1}-{t2}.{t}'.format(d=outdir,p=rdat.exper,v=rdat.names_uc[v],t=config['ptype'],t1=st,t2=en),dpi=400,bbox_inches='tight') + + plt.close() + + else: + + continue + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + + if (config['hist_multi'] | config['all3']): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel histograms comparing various polarimetric vars.\n') + outdir = outpath+'hist_multi/' + os.makedirs(outdir,exist_ok=True) + + if config['wname'] in rdat.data.variables.keys(): + numr,ncol = 2,2 + figsize = (16,14) + wspace = 0.25 + else: + numr,ncol = 1,2 + figsize = (12,8) + wspace = 0.5 + + fig, ax = plt.subplots(numr,ncol,figsize=figsize,gridspec_kw={'wspace': wspace, 'hspace': 0.2, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) axf = ax.flatten() zzdr_wrf,ed = rdat.hist2d(varx=rdat.dz_name,vary=rdat.zdr_name,binsx=config['dzbins'],binsy=config['drbins']) rdat.plot_2dhist(zzdr_wrf,ed,ax=axf[0]) - axf[0].set_xlabel('Zdr') - axf[0].set_ylabel('dBZ') - axf[0].set_title(title_string) + axf[0].set_xlabel(rdat.zdr_name+' '+rdat.units[rdat.zdr_name],fontsize=26) + axf[0].set_ylabel(rdat.dz_name+' '+rdat.units[rdat.dz_name],fontsize=26,labelpad=0) + #axf[0].set_title(title_string) + axf[0].text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=12, color='k', zorder=10, weight='bold', transform=axf[0].transAxes) # (a) Top-left + print('Panel 1: '+rdat.zdr_name+' vs. '+rdat.dz_name) + zkdp_wrf,edk = rdat.hist2d(varx=rdat.dz_name,vary=rdat.kdp_name,binsx=config['dzbins'],binsy=config['kdbins']) rdat.plot_2dhist(zkdp_wrf,edk,ax=axf[1]) - axf[1].set_title(title_string) - axf[1].set_xlabel('Kdp') - axf[1].set_ylabel('dBZ') - - - zw_wrf,edw = rdat.hist2d(varx=rdat.dz_name,vary=rdat.w_name,binsx=config['dzbins'],binsy=config['wbins']) - rdat.plot_2dhist(zw_wrf,edw,ax=axf[2]) - axf[2].set_title(title_string) - axf[2].set_xlabel('W') - axf[2].set_ylabel('dBZ') - - zr_wrf,edr = rdat.hist2d(varx=rdat.rr_name,vary=rdat.w_name,binsx=config['rrbins'],binsy=config['wbins'],xthr=0.00000) - cb6 = rdat.plot_2dhist(zr_wrf,edr,ax=axf[3],cbon=True) - axf[3].set_title(title_string) - axf[3].set_xlabel('W') - axf[3].set_ylabel(rdat.rr_name) - axf[3].set_ylim(0,50) + #axf[1].set_title(title_string) + axf[1].set_xlabel(rdat.kdp_name+' '+rdat.units[rdat.kdp_name],fontsize=26) + axf[1].set_ylabel(rdat.dz_name+' '+rdat.units[rdat.dz_name],fontsize=26,labelpad=0) + print('Panel 2: '+rdat.kdp_name+' vs. '+rdat.dz_name) - plt.savefig('{d}{p}_2dPDF_4panel_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) + if config['wname'] in rdat.data.variables.keys(): + zw_wrf,edw = rdat.hist2d(varx=rdat.dz_name,vary=rdat.w_name,binsx=config['dzbins'],binsy=config['wbins']) + rdat.plot_2dhist(zw_wrf,edw,ax=axf[2]) + #axf[2].set_title(title_string) + axf[2].set_xlabel(rdat.w_name+' '+rdat.units[rdat.w_name],fontsize=26) + axf[2].set_ylabel(rdat.dz_name+' '+rdat.units[rdat.dz_name],fontsize=26,labelpad=0) + print('Panel 3: '+rdat.w_name+' vs. '+rdat.dz_name) + + zr_wrf,edr = rdat.hist2d(varx=rdat.rr_name,vary=rdat.w_name,binsx=config['rrbins'],binsy=config['wbins'],xthr=0.00000) + cb6 = rdat.plot_2dhist(zr_wrf,edr,ax=axf[3]) + #axf[3].set_title(title_string) + axf[3].set_xlabel(rdat.w_name+' '+rdat.units[rdat.w_name],fontsize=26) + axf[3].set_ylabel(rdat.rr_name+' '+rdat.units[rdat.rr_name],fontsize=26,labelpad=10) + axf[3].set_ylim(0,50) + print('Panel 4: '+rdat.w_name+' vs. '+rdat.rr_name) + + plt.savefig('{d}{p}_2dPDF_4panel.{t}'.format(d=outdir,p=rdat.exper,t=config['ptype']),dpi=400,bbox_inches='tight') plt.clf() + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + - if flags['hid_prof'] == True: + if (config['hid_prof'] | config['all3']): + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating vertical profiles of water, graupel, hail and snow.') + + outdir = outpath+'vertical_profile/' + os.makedirs(outdir,exist_ok=True) + + fig, ax = plt.subplots(1,1,figsize=(18,12)) + hts, mwrf_water_vert = rdat.hid_vertical_fraction(config['hidwater'],z_resolution =config['z_resolution']) hts, mwrf_graup_vert = rdat.hid_vertical_fraction(config['hidgraup'],z_resolution =config['z_resolution']) hts, mwrf_hail_vert = rdat.hid_vertical_fraction(config['hidhail'],z_resolution =config['z_resolution']) @@ -909,117 +1081,313 @@ def make_single_pplots(rdat,flags,config,y=None): plt.plot(mwrf_graup_vert,hts,color='g',label='graupel',lw=lw) plt.plot(mwrf_hail_vert,hts,color='r',label='hail',lw=lw) plt.plot(mwrf_snow_vert,hts,color = 'yellow',label='snow',lw=lw) - plt.xlabel('Frequency (%)') - plt.ylabel('Height (km)') - plt.title(title_string) - plt.legend(loc = 'best') - plt.savefig('{d}{p}_HID_prof_{s:%Y%m%d%H%M%S}_{r}_{x}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype']),dpi=300) + ax.tick_params(axis='both',labelsize=22) + plt.xlabel('Frequency (%)',fontsize=24) + plt.ylabel('Height (km)',fontsize=24) + #plt.title(title_string) + plt.legend(loc='best',fontsize=22) + + ax.text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=24, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + plt.savefig('{d}{p}_HID_vertprof.{t}'.format(d=outdir,p=rdat.exper,t=config['ptype']),dpi=400,bbox_inches='tight') plt.clf() - if config['wname'] in rdat.data.variables.keys(): - if flags['up_width'] == True: + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + + if (config['up_width'] | config['all3']): + + if config['wname'] in rdat.data.variables.keys(): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating vertical profile of updraft width as a function of temperature.\n') + tmp, m_warea_wrf = rdat.updraft_width_profile(thresh_dz=True) - #print np.max(m_warea_wrf) + #print max(m_warea_wrf) + + fig, ax = plt.subplots(1,1,figsize=(18,12)) + plt.plot(m_warea_wrf,tmp,color='k',label='Obs',lw=5) plt.ylim(20,-60) - plt.xlabel('Updraft Width (km$^2$)') - plt.ylabel('Temperature (deg C)') - plt.title(title_string) - plt.savefig('{d}{p}_upwidth_{s:%Y%m%d%H%M%S}_{r}_{x}_{y}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=tstart,r=rdat.radar_name,x=config['extrax'],t=config['ptype'],y=config['y']),dpi=300) + plt.xlabel('Updraft Width (km$^2$)',fontsize=24) + plt.ylabel('Temperature (deg C)',fontsize=24) + ax.tick_params(axis='both',labelsize=22) + #plt.title(title_string) + + ax.text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=26, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + + plt.savefig('{d}{p}_updraft_width_{y}_vertprof.{t}'.format(d=outdir,p=rdat.exper,t=config['ptype'],y=config['y']),dpi=400,bbox_inches='tight') plt.clf() -# for k in flags.keys(): -# print('flag keys:',k,flags[k]) - for ts in tms: - - if flags['all_cappi']== True: - #z=2.0 - #print xlim -# print (config['cappi_vars']) -# print (config['cappi_multi']) - if config['cappi_multi'] is True: - #print('cappi mulit, vars',config['cappi_vars']) - #print config['cappi_vectres'],eval(config['cvectors']),eval(config['cappi_contours']),config['ylim'],config['xlim'],config['z'],rdat.date,eval(config['cappi_vars']) + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + + if (config['cappi_multi'] | config['all3']): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel CAPPIs for various polarimetric vars.') + print('Plotting CAPPIs by time for variables '+str(eval(config['cappi_vars']))+'...') + + outdir = outpath+'cappi_multi/' + os.makedirs(outdir,exist_ok=True) + + if not config['z'] == '': zspan = list(eval(str([config['z']]))) + else: zspan = rdat.data[rdat.z_name].values + + for z in zspan: + + print('\nz = '+str(z)) + xlim = config['xlim'] + ylim = config['ylim'] + + for ii in range(len(tms)): + + ts = tms[ii] + print(ts) - fig = rdat.cappi_multiplot(ts=ts,xlim=config['xlim'],ylim=config['ylim'],z=config['z'],res = config['cappi_vectres'],varlist = eval(config['cappi_vars']),vectors = eval(config['cvectors']),contours = eval(config['cappi_contours'])) - #plt.tight_layout() - # print np.shape(fig),type(fig), fig + fig = rdat.cappi_multiplot(ts=ts,xlim=xlim,ylim=config['ylim'],z=z,res = config['cappi_vectres'],varlist = eval(config['cappi_vars']),latlon=config['latlon'],statpt=True,dattype=config['type']) #eval(config['cappi_contours'])) + #fig = rdat.cappi_multiplot(ts=ts,xlim=config['xlim'],ylim=config['ylim'],z=config['z'],res = config['cappi_vectres'],varlist = eval(config['cappi_vars']),vectors = eval(config['cvectors']),contours = None,statpt=True) #eval(config['cappi_contours'])) + nvars = len(eval(config['cappi_vars'])) if nvars <=6: yof = 0.01 else: - yof=-0.02 - label_subplots(fig,yoff=yof,xoff=0.01,size=16,nlabels=nvars) - #plt.tight_layout() - plt.savefig('{d}{p}_polcappi_6panel_{s:%Y%m%d%H%M%S}_{r}_{x}_{z}km.{t}'.format(d=config['image_dir'],p=rdat.exper,s=ts,r=rdat.radar_name,x=config['extrax'],t=config['ptype'],z=config['z']),dpi=300) - plt.clf() + yof = -0.02 + yof = -0.01 + xof = 0.01 + + label_subplots(fig,yoff=yof,xoff=xof,size=16,nlabels=nvars,horizontalalignment='left',verticalalignment='top',color='k',bbox=dict(facecolor='w', edgecolor='w', pad=2.0),weight='bold') + + if not config['ptype'].startswith('mp4'): + plt.savefig('{i}{e}_multi_cappi_{t:%Y%m%d_%H%M%S}_{h}.{p}'.format(p=config['ptype'],i=outdir,e=rdat.exper,h=z,t=ts),dpi=400,bbox_inches='tight') + else: + if len(rdat.date) < 6: + plt.savefig('{i}{e}_multi_cappi_{t:%Y%m%d_%H%M%S}_{h}.png'.format(i=outdir,e=rdat.exper,h=z,t=ts),dpi=400,bbox_inches='tight') + else: + plt.savefig(outdir+'/fig'+str(ii).zfill(3)+'.png',dpi=400,bbox_inches='tight') + + plt.close() - else: - for i,v in enumerate(eval(config['cappi_vars'])): - #print config['cappi_vectres'],eval(config['cvectors'])[i],eval(config['cappi_contours'])[i],config['ylim'],config['xlim'],config['z'],rdat.date,v - #print str(v) - # print config['xlim'],config['ylim'],config['z'],config['cappi_vectres'],eval(config['cvectors'])[i],config['cappi_contours'] - fig= rdat.cappi(str(v),ts=ts,xlim=config['xlim'],ylim=config['ylim'],z=config['z'],res =config['cappi_vectres'],vectors = eval(config['cvectors'])[i],contours = eval(config['cappi_contours'])[i]) - plt.tight_layout() - #label_subplots(fig,yoff=0.01,xoff=0.01,size=16,nlabels=1) - plt.savefig('{d}{p}_polcappi_{v}_{s:%Y%m%d%H%M%S}_{r}_{x}_{z}km.{t}'.format(d=config['image_dir'],v=v,p=rdat.exper,s=ts,r=rdat.radar_name,x=config['extrax'],t=config['ptype'],z=config['z']),dpi=300) - plt.clf() + if config['ptype'].startswith('mp4') and len(rdat.date) >= 6: + + st = rdat.date[0].strftime('%Y%m%d_%H%M%S') + en = rdat.date[-1].strftime('%Y%m%d_%H%M%S') + + os.system('ffmpeg -nostdin -y -r 1 -i '+outdir+'/fig%03d.png -c:v libx264 -r '+str(len(np.array(rdat.date)))+' -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '+'{i}{e}_multi_cappi_{t1}-{t2}_{h}.mp4'.format(p=config['ptype'],e=rdat.exper,i=outdir,t1=st,t2=en,h=z)) + + plt.close() + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + - if flags['all_xsec']== True: - #y=-12.5 - print ("xsec_multi") - if config['xsec_multi'] == True: + if (config['cappi_individ'] | config['all3']): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating individual CAPPIs for various polarimetric vars.') + print('Plotting CAPPIs by time...\n') + + if not config['z'] == '': zspan = list(eval(str([config['z']]))) + else: zspan = rdat.data[rdat.z_name].values + + for i,v in enumerate(eval(config['cappi_vars'])): + + print(rdat.names_uc[v]) + + if v is None: + continue + else: + + for z in zspan: + + print('\nz = '+str(z)) + + for ii in range(len(tms)): + ts = tms[ii] + print(ts) + + outdir = outpath+'cappi_individ/'+rdat.names_uc[v]+'/' + os.makedirs(outdir,exist_ok=True) + + if v.startswith('HID'): cbar = 2 + else: cbar = 1 + + #fig, ax = rdat.cappi(str(v),ts=ts,xlim=config['xlim'],ylim=config['ylim'],cbar=cbar,z=config['z'],res =config['cappi_vectres'],vectors = eval(config['cvectors'])[i],statpt=True) + fig, ax = rdat.cappi(v,ts=ts,xlim=config['xlim'],ylim=config['ylim'],cbar=cbar,z=z,latlon=config['latlon'],statpt=True,dattype=config['type']) + + ax.text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(1, 1, '{d:%Y-%m-%d %H:%M:%S} UTC'.format(d=ts), horizontalalignment='right', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(0.99, 0.99, 'z = {a} km'.format(a=config['z']), horizontalalignment='right',verticalalignment='top', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes, bbox=dict(facecolor='w', edgecolor='none', pad=0.0)) + + if not config['ptype'].startswith('mp4'): + plt.savefig('{i}{e}_{v}_individ_cappi_{t:%Y%m%d_%H%M%S}_{h}.{p}'.format(p=config['ptype'],i=outdir,e=rdat.exper,h=config['z'],t=ts,v=rdat.names_uc[v]),dpi=400,bbox_inches='tight') + else: + if len(rdat.date) < 6: + plt.savefig('{i}{e}_{v}_individ_cappi_{t:%Y%m%d_%H%M%S}_{h}.png'.format(p=config['ptype'],i=outdir,e=rdat.exper,h=config['z'],t=ts,v=rdat.names_uc[v]),dpi=400,bbox_inches='tight') + else: + plt.savefig(outdir+'/fig'+str(ii).zfill(3)+'.png',dpi=400,bbox_inches='tight') + + plt.close() + + if config['ptype'].startswith('mp4') and len(rdat.date) >= 6: + + st = rdat.date[0].strftime('%Y%m%d_%H%M%S') + en = rdat.date[-1].strftime('%Y%m%d_%H%M%S') + + os.system('ffmpeg -nostdin -y -r 1 -i '+outdir+'/fig%03d.png -c:v libx264 -r '+str(len(np.array(rdat.date)))+' -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '+'{i}{e}_{v}_individ_cappi_{t1}-{t2}_{h}.mp4'.format(p=config['ptype'],e=rdat.exper,i=outdir,v=rdat.names_uc[v],t1=st,t2=en,h=z)) + + print('') + + print('Done! Saved to '+outdir) + print('Moving on.\n') + + + if (config['rhi_multi'] | config['all3']): + + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating multi-panel RHIs for various polarimetric vars.') + print('Plotting RHIs at y = '+str(config['y'])+'km north of the radar by time for variables '+str(eval(config['cappi_vars']))+'...') + + outdir = outpath+'rhi_multi/' + os.makedirs(outdir,exist_ok=True) + + if not config['y'] == '': yspan = list([config['y']]) + else: yspan = rdat.data[rdat.y_name].values[0::50] + + for y in yspan: + + print('\ny = '+str(y)) + + for ii in range(len(tms)): + ts = tms[ii] + print(ts) + if rdat.w_name is not None: - fig = rdat.xsec_multiplot(ts=ts,y=config['y'],vectors=eval(config['rvectors']),res = config['rhi_vectres'],xlim=config['xlim'],varlist=eval(config['rhi_vars'])) + fig = rdat.xsec_multiplot(ts=ts,y=y,vectors=eval(config['rvectors']),res = config['rhi_vectres'],xlim=config['xlim'],zmax=config['zmax'],varlist=eval(config['rhi_vars']),latlon=config['latlon']) else: - fig = rdat.xsec_multiplot(ts=ts,y=config['y'],xlim=config['xlim'],varlist=eval(config['rhi_vars'])) - #plt.tight_layout() - nvars = len(eval(config['rhi_vars'])) - if nvars <=6: + fig = rdat.xsec_multiplot(ts=ts,y=y,xlim=config['xlim'],zmax=config['zmax'],varlist=eval(config['rhi_vars']),latlon=config['latlon']) + + nvars = len(eval(config['rhi_vars']))-1*(rdat.w_name is None) + if nvars <= 6: yof = 0.01 else: yof=-0.02 - - #plt.tight_layout() + yof = -0.01 + xof = 0.01 - label_subplots(fig,yoff=yof,xoff=0.01,size=16,nlabels=nvars) - plt.savefig('{d}{p}_polrhi_{v}panel_{s:%Y%m%d%H%M%S}_{r}_{x}_{y}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=ts,r=rdat.radar_name,x=config['extrax'],v=nvars,t=config['ptype'],y=config['y']),dpi=300) - plt.clf() - else: - for i,v in enumerate(eval(config['rhi_vars'])): - #print i, v - #print eval(config['rvectors'])[i],config['rhi_vectres'][i],config['xlim'],config['y'] - fig = rdat.xsec(v,ts=ts,y=config['y'],vectors=eval(config['rvectors'])[i],res = config['rhi_vectres'],xlim=config['xlim']) - plt.tight_layout() - plt.savefig('{d}{p}_polrhi_{v}_{s:%Y%m%d%H%M%S}_{r}_{x}_{y}.{t}'.format(d=config['image_dir'],v=v,p=rdat.exper,s=ts,r=rdat.radar_name,x=config['extrax'],t=config['ptype'],y=config['y']),dpi=300) - plt.clf() + label_subplots(fig,yoff=yof,xoff=xof,size=16,nlabels=nvars,horizontalalignment='left',verticalalignment='top',color='k',bbox=dict(facecolor='w', edgecolor='w', pad=2.0),weight='bold') + + if not config['ptype'].startswith('mp4'): + plt.savefig('{i}{e}_multi_rhi_{t:%Y%m%d_%H%M%S}_{h}.{p}'.format(p=config['ptype'],i=outdir,e=rdat.exper,h=y,t=ts),dpi=400,bbox_inches='tight') + else: + if len(rdat.date) < 6: + plt.savefig('{i}{e}_multi_rhi_{t:%Y%m%d_%H%M%S}_{h}.png'.format(i=outdir,e=rdat.exper,h=y,t=ts),dpi=400,bbox_inches='tight') + else: + plt.savefig(outdir+'/fig'+str(ii).zfill(3)+'.png',dpi=400,bbox_inches='tight') + + plt.close() + + if config['ptype'].startswith('mp4') and len(rdat.date) >= 6: + + st = rdat.date[0].strftime('%Y%m%d_%H%M%S') + en = rdat.date[-1].strftime('%Y%m%d_%H%M%S') + + os.system('ffmpeg -nostdin -y -r 1 -i '+outdir+'/fig%03d.png -c:v libx264 -r '+str(len(np.array(rdat.date)))+' -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '+'{i}{e}_multi_rhi_{t1}-{t2}_{h}.mp4'.format(p=config['ptype'],e=rdat.exper,i=outdir,t1=st,t2=en,h=y)) + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + + if (config['rhi_individ'] | config['all3']): + print('IN PLOT_DRIVER.MAKE_SINGLE_PLOTS... creating individual RHIs for various polarimetric vars.') + print('Plotting RHIs at y = '+str(config['y'])+'km north of the radar by time.\n') - if flags['qr_cappi'] == True: + if not config['y'] == '': yspan = list(eval(str([config['y']]))) + else: yspan = rdat.data[rdat.y_name].values[0::50] + + for i,v in enumerate(eval(config['rhi_vars'])): + + if v is None: + continue + else: + + print(rdat.names_uc[v]) + + for y in yspan: + + print('\ny = '+str(y)) + + for ii in range(len(tms)): + ts = tms[ii] + print(ts) + + outdir = outpath+'rhi_individ/'+rdat.names_uc[v]+'/' + os.makedirs(outdir,exist_ok=True) + + if v.startswith('HID'): cbar = 2 + else: cbar = 1 + + fig, ax = rdat.xsec(v,ts=ts,y=y,res = config['rhi_vectres'],xlim=config['xlim'],cbar=cbar,zmax=config['zmax'],latlon=config['latlon']) + #fig, ax = rdat.xsec(v,ts=ts,y=config['y'],vectors=eval(config['rvectors'])[i],res = config['rhi_vectres'],xlim=config['xlim'],cbar=cbar,zmax=config['zmax']) + + ax.text(0, 1, '{e} {r}'.format(e=rdat.exper,r=rdat.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(1, 1, '{d:%Y-%m-%d %H:%M:%S} UTC'.format(d=ts), horizontalalignment='right', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(0.99, 0.99, 'y = {a} km'.format(a=y), horizontalalignment='right',verticalalignment='top', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes, bbox=dict(facecolor='w', edgecolor='none', pad=0.0)) + + if not config['ptype'].startswith('mp4'): + plt.savefig('{i}{e}_{v}_individ_rhi_{t:%Y%m%d_%H%M%S}_{h}.{p}'.format(p=config['ptype'],i=outdir,e=rdat.exper,h=y,t=ts,v=rdat.names_uc[v]),dpi=400,bbox_inches='tight') + else: + if len(rdat.date) < 6: + plt.savefig('{i}{e}_{v}_individ_rhi_{t:%Y%m%d_%H%M%S}_{h}.png'.format(i=outdir,e=rdat.exper,h=y,t=ts,v=rdat.names_uc[v]),dpi=400,bbox_inches='tight') + else: + plt.savefig(outdir+'/fig'+str(ii).zfill(3)+'.png',dpi=400,bbox_inches='tight') + + plt.close() + + if config['ptype'].startswith('mp4') and len(rdat.date) >= 6: + st = rdat.date[0].strftime('%Y%m%d_%H%M%S') + en = rdat.date[-1].strftime('%Y%m%d_%H%M%S') + + os.system('ffmpeg -nostdin -y -r 1 -i '+outdir+'/fig%03d.png -c:v libx264 -r '+str(len(np.array(rdat.date)))+' -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '+'{i}{e}_{v}_individ_rhi_{t1}-{t2}_{h}.mp4'.format(p=config['ptype'],e=rdat.exper,i=outdir,v=rdat.names_uc[v],t1=st,t2=en,h=y)) + + print('') + + print('Done! Saved to '+outdir) + print('Moving on.\n') + + + if config['qr_cappi']: + + for ts in tms: + print ("qr_cappi") fig = rdat.cappi_multiplot(z=config['z'],ts=ts,xlim=config['xlim'],ylim=config['ylim'],varlist=eval(config['mix_vars'])) - plt.savefig('{d}{p}_qcappi_6panel_{s:%Y%m%d%H%M%S}_{r}_{x}_{z}km.{t}'.format(d=config['image_dir'],p=rdat.exper,s=ts,r=rdat.radar_name,x=config['extrax'],t=config['ptype'],z=config['z']),dpi=300) + plt.savefig('{d}{p}_qcappi_6panel_{s:%Y%m%d%H%M%S}_{r}_{z}km.{t}'.format(d=outdir,p=rdat.exper,s=ts,r=rdat.band+'-band',t=config['ptype'],z=config['z']),dpi=300) plt.clf() - if flags['qr_rhi'] == True: + + if config['qr_rhi']: + + for ts in tms: + print ("qr_rhi") fig = rdat.xsec_multiplot(ts=ts,y=config['y'],xlim=config['xlim'],varlist=eval(config['mix_vars'])) - plt.savefig('{d}{p}_qrhi_6panel_{s:%Y%m%d%H%M%S}_{r}_{x}_{y}.{t}'.format(d=config['image_dir'],p=rdat.exper,s=ts,r=rdat.radar_name,x=config['extrax'],t=config['ptype'],y=config['y']),dpi=300) + plt.savefig('{d}{p}_qrhi_6panel_{s:%Y%m%d%H%M%S}_{r}_{y}.{t}'.format(d=outdir,p=rdat.exper,s=ts,r=rdat.band+'-band',t=config['ptype'],y=config['y']),dpi=300) plt.clf() - -def subset_convstrat(data,rdata,zlev=1): - cssum =(rdata.data[rdata.cs_name].max(dim='z')) + + +def subset_convstrat(data,rdat,zlev=1): + cssum =(rdat.data[rdat.cs_name].max(dim='z')) stratsub=data.sel(z=slice(zlev,zlev+1)).where(cssum==1) convsub=data.sel(z=slice(zlev,zlev+1)).where(cssum==2) allsub=data.sel(z=slice(zlev,zlev+1)).where(cssum>0) return stratsub,convsub,allsub -def plot_timeseries(data,tm,ax,ls = '-',cs=False,rdata=None,thresh=-50,typ='',zlev=1,make_zeros=False,areas=False,domain_rel=False): +def plot_timeseries(data,tm,ax,ls = '-',cs=False,rdat=None,thresh=-50,typ='',zlev=1,make_zeros=False,areas=False,domain_rel=False): data.values[data.valuesthresh).mean(dim=['z','y','x'],skipna=True),color='k',label='Total') - ax.xaxis.set_major_formatter(hourFormatter) - ax.xaxis.set_major_locator(HourLocator(interval=1)) - d=plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right') - ax.set_xlabel('Time (UTC)') + #ax.xaxis.set_major_formatter(hourFormatter) + #ax.xaxis.set_major_locator(HourLocator(interval=1)) + #d=plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right') + ax.tick_params(axis='both',labelsize=14) + ax.set_xlabel('Time (UTC)',fontsize=16) return ax#,adat,cdat,sdat @@ -1075,7 +1444,7 @@ def plot_quartiles(data,q1,q2,q3,z,ax,c1='goldenrod',c2='r',c3='k',split_updn=Fa ax.plot(wup50,zdat,color=c2,label='50th {e}'.format(e=typ),ls=ls) ax.plot(wup90,zdat,color=c1,label='90th {e}'.format(e=typ),ls=ls) ax.plot(wup99,zdat,color=c3,label='99th {e}'.format(e=typ),ls=ls) - ax.legend(loc='best') + ax.legend(loc='best',fontsize=14) ax.plot(wdn50,zdat,color=c2) ax.plot(wdn90,zdat,color=c1) ax.plot(wdn99,zdat,color=c3) @@ -1096,16 +1465,18 @@ def plot_quartiles(data,q1,q2,q3,z,ax,c1='goldenrod',c2='r',c3='k',split_updn=Fa ax.plot(wup50,zdat,color=c2,label='50th {e}'.format(e=typ),ls=ls) ax.plot(wup90,zdat,color=c1,label='90th {e}'.format(e=typ),ls=ls) ax.plot(wup99,zdat,color=c3,label='99th {e}'.format(e=typ),ls=ls) - ax.legend(loc='best') + ax.legend(loc='best',fontsize=14) + + ax.tick_params(axis='both',labelsize=14) + ax.set_ylabel('Height (km)',fontsize=16) - ax.set_ylabel('Height (km)') return ax def plot_verprof(data,z,ax,c='r',lab='',split_updn=False,ls = '-',typ='',thresh=-50): if split_updn == True: - pdat=data.load() + pdat=data.load().copy() pdat.values[pdat.values<-100] = np.nan wup = pdat.where(data>0) @@ -1121,10 +1492,10 @@ def plot_verprof(data,z,ax,c='r',lab='',split_updn=False,ls = '-',typ='',thresh= zdat = z.values ax.plot(wup50,zdat,color=c,label='{l} {e}'.format(l=lab,e=typ),ls=ls) ax.plot(wdn50,zdat,color=c,label='{l} {e}'.format(l=lab,e=typ),ls=ls) - ax.legend(loc='best') + ax.legend(loc='best',fontsize=14) else: - pdat =data.load() + pdat =data.load().copy() pdat.values[pdat.values 0: + if max(lev_hist) > 0: cfad_out[ivl, :] = lev_hist if ret_z == 1: @@ -1297,7 +1668,7 @@ def cfad(data,rdata,zvals, var='zhh01',nbins=30,value_bins=None, multiple=1,ret_ else: return cfad_out,value_bins -def plot_cfad(cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, +def plot_cfad(fig,cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, log=False, pick=None, z_resolution=1.0,levels=None,tspan =None,cont = False, rconf = None,mask = None,**kwargs): @@ -1318,9 +1689,9 @@ def plot_cfad(cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, cfad_ma = np.ma.masked_where(cfad==0, cfad) #print('CFAD shape',np.shape(cfad_ma)) + levs = [0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.] + cols = ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet'] if cont is True: - levs = [0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.] - cols = ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet'] try: #print(np.shape(cfad_ma),np.shape(hts),'ln 1283') pc = ax.contourf(vbins[0:-1],hts,cfad_ma,levs,colors=cols,extend = 'both') @@ -1330,7 +1701,7 @@ def plot_cfad(cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, else: if levels is not None: - cmap, norm = from_levels_and_colors([0.02,0.05,0.1,0.2,0.5,1.0,2.0,5.0,10.0,15.0,20.,25.], ['silver','darkgray','slategrey','dimgray','blue','mediumaquamarine','yellow','orange','red','fuchsia','violet']) # mention levels and colors here + cmap, norm = from_levels_and_colors(levs,cols) # mention levels and colors here #print cmap pc = ax.pcolormesh(vbins, hts, cfad_ma, norm=norm, cmap=cmap) else: @@ -1338,9 +1709,17 @@ def plot_cfad(cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, # pc = ax.pcolormesh(vbins, hts, cfad_ma, vmin=0, vmax=maxval, norm=norm, **kwargs) pc = ax.pcolormesh(vbins, hts, cfad_ma, vmin=0, vmax=maxval, norm=norm, **kwargs) - cb = plt.colorbar(pc, ax=ax) - cb.set_label('Frequency (%)') - ax.set_ylabel('Height (km MSL)') + #cb = plt.colorbar(pc, ax=ax) + #cb.set_label('Frequency (%)',fontsize=16) + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.02,bur-0.001,0.03,hur] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(pc,cax=cbar_ax) + cbt.ax.tick_params(labelsize=16) + cbt.set_label('Frequency (%)', fontsize=16, rotation=270, labelpad=20) + + ax.tick_params(axis='both',labelsize=14) + ax.set_ylabel('Height (km MSL)',fontsize=16) # try: if rconf is not None: if var == 'DRC' or var == 'DRS': @@ -1359,7 +1738,7 @@ def plot_cfad(cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, ax.set_xlabel('{n} {u}'.format(n=rconf.names[varn], u=rconf.units[varn])) #print rconf.print_title(tm=tspan) # ax.set_title("{d}".format(d=rconf.print_title(tm=tspan))) - # ax.set_title('%s %s %s CFAD' % (self.print_date(), self.radar_name, self.longnames[var])) + # ax.set_title('%s %s %s CFAD' % (self.print_date(), self.band+'-band', self.longnames[var])) else: ax.set_xlabel('{n}'.format(n=var)) #print rconf.print_title(tm=tspan) @@ -1369,83 +1748,108 @@ def plot_cfad(cfad,hts,vbins, ax, maxval=10.0, above=2.0, below=15.0, bins=None, return ax -def plot_composite(rdata,var,time,resolution='10m',cs_over=False): - dat = deepcopy(rdata.data[var].sel(d=time)) - whbad = np.where(rdata.data['CSS'].sel(d=time).values<0) +###################################### +##### plot_driver.PLOT_COMPOSITE ##### +###################################### + +# Description: plot_composite overlays a Cartopy basemap with a colormesh plot of a given variable. + +def plot_composite(rdat,var,time,resolution='10m',cs_over=False,statpt=False): + + from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + + # (1) Create an array that is a copy of the variable of interest. Remove bad data. + dat = deepcopy(rdat.data[var].sel(d=time)) + # dat = np.ma.masked_below(rdat.data[rdat.zdr_name].sel(d=time).values,-2) + whbad = np.where(rdat.data['CSS'].sel(d=time).values<0) dat.values[whbad] = np.nan - cs_arr = np.nanmax(np.squeeze(rdata.data['CSS'].sel(d=time).values),axis=0) - cs_arr = np.squeeze(cs_arr) dat = np.squeeze(dat.values) -# dat = np.ma.masked_below(rdata.data[rdata.zdr_name].sel(d=time).values,-2) dzcomp = np.nanmax(dat,axis=0) - - fig = plt.figure(figsize=(10, 8)) - ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mercator()) - from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter - - #ax.stock_img() - if not rdata.lat_name in rdata.data.keys(): - print('no Latitude. cAlculating....') - rdata.get_latlon_fromxy() - lats = rdata.data['lat'] - lons = rdata.data['lon'] + cs_arr = np.squeeze(np.nanmax(np.squeeze(rdat.data['CSS'].sel(d=time).values),axis=0)) + + # (2) Find lat/lon array for the basemap. If not found, calculate it using get_latlon_fromxy(). + if not rdat.lat_name in rdat.data.keys(): + print('No latitude. Calculating....') + rdat.get_latlon_fromxy() + lats = rdat.data['lat'] + lons = rdat.data['lon'] else: - if 'd' in rdata.data[rdata.lat_name].dims: - lats = rdata.data[rdata.lat_name].sel(d=time).values - lons= rdata.data[rdata.lon_name].sel(d=time).values + if 'd' in rdat.data[rdat.lat_name].dims: + lats = rdat.data[rdat.lat_name].sel(d=time).values + lons= rdat.data[rdat.lon_name].sel(d=time).values else: - lats = rdata.data[rdata.lat_name].values - lons= rdata.data[rdata.lon_name].values + lats = rdat.data[rdat.lat_name].values + lons= rdat.data[rdat.lon_name].values # Specifies the detail level of the map. # Options are '110m' (default), '50m', and '10m' - ax.coastlines(resolution=resolution) -# print(np.min(lons),np.max(lons)) - ax.set_extent([np.min(lons), np.max(lons), np.min(lats), np.max(lats)]) - lon_formatter = LongitudeFormatter(number_format='.1f') - lat_formatter = LatitudeFormatter(number_format='.1f') - ax.xaxis.set_major_formatter(lon_formatter) - ax.yaxis.set_major_formatter(lat_formatter) + # print(min(lons),max(lons)) - if var in rdata.lims.keys(): - print( 'var:',var) - range_lim = rdata.lims[var][1] - rdata.lims[var][0] + # (3) Extract the range of values in the variable of interest and derive a colourmap. + if var in rdat.lims.keys(): # If the variable exists in the dataset: + #print( 'var:',var) + range_lim = rdat.lims[var][1] - rdat.lims[var][0] # print np.shape(data), np.shape(xdat),np.shape(ydat) # print 'in var',var #print **kwargs - vmin=rdata.lims[var][0] - vmax=rdata.lims[var][1] - cmap=rdata.cmaps[var] - else: + vmin=rdat.lims[var][0] + vmax=rdat.lims[var][1] + cmap=rdat.cmaps[var] + else: # If not print ('unrecognized var',var) - dat = rdata.data[var].data + dat = rdat.data[var].data dat[dat<-900.0]=np.nan - range_lim = np.nanmax(dat) - np.nanmin(dat) + range_lim = np.nanmax(dat) - np.nanmin(dat) vmin=np.nanmin(dat) vmax=np.nanmax(dat) cmap = plt.cm.gist_ncar + # (4) Initiate a new figure with Mercator projection. + fig = plt.figure(figsize=(10,8)) + ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mercator()) + + lnspc = 2 + ltspc = 1 + + # (5) Overlay variable data as a colormesh plot (with colorbar) using PlateCarree projection. + cb = ax.pcolormesh(lons,lats,dzcomp,vmin=vmin,vmax=vmax,cmap=cmap,transform=ccrs.PlateCarree()) + if cs_over == True: ax.contour(lons,lats,cs_arr,levels=[0,1,2,3],linewidths=3,colors=['black','black'],transform=ccrs.PlateCarree()) + if statpt: ax.plot(rdat.lon_0,rdat.lat_0,markersize=12,marker='^',color='k',transform=ccrs.PlateCarree()) + + lur,bur,wur,hur = ax.get_position().bounds + cbar_ax_dims = [lur+wur+0.02,bur-0.001,0.03,hur] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(cb,cax=cbar_ax) + cbt.ax.tick_params(labelsize=16) + if var.startswith('REF'): labtxt = 'Composite Reflectivity (dBZ)' + else: labtxt = var + cbt.set_label(labtxt, fontsize=16, rotation=270, labelpad=20) + + # (6) Make the figure look pretty! + ax.coastlines(resolution=resolution) - cb = ax.pcolormesh(lons,lats,dzcomp, vmin =vmin,vmax=vmax,cmap=cmap,transform=ccrs.PlateCarree()) - cbt = plt.colorbar(cb) - cbt.set_label(var) - ax.yaxis.set_major_formatter(ticker.FormatStrFormatter('%.2f')) - ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%.2f')) - if cs_over == True: - ax.contour(lons,lats,cs_arr,levels=[0,1,2,3],linewidths=3,colors=['black','black'],transform=ccrs.PlateCarree()) - - for tick in ax.xaxis.get_major_ticks(): - tick.label.set_fontsize(22) - for tick in ax.yaxis.get_major_ticks(): - tick.label.set_fontsize(22) - - gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, - linewidth=2, color='gray', alpha=0.5, linestyle='--') - + minlon = np.floor(lons[(0,0)]) + maxlon = np.ceil(lons[(0,-1)]) + minlat = np.floor(lats[(0,0)]) + maxlat = np.ceil(lats[(-1,0)]) + lonticks = np.linspace(minlon,maxlon,int((maxlon-minlon)/lnspc+1)) + latticks = np.linspace(minlat,maxlat,int((maxlat-minlat)/ltspc+1)) + gl.xlocator = ticker.FixedLocator(lonticks) + gl.ylocator = ticker.FixedLocator(latticks) + ax.set_extent([minlon-0.001,maxlon+0.001,minlat-0.001,maxlat+0.001]) + + gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1.5, alpha=0.75, linestyle='--') gl.xlabels_top = False gl.ylabels_right = False - gl.xlabel_style = {'size': 16, 'color': 'gray','rotation':-15} - gl.ylabel_style = {'size': 16, 'color': 'gray'}#,'rotation':-15} - + gl.x_inline = False + gl.y_inline = False + gl.xlabel_style = {'size': 16, 'color': 'black'}#,'rotation':-15} + gl.ylabel_style = {'size': 16, 'color': 'black'}#,'rotation':-15} - return fig,ax#,gl#,dzcomp + newax = fig.add_axes(ax.get_position(), frameon=False) + newax.tick_params(axis='x', labelsize=0, length=0, pad=15) + newax.tick_params(axis='y', labelsize=0, length=0, pad=45) + newax.set_xlabel('Longitude',fontsize=16) + newax.set_ylabel('Latitude',fontsize=16) + + return fig, ax diff --git a/polarris_driver.py b/polarris_driver.py new file mode 100644 index 0000000..0ffaed7 --- /dev/null +++ b/polarris_driver.py @@ -0,0 +1,483 @@ +""" +This is the configruation file for setting up iPOLARRIS. Herein, the specifics of the dataset need to be defined such as the experiment, location and type of reading, etc. +Written by Brenda Dolan (CSU) and Anthony Di Stefano (UBC) +Released: May 2017 +Last Modified: June 2021 +bdolan@atmos.colostate.edu +""" +from __future__ import print_function + +import datetime +import glob +import matplotlib.pyplot as plt +from netCDF4 import Dataset +import numpy as np +import os +import pandas as pd +import re +import sys +import xarray as xr +import time +from copy import deepcopy +import RadarData +import GeneralFunctions as GF +import RadarConfig +import plot_driver +from skewPy import SkewT + +def fix_my_data(ds): + return(ds.drop(['VTZCS','CVECS'])) + +def find_dd_match(rdum,ddum,rdate,ddates): + + radlist=[] + + mdfiles = {} + for v,cname in enumerate(rdum): + #print cname + base = os.path.basename(cname) + dates = rdate[v] + #print dates, etime,stime + #print cname + mval = match_dd(dates,ddates) + #print( dates,ddates) + + if mval != 'no': + dfile = ddum[mval[0]] + print('Found DD match!', dfile) + mdfiles[cname] = dfile + else: + mdfiles[cname] = None + + + return mdfiles + +def match_dd(rdate,ddates): + dum=abs(rdate-np.array(ddates)) + + try: + mval=np.argwhere(dum == np.min(dum))[0] + diff=np.min(dum) + if diff.total_seconds() < 600.: + return mval + else: + return 'no' + except ValueError: + print ('Something DD is not working here!') + + +def match_snd(rdate,sdates): + dum=abs(rdate-np.array(sdates)) + + try: + mval=np.argwhere(dum == np.min(dum)) + diff=np.min(dum) + #allow 12 hours between the radar obs and the sounding + if diff.total_seconds() < 43200: + return mval + else: + return 'no' + except ValueError: + print ('Something sound is not working here!') + + +def find_snd_match(config): + rdum =[] + with open(config['rfiles']) as f: + #dum.append(foo(f.readline())) + #dum.append(foo(f.readline())) + + for line in f: + dat = (line) + rdum.append(foo(dat)) + #print('sfiles:',config['sfiles']) + #rdum = glob.glob(config['rfiles']+'*') + #slist = sorted(glob.glob('{p}*{s}_*.txt'.format(p=config['sfiles'],s=(config['sstat'])))) + with open(config['sfiles']) as f: + slist = f.read().splitlines() + #slist = glob.glob(config['sfiles']+'*') + sdates=[] + for v,sname in enumerate(slist): + + base = os.path.basename(sname) +# print base + radcdate=str(base[config['sdstart']:config['sdend']]) + #print('radcdate',radcdate) + dates=datetime.datetime.strptime('{r}'.format(r=radcdate),config['sdate_format']) + sdates.append(dates) + + msfiles = {} + + for v,cname in enumerate(rdum): +# print cname + base = os.path.basename(cname) +# print('base',base) + radcdate=str(base[config['rdstart']:config['rdend']]) + #dates=datetime.datetime.strptime(radcdate,config['rdate_format']) + dates = datetime.datetime.strptime('{r}'.format(r=radcdate),config['rdate_format']) + sdt = datetime.datetime.strptime(config['sdatetime'],config['sdatetime_format']) + edt = datetime.datetime.strptime(config['edatetime'],config['edatetime_format']) + #if (dates >= config['etime']) and (dates <= config['stime']): + if (dates <= edt) and (dates >= sdt): + #print cname + #now find a sounding match + mv = match_snd(dates,sdates) + if mv != 'no': + #print ('sounding match',mv[0][0]) + msfiles[cname] = np.array(slist)[mv[0][0]] + else: + return None + + return msfiles + +def find_wrfpol_match(config): + rdum =[] + with open(config['rfiles']) as f: + for line in f: + dat = (line) + rdum.append(foo(dat)) + + with open(config['wfiles']) as f: + slist = f.read().splitlines() + + wdates=[] + for v,sname in enumerate(slist): + + base = os.path.basename(sname) + radcdate=str(base[config['wdstart']:config['wdend']]) + dates=datetime.datetime.strptime('{r}'.format(r=radcdate),config['wdate_format']) + wdates.append(dates) + + msfiles = {} + + for v,cname in enumerate(rdum): + base = os.path.basename(cname) + radcdate=str(base[config['rdstart']:config['rdend']]) + dates = datetime.datetime.strptime('{r}'.format(r=radcdate),config['rdate_format']) + sdt = datetime.datetime.strptime(config['sdatetime'],config['sdatetime_format']) + edt = datetime.datetime.strptime(config['edatetime'],config['edatetime_format']) + if (dates <= edt) and (dates >= sdt): + mv = match_snd(dates,wdates) + if mv != 'no': + msfiles[cname] = np.array(slist)[mv[0][0]] + else: + return None + + return msfiles + + +def foo(s1): + return '{}'.format(s1.rstrip()) + +def reduce_dim(ds): + try: + t1= ds['time'][0].values + except KeyError as ke: + #print(f"{ke} skipping preprocessing") + return(ds) + for v in ds.data_vars.keys(): + try: + ds[v]=ds[v].sel(time=t1).drop('time') + except KeyError as k: + #except ValueError as e: + pass +# print(e) +# print(v) + return(ds) + +from matplotlib.dates import DateFormatter,HourLocator +dayFormatter = DateFormatter('%H%M') # e.g., 12 +hourFormatter = DateFormatter('%H') # e.g., 12 + + +def hasNumbers(inputString): + return any(char.isdigit() for char in inputString) + + +def polarris_driver(configfile): + # ===== + # (1) Read in config file line by line. + # ===== + + config = {} # Load variable for config file data + + print('\nReading '+str(configfile[0])+'...') + with open(configfile[0]) as f: + lines1 = [mm for mm in (line.replace('\t',' ') for line in f) if mm] + lines2 = [nn for nn in (line.strip() for line in lines1) if nn] # NEW! Allow new lines in config file - can be skipped over! + for line in lines2: #f: + if not line.startswith("#"): + key, val, comment = line.split('==') + vval = val.replace(" ","") + numck = hasNumbers(vval) + if key.replace(" ", "") == 'exper' or key.replace(" ", "") == 'dz_name' or key.replace(" ", "") == 'drop_vars' or key.replace(" ", "") == 'dr_name' or key.replace(" ", "") == 'kd_name' or key.replace(" ", "") == 'rh_name' or key.replace(" ", "") == 'vr_name' or key.replace(" ", "") == 'mphys' or key.replace(" ", "") == 'xname' or key.replace(" ", "") == 'yname' or key.replace(" ", "") == 'zname' or key.replace(" ", "") == 'latname' or key.replace(" ", "") == 'lonname': + numck = False + if key.replace(" ", "") == 'exper': # or key.replace(" ", "") == 'ptype': + vval = vval.strip("''") + if key.replace(" ", "") == 'image_dir': + numck = True + if key.replace(" ", "") == 'rfiles': + numck = True + + if numck is True or vval == 'None' or vval == 'True' or vval == 'False': + try: + config[(key.replace(" ", ""))] = eval(vval) + except: + if "datetime" in vval: + config[(key.replace(" ", ""))] = vval + else: + config[(key.replace(" ", ""))] = vval + + print('Read-in complete.\n') + + # ===== + # (2) Find input radar files and concatenate the data. Rename x, y, z variables. + # ===== + + print('Station/experiment: '+config['exper']) + print('Input: '+config['mphys'].upper()) + print('Start: '+config['sdatetime']) + print('End: '+config['edatetime']) + time.sleep(3) + + drop_vars = config['drop_vars'] + sdatetime = int(config['sdatetime'][0:8]+config['sdatetime'][9:13]) + edatetime = int(config['edatetime'][0:8]+config['edatetime'][9:13]) + rfiles = [] + with open(config['rfiles'], 'r') as f: + allrfiles = f.read().splitlines() + for rfile in allrfiles: + fullname = os.path.basename(rfile) + filedatestr = fullname[config['rdstart']:config['rdend']].replace('_','').replace(':','').replace('-','') + filedate = int(filedatestr[0:-2]) + if filedate >= sdatetime and filedate <= edatetime: + rfiles.append(rfile) + + if rfiles == []: + print("\nOops! There is no radar data for the dates given in your config file. Exiting...\n") + sys.exit(1) + + if config['exper'] == 'MC3E' and config['mphys'] == 'obs': + print("special handling for ",config['exper']) + + file = open(config['rfiles'], "r") + rf1=[] + rf2=[] + for line in file: + if re.search('vtzms', line): + rf1.append(line.rstrip('\n')) + else: + rf2.append(line.rstrip('\n')) + if not rf2: + rvar = xr.open_mfdataset(rf1,autoclose=True,combine='nested',concat_dim='d',preprocess=fix_my_data) + else: + rvar1 = xr.open_mfdataset(rf1,autoclose=True,combine='nested',compat='override',preprocess=fix_my_data) + rvar2 = xr.open_mfdataset(rf2,autoclose=True,concat_dim='d') + rvar = xr.concat((rvar1,rvar2),dim='d') + rfiles = list(np.append(rf1,rf2)) + else: + rvar = xr.open_mfdataset(rfiles,autoclose=True,combine='nested',concat_dim='d',preprocess=reduce_dim) + #rvar = xr.open_mfdataset(rfiles,autoclose=True,concat_dim='d',preprocess=reduce_dim,combine='by_coords') + #rvar = xr.open_mfdataset(rfiles,autoclose=True,concat_dim='d',preprocess=reduce_dim) + + if config['type'].startswith('wrf'): + refvals = deepcopy(rvar[config['dz_name']].values) + refvals[refvals < float(config['refthresh'])] = np.nan + newref = xr.DataArray(refvals, dims=['d','z','y','x'], name=config['dz_name']) + rvar[config['dz_name']] = newref + + parsers = ['dr_name','kd_name','rh_name','vr_name'] + for v in parsers: + newvals = deepcopy(rvar[config[v]].values) + newvals = np.where(newvals == -999.0,np.nan,newvals) + #newvals = np.where(np.logical_and(newvals >= 0.0,newvals < 0.1),np.nan,newvals) + newvals = np.where(newvals == 0.0,np.nan,newvals) + newvals = np.where(np.isnan(refvals),np.nan,newvals) + newvar = xr.DataArray(newvals, dims=['d','z','y','x'], name=config[v]) + rvar[config[v]] = newvar + + # ===== + # (3) Get datetime objects from radar file names. + # ===== + + tm = [] + for d in rfiles: + dformat = config['rdate_format'] + base = os.path.basename(d) + radcdate=str(base[config['rdstart']:config['rdend']]) + date=datetime.datetime.strptime(radcdate,dformat) + tm.append(date) + + rvar = rvar.rename({config['xname']:'x'}) + rvar = rvar.rename({config['yname']:'y'}) + + if config['type'].startswith('obs'): + rvar = rvar.rename({config['zname']:'z'}) + elif config['type'].startswith('wrf'): + currx = deepcopy(rvar['x'].values) + newx = xr.DataArray(currx-np.mean(currx), dims=['x'], name='x') + rvar['x'] = newx + + curry = deepcopy(rvar['y'].values) + newy = xr.DataArray(curry-np.mean(curry), dims=['y'], name='y') + rvar['y'] = newy + + if 'd' in rvar['hgt'].dims: hgt = rvar['hgt'].values[0,:] + else: hgt = rvar['hgt'].values + newz = xr.DataArray(hgt, coords={'z': hgt}) + rvar['z'] = newz + + if drop_vars: + print("dropping extra variables for memory!") + rvar= rvar.drop(['vrad03','vdop02','elev03','elev02','vdop03','vang02','vang03','vrad02','zhh02','zhh03','zdr02','zdr03','kdp02','kdp03','rhohv02','rhohv03']) + + print('Radar files ready.') + time.sleep(3) + + # ===== + # (4) + # ===== + + if config['dd_on']: + print('In your config file, dd_on is set to True.') + time.sleep(3) + with open(config['dfiles'], 'r') as g: + dfiles1 = g.read().splitlines() + tmd = [] + for d in dfiles1: + dformat = config['ddate_format'] + base = os.path.basename(d) + radcdate = base[config['ddstart']:config['ddend']] + if dformat == '%H%M': + hr=int(base[config['ddstart']:config['ddstart']+2]) + mn=int(base[config['ddstart']+2:config['ddstart']+4]) + dstart=datetime.datetime.strptime(config['date'],'%Y%m%d') + dat2 = datetime.datetime(dstart.year,dstart.month,dstart.day,hr,mn) + else: + dat2=datetime.datetime.strptime(radcdate,dformat) + tmd.append(dat2) + + print('Matching Dual-Doppler') + dmatch = find_dd_match(rfiles,dfiles1,tm,tmd) + try: + dvar = xr.open_mfdataset(dfiles1,concat_dim='d') + except ValueError as ve: + print('Trying nested instead of concat_dim to read DD files') + dvar = xr.open_mfdataset(dfiles1,combine='nested',concat_dim='d') + nf= len(dfiles1) + + # NEW! MultiDop names velocity fields in long-form. Shorten fieldnames in dopp files here for plotting labels. + Uname = 'U' + Vname = 'V' + Wname = 'W' + dvar = dvar.rename({config['uname']:Uname}) + dvar = dvar.rename({config['vname']:Vname}) + dvar = dvar.rename({config['wname']:Wname}) + + wvar = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) + wvar.fill(np.nan) + + unew = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) + unew.fill(np.nan) + + vnew = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) + vnew.fill(np.nan) + + conv = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) + conv.fill(np.nan) + + # NEW! MultiDop only works if distance values are in metres, not km. Need a condition to convert back to km so that doppler and radar distances are comparable. + if np.array_equal(dvar.variables['x'].values, 1000.0*rvar.variables['x'].values): + dvar['x'] = rvar['x'] + dvar['y'] = rvar['y'] + dvar['z'] = rvar['z'] + + xsubmin = np.where(rvar.variables['x']==np.min(dvar.variables['x']))[0][0] + xsubmax = np.where(rvar.variables['x']==np.max(dvar.variables['x']))[0][0] + + ysubmin = np.where(rvar.variables['y']==np.min(dvar.variables['y']))[0][0] + ysubmax = np.where(rvar.variables['y']==np.max(dvar.variables['y']))[0][0] + + zsubmin = np.where(rvar.variables['z']==np.min(dvar.variables['z']))[0][0] + zsubmax = np.where(rvar.variables['z']==np.max(dvar.variables['z']))[0][0] + + for q,d in enumerate(dmatch.keys()): + if dmatch[d] is not None: + dfile = dmatch[d] + if dfile in dfiles1: + i = dfiles1.index(dfile) + #wvar[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[config['wname']].sel(d=i) + wvar[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[Wname][i,:,:,:] + unew[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[Uname][i,:,:,:] + vnew[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[Vname][i,:,:,:] + #conv[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[config['convname']][i,:,:,:] + + rvar[Wname] = (['d','z','y','x'],wvar) + rvar[Uname] = (['d','z','y','x'],unew) + rvar[Vname] = (['d','z','y','x'],vnew) + + else: + Uname = None + Vname = None + Wname = None + + print('\nSending data to RadarData...') + + if config['wrft_on']: + print('In your config file, wrft_on is set to True.') + time.sleep(3) + if not 't_air' in list(rvar.keys()): + wmatch = find_wrfpol_match(config) + if len(wmatch) > 0: + print('Found POLARRIS-f files!') + try: + tvar = xr.open_mfdataset(list(wmatch.values()),concat_dim='d') + except ValueError as ve: + tvar = xr.open_mfdataset(list(wmatch.values()),combine='nested',concat_dim='d') + rvar[config['t_name']] = tvar['t_air']-273.15 + else: + rvar[config['t_name']].values = deepcopy(rvar[config['t_name']])-273.15 + + rdata = RadarData.RadarData(rvar,tm,ddata = None,dz=config['dz_name'],zdr=config['dr_name'],kdp=config['kd_name'],rho=config['rh_name'],temp=config['t_name'],u=Uname,v=Vname,w=Wname,conv=config['convname'],rr=config['rr_name'],band = config['band'],vr = config['vr_name'],lat_r=config['lat'],lon_r=config['lon'],lat=config['latname'], lon=config['lonname'],lat_0=config['lat'],lon_0=config['lon'],exper=config['exper'],mphys=config['mphys'],z_thresh=0,conv_types=config['conv_types'],strat_types=config['strat_types'],color_blind=config['cb_friendly']) + + if config['snd_on']: + print('In your config file, snd_on is set to True.') + time.sleep(3) + smatch = find_snd_match(config) + if len(smatch) > 0: + sfile = smatch[rfiles[0]] + print ('Found sounding match!',sfile,'\n') + snd = SkewT.Sounding(sfile) + rdata.add_sounding_object(snd) # this will add the sounding object to the radar object and then will take the heights and temps + rdata.interp_sounding() + + if config['mask_model']: + print('masking model data') + rdata.mask_model() + + rdata.calc_pol_analysis(tm,config) + rdata.calc_cs_shy(cs_z=config['cs_z']) + rdata.raintype=rdata.data['CSS'].values + + if config['comb_vicr']: + whvi = np.where(rdata.hid == 6) + rdata.hid[whvi] = 3 + +#Do some quick masking of the data#### +# mask = np.zeros([rdata.data.dims['d'],rdata.data.dims['z'],rdata.data.dims['y'],rdata.data.dims['x']]) +# whbad = np.logical_or(np.logical_or(np.logical_or(np.logical_or(rdata.data[rdata.dz_name].values>-20.,rdata.data[rdata.zdr_name].values>-2.),rdata.data[rdata.kdp_name].values<10.),rdata.data[rdata.zdr_name].values<10.),rdata.data[rdata.dz_name].values<70.) +# whbad2= np.where(~whbad) +# mask[whbad] = 1 +# if np.nanmin(rdata.data['CSS'].values)<1.: +# mask[rdata.data['CSS'].values<=0] = 0 +# else: +# mask[np.isnan(rdata.data['CSS'].values)]=0 +# +# rdata.data['CSS'] = rdata.data['CSS'].where(mask ==1) +# rdata.data[rdata.dz_name].values[whbad2] = np.nan +# rdata.data[rdata.zdr_name].values[whbad2] = np.nan +# rdata.data[rdata.kdp_name].values[whbad2] = np.nan +# rdata.data[rdata.rho_name].values[whbad2] = np.nan +# rdata.data[rdata.w_name].values[whbad2] = np.nan + + return rdata, config, Uname, Vname, Wname diff --git a/polarris_driver_new.py b/polarris_driver_new.py deleted file mode 100644 index e722d1b..0000000 --- a/polarris_driver_new.py +++ /dev/null @@ -1,371 +0,0 @@ -""" -This is the configruation file for setting up iPOLARRIS. Herein, the speicifcs of the dataset need to be defined such as the experiment, location and type of reading, etc. -Written by Brenda Dolan -May 2017 -bdolan@atmos.colostate.edu -""" -from __future__ import print_function -import glob -import os -import sys -import re -from netCDF4 import Dataset -import pandas as pd -import xarray as xr -import RadarData -import datetime -import matplotlib.pyplot as plt -import numpy as np -import GeneralFunctions as GF -import RadarConfig -import plot_driver -from skewPy import SkewT - -def fix_my_data(ds): - return(ds.drop(['VTZCS','CVECS'])) - -def find_dd_match(rdum,ddum,rdate,ddates): - - radlist=[] - - mdfiles = {} - for v,cname in enumerate(rdum): - #print cname - base = os.path.basename(cname) - dates = rdate[v] - #print dates, etime,stime - #print cname - mval = match_dd(dates,ddates) - #print( dates,ddates) - - if mval != 'no': - dfile = ddum[mval[0]] - print ('Found DD match!', dfile) - mdfiles[cname] = dfile - else: - mdfiles[cname] = None - - - return mdfiles - -def match_dd(rdate,ddates): - dum=abs(rdate-np.array(ddates)) - - try: - mval=np.argwhere(dum == np.min(dum))[0] - diff=np.min(dum) - if diff.total_seconds() < 600.: - return mval - else: - return 'no' - except ValueError: - print ('Something DD is not working here!') - - -def match_snd(rdate,sdates): - dum=abs(rdate-np.array(sdates)) - - try: - mval=np.argwhere(dum == np.min(dum)) - diff=np.min(dum) - #allow 12 hours between the radar obs and the sounding - if diff.total_seconds() < 43200: - return mval - else: - return 'no' - except ValueError: - print ('Something sound is not working here!') - - -def find_snd_match(config): - rdum =[] - with open(config['radar_files']) as f: - # dum.append(foo(f.readline())) - # dum.append(foo(f.readline())) - - for line in f: - dat = (line) - rdum.append(foo(dat)) - #print('sfiles:',config['sfiles']) - slist = sorted(glob.glob('{p}*{s}_*.txt'.format(p=config['sfiles'],s=(config['sstat'])))) - sdates=[] - for v,sname in enumerate(slist): - - base = os.path.basename(sname) -# print base - radcdate=np.str(base[13:13+10]) - #print('radcdate',radcdate) - dates=datetime.datetime.strptime('{r}'.format(r=radcdate),config['sdate_format']) - sdates.append(dates) - - msfiles = {} - - for v,cname in enumerate(rdum): -# print cname - base = os.path.basename(cname) - radcdate=np.str(base[config['doff']:config['doff']+15]) - dates=datetime.datetime.strptime(radcdate,config['rdate_format']) - if (dates >= config['etime']) and (dates <= config['stime']): - #print cname - #now find a sounding match - mv = match_snd(dates,sdates) - if mv != 'no': - #print ('sounding match',mv[0][0]) - msfiles[cname] = np.array(slist)[mv[0][0]] - else: - return None - - return msfiles - -def foo(s1): - return '{}'.format(s1.rstrip()) - -def reduce_dim(ds): - try: - t1= ds['time'][0].values - except KeyError as ke: - print(f"{ke} skipping preprocessing") - return(ds) - for v in ds.data_vars.keys(): - try: - ds[v]=ds[v].sel(time=t1).drop('time') - except ValueError as e: - pass -# print(e) -# print(v) - return(ds) - -from matplotlib.dates import DateFormatter,HourLocator -dayFormatter = DateFormatter('%H%M') # e.g., 12 -hourFormatter = DateFormatter('%H') # e.g., 12 - - -def hasNumbers(inputString): - return any(char.isdigit() for char in inputString) - - -def polarris_driver(configfile): - - config = {} - print('ready to roll') - with open(configfile[0]) as f: - for line in f: - #print line - if not line.startswith("#"): - #print('line',line) - key, val, comment = line.split('==') - vval = val.replace(" ","") - numck = hasNumbers(vval) - if key.replace(" ", "") == 'exper' or key.replace(" ", "") == 'dz_name' or key.replace(" ", "") == 'drop_vars' or key.replace(" ", "") == 'extrax' or key.replace(" ", "") == 'radarname' or key.replace(" ", "") == 'dr_name' or key.replace(" ", "") == 'kd_name' or key.replace(" ", "") == 'rh_name' or key.replace(" ", "") == 'vr_name' or key.replace(" ", "") == 'mphys': - numck = False - if key.replace(" ", "") == 'exper' or key.replace(" ", "") == 'extra' or key.replace(" ", "") == 'ptype' or key.replace(" ", "") == 'extrax': - vval = vval.strip("''") - #print numck - #print vval,key - if key.replace(" ", "") == 'image_dir': - numck = True - if key.replace(" ", "") == 'radar_files': - numck = True - - if numck is True or vval == 'None' or vval == 'True' or vval == 'False': - try: - config[(key.replace(" ", ""))] = eval(vval) - except: - if "datetime" in vval: - config[(key.replace(" ", ""))] = vval - else: - config[(key.replace(" ", ""))] = vval - - print(config['radar_files']) - drop_vars=config['drop_vars'] - with open(config['radar_files'], 'r') as f: - rfiles = f.read().splitlines() - #rfiles= glob.glob('*.nc') - print((config['exper']),(config['mphys'])) - if config['exper'] == 'MC3E' and config['mphys'] == 'obs': - print("special handling for ",config['exper']) - - file = open(config['radar_files'], "r") - rf1=[] - rf2=[] - for line in file: - print(line) - if re.search('vtzms', line): - rf1.append(line.rstrip('\n')) - else: - #print('other') - rf2.append(line.rstrip('\n')) - #print(rf1) - rvar1 = xr.open_mfdataset(rf1,autoclose=True,concat_dim='d',preprocess=fix_my_data) - rvar2= xr.open_mfdataset(rf2,autoclose=True,concat_dim='d') - rvar = xr.concat((rvar1,rvar2),dim='d') - rfiles =list(np.append(rf1,rf2)) - else: -# try: -# print('trying to read normally') -# rvar = xr.open_mfdataset(rfiles,autoclose=True,concat_dim='d',preprocess=reduce_dim,combine='by_coords') -# except ValueError as ve: - print("trying nesting") - rvar = xr.open_mfdataset(rfiles,autoclose=True,combine='nested',concat_dim='d',preprocess=reduce_dim) - try: - rvar = rvar.rename({'x0':'x'}) - rvar = rvar.rename({'y0':'y'}) - rvar = rvar.rename({'z0':'z'}) - except: - print('Dims do not need renaming') - print('Current dimensions:',rvar.dims) - - if drop_vars == True: - print("dropping extra variables for memory!") - rvar= rvar.drop(['vrad03','vdop02','elev03','elev02','vdop03','vang02','vang03','vrad02','zhh02','zhh03','zdr02','zdr03','kdp02','kdp03','rhohv02','rhohv03']) - lon_0 = config['lon'] - lat_0 = config['lat'] - - lat_r = config['lat'] - lon_r = config['lon'] - - if config['snd_on'] == True: - smatch = find_snd_match(config) - #print("rfiles",rfiles[0]) - sfile = smatch[rfiles[0]] - print('matching sounding') - else: - smatch = None - - - - tm = [] - for d in rfiles: - print(d) - dformat = config['wdate_format'] - base = os.path.basename(d) - radcdate=np.str(base[config['time_parse'][0]:config['time_parse'][1]]) - date=datetime.datetime.strptime(radcdate,dformat) - tm.append(date) - - if config['dd_on']==True: - with open(config['dd_files'], 'r') as f: - dfiles1 = f.read().splitlines() - tmd = [] - for d in dfiles1: - dformat = config['ddate_format'] - base = os.path.basename(d) -# print('dd base',base,config['ddoff'],config['ddadd']) - radcdate = base[config['ddoff']:config['ddadd']] -# print (radcdate) -# print('dformat is',dformat,radcdate) - if dformat == '%H%M': - - hr=int(base[config['ddoff']:config['ddoff']+2]) - mn=int(base[config['ddoff']+2:config['ddoff']+4]) - #print('hr','mn',hr,mn) - # print radcdate - #date=datetime.datetime.strptime(radcdate,dformat) - #print(config['date']) - dstart=datetime.datetime.strptime(config['date'],'%Y%m%d') - dat2 = datetime.datetime(dstart.year,dstart.month,dstart.day,hr,mn) - else: - dat2=datetime.datetime.strptime(radcdate,dformat) - #dstart=datetime.datetime.strptime(config['date'],'%Y%m%d') - tmd.append(dat2) - - print('Matching Dual-Doppler') - dmatch = find_dd_match(rfiles,dfiles1,tm,tmd) - #print('dmatch is ',dmatch) - dvar = xr.open_mfdataset(dfiles1,concat_dim='d') - - wvar = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) - wvar.fill(np.nan) - - unew = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) - unew.fill(np.nan) - - vnew = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) - vnew.fill(np.nan) - - conv = np.zeros([rvar.dims['d'],rvar.dims['z'],rvar.dims['y'],rvar.dims['x']]) - conv.fill(np.nan) - xsubmin = np.where(rvar.variables['x']==np.min(dvar.variables['x']))[0][0] - xsubmax = np.where(rvar.variables['x']==np.max(dvar.variables['x']))[0][0] - - ysubmin = np.where(rvar.variables['y']==np.min(dvar.variables['y']))[0][0] - ysubmax = np.where(rvar.variables['y']==np.max(dvar.variables['y']))[0][0] - - zsubmin = np.where(rvar.variables['z']==np.min(dvar.variables['z']))[0][0] - zsubmax = np.where(rvar.variables['z']==np.max(dvar.variables['z']))[0][0] - - for q,d in enumerate(dmatch.keys()): - #print(q,'i outer',dmatch[d]) - if dmatch[d] is not None: - #print('good, dmatch is not none') - dfile = dmatch[d] - if dfile in dfiles1: - i = dfiles1.index(dfile) - #print(i,'i inner') - wvar[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[config['wname']].sel(d=i) - unew[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[config['uname']].sel(d=i) - vnew[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[config['vname']].sel(d=i) - conv[q,zsubmin:zsubmax+1,ysubmin:ysubmax+1,xsubmin:xsubmax+1] = dvar[config['convname']].sel(d=i) - - - rvar[config['wname']] = (['d','z','y','x'],wvar) - rvar[config['uname']] = (['d','z','y','x'],unew) - rvar[config['vname']] = (['d','z','y','x'],vnew) - rvar[config['convname']] = (['d','z','y','x'],conv) - - print('sending data to RadarData!') - rdata = RadarData.RadarData(rvar,tm,ddata = None,dz =config['dz_name'],zdr=config['dr_name'], - kdp=config['kd_name'],rho=config['rh_name'],temp=config['t_name'], - u=config['uname'],v=config['vname'],w=config['wname'],conv=config['convname'],x=config['xname'], - rr=config['rr_name'],band = config['band'],vr = config['vr_name'],lat_r=lat_r,lon_r=lon_r, - y=config['yname'],z=config['zname'],lat=config['latname'], lon=config['lonname'],lat_0=lat_0,lon_0=lon_0, - exper=config['exper'],mphys=config['mphys'],radar_name =config['radarname'], - z_thresh=0,conv_types = config['conv_types'], - strat_types = config['strat_types']) - - if smatch is not None: - print ('Smatch',sfile) - snd = SkewT.Sounding(sfile) - rdata.add_sounding_object(snd) # this will add the sounding object to the radar object - # and then will take the heights and temps - rdata.interp_sounding() - - - if config['convert_Tk_Tc'] == True: - print('converting T') - rdata.convert_t() - #print 'Calculating polarimetric fields like HID and rain...' - #if config['pol_on'] == True: - if config['mask_model'] == True: - print('masking model data') - rdata.mask_model() - - rdata.calc_pol_analysis() -# print(config['cs_z'],'in 312 cs_z') - rdata.calc_cs_shy(cs_z=config['cs_z']) - rdata.raintype=rdata.data['CSS'].values# rdata.set_hid() - - if config['comb_vicr'] == True: - whvi = np.where(rdata.hid == 6) - rdata.hid[whvi] = 3 - - - #Do some quick masking of the data#### -# mask = np.zeros([rdata.data.dims['d'],rdata.data.dims['z'],rdata.data.dims['y'],rdata.data.dims['x']]) -# whbad = np.logical_or(np.logical_or(np.logical_or(np.logical_or(rdata.data[rdata.dz_name].values>-20.,rdata.data[rdata.zdr_name].values>-2.),rdata.data[rdata.kdp_name].values<10.),rdata.data[rdata.zdr_name].values<10.),rdata.data[rdata.dz_name].values<70.) -# whbad2= np.where(~whbad) -# mask[whbad] = 1 -# if np.nanmin(rdata.data['CSS'].values)<1.: -# mask[rdata.data['CSS'].values<=0] = 0 -# else: -# mask[np.isnan(rdata.data['CSS'].values)]=0 -# -# rdata.data['CSS'] = rdata.data['CSS'].where(mask ==1) -# rdata.data[rdata.dz_name].values[whbad2] = np.nan -# rdata.data[rdata.zdr_name].values[whbad2] = np.nan -# rdata.data[rdata.kdp_name].values[whbad2] = np.nan -# rdata.data[rdata.rho_name].values[whbad2] = np.nan -# rdata.data[rdata.w_name].values[whbad2] = np.nan - - - return rdata, config diff --git a/run_ipolarris.py b/run_ipolarris.py new file mode 100644 index 0000000..9faa77b --- /dev/null +++ b/run_ipolarris.py @@ -0,0 +1,589 @@ +#=================================================== +#================ RUN_IPOLARRIS.PY ================= +#=================================================== + +import sys +import time +''' +# WARNING TO USERS to activate conda environment # +print("\n####################################") +print("### Welcome, user, to iPOLARRIS! ###") +print("####################################\n") + +print("WARNING: Before proceeding, ensure that you have: \n\n (a) installed the Anaconda package manager. Latest versions and instructions can be found here: \n https://conda.io/projects/conda/en/latest/user-guide/install/index.html \n\n (b) installed the Conda environment required to run iPOLARRIS with the command `conda env create -f env.yml` \n\n (c) activated the new environment with the command `conda activate pol` \n\n (d) Put /usr/bin ahead of your 'default' executable directories (i.e. before /opt/local/bin) in $PATH, if it is not already. It does not need to be ahead of your custom executable directories (i.e. ~/../anaconda3/bin) \n\n (e) Run: `f2py -c calc_kdp_ray_fir.f -m calc_kdp_ray_fir`. This will allow you to use the Fortran compiler in /usr/bin to convert your .f file into a readable .so file for your MAC or Linux OS. \n") + +print("If you have NOT performed the required setup above, click x and Enter to exit. Otherwise, press any other key. \n") + +usersays=input() +if usersays.lower().startswith('x'): + print('\nExiting gracefully.\n') + import sys + sys.exit() +else: + print('\niPOLARRIS INITIATING... If Conda env activated, no import errors...') + import time + time.sleep(3) +''' +# Import core Python packages +from collections import OrderedDict +import csv +import datetime +import glob +import matplotlib +matplotlib.use('Agg') +from netCDF4 import Dataset +import numpy as np +import os +import matplotlib.pyplot as plt +import pandas as pd +import sys +import time +import warnings +warnings.filterwarnings('ignore') +import xarray as xr + +# Import iPOLARRIS functions +import GeneralFunctions as GF +from polarris_driver import polarris_driver +import plot_driver +import RadarData +import RadarConfig +from skewPy import SkewT + +#--------------- Main Program ---------------- + +time.sleep(3) + +print('\nSUCCESS! Requisite packages loaded.') + +if len(sys.argv) > 2: + print('\n***Entering SIMULATION MODE: you are about to compare radar observations with simulated radar observables created from wrfout files by POLARRIS-f!***') +else: + print('\n***Entering OBSERVATION MODE: you are about to analyze radar observations recorded by a station!***') + +time.sleep(3) + +print('\n#############################################') +print('########## Starting run_ipolarris.py ########') +print('#############################################') + +configfile = sys.argv[1:] # Feed config file name as arg +#print sys.argv[1:] + +print('\n##########################################################') +print('############ Calling polarris_driver.py to read in obs ###') +print('##########################################################') + +time.sleep(3) + +rdata, config, config['uname'], config['vname'], config['wname'] = polarris_driver(configfile) + +print('\n#################################################') +print('########## Returning to run_ipolarris.py ########') +print('#################################################') + +#print(,'EXTRA 1 is') + +# If a second argument is passed for WRF config file, produce a bunch of comparison plots! +# More comments in this section TBD! +if sys.argv[2:]: + + configfile1 = sys.argv[2:] + + print('\n###############################################################') + print('############ Calling polarris_driver.py to read in sim data ###') + print('###############################################################') + time.sleep(3) + + rdata2, config2, config2['uname'], config2['vname'], config2['wname'] = polarris_driver(configfile1) + + print('\n#################################################') + print('########## Returning to run_ipolarris.py ########') + print('#################################################') + + if (config2['cfad_compare'] | config2['all3']): + + print('\nIN RUN_IPOLARRIS... creating CFAD COMPARISON figures.') + outdir = config['image_dir']+'cfad_diff_individ/' + os.makedirs(outdir,exist_ok=True) + + zmax = config['zmax'] + st = rdata.date[0].strftime('%Y%m%d_%H%M%S') + en = rdata.date[-1].strftime('%Y%m%d_%H%M%S') + + if st.startswith(en): dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+' UTC' + elif st[0:8].startswith(en[0:8]): dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+'-'+en[9:11]+':'+en[11:13]+' UTC' + else: dtlab = st[0:4]+'-'+st[4:6]+'-'+st[6:8]+' '+st[9:11]+':'+st[11:13]+'\n- '+en[0:4]+'-'+en[4:6]+'-'+en[6:8]+' '+en[9:11]+':'+en[11:13]+' UTC' + + for i,v in enumerate(eval(config['cfad_compare_vars'])): + + if v is None: + continue + else: + + if v.startswith('HID'): + + print(v) + + fig, ax = plt.subplots(1,2,figsize=(14,8),gridspec_kw={'wspace': 0.08, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + if not isinstance(ax, np.ndarray) or not isinstance(ax, list): + ax = np.array([ax]) + axf = ax.flatten() + + if not zmax == '': + rdata.plot_hid_cdf(ax=axf[0],cbar=False,z_resolution=config['z_resolution'],zmax=zmax) + rdata2.plot_hid_cdf(ax=axf[1],ylab=False,cbar=False,z_resolution=config['z_resolution'],zmax=zmax) + else: + rdata.plot_hid_cdf(ax=axf[0],cbar=False,z_resolution=config['z_resolution']) + rdata2.plot_hid_cdf(ax=axf[1],ylab=False,cbar=False,z_resolution=config['z_resolution']) + + lur,bur,wur,hur = axf[0].get_position().bounds + lur2,bur2,wur2,hur2 = axf[1].get_position().bounds + cbar_ax_dims = [lur,bur-0.15,lur2+wur2,0.05] + rdata.HID_barplot_colorbar(fig,cbar_ax_dims,orientation='horizontal',names='longnames') + + axf[0].text(0,1,'{e} {r}'.format(e=rdata.exper,r=rdata.band+'-band'),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=axf[0].transAxes) + axf[1].text(0,1,'{e} {r}'.format(e=rdata2.exper,r=rdata2.band+'-band'),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=axf[1].transAxes) + axf[1].text(1,1, dtlab, horizontalalignment='right', verticalalignment='bottom', size=18, color='k', zorder=10, weight='bold', transform=axf[1].transAxes) # (a) Top-left + + if config['ptype'].startswith('mp4'): + plt.savefig('{d}{p}_HID_CFAD_{t1}-{t2}.png'.format(d=outdir,p=rdata.exper,t1=st,t2=en),dpi=400,bbox_inches='tight') + else: + plt.savefig('{d}{p}_HID_CFAD_{t1}-{t2}.{t}'.format(d=outdir,p=rdata.exper,t=config['ptype'],t1=st,t2=en),dpi=400,bbox_inches='tight') + + plt.close() + + else: + + if not rdata.cfbins[config[v]] == '' and config[v] in rdata.data.variables.keys(): + + print(v) + + fig, ax = plt.subplots(1,3,figsize=(16,8),gridspec_kw={'wspace': 0.1, 'top': 1., 'bottom': 0., 'left': 0., 'right': 1.}) + if not isinstance(ax, np.ndarray) or not isinstance(ax, list): + ax = np.array([ax]) + axf = ax.flatten() + + if not zmax == '': + ocfad, hts, pc, fig0, ax0 = rdata.cfad_plot(config[v],ax=axf[0],cbar=False,bins=rdata.cfbins[config[v]],z_resolution=config['z_resolution'],levels=1,zmax=zmax) + scfad, hts2, pc2, fig1, ax1 = rdata2.cfad_plot(config2[v],ax=axf[1],ylab=False,cbar=False,bins=rdata2.cfbins[config2[v]],z_resolution=config['z_resolution'],levels=1,zmax=zmax) + dcfad, hts3, pc3, fig2, ax2 = rdata.cfad_plot(config[v],cfad=ocfad-scfad,hts=hts,ax=axf[2],ylab=False,cbar=False,bins=rdata.cfbins[config[v]],z_resolution=config['z_resolution'],levels=1,zmax=zmax,diff=1) + else: + ocfad, hts, pc, fig0, ax0 = rdata.cfad_plot(config[v],ax=axf[0],cbar=False,bins=rdata.cfbins[config[v]],z_resolution=config['z_resolution'],levels=1) + scfad, hts2, pc2, fig1, ax1 = rdata2.cfad_plot(config2[v],ax=axf[1],ylab=False,cbar=False,bins=rdata2.cfbins[config2[v]],z_resolution=config['z_resolution'],levels=1) + dcfad, hts3, pc3, fig2, ax2 = rdata.cfad_plot(config[v],cfad=ocfad-scfad,hts=hts,ax=axf[2],ylab=False,cbar=False,bins=rdata.cfbins[config[v]],z_resolution=config['z_resolution'],levels=1,diff=1) + + lur,bur,wur,hur = axf[0].get_position().bounds + lur2,bur2,wur2,hur2 = axf[1].get_position().bounds + cbar_ax_dims = [lur,bur-0.13,lur2+wur2,0.03] + cbar_ax = fig.add_axes(cbar_ax_dims) + cbt = plt.colorbar(pc,cax=cbar_ax,orientation='horizontal') + cbt.ax.tick_params(labelsize=16) + cbt.set_ticks(rdata.cfad_levs) + cbt.set_label('Frequency (%)', fontsize=16, labelpad=10) + + lur3,bur3,wur3,hur3 = axf[2].get_position().bounds + cbar_ax_dims3 = [lur3,bur3-0.13,wur3,0.03] + cbar_ax3 = fig.add_axes(cbar_ax_dims3) + cbt3 = plt.colorbar(pc3,cax=cbar_ax3,orientation='horizontal') + cbt3.ax.tick_params(labelsize=16) + cbt.set_ticks(rdata.cfad_levs) + cbt3.set_label('Frequency Difference (%)', fontsize=16, labelpad=10) + + axf[0].text(0,1,'{e} {r}'.format(e=rdata.exper,r=rdata.band+'-band'),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=axf[0].transAxes) + axf[1].text(0,1,'{e} {r}'.format(e=rdata2.exper,r=rdata2.band+'-band'),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=axf[1].transAxes) + axf[2].text(0,1,'({e1} - {e2})'.format(e1=rdata.exper,e2=rdata2.exper),horizontalalignment='left',verticalalignment='bottom',size=18,color='k',zorder=10,weight='bold',transform=axf[2].transAxes) + axf[2].text(0.99,0.99, dtlab, horizontalalignment='right', verticalalignment='top', size=18, color='k', zorder=10, weight='bold', transform=axf[2].transAxes, bbox=dict(facecolor='w', edgecolor='none', pad=0.0)) # (a) Top-left + + if config['ptype'].startswith('mp4'): + plt.savefig('{d}{p}_{v}_CFAD_{t1}-{t2}.png'.format(d=outdir,p=rdata.exper,v=rdata.names_uc[config[v]],t1=st,t2=en),dpi=400,bbox_inches='tight') + else: + plt.savefig('{d}{p}_{v}_CFAD_{t1}-{t2}.{t}'.format(d=outdir,p=rdata.exper,v=rdata.names_uc[config[v]],t=config['ptype'],t1=st,t2=en),dpi=400,bbox_inches='tight') + + plt.close() + + else: + + continue + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + ''' + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.dz_name,rdata2.dz_name,config,bins=config['dzbins'],xlab=rdata.longnames[rdata.dz_name]+' '+rdata.units[rdata.dz_name],cscfad=False,xlim=[min(rdata.cfbins[rdata.dz_name]),max(rdata.cfbins[rdata.dz_name])],ylim=config['zmax'],nor=10) + ax[0].set_title(rdata.exper+' '+rdata.exper,fontsize=16,fontweight='bold') + ax[0].set_ylabel('Height (km MSL)',fontsize=16) + ax[1].set_title(rdata2.mphys.upper(),fontsize=16,fontweight='bold') + ax[3].set_title('({e} - {v})'.format(e=rdata.exper,v=rdata2.mphys.upper()),fontsize=16,fontweight='bold') + plt.savefig('{i}{e}_{m}_{v}_CFAD_diff.{p}'.format(p=config2['ptype'],i=outdir,e=rdata2.exper,m=rdata2.mphys.upper(),v=rdata.dz_name),dpi=400,bbox_inches='tight') + plt.close(fig) + + print('\nDone! Saved to '+outdir) + print('Moving on.') + print('\nPlotting composites by time for variable '+rdata.zdr_name+'...') + + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.zdr_name,rdata2.zdr_name,config,bins=config['drbins'],xlab=rdata.longnames[rdata.zdr_name]+' '+rdata.units[rdata.zdr_name],cscfad=False,xlim=[min(config['drbins']),max(config['drbins'])+1],ylim=config['zlim'],nor=3) + ax[0].set_title(rdata.exper+' '+rdata.exper,fontsize=16,fontweight='bold') + ax[0].set_ylabel('Height (km MSL)',fontsize=16) + ax[1].set_title(rdata2.mphys.upper(),fontsize=16,fontweight='bold') + ax[3].set_title('({e} - {v})'.format(e=rdata.exper,v=rdata2.mphys.upper()),fontsize=16,fontweight='bold') + plt.savefig('{i}{e}_{m}_{v}_CFAD_diff.{p}'.format(p=config2['ptype'],i=outdir,e=rdata2.exper,m=rdata2.mphys.upper(),v=rdata.zdr_name),dpi=400,bbox_inches='tight') + plt.close(fig) + + print('\nDone! Saved to '+outdir) + print('Moving on.') + print('\nPlotting composites by time for variable '+rdata.kdp_name+'...') + + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.kdp_name,rdata2.kdp_name,config,bins=config['kdbins'],xlab=rdata.longnames[rdata.kdp_name]+' '+rdata.units[rdata.kdp_name],cscfad=False,xlim=[min(config['kdbins']),max(config['kdbins'])+1],ylim=config['zlim'],nor=3) + ax[0].set_title(rdata.exper+' '+rdata.exper,fontsize=16,fontweight='bold') + ax[0].set_ylabel('Height (km MSL)',fontsize=16) + ax[1].set_title(rdata2.mphys.upper(),fontsize=16,fontweight='bold') + ax[3].set_title('({e} - {v})'.format(e=rdata.exper,v=rdata2.mphys.upper()),fontsize=16,fontweight='bold') + plt.savefig('{i}{e}_{m}_{v}_CFAD_diff.{p}'.format(p=config2['ptype'],i=outdir,e=rdata2.exper,m=rdata2.mphys.upper(),v=rdata.kdp_name),dpi=400,bbox_inches='tight') + plt.close(fig) + + print('\nDone! Saved to '+outdir) + print('Moving on.') + print('\nPlotting composites by time for variable '+rdata.hid_name+'...') + #fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.w_name,rdata2.w_name,'Vertical Velocity',config,config2,bins=np.arange(-20,21,1),savefig=True,cscfad=False) + fig,ax = plot_driver.plot_hid_comparison_cfad(rdata,rdata2,config=config,cscfad=None) + ax[0].set_title(rdata.exper+' '+rdata.exper,fontsize=16,fontweight='bold') + ax[1].set_title(rdata2.mphys.upper(),fontsize=16,fontweight='bold') + plt.setp(ax, ylim=[0,10]) + plt.savefig('{i}{e}_{m}_{v}_CFAD_diff.{p}'.format(p=config2['ptype'],i=outdir,e=rdata2.exper,m=rdata2.mphys.upper(),v=rdata.hid_name),dpi=400,bbox_inches='tight') + plt.close(fig) + + print('\nDone! Saved to '+outdir) + print('Moving on.') + + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.dz_name,rdata2.dz_name,'Reflectivity',config,config2,bins=np.arange(0,82,2),savefig=True,cscfad='convective') + + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.zdr_name,rdata2.zdr_name,'Z$_{dr}$',config,config2,bins=np.arange(-2,8,0.2),savefig=True,cscfad='convective') + + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.kdp_name,rdata2.kdp_name,'K$_{dp}$',config,config2,bins=np.arange(-2,6,0.2),savefig=True,cscfad='convective') + + fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.w_name,rdata2.w_name,'Vertical Velocity',config,config2,bins=np.arange(-20,21,1),savefig=True,cscfad='convective') + + fig,ax = plot_driver.plot_hid_comparison_cfad(rdata,rdata2,config=config,cscfad='convective',savefig=True) + ''' + print('\niPOLARRIS RUN COMPLETE FOR '+config2['mphys'].upper()+' '+config['sdatetime']+' - '+config['edatetime']+'\n') + +################################################################################ +################## Now you can just start plotting! ############################ +################################################################################ + +### To see the variables that are available to plot, type: + +#rdata.data.keys() + +else: + + ############################################################################# + + if (config['compo_ref'] | config['all1']): + + print('\nIN RUN_IPOLARRIS_NEW... creating COMPOSITE figures.') + print('\nPlotting composites by time for variable '+rdata.dz_name+'...') + + outdir = config['image_dir']+'composite_'+rdata.names_uc[rdata.dz_name]+'/' + os.makedirs(outdir,exist_ok=True) + + for i,rtimematch in enumerate(np.array(rdata.date)): + + fig, ax = rdata.plot_composite(rdata.dz_name,i,statpt=True) + ax.text(0, 1, '{e} {r}'.format(e=rdata.exper,r=rdata.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(1, 1, '{d:%Y-%m-%d %H:%M:%S} UTC'.format(d=rtimematch), horizontalalignment='right', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + + if not config['ptype'].startswith('mp4'): + plt.savefig('{i}{e}_{v}_{d:%Y%m%d_%H%M%S}.{p}'.format(p=config['ptype'],e=rdata.exper,i=outdir,d=rtimematch,v=rdata.dz_name),dpi=400,bbox_inches='tight') + else: + if len(rdata.date) < 6: + plt.savefig('{i}{e}_{v}_{d:%Y%m%d_%H%M%S}.png'.format(e=rdata.exper,i=outdir,d=rtimematch,v=rdata.dz_name),dpi=400,bbox_inches='tight') + else: + plt.savefig(outdir+'/fig'+str(i).zfill(3)+'.png',dpi=400,bbox_inches='tight') + + plt.close() + print(rtimematch) + + if config['ptype'].startswith('mp4') and len(rdata.date) >= 6: + + st = rdata.date[0].strftime('%Y%m%d_%H%M%S') + en = rdata.date[-1].strftime('%Y%m%d_%H%M%S') + + os.system('ffmpeg -nostdin -y -r 1 -i '+outdir+'/fig%03d.png -c:v libx264 -r '+str(len(np.array(rdata.date)))+' -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '+'{i}{e}_{v}_{t1}-{t2}.mp4'.format(p=config['ptype'],e=rdata.exper,i=outdir,v=rdata.dz_name,t1=st,t2=en)) + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + ############################################################################# + + if (config['cappi_rr'] | config['all1']): + + print('\nIN RUN_IPOLARRIS_NEW... creating CAPPI figures.') + print('Plotting CAPPIs for all heights by time for variable '+rdata.rr_name+'...') + + outdir = config['image_dir']+'cappi_'+rdata.rr_name+'/' + os.makedirs(outdir,exist_ok=True) + + if not config['z'] == '': zspan = list(eval(str([config['z']]))) + else: zspan = rdata.data[rdata.z_name].values + + for z in zspan: + + print('\nz = '+str(z)) + + for i,rtimematch in enumerate(np.array(rdata.date)): + + print(rtimematch) + + dummy, ax = rdata.cappi(rdata.rr_name,z=z,xlim=config['xlim'],ylim=config['ylim'],ts=rtimematch,latlon=config['latlon'],statpt=True,xlab=True,ylab=True,dattype=config['type']) + + ax.text(0, 1, '{e} {r}'.format(e=rdata.exper,r=rdata.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(1, 1, '{d:%Y-%m-%d %H:%M:%S} UTC'.format(d=rtimematch), horizontalalignment='right', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + ax.text(0.99, 0.99, 'z = {a} km'.format(a=z), horizontalalignment='right',verticalalignment='top', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes, bbox=dict(facecolor='w', edgecolor='none', pad=0.0)) + + if not config['ptype'].startswith('mp4'): + plt.savefig('{i}{e}_{v}_cappi_{d:%Y%m%d_%H%M%S}_{h}.png'.format(i=outdir,e=rdata.exper,h=z,v=rdata.rr_name,d=rtimematch),dpi=400,bbox_inches='tight') + else: + if len(rdata.date) < 6: + plt.savefig('{i}{e}_{v}_cappi_{d:%Y%m%d_%H%M%S}_{h}.png'.format(i=outdir,e=rdata.exper,h=z,v=rdata.rr_name,d=rtimematch),dpi=400,bbox_inches='tight') + else: + plt.savefig(outdir+'/fig'+str(i).zfill(3)+'.png',dpi=400,bbox_inches='tight') + + plt.close() + + if config['ptype'].startswith('mp4') and len(rdata.date) >= 6: + + st = rdata.date[0].strftime('%Y%m%d_%H%M%S') + en = rdata.date[-1].strftime('%Y%m%d_%H%M%S') + + os.system('ffmpeg -nostdin -y -r 1 -i '+outdir+'/fig%03d.png -c:v libx264 -r '+str(len(np.array(rdata.date)))+' -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '+'{i}{e}_{v}_{t1}-{t2}_{h}.mp4'.format(p=config['ptype'],e=rdata.exper,i=outdir,v=rdata.rr_name,t1=st,t2=en,h=z)) + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + ############################################################################# + + if (config['rrstats_txt'] | config['all2']): + + print('\nIN RUN_IPOLARRIS_NEW... creating text files.') + print('Printing unconditional-mean statistics for variable '+rdata.rr_name+'...') + + ##Calculate a timeseries for writing out + rrstratu,rrconvu,rrallu = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2.5,cs_flag=True,thresh=-0.1) + rrstrat,rrconv,rrall = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2.5,cs_flag=True,thresh=0.0) + + tformat = '%Y%m%d-%H%M%S' + outdir = config['image_dir']+'txtfiles/' + os.makedirs(outdir,exist_ok=True) + with open('{i}{e}_{v}_uncondmean_stats.txt'.format(i=outdir,v=rdata.rr_name,e=rdata.exper),mode='w') as csv_file: + v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) + v_writer.writerow(['Date', 'Unc_Conv_RR', 'Unc_Strat_RR', 'Unc_Tot_RR']) + for i,v in enumerate(rdata.date): + #print( v) + tim = v.strftime(tformat) + dum =[tim,rrconvu[i].values,rrstratu[i].values,rrallu[i].values] + v_writer.writerow(dum) + + print('\nDone! Saved to '+outdir) + print('Printing conditional-mean statistics for variable '+rdata.rr_name+'...') + + with open('{i}{e}_{v}_condmean_stats.txt'.format(i=outdir,v=rdata.rr_name,e=rdata.exper),mode='w') as csv_file: + v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) + v_writer.writerow(['Date', 'Conv_RR', 'Strat_RR', 'Tot_RR']) + for i,v in enumerate(rdata.date): + #print (v) + tim = v.strftime(tformat) + dum =[tim,rrconv[i].values,rrstrat[i].values,rrall[i].values] + v_writer.writerow(dum) + + print('\nDone! Saved to '+outdir) + print('Printing relative frequency statistics for variable '+rdata.rr_name+'...') + + rain_area = rdata.radar_area + with open('{i}{e}_{v}_rel_frequency_stats.txt'.format(i=outdir,v=rdata.rr_name,e=rdata.exper), mode='w') as csv_file: + v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) + v_writer.writerow(['Date', 'Conv', 'Strat', 'Tot']) + for i,v in enumerate(rdata.date): + #print( v) + tim = v.strftime(tformat) + dum =[tim,rrconv[i].values*rdata.dx*rdata.dy/rain_area*100.,rrstrat[i].values*rdata.dx*rdata.dy/rain_area*100.,rrall[i].values*rdata.dx*rdata.dy/rain_area*100.] + v_writer.writerow(dum) + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + if (config['rrhist_txt'] | config['all2']): + + print('\nIN RUN_IPOLARRIS_NEW... creating text files.') + print('Printing histogram data for variable '+rdata.rr_name+'...') + + conv = np.where(rdata.data[rdata.cs_name].values == 2) + strat = np.where(rdata.data[rdata.cs_name].values == 1) + hist, eg = np.histogram(np.ravel((rdata.data[rdata.rr_name].values)),bins=np.logspace(-1,2.4,40)) + histc, eg = np.histogram(np.ravel((rdata.data[rdata.rr_name].values[conv])),bins=np.logspace(-1,2.4,40)) + hists, eg = np.histogram(np.ravel((rdata.data[rdata.rr_name].values[strat])),bins=np.logspace(-1,2.4,40)) + + #tformat = '%Y%m%d-%H%M%S' + outdir = config['image_dir']+'txtfiles/' + os.makedirs(outdir,exist_ok=True) + with open('{i}{e}_{v}_rr_histgram_{m}.txt'.format(i=outdir,v=rdata.rr_name,e=rdata.exper,m=rdata.mphys), mode='w') as csv_file: + v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) + v_writer.writerow(['Date', 'Con', 'Strat', 'Tot']) + for i,v in enumerate(eg[:-1]): + dum =[v,histc[i],hists[i],hist[i]] + v_writer.writerow(dum) + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + if (config['rrstats_areas_txt'] | config['all2']): + ###Areas + print('\nIN RUN_IPOLARRIS_NEW... creating text files.') + print('Printing domain area statistics for '+rdata.rr_name+'...') + + rrstratu_area,rrconvu_area,rrallu_area = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2,cs_flag=True,thresh=-0.1,areas=True) + rrstrat_area,rrconv_area,rrall_area = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2,cs_flag=True,thresh=0.0,areas=True) + + #grid_area=rdata.radar_area() + rain_area = rdata.radar_area + tformat = '%Y%m%d-%H%M%S' + outdir = config['image_dir']+'txtfiles/' + os.makedirs(outdir,exist_ok=True) + with open('{i}{e}_domain_area_stats.txt'.format(i=outdir,e=rdata.exper), mode='w') as csv_file: + v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) + v_writer.writerow(['Date', 'Unc_Con', 'Unc_Strat', 'Unc_Tot']) + for i,v in enumerate(rdata.date): + print (v) + tim = v.strftime(tformat) + dum =[tim,rrconvu_area[i].values.astype(float)*rdata.dx*rdata.dy,rrstratu_area[i].values.astype(float)*rdata.dx*rdata.dy,rrallu_area[i].values.astype(float)*rdata.dx*rdata.dy] + v_writer.writerow(dum) + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + if (config['rr_timeseries'] | config['all1']): + + print('\nIN RUN_IPOLARRIS_NEW... creating timeseries.') + print('Plotting timeseries for variable '+rdata.rr_name+'...') + + ##First make a timeseries of rain rate, unconditional and conditional. This puts strat, conv, and total on the same plot but you can split the out by putting cs==False. + ## The conditional rain rate is achieved by sending threshold = 0. + fig,ax = plt.subplots(1,1,figsize=(12,8)) + ax = plot_driver.plot_timeseries(rdata.data[rdata.rr_name],rdata.date,ax,cs=True,rdata=rdata,thresh=0,zlev=1,make_zeros=False) + ax = plot_driver.plot_timeseries(rdata.data[rdata.rr_name],rdata.date,ax,cs=True,rdata=rdata,thresh=0,zlev=1,ls='--',typ='uncond',make_zeros=True)#,zlev=0) + + ax.set_ylabel('Rain Rate (mm/hr)',fontsize=16) + #ax.set_title('Precipitation Timeseries ') + ax.text(0, 1, '{e} {r}'.format(e=rdata.exper,r=rdata.exper), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + #plt.tight_layout() + #plt.savefig('{i}precip_timeseries_convstrat_{e}_{m}.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys),dpi=400,bbox_inches='tight') + plt.savefig('{i}{e}_{v}_timeseries_convstrat.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,v=rdata.rr_name),dpi=400,bbox_inches='tight') + plt.close() + + print('\nDone! Saved to '+config['image_dir']) + print('Moving on.\n') + + + ############################################################################ + + ##Next let's make quantile (50,90,99) plots of the vertical velocity. This splits it by up and down, but you can turn split_updn == False + if rdata.w_name is not None: + + if (config['vv_profiles'] | config['all1']): + + print('\nIN RUN_IPOLARRIS_NEW... creating vertical profile figure.') + print('Plotting vertical profile for variable '+rdata.w_name+'...') + + outdir = config['image_dir']+'vertical_profile/' + os.makedirs(outdir,exist_ok=True) + + fig,ax = plt.subplots(1,1,figsize=(12,8)) + ax = plot_driver.plot_quartiles(rdata.data[rdata.w_name],0.9,0.5,0.99,rdata.data[rdata.z_name],ax,split_updn=True) + ax = plot_driver.plot_quartiles(rdata.data[rdata.w_name],0.9,0.5,0.99,rdata.data[rdata.z_name],ax,split_updn=False) + ax.set_xlabel('Vertical Velocity (m/s)',fontsize=16) + #ax.set_title('Vertical velocity profiles') + ax.text(0, 1, '{e} {r}'.format(e=rdata.exper,r=rdata.exper), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + #plt.tight_layout() + #plt.savefig('{i}quantile_vvel_{e}_{m}.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys),dpi=400,bbox_inches='tight') + plt.savefig('{i}{e}_{v}_vertprof.{p}'.format(p=config['ptype'],i=outdir,e=rdata.exper,v=rdata.w_name),dpi=400,bbox_inches='tight') + plt.close() + + print('\nDone! Saved to '+config['image_dir']) + print('Moving on.\n') + + if (config['percentiles_txt'] | config['all2']): + + print('\nIN RUN_IPOLARRIS_NEW... creating percentile text file.') + print('Printing percentile data for variable '+rdata.w_name+'...') + + p99u,p90u,p50u,ht = rdata.percentile(wup=True) + p99d,p90d,p50d,ht = rdata.percentile(wdown=True) + p99a,p90a,p50a,ht = rdata.percentile(wdown=False) + + outdir = config['image_dir']+'txtfiles/' + os.makedirs(outdir,exist_ok=True) + file = open('{i}{e}_{v}_updown_percentiles.txt'.format(i=outdir,v=rdata.w_name,e=rdata.exper),'w') + + file.write("Updraft\n") + file.write("Height (km). P99. P90. P50\n") + for i,h in enumerate(ht): + file.write("{h} {p1} {p2} {p3}\n".format(h=h,p1=p99u[i],p2=p90u[i],p3=p50u[i])) + + file.write("Downdraft\n") + file.write("Height (km). P99. P90. P50\n") + for i,h in enumerate(ht): + file.write("{h} {p1} {p2} {p3}\n".format(h=h,p1=p99d[i],p2=p90d[i],p3=p50d[i])) + + file.write("ALL\n") + file.write("Height (km). P99. P90. P50\n") + for i,h in enumerate(ht): + file.write("{h} {p1} {p2} {p3}\n".format(h=h,p1=p99a[i],p2=p90a[i],p3=p50a[i])) + + file.close() + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + else: + print("\nNo vertical velocity data.") + print('Moving on.\n') + + ############################################################################# + + if (config['vert_ref'] | config['all1']): + + print('\nIN RUN_IPOLARRIS_NEW... creating vertical profile figure.') + print('Plotting vertical profile for variable '+rdata.dz_name+'...') + + outdir = config['image_dir']+'vertical_profile/' + os.makedirs(outdir,exist_ok=True) + + ##Next let's make mean vertical profile of reflectivity + fig,ax = plt.subplots(1,1,figsize=(12,8)) + ax = plot_driver.plot_verprof(rdata.data[rdata.dz_name],rdata.data[rdata.z_name],ax,split_updn=False,lab='dz',thresh=-50) + #ax.set_title('Vertical profile of reflectivity') + ax.set_xlabel('Reflectivity (dBZ)',fontsize=16) + ax.text(0, 1, '{e} {r}'.format(e=rdata.exper,r=rdata.band+'-band'), horizontalalignment='left', verticalalignment='bottom', size=16, color='k', zorder=10, weight='bold', transform=ax.transAxes) # (a) Top-left + #plt.tight_layout() + #plt.savefig('{i}meanprofile_refl_{e}_{m}.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys),dpi=400,bbox_inches='tight') + plt.savefig('{i}{e}_{v}_vertprof.{p}'.format(p=config['ptype'],i=outdir,e=rdata.exper,v=rdata.dz_name),dpi=400,bbox_inches='tight') + plt.close() + + print('\nDone! Saved to '+outdir) + print('Moving on.\n') + + ############################################################################# + + print('\n########################################') + print('############ Calling plot_driver.py ####') + print('#########################################\n') + time.sleep(3) + + plot_driver.make_single_pplots(rdata,config) + + print('\n#################################################') + print('####### Returning to run_ipolarris_new.py #######') + print('#################################################\n') + + print('\niPOLARRIS RUN COMPLETE FOR '+config['exper']+' '+config['sdatetime']+' - '+config['edatetime']+'\n') diff --git a/run_ipolarris_new.py b/run_ipolarris_new.py deleted file mode 100644 index 40d8484..0000000 --- a/run_ipolarris_new.py +++ /dev/null @@ -1,312 +0,0 @@ -import numpy as np -import os -import glob -from netCDF4 import Dataset -import matplotlib -matplotlib.use('Agg') -import matplotlib.pyplot as plt -import pandas as pd -import xarray as xr - -import numpy as np - -import RadarData -import datetime - -import RadarConfig -import plot_driver -#from polarris_config import run_exper -#from polarris_config import get_data -import warnings -warnings.filterwarnings('ignore') -import GeneralFunctions as GF -from skewPy import SkewT -from collections import OrderedDict -from polarris_driver_new import polarris_driver -import os -import sys - - -configfile = sys.argv[1:] -#print sys.argv[1:] - -rdata, config = polarris_driver(configfile) -#config['image_dir'] ='./' -print(config['extrax'],'EXTRA 1 is') -######################################### - -if sys.argv[2:]: - configfile1 = sys.argv[2:] - rdata2, config2 = polarris_driver(configfile1) - - print('calculating CFAD differences') - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.dz_name,rdata2.dz_name,'Reflectivity',config,config2,bins=np.arange(0,82,2),savefig=False,cscfad=False) - ax[0].set_title(rdata.exper) - ax[1].set_title(rdata2.exper) - ax[2].set_title("{e} - {v}".format(e=rdata.exper,v=rdata2.exper)) - plt.suptitle("Reflectivity") - plt.savefig('{d}CFAD_diff_{e1}_{e2}_{c}{l}_{x}.{p}'.format(p=config['ptype'],d=config['image_dir'],c='ALL',x=config['extrax'],e1=rdata.exper,e2=rdata2.exper,l='reflectivity'),dpi=400,bbox_inches='tight') - plt.close() - - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.zdr_name,rdata2.zdr_name,'Z$_{dr}$',config,config2,bins=np.arange(-2,8,0.2),savefig=True,cscfad=False) - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.kdp_name,rdata2.kdp_name,'K$_{dp}$',config,config2,bins=np.arange(-2,6,0.2),savefig=True,cscfad=False) - - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.w_name,rdata2.w_name,'Vertical Velocity',config,config2,bins=np.arange(-20,21,1),savefig=True,cscfad=False) - - - fig,ax = plot_driver.plot_hid_comparison_cfad(rdata,rdata2,config=config,cscfad=None) - ##Convective - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.dz_name,rdata2.dz_name,'Reflectivity',config,config2,bins=np.arange(0,82,2),savefig=True,cscfad='convective') - - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.zdr_name,rdata2.zdr_name,'Z$_{dr}$',config,config2,bins=np.arange(-2,8,0.2),savefig=True,cscfad='convective') - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.kdp_name,rdata2.kdp_name,'K$_{dp}$',config,config2,bins=np.arange(-2,6,0.2),savefig=True,cscfad='convective') - - - fig,ax = plot_driver.plot_difference_cfad(rdata,rdata2,rdata.w_name,rdata2.w_name,'Vertical Velocity',config,config2,bins=np.arange(-20,21,1),savefig=True,cscfad='convective') - - - fig,ax = plot_driver.plot_hid_comparison_cfad(rdata,rdata2,config=config,cscfad='convective',savefig=True) - -################################################################################ -##################Now you can just start plotting!############################## -################################################################################ - -### To see the variables that are available to plot, type: - -#rdata.data.keys() - -else: - ################################################################################ - ##Plot a composite reflectivity at a given time. - - - #tdate = datetime.datetime(2011,5,23,22,00) - # tdate = datetime.datetime(2006,1,23,18,0,0) - # whdate = np.where(np.abs(tdate-np.array(rdata.date)) == np.min(np.abs(tdate-np.array(rdata.date)))) - print('In run_ipolarris...running the COMPOSITE figs.') - for i,d in enumerate(np.array(rdata.date)): - print('plotting composites by time....') - fig, ax = plot_driver.plot_composite(rdata,rdata.dz_name,i,cs_over=True) - print('made composite') - rtimematch = d - ax.set_title('{e} {r} composite {d:%Y%m%d %H%M}'.format(d=rtimematch,e=rdata.exper,r=rdata.radar_name)) - minlat = config['ylim'][0] - maxlat = config['ylim'][1] - minlon = config['xlim'][0] - maxlon = config['xlim'][1] - ax.set_extent([minlon, maxlon, minlat,maxlat]) - - plt.tight_layout() - plt.savefig('{i}Composite_{v}_{t:%Y%m%d%H%M}_{e}_{m}_{x}.{p}'.format(p=config['ptype'],i=config['image_dir'],v=rdata.dz_name,t=rtimematch,e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - plt.close() - - print('plotting cappis at 1 km by time...') - fig, ax = plt.subplots(1,1,figsize=(8,8)) - if 'd' in rdata.data[rdata.z_name].dims: - try: - whz = np.where(rdata.data[rdata.z_name].sel(d=i).values==config['z'])[0][0] - except IndexError as ie: - #print('checking z...',rdata.data[rdata.z_name].sel(d=i).values) - zdiffs = np.median(np.diff(rdata.data[rdata.z_name].values)) - whz = np.where(np.isclose(rdata.data[rdata.z_name].sel(d=i).values,config['z'],rtol=zdiffs))[0][0] - - else: - whz = np.where(rdata.data[rdata.z_name].values==config['z'])[0][0] - print('whz in run 122',whz) - rdata.cappi(rdata.dz_name,z=whz,ts=d,contour='CS',ax=ax) - ax.set_title('CAPPI DZ {t:%Y%m%d_%M%H%S} {h} km'.format(t=d,h=rdata.data['z'].values[whz])) - ax.set_xlim(config['xlim'][0],config['xlim'][1]) - ax.set_ylim(config['ylim'][0],config['ylim'][1]) -# ax.set_extent([minlon, maxlon, minlat,maxlat]) - plt.savefig('{i}DZ_CAPPI_{h}_{v}_{t:%Y%m%d%H%M}_{e}_{m}_{x}.{p}'.format(p=config['ptype'],i=config['image_dir'],h=config['z'],v=rdata.dz_name,t=rtimematch,e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - plt.close() - - fig, ax = plt.subplots(1,1,figsize=(8,8)) - # whz = np.where(rdata.data[rdata.z_name].values==config['z'])[0][0] - rdata.cappi(rdata.rr_name,z=whz,ts=d,contour='CS',ax=ax) - ax.set_xlim(config['xlim'][0],config['xlim'][1]) - ax.set_ylim(config['ylim'][0],config['ylim'][1]) - ax.set_title('CAPPI RR {t:%Y%m%d_%M%D%S} {h} km'.format(t=d,h=rdata.data['z'].values[2])) - plt.savefig('{i}RR_CAPPI_{h}_{v}_{t:%Y%m%d%H%M}_{e}_{m}_{x}.{p}'.format(p=config['ptype'],i=config['image_dir'],h=config['z'],v=rdata.dz_name,t=rtimematch,e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - plt.close() - - - # tdate = datetime.datetime(2006,1,23,18,00) - # whdate = np.where(np.abs(tdate-np.array(rdata.date)) == np.min(np.abs(tdate-np.array(rdata.date)))) - # fig, ax = plot_driver.plot_composite(rdata,rdata.cs_name,whdate[0][0]) - # rtimematch = rdata.date[whdate[0][0]] - # ax.set_title('C/S composite {d:%Y%m%d %H%M}'.format(d=rtimematch)) - # plt.tight_layout() - # plt.savefig('{i}Composite_{v}_{t:%Y%m%d%H%M}_{e}_{m}_{x}.{p}'.format(i=config['image_dir'],v=rdata.cs_name,t=rtimematch,e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - # plt.clf() - - ################################################################################ - ##Calculate a timeseries for writing out - rrstratu,rrconvu,rrallu = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2,cs_flag=True,thresh=-0.1) - rrstrat,rrconv,rrall = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2,cs_flag=True,thresh=0.0) - - import csv - tformat = '%Y%m%d-%H%M%S' - with open('{i}{e}_rr_uncondmean_stats.txt'.format(i=config['image_dir'],e=config['exper']), mode='w') as csv_file: - v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) - v_writer.writerow(['Date', 'Unc_Conv_RR', 'Unc_Strat_RR', 'Unc_Tot_RR']) - for i,v in enumerate(rdata.date): - print( v) - tim = v.strftime(tformat) - dum =[tim,rrconvu[i].values,rrstratu[i].values,rrallu[i].values] - v_writer.writerow(dum) - - tformat = '%Y%m%d-%H%M%S' - with open('{i}{e}_rr_condmean_stats.txt'.format(i=config['image_dir'],e=config['exper']), mode='w') as csv_file: - v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) - v_writer.writerow(['Date', 'Conv_RR', 'Strat_RR', 'Tot_RR']) - for i,v in enumerate(rdata.date): - print (v) - tim = v.strftime(tformat) - dum =[tim,rrconv[i].values,rrstrat[i].values,rrall[i].values] - v_writer.writerow(dum) - - conv = np.where(rdata.data[rdata.cs_name].values == 2) - strat = np.where(rdata.data[rdata.cs_name].values == 1) - hist, eg = np.histogram(np.ravel((rdata.data[rdata.rr_name].values)),bins=np.logspace(-1,2.4,40)) - histc, eg = np.histogram(np.ravel((rdata.data[rdata.rr_name].values[conv])),bins=np.logspace(-1,2.4,40)) - hists, eg = np.histogram(np.ravel((rdata.data[rdata.rr_name].values[strat])),bins=np.logspace(-1,2.4,40)) - - - tformat = '%Y%m%d-%H%M%S' - with open('{i}{e}_rr_histgram_{m}.txt'.format(i=config['image_dir'],e=config['exper'],m=config['mphys']), mode='w') as csv_file: - v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) - v_writer.writerow(['Date', 'Con', 'Strat', 'Tot']) - for i,v in enumerate(eg[:-1]): - dum =[v,histc[i],hists[i],hist[i]] - v_writer.writerow(dum) - - - ###Areas - - rrstratu_area,rrconvu_area,rrallu_area = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2,cs_flag=True,thresh=-0.1,areas=True) - rrstrat_area,rrconv_area,rrall_area = rdata.calc_timeseries_stats(rdata.rr_name,ht_lev=2,cs_flag=True,thresh=0.0,areas=True) - - #grid_area=rdata.radar_area() - rain_area = rdata.radar_area - import csv - tformat = '%Y%m%d-%H%M%S' - with open('{i}{e}_domain_area_stats.txt'.format(i=config['image_dir'],e=config['exper']), mode='w') as csv_file: - v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) - v_writer.writerow(['Date', 'Unc_Con', 'Unc_Strat', 'Unc_Tot']) - for i,v in enumerate(rdata.date): - print (v) - tim = v.strftime(tformat) - dum =[tim,rrconvu_area[i].values.astype(float)*rdata.dx*rdata.dy,rrstratu_area[i].values.astype(float)*rdata.dx*rdata.dy,rrallu_area[i].values.astype(float)*rdata.dx*rdata.dy] - v_writer.writerow(dum) - - tformat = '%Y%m%d-%H%M%S' - with open('{i}{e}_rel_frequency_stats.txt'.format(i=config['image_dir'],e=config['exper']), mode='w') as csv_file: - v_writer = csv.writer(csv_file, delimiter=' ', quotechar=' ', quoting=csv.QUOTE_NONNUMERIC) - v_writer.writerow(['Date', 'Conv', 'Strat', 'Tot']) - for i,v in enumerate(rdata.date): - print( v) - tim = v.strftime(tformat) - dum =[tim,rrconv[i].values*rdata.dx*rdata.dy/rain_area*100.,rrstrat[i].values*rdata.dx*rdata.dy/rain_area*100.,rrall[i].values*rdata.dx*rdata.dy/rain_area*100.] - v_writer.writerow(dum) - - - - - ################################################################################ - ##First make a timeseries of rain rate, unconditional and conditional. This puts strat, conv, and total on the same plot but you can split the out by putting cs==False. - ## The conditional rain rate is achieved by sending threshold = 0. - fig,ax = plt.subplots(1,1,figsize=(10,10)) - ax = plot_driver.plot_timeseries(rdata.data[rdata.rr_name],rdata.date,ax,cs=True,rdata=rdata,thresh=0,zlev=1,make_zeros=False) - ax = plot_driver.plot_timeseries(rdata.data[rdata.rr_name],rdata.date,ax,cs=True,rdata=rdata,thresh=0,zlev=1,ls='--',typ='uncond',make_zeros=True)#,zlev=0) - - ax.set_ylabel('Rain Rate (mm/hr)') - ax.set_title('Precipitation Timeseries ') - plt.tight_layout() - plt.savefig('{i}Precip_timeseries_convstrat_{e}_{m}_{x}.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - plt.close() - - - ############################################################################ - - ################################################################################ - ##Next let's make quantile (50,90,99) plots of the vertical velocity. This splits it by up and down, but you can turn split_updn == False - if rdata.w_name is not None: - fig,ax = plt.subplots(1,1,figsize=(10,10)) - ax = plot_driver.plot_quartiles(rdata.data[rdata.w_name],0.9,0.5,0.99,rdata.data[rdata.z_name],ax,split_updn=True) - ax = plot_driver.plot_quartiles(rdata.data[rdata.w_name],0.9,0.5,0.99,rdata.data[rdata.z_name],ax,split_updn=False) - ax.set_xlabel('Vertical velocity m/s') - ax.set_title('Vertical velocity profiles') - plt.tight_layout() - plt.savefig('{i}Quantile_vvel_{e}_{m}_{x}.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - plt.close() - - p99u,p90u,p50u,ht = rdata.percentile(wup=True) - p99d,p90d,p50d,ht = rdata.percentile(wdown=True) - p99a,p90a,p50a,ht = rdata.percentile(wdown=False) - - file = open('{i}{e}_{m}_updown_percentiles.txt'.format(i=config['image_dir'],e=rdata.exper,m=rdata.mphys),'w') - - file.write("Updraft\n") - file.write("Height (km). P99. P90. P50\n") - for i,h in enumerate(ht): - file.write("{h} {p1} {p2} {p3}\n".format(h=h,p1=p99u[i],p2=p90u[i],p3=p50u[i])) - - file.write("Downdraft\n") - file.write("Height (km). P99. P90. P50\n") - for i,h in enumerate(ht): - file.write("{h} {p1} {p2} {p3}\n".format(h=h,p1=p99d[i],p2=p90d[i],p3=p50d[i])) - - file.write("ALL\n") - file.write("Height (km). P99. P90. P50\n") - for i,h in enumerate(ht): - file.write("{h} {p1} {p2} {p3}\n".format(h=h,p1=p99a[i],p2=p90a[i],p3=p50a[i])) - - - file.close() - else: - print("No vertical velocity data.") - ################################################################################ - - ################################################################################ - ##Next let's make mean vertical profile of reflectivity - fig,ax = plt.subplots(1,1,figsize=(10,10)) - ax = plot_driver.plot_verprof(rdata.data[rdata.dz_name],rdata.data[rdata.z_name],ax,split_updn=False,lab='dz',thresh=-50) - ax.set_title('Vertical profile of reflectivity') - ax.set_xlabel('Reflectivity') - plt.tight_layout() - plt.savefig('{i}MeanProfile_refl_{e}_{m}_{x}.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - - plt.close() - ################################################################################ - ##Next let's make a reflectivity CFAD - -# cfaddat,vbins = plot_driver.cfad(rdata.data[rdata.dz_name],rdata,rdata.data[rdata.z_name],var=rdata.dz_name,nbins=40) - cfaddat,vbins,r1ht = rdata.cfad(rdata.dz_name,ret_z=1,z_resolution=1.0,value_bins=np.arange(0,82,2),cscfad=False) - - fig,ax = plt.subplots(1,1,figsize=(10,10)) - ax = plot_driver.plot_cfad(cfaddat, hts = r1ht, vbins = vbins,ax=ax,cfad_on = 0,tspan = config['date'],maxval=20,cont=True,levels = True) - - ax.set_xlabel('Reflectivity') - ax.set_ylabel('Height (km)') - ax.set_title('{c} CFAD'.format(c=rdata.exper)) - plt.tight_layout() - plt.savefig('{i}CFAD_refl_{e}_{m}_{x}_new.{p}'.format(p=config['ptype'],i=config['image_dir'],e=rdata.exper,m=rdata.mphys,x=config['extrax']),dpi=400) - plt.close() - - - flags = {} - for k in eval(config['ks']): - flags[k]=config[k] - - if any(flags.values()) == True: - plot_driver.make_single_pplots(rdata,flags,config) - - diff --git a/samples/KLGX_20151203_010200_V06.nc b/samples/KLGX_20151203_010200_V06.nc new file mode 100644 index 0000000..bf16cfc Binary files /dev/null and b/samples/KLGX_20151203_010200_V06.nc differ diff --git a/samples/KLGX_20151203_010607_V06.nc b/samples/KLGX_20151203_010607_V06.nc new file mode 100644 index 0000000..ea2b38a Binary files /dev/null and b/samples/KLGX_20151203_010607_V06.nc differ diff --git a/samples/KLGX_20151203_030115_V06.nc b/samples/KLGX_20151203_030115_V06.nc new file mode 100644 index 0000000..048a876 Binary files /dev/null and b/samples/KLGX_20151203_030115_V06.nc differ diff --git a/samples/KLGX_20151203_030508_V06.nc b/samples/KLGX_20151203_030508_V06.nc new file mode 100644 index 0000000..527a5d8 Binary files /dev/null and b/samples/KLGX_20151203_030508_V06.nc differ diff --git a/samples/KLGX_KATX_20151203_010200_V06_dopvel_gridded.nc b/samples/KLGX_KATX_20151203_010200_V06_dopvel_gridded.nc new file mode 100644 index 0000000..37b81d2 Binary files /dev/null and b/samples/KLGX_KATX_20151203_010200_V06_dopvel_gridded.nc differ diff --git a/samples/KLGX_KATX_20151203_010607_V06_dopvel_gridded.nc b/samples/KLGX_KATX_20151203_010607_V06_dopvel_gridded.nc new file mode 100644 index 0000000..123018e Binary files /dev/null and b/samples/KLGX_KATX_20151203_010607_V06_dopvel_gridded.nc differ diff --git a/samples/UIL_20151203_000000.txt b/samples/UIL_20151203_000000.txt new file mode 100644 index 0000000..749620e --- /dev/null +++ b/samples/UIL_20151203_000000.txt @@ -0,0 +1,148 @@ + pressure height temperature dewpoint direction speed u_wind v_wind station station_number time latitude longitude elevation pw +0 1004.0 62 12.2 9.4 130.0 11.0 -8.42648887430876 7.070663706551931 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +1 1000.0 88 11.8 9.9 135.0 14.0 -9.899494936611665 9.899494936611664 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +2 974.3 305 10.3 9.1 145.0 28.0 -16.060140217829286 22.936257240091773 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +3 939.2 610 8.1 8.1 160.0 37.0 -12.654745303049749 34.76862696907861 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +4 937.0 630 8.0 8.0 161.0 37.0 -12.046021714914794 34.98418729717472 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +5 925.0 736 7.6 7.6 165.0 39.0 -10.09394275899832 37.67110722527366 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +6 905.1 914 6.7 6.7 170.0 40.0 -6.94592710667721 39.392310120488325 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +7 872.1 1219 5.2 5.2 180.0 36.0 -4.408728476930472e-15 36.0 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +8 860.0 1334 4.6 4.6 180.0 35.0 -4.2862637970157365e-15 35.0 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +9 850.0 1429 3.2 2.5 180.0 34.0 -4.1637991171010006e-15 34.0 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +10 845.0 1477 2.8 1.3 180.0 32.0 -3.91886975727153e-15 32.0 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +11 840.1 1524 2.8 0.8 180.0 31.0 -3.796405077356795e-15 31.0 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +12 834.0 1583 2.8 0.2 181.0 32.0 0.5584770059930764 31.99512624500452 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +13 828.0 1642 2.2 -2.8 182.0 32.0 1.1167838944800286 31.980506464611064 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +14 809.0 1829 1.2 -5.4 185.0 34.0 2.96329525342037 33.87061973511935 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +15 805.0 1869 1.0 -6.0 184.0 34.0 2.371720107300259 33.917177708834025 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +16 793.0 1989 0.6 -6.4 182.0 35.0 1.2214823845875313 34.97867894566835 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +17 778.8 2134 -0.2 -4.3 180.0 35.0 -4.2862637970157365e-15 35.0 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +18 769.0 2236 -0.7 -2.8 182.0 35.0 1.2214823845875313 34.97867894566835 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +19 756.0 2372 -1.5 -9.5 184.0 35.0 2.441476581044385 34.91474175909385 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +20 752.0 2414 -1.1 -7.1 185.0 35.0 3.050450996168028 34.8668144332111 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +21 749.8 2438 -1.2 -7.3 185.0 35.0 3.050450996168028 34.8668144332111 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +22 721.5 2743 -2.7 -9.5 200.0 45.0 15.39090644965509 42.28616793536588 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +23 714.0 2827 -3.1 -10.1 202.0 45.0 16.85729670371604 41.723273455505435 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +24 700.0 2983 -4.3 -11.3 205.0 46.0 19.44044004007217 41.690158203685904 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +25 696.0 3028 -4.7 -11.7 205.0 46.0 19.44044004007217 41.690158203685904 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +26 694.2 3048 -4.8 -13.0 205.0 46.0 19.44044004007217 41.690158203685904 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +27 684.0 3165 -5.5 -20.5 204.0 46.0 18.70988558148681 42.02309105155964 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +28 677.0 3246 -5.9 -21.9 203.0 47.0 18.364363038995858 43.2637281122647 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +29 660.0 3444 -7.9 -17.9 202.0 47.0 17.606509890547866 43.57764116463901 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +30 647.0 3599 -9.3 -19.3 200.0 48.0 16.416966879632096 45.105245797723605 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +31 642.0 3658 -9.9 -15.3 200.0 48.0 16.416966879632096 45.105245797723605 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +32 640.0 3683 -10.1 -13.6 200.0 48.0 16.416966879632096 45.105245797723605 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +33 634.0 3755 -10.5 -13.3 198.0 46.0 14.214781741247576 43.74859974957707 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +34 620.0 3927 -11.1 -13.9 196.0 44.0 12.128043655947955 42.29551462128603 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +35 617.2 3962 -10.7 -13.1 195.0 43.0 11.129218939408394 41.53481053042994 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +36 611.0 4040 -9.7 -11.4 200.0 46.0 15.732926592980759 43.22586055615179 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +37 593.2 4267 -11.1 -12.2 215.0 55.0 31.54670399930754 45.05336243589454 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +38 571.0 4560 -12.9 -13.2 225.0 53.0 37.476659402887016 37.47665940288703 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +39 559.0 4722 -13.7 -14.5 230.0 51.0 39.068266599067876 32.78216809401352 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +40 547.7 4877 -14.9 -15.8 235.0 50.0 40.95760221444958 28.67882181755232 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +41 544.0 4929 -15.3 -16.3 237.0 50.0 41.9335283972712 27.23195175075135 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +42 537.0 5027 -16.3 -18.4 240.0 49.0 42.43524478543748 24.50000000000002 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +43 532.0 5097 -17.3 -21.7 242.0 48.0 42.381484457228495 22.534635013722756 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +44 526.0 5182 -17.8 -22.2 245.0 47.0 42.59646599072256 19.86305830181286 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +45 502.0 5530 -19.7 -24.5 240.0 48.0 41.56921938165304 24.00000000000002 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +46 500.0 5560 -19.9 -24.5 240.0 48.0 41.56921938165304 24.00000000000002 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +47 488.0 5739 -21.1 -23.2 237.0 46.0 38.578846125489505 25.05339561069124 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +48 478.0 5891 -22.3 -23.9 234.0 44.0 35.596747752497684 25.862551100868824 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +49 464.7 6096 -23.9 -26.0 230.0 42.0 32.173866610997074 26.997079606834664 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +50 445.6 6401 -26.2 -29.2 230.0 42.0 32.173866610997074 26.997079606834664 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +51 438.0 6525 -27.1 -30.5 229.0 44.0 33.20722152980196 28.866597275582325 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +52 400.0 7170 -32.7 -36.5 225.0 54.0 38.18376618407356 38.183766184073576 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +53 399.0 7188 -32.7 -36.4 225.0 54.0 38.18376618407356 38.183766184073576 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +54 395.0 7259 -33.3 -38.0 225.0 55.0 38.89087296526011 38.89087296526012 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +55 375.0 7620 -36.5 -40.8 225.0 59.0 41.7193000900063 41.719300090006314 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +56 361.0 7886 -38.9 -42.9 227.0 60.0 43.88122209715023 40.91990160374991 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +57 349.0 8118 -40.7 -45.7 229.0 61.0 46.03728439358908 40.01960076842095 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +58 313.4 8839 -47.4 -51.1 235.0 63.0 51.60657879020647 36.13531549011592 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +59 302.0 9086 -49.7 -52.9 235.0 75.0 61.43640332167437 43.01823272632848 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +60 300.0 9130 -49.9 -52.9 235.0 77.0 63.07470741025235 44.16538559903057 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +61 299.3 9144 -50.0 -53.0 235.0 77.0 63.07470741025235 44.16538559903057 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +62 250.0 10290 -59.3 -63.8 245.0 104.0 94.25600985181161 43.95229922103271 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +63 247.0 10366 -59.9 -64.3 246.0 107.0 97.7493639677583 43.52082080911061 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +64 223.8 10973 -63.9 -68.7 250.0 128.0 120.28065546059628 43.77857834568557 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +65 223.0 10994 -64.1 -68.8 250.0 128.0 120.28065546059628 43.77857834568557 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +66 206.0 11481 -67.3 -72.3 255.0 107.0 103.35406341293032 27.693637825969706 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +67 202.0 11600 -66.5 -71.5 255.0 102.0 98.52443428148497 26.399542600457103 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +68 200.0 11660 -66.7 -71.5 255.0 99.0 95.62665680261776 25.623085465149543 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +69 196.0 11782 -66.5 -71.3 255.0 98.0 94.6607309763287 25.36426642004702 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +70 192.7 11887 -65.2 -72.5 255.0 98.0 94.6607309763287 25.36426642004702 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +71 179.0 12342 -59.5 -77.5 250.0 69.0 64.83879083422768 23.599389889471126 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +72 171.0 12629 -58.1 -81.1 247.0 51.0 46.945747526074456 19.927287552952965 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +73 166.3 12802 -58.8 -82.1 245.0 40.0 36.25231148146601 16.904730469627964 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +74 158.5 13106 -60.1 -83.9 225.0 54.0 38.18376618407356 38.183766184073576 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +75 155.0 13245 -60.7 -84.7 227.0 62.0 45.34392950038857 42.283898323874915 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +76 150.9 13411 -59.6 -84.4 230.0 71.0 54.38915546144743 45.63792028774431 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +77 150.0 13450 -59.3 -84.3 230.0 71.0 54.38915546144743 45.63792028774431 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +78 140.0 13885 -56.3 -84.3 237.0 55.0 46.12688123699832 29.955146925826483 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +79 130.5 14326 -58.1 -85.6 245.0 38.0 34.439695907392704 16.059493946146567 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +80 123.0 14700 -59.7 -86.7 239.0 50.0 42.85836503510561 25.751903745502723 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +81 120.0 14855 -57.5 -85.5 236.0 55.0 45.597066490527304 30.755609690891063 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +82 118.5 14935 -57.1 -85.4 235.0 58.0 47.510818568761515 33.26743330836069 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +83 115.0 15124 -56.1 -85.1 244.0 53.0 47.636084453855844 23.23367077982112 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +84 113.0 15236 -56.5 -85.5 250.0 50.0 46.98463103929542 17.101007166283424 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +85 112.9 15240 -56.5 -85.5 250.0 50.0 46.98463103929542 17.101007166283424 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +86 111.0 15349 -56.1 -86.1 248.0 45.0 41.72327345550543 16.857296703716052 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +87 107.6 15545 -56.9 -86.2 245.0 37.0 33.53338812035606 15.636875684405867 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +88 106.0 15641 -57.3 -86.3 244.0 37.0 33.255379713069175 16.219732431195876 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +89 103.0 15823 -56.5 -86.5 242.0 37.0 32.6690609357803 17.370447823077956 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +90 100.0 16010 -56.9 -85.9 240.0 37.0 32.04293994002422 18.500000000000018 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +91 93.5 16436 -56.3 -86.3 240.0 45.0 38.971143170299726 22.50000000000002 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +92 93.2 16459 -56.1 -86.2 240.0 45.0 38.971143170299726 22.50000000000002 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +93 88.3 16802 -53.5 -85.5 249.0 36.0 33.60889535389926 12.901246183630825 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +94 80.7 17374 -56.0 -86.7 265.0 20.0 19.92389396183491 1.743114854953165 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +95 77.1 17667 -57.3 -87.3 251.0 15.0 14.182778633989752 4.883522316857349 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +96 77.0 17678 -57.2 -87.3 250.0 15.0 14.095389311788626 5.130302149885027 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +97 75.3 17817 -55.9 -86.9 250.0 22.0 20.673237657289985 7.5244431531647065 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +98 73.3 17983 -56.2 -87.2 250.0 31.0 29.13047124436316 10.602624443095722 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +99 70.0 18280 -56.7 -87.7 250.0 21.0 19.733545036504076 7.182423009839038 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +100 69.9 18288 -56.7 -87.7 260.0 25.0 24.6201938253052 4.341204441673258 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +101 66.6 18593 -57.9 -87.9 215.0 29.0 16.63371665418034 23.755409284380757 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +102 66.5 18603 -57.9 -87.9 216.0 29.0 17.045772316481717 23.461492836873475 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +103 63.5 18898 -56.3 -87.4 230.0 36.0 27.577599952283204 23.140353948715426 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +104 61.3 19118 -55.1 -87.1 252.0 32.0 30.433808521444913 9.888543819998322 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +105 60.5 19202 -55.2 -87.0 260.0 31.0 30.529040343378448 5.3830935076748405 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +106 57.8 19492 -55.5 -86.5 241.0 31.0 27.113210921321272 15.029098227636442 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +107 57.7 19507 -55.4 -86.5 240.0 31.0 26.84678751731759 15.500000000000014 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +108 55.0 19812 -54.2 -86.0 250.0 33.0 31.00985648593498 11.286664729747061 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +109 52.4 20117 -52.9 -85.5 240.0 39.0 33.774990747593094 19.500000000000018 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +110 51.2 20267 -52.3 -85.3 245.0 33.0 29.908156972209454 13.94640263744307 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +111 50.0 20422 -52.9 -84.9 240.0 31.0 26.84678751731759 15.500000000000014 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +112 50.0 20420 -52.9 -84.9 250.0 27.0 25.37170076121953 9.234543869793049 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +113 47.7 20726 -53.0 -85.0 250.0 40.0 37.58770483143634 13.68080573302674 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +114 45.5 21031 -53.0 -85.0 275.0 24.0 23.908672754201895 -2.091737825943789 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +115 43.4 21336 -53.1 -85.1 255.0 19.0 18.352590699492296 4.917561856947892 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +116 42.0 21547 -53.1 -85.1 253.0 19.0 18.169790363297672 5.5550623897320035 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +117 39.5 21946 -50.9 -84.5 250.0 20.0 18.79385241571817 6.84040286651337 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +118 38.9 22045 -50.3 -84.3 258.0 20.0 19.56295201467611 4.158233816355196 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +119 37.7 22250 -50.8 -84.5 275.0 21.0 20.920088659926655 -1.8302705977008156 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +120 34.3 22860 -52.3 -85.2 250.0 16.0 15.035081932574535 5.472322293210696 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +121 32.7 23165 -53.0 -85.5 245.0 21.0 19.032463527769654 8.874983496554682 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +122 31.0 23518 -53.9 -85.9 267.0 25.0 24.965738368864347 1.3083989060736076 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +123 30.0 23730 -52.3 -85.3 280.0 27.0 26.58980933132962 -4.6885007970071095 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +124 29.8 23774 -52.2 -85.2 280.0 27.0 26.58980933132962 -4.6885007970071095 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +125 28.4 24079 -51.2 -84.7 245.0 26.0 23.564002462952903 10.988074805258178 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +126 27.3 24343 -50.3 -84.3 254.0 32.0 30.760374270026208 8.820395386143964 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +127 27.1 24384 -50.4 -84.4 255.0 33.0 31.875552267539256 8.54102848838318 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +128 25.9 24689 -51.2 -84.8 250.0 29.0 27.251086002791343 9.918584156444386 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +129 24.4 25072 -52.3 -85.3 269.0 29.0 28.995583159535347 0.5061197866812215 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +130 21.4 25908 -51.6 -84.6 310.0 29.0 22.215288850450367 -18.640840680909637 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +131 21.2 25983 -51.5 -84.5 308.0 28.0 22.06430110098821 -17.23852130911844 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +132 20.0 26360 -53.1 -85.1 300.0 23.0 19.918584287042087 -11.5 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +133 19.5 26518 -53.9 -85.4 300.0 23.0 19.918584287042087 -11.5 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +134 19.0 26689 -54.7 -85.7 303.0 31.0 25.998787606308152 -16.883810085465825 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +135 18.6 26822 -54.4 -85.6 305.0 38.0 31.127777682981687 -21.795904581339748 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +136 16.9 27432 -52.9 -85.3 305.0 36.0 29.489473594403705 -20.648751708637658 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +137 16.1 27755 -52.1 -85.1 305.0 37.0 30.308625638692696 -21.222328144988705 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +138 15.0 28211 -53.9 -85.9 305.0 38.0 31.127777682981687 -21.795904581339748 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +139 12.8 29234 -51.9 -84.9 305.0 41.0 33.58523381584866 -23.51663389039289 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +140 11.0 30206 -56.1 -87.1 305.0 43.0 35.22353790442665 -24.66378676309498 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +141 10.8 30323 -55.3 -86.3 305.0 44.0 36.04268994871564 -25.237363199446026 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +142 10.5 30480 -56.6 -87.0 305.0 44.0 36.04268994871564 -25.237363199446026 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +143 10.3 30623 -57.7 -87.7 305.0 45.0 36.86184199300463 -25.810939635797073 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +144 10.0 30810 -57.3 -88.3 305.0 46.0 37.68099403729362 -26.384516072148116 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +145 10.0 30785 -57.4 -88.2 305.0 46.0 37.68099403729362 -26.384516072148116 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 +146 9.4 31200 -58.7 -88.7 UIL 72797 2015-12-03 47.95 -124.55 62.0 20.93 diff --git a/samples/UIL_20151203_120000.txt b/samples/UIL_20151203_120000.txt new file mode 100644 index 0000000..5432720 --- /dev/null +++ b/samples/UIL_20151203_120000.txt @@ -0,0 +1,111 @@ + pressure height temperature dewpoint direction speed u_wind v_wind station station_number time latitude longitude elevation pw +0 991.0 62 12.8 10.6 145.0 23.0 -13.192258036074056 18.840497018646815 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +1 973.0 215 14.0 12.1 154.0 32.0 -14.027876697250473 28.761409481573345 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +2 962.4 305 13.3 11.8 160.0 37.0 -12.654745303049749 34.76862696907861 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +3 927.7 610 11.0 10.7 165.0 45.0 -11.646857029613447 43.46666218300807 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +4 925.0 634 10.8 10.6 165.0 45.0 -11.646857029613447 43.46666218300807 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +5 910.0 771 10.0 9.9 175.0 51.0 -4.444942880130568 50.80592960267902 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +6 894.4 914 9.5 9.4 185.0 58.0 5.0550330793641605 57.77929248932124 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +7 862.2 1219 8.4 8.3 190.0 58.0 10.071594304681968 57.118849674708066 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +8 850.0 1337 8.0 7.9 190.0 56.0 9.724297949348106 55.14923416868365 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +9 829.0 1544 7.4 7.2 192.0 49.0 10.187672850070216 47.92923243595647 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +10 800.6 1829 5.6 5.4 195.0 40.0 10.352761804100831 38.63703305156273 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +11 771.3 2134 3.6 3.4 195.0 40.0 10.352761804100831 38.63703305156273 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +12 754.0 2319 2.4 2.2 195.0 40.0 10.352761804100831 38.63703305156273 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +13 743.0 2438 1.9 1.6 195.0 40.0 10.352761804100831 38.63703305156273 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +14 715.4 2743 0.5 0.2 195.0 38.0 9.83512371389579 36.70518139898459 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +15 700.0 2918 -0.3 -0.6 195.0 37.0 9.57630466879327 35.73925557269553 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +16 686.0 3080 -0.9 -1.3 197.0 37.0 10.817753074741262 35.38327597063231 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +17 637.8 3658 -4.6 -5.1 205.0 36.0 15.214257422665174 32.6270803333194 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +18 626.0 3805 -5.5 -6.1 203.0 38.0 14.847782882592394 34.979184431192735 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +19 601.0 4125 -6.5 -7.2 197.0 41.0 11.98723989363221 39.208494994484454 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +20 590.0 4267 -7.4 -8.2 195.0 43.0 11.129218939408394 41.53481053042994 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +21 545.1 4877 -11.3 -12.2 200.0 45.0 15.39090644965509 42.28616793536588 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +22 507.0 5435 -14.9 -16.0 204.0 48.0 19.52335886763841 43.85018196684484 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +23 500.0 5540 -15.7 -16.6 205.0 49.0 20.708294825294264 44.409081564795855 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +24 468.0 6035 -19.7 -20.7 205.0 56.0 23.66662265747916 50.7532360740524 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +25 464.1 6096 -20.2 -21.6 205.0 57.0 24.089240919219858 51.659543861089055 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +26 447.0 6374 -22.3 -25.4 204.0 62.0 25.21767187069961 56.63981837384125 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +27 401.0 7162 -27.9 -30.1 200.0 76.0 25.99353089275082 71.41663917972905 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +28 400.0 7180 -28.1 -30.4 200.0 76.0 25.99353089275082 71.41663917972905 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +29 394.0 7288 -28.9 -32.9 201.0 76.0 27.235964165442834 70.95211241378732 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +30 387.0 7416 -29.7 -33.7 203.0 77.0 30.086296893674064 70.87887371583791 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +31 376.0 7620 -31.6 -37.2 205.0 77.0 32.54160615403384 69.78569960182206 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +32 374.0 7658 -31.9 -37.9 205.0 77.0 32.54160615403384 69.78569960182206 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +33 340.0 8323 -37.9 -42.5 211.0 85.0 43.7782363673546 72.85922055967954 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +34 335.0 8424 -38.9 -44.9 212.0 86.0 45.57305672405561 72.93213626945264 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +35 325.0 8631 -40.5 -45.5 213.0 89.0 48.47287411633741 74.64168054714274 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +36 321.0 8715 -41.3 -48.3 214.0 90.0 50.3273613123672 74.61338152995377 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +37 317.0 8800 -42.3 -50.3 215.0 91.0 52.1954557079452 74.54283603029825 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +38 315.2 8839 -42.6 -50.6 215.0 91.0 52.1954557079452 74.54283603029825 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +39 301.2 9144 -45.1 -53.1 215.0 88.0 50.47472639889206 72.08537989743127 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +40 300.0 9170 -45.3 -53.3 215.0 88.0 50.47472639889206 72.08537989743127 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +41 269.0 9888 -51.9 -58.9 212.0 83.0 43.983298931355996 70.38799198098336 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +42 250.0 10360 -55.5 -61.5 210.0 79.0 39.50000000000001 68.41600689897065 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +43 228.0 10939 -60.7 -64.6 210.0 77.0 38.50000000000001 66.68395609140177 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +44 205.2 11582 -65.7 -69.7 210.0 75.0 37.50000000000001 64.9519052838329 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +45 200.0 11740 -66.9 -70.9 210.0 79.0 39.50000000000001 68.41600689897065 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +46 198.0 11801 -67.7 -71.8 210.0 82.0 41.00000000000001 71.01408311032397 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +47 195.2 11887 -67.3 -71.3 215.0 93.0 53.342608580647294 76.18114011887623 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +48 191.0 12019 -66.6 -70.6 215.0 93.0 53.342608580647294 76.18114011887623 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +49 189.0 12083 -66.3 -70.3 215.0 91.0 52.1954557079452 74.54283603029825 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +50 185.0 12214 -63.5 -68.5 215.0 86.0 49.32757352618997 70.44707580885328 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +51 180.0 12382 -63.3 -70.3 215.0 80.0 45.88611490808369 65.53216354311934 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +52 174.0 12593 -61.1 -71.1 215.0 73.0 41.87107985362637 59.798099233096394 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +53 171.0 12702 -58.3 -69.3 215.0 69.0 39.57677410822218 56.52149105594042 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +54 152.8 13411 -57.8 -71.4 215.0 45.0 25.810939635797077 36.861841993004624 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +55 150.0 13530 -57.7 -71.7 210.0 51.0 25.500000000000007 44.167295593006365 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +56 149.0 13572 -57.5 -71.5 210.0 53.0 26.500000000000007 45.89934640057525 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +57 143.0 13831 -58.7 -72.7 213.0 65.0 35.40153727597676 54.51358691645256 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +58 140.0 13965 -56.9 -70.9 215.0 71.0 40.723926980924276 58.15979514451841 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +59 139.0 14010 -56.6 -70.6 215.0 73.0 41.87107985362637 59.798099233096394 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +60 138.8 14021 -56.6 -70.6 215.0 73.0 41.87107985362637 59.798099233096394 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +61 137.0 14102 -56.1 -70.1 219.0 71.0 44.68174776453847 55.177363263444924 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +62 135.0 14196 -53.7 -68.7 224.0 70.0 48.62608593212982 50.353786023705574 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +63 126.1 14630 -55.0 -70.0 245.0 61.0 55.28477500923566 25.779713966182644 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +64 120.2 14935 -55.9 -70.9 240.0 38.0 32.90896534380866 19.000000000000018 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +65 120.0 14949 -55.9 -70.9 240.0 38.0 32.90896534380866 19.000000000000018 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +66 118.0 15055 -55.9 -69.9 236.0 39.0 32.33246532964663 21.808523235359118 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +67 115.0 15220 -54.5 -68.5 231.0 41.0 31.862984419735792 25.80213603304335 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +68 114.6 15240 -54.6 -68.6 230.0 41.0 31.407822167878095 26.354291997148124 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +69 111.0 15446 -55.5 -69.5 228.0 41.0 30.468937844573166 27.43435486071318 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +70 110.0 15503 -55.5 -69.5 227.0 41.0 29.98550176638599 27.96193276256244 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +71 100.0 16110 -55.9 -69.9 220.0 40.0 25.71150438746157 30.641777724759123 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +72 86.0 17069 -57.1 -71.1 225.0 25.0 17.677669529663685 17.677669529663692 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +73 83.9 17224 -57.3 -71.3 228.0 27.0 20.064910287889646 18.066526371689168 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +74 77.5 17729 -54.5 -68.5 236.0 35.0 29.016315039426466 19.571751621476132 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +75 74.1 18016 -55.3 -69.3 241.0 40.0 34.98478828557583 19.392384809853475 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +76 71.0 18288 -54.2 -67.5 245.0 44.0 39.877542629612606 18.59520351659076 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +77 70.0 18380 -53.9 -66.9 255.0 39.0 37.671107225273666 10.093942758998304 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +78 69.9 18389 -53.9 -66.9 255.0 38.0 36.70518139898459 9.835123713895785 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +79 67.7 18593 -53.0 -66.8 260.0 26.0 25.60500157831741 4.514852619340188 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +80 67.5 18614 -52.9 -66.8 258.0 25.0 24.45369001834514 5.197792270443995 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +81 64.6 18898 -53.5 -66.8 235.0 16.0 13.106432708623865 9.177222981616742 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +82 61.6 19202 -54.0 -66.7 220.0 19.0 12.212964584044245 14.554844419260585 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +83 58.7 19507 -54.6 -66.6 250.0 20.0 18.79385241571817 6.84040286651337 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +84 54.7 19964 -55.5 -66.5 248.0 30.0 27.81551563700362 11.23819780247737 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +85 50.8 20438 -53.7 -66.3 245.0 40.0 36.25231148146601 16.904730469627964 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +86 50.0 20540 -53.7 -66.3 245.0 42.0 38.06492705553931 17.749966993109364 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +87 48.6 20726 -53.7 -66.3 255.0 43.0 41.53481053042994 11.129218939408387 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +88 46.3 21031 -53.7 -66.2 260.0 38.0 37.42269461446391 6.598630751343353 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +89 44.2 21336 -53.7 -66.1 240.0 36.0 31.17691453623978 18.000000000000014 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +90 42.6 21569 -53.7 -66.0 236.0 40.0 33.161502902201676 22.367716138829863 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +91 42.1 21641 -53.4 -66.0 235.0 41.0 33.58523381584865 23.516633890392903 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +92 40.2 21946 -52.0 -65.9 270.0 30.0 30.0 5.510910596163089e-15 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +93 39.5 22057 -51.5 -65.9 268.0 28.0 27.98294315653468 0.9771859076700211 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +94 38.3 22250 -51.6 -65.8 265.0 24.0 23.908672754201895 2.091737825943798 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +95 34.9 22860 -51.7 -65.7 260.0 34.0 33.48346360241507 5.904038040675632 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +96 32.0 23423 -51.9 -65.5 258.0 30.0 29.344428022014167 6.237350724532795 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +97 28.2 24247 -49.5 -65.3 255.0 25.0 24.148145657226706 6.470476127563016 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +98 27.6 24384 -49.8 -65.3 255.0 24.0 23.18221983093764 6.211657082460495 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +99 26.3 24689 -50.6 -65.2 235.0 19.0 15.56388884149084 10.897952290669881 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +100 24.0 25298 -52.0 -65.0 265.0 24.0 23.908672754201895 2.091737825943798 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +101 22.9 25603 -52.8 -64.9 255.0 18.0 17.38666487320323 4.6587428118453715 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +102 20.8 26213 -54.3 -64.8 250.0 32.0 30.07016386514907 10.944644586421392 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +103 20.0 26470 -54.9 -64.7 260.0 30.0 29.544232590366242 5.2094453300079095 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +104 19.4 26664 -55.5 -64.6 266.0 33.0 32.9196136585742 2.301963633556144 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +105 17.2 27432 -52.5 -64.4 290.0 45.0 42.286167935365874 -15.390906449655107 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +106 16.9 27550 -52.1 -64.4 293.0 46.0 42.34322325881226 -17.97363191050658 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +107 15.7 28042 -52.6 -64.3 305.0 50.0 40.95760221444959 -28.678821817552304 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +108 14.9 28346 -52.8 -64.2 295.0 29.0 26.282925824062843 -12.255929590480289 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 +109 14.3 28629 -53.1 -64.1 UIL 72797 "2015-12-03_12:00:00" 47.95 -124.55 62.0 31.57 diff --git a/samples/wrfout_06_d03_2015-12-03_03:00:00.POLARRIS.matsui2018.nc b/samples/wrfout_06_d03_2015-12-03_03:00:00.POLARRIS.matsui2018.nc new file mode 100644 index 0000000..b77c3e2 Binary files /dev/null and b/samples/wrfout_06_d03_2015-12-03_03:00:00.POLARRIS.matsui2018.nc differ diff --git a/samples/wrfout_06_d03_2015-12-03_03:05:00.POLARRIS.matsui2018.nc b/samples/wrfout_06_d03_2015-12-03_03:05:00.POLARRIS.matsui2018.nc new file mode 100644 index 0000000..6fb08ce Binary files /dev/null and b/samples/wrfout_06_d03_2015-12-03_03:05:00.POLARRIS.matsui2018.nc differ diff --git a/skewPy/SkewT.py b/skewPy/SkewT.py index 72d0a2d..13ce061 100644 --- a/skewPy/SkewT.py +++ b/skewPy/SkewT.py @@ -12,6 +12,7 @@ import numpy as np import matplotlib.pyplot as plt from copy import deepcopy +import re from .thermodynamics import VirtualTemp,Latentc,SatVap,MixRatio,GammaW,\ VirtualTempFromMixR,MixR2VaporPress,DewPoint,Theta,TempK @@ -19,6 +20,7 @@ from collections import UserDict +#from UserDict import UserDict from datetime import datetime import os,sys import scipy.interpolate as si @@ -465,7 +467,6 @@ def __init__(self, filename=None, data=None, fmt='UWYO', station_name=None, parc if data is None: self.data={} self.readfile(filename) - else: self.data=data self['SoundingDate']="" @@ -517,8 +518,9 @@ def interp_parcel(self): # let's try to interpolate the parcel stuff onto the environmental stuff - f_pt = si.interp1d(all_parcel_p, all_parcel_t, bounds_error=True) - + #print('Hello') + #f_pt = si.interp1d(all_parcel_p, all_parcel_t, bounds_error=True) + f_pt = si.interp1d(all_parcel_p, all_parcel_t, fill_value="extrapolate") self.parcel_p = self.data['pres'].copy() ###BD added .compressed here because I was getting an error about being a masked array in si.interp1d 3/2017 self.parcel_t = f_pt(self.parcel_p.compressed()) @@ -909,7 +911,7 @@ def readfile(self, fname): # This *should* be a convenient way to read a uwyo sounding #-------------------------------------------------------------------- if self.fmt == 'UWYO': # READING IN STANDARD UNIVERSITY OF WYOMING FILES - + print('working with UWYO sounding!') fid = open(fname) lines = fid.readlines() nlines = len(lines) @@ -922,51 +924,113 @@ def readfile(self, fname): fields = lines[3].split() units = lines[4].split() - - # First line for WRF profiles differs from the UWYO soundings - header = lines[0] - if header[:5] == '00000': - # WRF profile - self.station = '-99999' - self['Longitude'] = float(header.split()[5].strip(",")) - self['Latitude'] = float(header.split()[6]) - self.sounding_date = header.split()[-1] + + txtfields = lines[0].split() + #Look for soundings that start with the column labels and handle them slightly differently + if 'pressure' in txtfields: + fields = deepcopy(txtfields) + for ii, var in enumerate(fields): + if var == 'pressure': + fields[ii] = 'pres' + elif var == 'height': + fields[ii] = 'hght' + elif var == 'temperature': + fields[ii] = 'temp' + elif var == 'dewpoint': + fields[ii] = 'dwpt' + + # First line for WRF profiles differs from the UWYO soundings + header = lines[1] + if header[:5] == '00000': + # WRF profile + self.station = '-99999' + self['Longitude'] = float(header.split()[5].strip(",")) + self['Latitude'] = float(header.split()[6]) + self.sounding_date = header.split()[-1] + else: + findstat = np.where([x.isalpha() for x in str(header)])[0] + self.station = header[min(findstat):max(findstat)+1] + dstr = (' ').join(header.split()[-5:-4]) + try: + self.sounding_date = datetime.strptime(dstr, "%Y-%m-%d").strftime("%Y-%m-%d_%H:%M:%S") + except ValueError: + self.sounding_date = datetime.strptime(dstr, '"%Y-%m-%d_%H:%M:%S"').strftime("%Y-%m-%d_%H:%M:%S") + + if self.station_name is not None: self.station = self.station_name + + lhi=[1, 9,16,23,30,37,46,53,58,65,72] + rhi=[7,14,21,28,35,42,49,56,63,70,77] + + + # NEW! For loop to read in output data from sounding file + # First, determine number of columns, and find lines in the text file where data is missing ==> omit. May not be necessary if masking handles missing values properly... + numcols = len(lines[0].split())+1 + for line in lines[1:]: + if len(line.split()) != numcols: + lines.remove(line) + continue + + for ff in fields: + output[ff.lower()] = zeros((len(lines[1:])-1)) - 999. + + # Next, read each column into a dictionary. + for line, ii in zip(lines[1:],range(1,len(lines[1:]))): + for jj in range(0,numcols-1): + try: + output[fields[jj].lower()][ii-1] = float(line.split()[jj+1]) + except ValueError: + continue + + for field in fields: + #print field + ff=field.lower() + # here is where the copy is made from output to self.data + self.data[ff]=ma.masked_values(output[ff], -999.) + else: - self.station = header[:5] - dstr = (' ').join(header.split()[-4:]) - self.sounding_date = datetime.strptime(dstr, "%HZ %d %b %Y").strftime("%Y-%m-%d_%H:%M:%S") - if self.station_name is not None: self.station = self.station_name - - for ff in fields: - output[ff.lower()]=zeros((nlines-skip)) - 999. - - #print 'output keys: {}'.format(output.keys()) - - lhi=[1, 9,16,23,30,37,46,53,58,65,72] - rhi=[7,14,21,28,35,42,49,56,63,70,77] - - lcounter = 5 - for line,idx in zip(lines[6:],range(ndata)): - lcounter += 1 - - try: output[fields[0].lower()][idx] = float(line[lhi[0]:rhi[0]]) - except ValueError: - break + # First line for WRF profiles differs from the UWYO soundings + header = lines[0] + if header[:5] == '00000': + # WRF profile + self.station = '-99999' + self['Longitude'] = float(header.split()[5].strip(",")) + self['Latitude'] = float(header.split()[6]) + self.sounding_date = header.split()[-1] + else: + self.station = header[:5] + dstr = (' ').join(header.split()[-4:]) + self.sounding_date = datetime.strptime(dstr, "%HZ %d %b %Y").strftime("%Y-%m-%d_%H:%M:%S") + print('station ',self.station) + if self.station_name is not None: self.station = self.station_name + + for ff in fields: + output[ff.lower()]=zeros((nlines-skip)) - 999. + + lhi=[1, 9,16,23,30,37,46,53,58,65,72] + rhi=[7,14,21,28,35,42,49,56,63,70,77] + + lcounter = 5 + for line,idx in zip(lines[6:],range(ndata)): + lcounter += 1 - for ii in range(1, len(rhi)): - try: - # Debug only: - # print fields[ii].lower(), float(line[lhi[ii]:rhi[ii]].strip()) - output[fields[ii].lower()][idx]=float(line[lhi[ii]:rhi[ii]].strip()) + try: output[fields[0].lower()][idx] = float(line[lhi[0]:rhi[0]]) except ValueError: - pass + break - for field in fields: - #print field - ff=field.lower() - # here is where the copy is made from output to self.data - self.data[ff]=ma.masked_values(output[ff], -999.) + for ii in range(1, len(rhi)): + try: + # Debug only: + # print fields[ii].lower(), float(line[lhi[ii]:rhi[ii]].strip()) + output[fields[ii].lower()][idx]=float(line[lhi[ii]:rhi[ii]].strip()) + except ValueError: + pass + + for field in fields: + #print field + ff=field.lower() + # here is where the copy is made from output to self.data + self.data[ff]=ma.masked_values(output[ff], -999.) @@ -1046,7 +1110,7 @@ def lift_parcel(self,startp,startt,startdp, plotkey = False): """ from numpy import interp - # print startp, startt, startdp + print ('vals',startp, startt, startdp) assert startt >startdp, "Not a valid parcel. Check Td