import numpy,os,time import matplotlib import argparse import matplotlib.pyplot as plt from wradlib.io import read_generic_hdf5 from wradlib.util import get_wradlib_data_file from plotting_codes import sophy_cb_tables from scipy import stats import wradlib from wradlib.io import read_generic_hdf5 from wradlib.util import get_wradlib_data_file import warnings warnings.filterwarnings('ignore') for name, cb_table in sophy_cb_tables: ncmap = matplotlib.colors.ListedColormap(cb_table, name=name) matplotlib.pyplot.register_cmap(cmap=ncmap) ''' NOTA: #python test_zdr.py --parameters Z --grado 90 --mode 'PPI' --range 10 --type plot_WR --channel H - python3.10 - Conda environment: WR_CONDA_JUN14 * /home/soporte/anaconda3/envs/WR_CONDA_JUN14 export WRADLIB_DATA="/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/" - Update de plotting_codes ''' PARAM = { 'S': {'var': 'power' ,'vmin': -45, 'vmax': -15, 'cmap': 'jet' ,'label': 'Power' ,'unit': 'dBm'}, 'V': {'var': 'velocity' ,'vmin': -10, 'vmax': 10 , 'cmap': 'sophy_v','label': 'Velocity' ,'unit': 'm/s'}, 'Z': {'var': 'reflectivity' ,'vmin': -20, 'vmax': 80 , 'cmap': 'sophy_z','label': 'Reflectivity' ,'unit': 'dBZ'}, 'W': {'var': 'spectral_width' ,'vmin': 0 , 'vmax': 12 , 'cmap': 'sophy_w','label': 'Spectral Width','unit': 'm/s'}, 'R': {'var': 'rhoHV' ,'vmin': 0.2, 'vmax': 1 , 'cmap': 'sophy_r','label': 'RhoHV' , 'unit': ' '}, 'D': {'var': 'differential_reflectivity','vmin': -9 , 'vmax': 12 , 'cmap': 'sophy_d','label': 'ZDR' , 'unit': 'dB'} } class Readsophy(): def __init__(self): self.list_file = None self.grado = None self.variable = None self.save = None self.range = None def setup(self, path_file,mode,channel,type,grado,range,r_min,variable,save): self.path_file = path_file self.mode = mode self.channel = channel self.range = range self.grado = grado self.r_min = r_min self.variable = variable self.save = save self.type_ = type self.list_file = self.read_files(path_file=self.path_file,mode=self.mode,grado=self.grado, variable=self.variable) #print("self.list_file",self.list_file) def read_files(self,path_file,mode=None,grado=None, variable=None): if mode =='PPI': filter= "_E"+str(grado)+".0_"+variable else: filter= "_A"+str(grado)+".0_"+variable #print("Filter :",filter) validFilelist = [] fileList= os.listdir(path_file) for thisFile in fileList: #print(thisFile) if not os.path.splitext(thisFile)[0][-7:] in filter: #print("s_:",os.path.splitext(thisFile)[0][-7:]) continue validFilelist.append(thisFile) validFilelist.sort() return validFilelist def readAttributes(self,obj,variable,channel,type_): var = PARAM[variable]['var'] unit = PARAM[variable]['unit'] cmap = PARAM[variable]['cmap'] vmin = PARAM[variable]['vmin'] vmax = PARAM[variable]['vmax'] label = PARAM[variable]['label'] utc_time = numpy.array(obj['Data/time']['data']) data_azi = numpy.array(obj['Metadata/azimuth']['data']) # th data_ele = numpy.array(obj["Metadata/elevation"]['data']) heightList = numpy.array(obj["Metadata/range"]['data']) # r if type_ =='Diagonal': var_H = 'Data/'+var+'/'+str('H') var_V = 'Data/'+var+'/'+str('V') data_arr_H = numpy.array(obj[var_H]['data']) # data data_arr_V = numpy.array(obj[var_V]['data']) # data data_arr = numpy.array([data_arr_H ,data_arr_V]) else: var_ = 'Data/'+var+'/'+str(channel) data_arr = numpy.array(obj[var_]['data']) # data return data_arr, utc_time, data_azi,data_ele, heightList,unit,cmap,vmin,vmax,label def selectHeights(self,heightList,minHei,maxHei): if minHei and maxHei: if (minHei < heightList[0]): minHei = heightList[0] if (maxHei > heightList[-1]): maxHei = heightList[-1] minIndex = 0 maxIndex = 0 heights = heightList inda = numpy.where(heights >= minHei) indb = numpy.where(heights <= maxHei) try: minIndex = inda[0][0] except: minIndex = 0 try: maxIndex = indb[0][-1] except: maxIndex = len(heights) new_heightList= self.selectHeightsByIndex(heightList=heightList,minIndex=minIndex, maxIndex=maxIndex) return new_heightList, minIndex,maxIndex def selectHeightsByIndex(self,heightList,minIndex, maxIndex): if (minIndex < 0) or (minIndex > maxIndex): raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) if (maxIndex >= len(heightList)): maxIndex = len(heightList) new_h = heightList[minIndex:maxIndex] return new_h def plot_RTI_PPI_RHI(self,count,x,y,z,cmap,my_time,vmin,vmax,label,unit,mode,grado): if count==1: fig = plt.figure(figsize=(8,6)) plt.pcolormesh(x,y,z,cmap =cmap, vmin = vmin, vmax = vmax) title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" N° "+str(count) t = plt.title(title, fontsize=12,y=1.05) cbar = plt.colorbar() cbar.set_label(label+'[' + unit + ']') else: plt.pcolormesh(x,y,z, cmap =cmap, vmin = vmin, vmax = vmax) title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" N° "+str(count) t = plt.title(title, fontsize=12,y=1.05) cbar = plt.colorbar() cbar.set_label(label+'[' + unit + ']') def plot_PROFILE(self,count,z,y,my_time,label,mode,grado): if count==1: fig = plt.figure(figsize=(8,6)) plt.plot(numpy.nanmean(z,1),y) title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" N° "+str(count) t = plt.title(title, fontsize=12,y=1.05) plt.ylim(0,self.range+1) plt.xlabel(label) plt.ylabel('Height(Km)') if self.variable=="R": plt.xlim(-1,3) if self.variable=='D': plt.xlim(-10,10) if self.variable=='Z': plt.xlim(-20,80) else: plt.plot(numpy.nanmean(z,1),y) title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" N° "+str(count) t = plt.title(title, fontsize=12,y=1.05) plt.ylim(0,self.range+1) plt.xlabel(label) plt.ylabel('Height(Km)') if self.variable=="R": plt.xlim(-1,3) if self.variable=='D': plt.xlim(-10,10) if self.variable=='Z': plt.xlim(-20,80) def save_PIC(self,count,time_save): print("save",count) if self.channel=='H': ch_='0' else: ch_='1' if count ==1: #filename = "SOPHY"+"_"+time_save+"_"+self.mode+"_"+self.grado+"_"+self.variable+str(self.range)+".png" filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+" "+self.channel+" "+str(self.range)+".png" dir =self.variable+"_"+self.mode+"_"+self.grado+"_"+"CH"+ch_+"/" filesavepath = os.path.join(self.path_file,dir) try: os.mkdir(filesavepath) except: pass else: dir =self.variable+"_"+self.mode+"_"+self.grado+"_"+"CH"+ch_+"/" filesavepath = os.path.join(self.path_file,dir) filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+" "+self.channel+" "+str(self.range)+".png" plt.savefig(filesavepath+filename) def seleccion_roHV_min(self,count,z,y,arr_): ##print("y",y) if self.variable=='R': len_Z= z.shape[1] min_CC=numpy.zeros(len_Z) min_index_CC = numpy.zeros(len_Z) for i in range(len_Z): tmp=numpy.nanmin(z[:,i]) tmp_index = numpy.nanargmin((z[:,i])) if tmp <0.5: tmp_index= numpy.nan value = numpy.nan else: value= y[tmp_index] min_CC[i] =value moda_,count_m_ = stats.mode(min_CC) #print("MODA",moda_) for i in range(len_Z): if min_CC[i]>moda_[0]+0.15 or min_CC[i]