##// END OF EJS Templates
Update para ploteo de Zh vs Zv , METODO plot_D, atributo Diagonal
avaldez -
r1591:d9024fd73e87
parent child
Show More
@@ -6,12 +6,20 from wradlib.io import read_generic_hdf5
6 6 from wradlib.util import get_wradlib_data_file
7 7 from plotting_codes import sophy_cb_tables
8 8 from scipy import stats
9 import wradlib
10 from wradlib.io import read_generic_hdf5
11 from wradlib.util import get_wradlib_data_file
12 import warnings
13
14 warnings.filterwarnings('ignore')
9 15
10 16 for name, cb_table in sophy_cb_tables:
11 17 ncmap = matplotlib.colors.ListedColormap(cb_table, name=name)
12 18 matplotlib.pyplot.register_cmap(cmap=ncmap)
13 19 '''
14 20 NOTA:
21 #python test_zdr.py --parameters Z --grado 90 --mode 'PPI' --range 10 --type plot_WR --channel H
22
15 23 - python3.10
16 24 - Conda environment:
17 25 WR_CONDA_JUN14 * /home/soporte/anaconda3/envs/WR_CONDA_JUN14
@@ -34,9 +42,10 class Readsophy():
34 42 self.variable = None
35 43 self.save = None
36 44 self.range = None
37 def setup(self, path_file,mode,type,grado,range,r_min,variable,save):
45 def setup(self, path_file,mode,channel,type,grado,range,r_min,variable,save):
38 46 self.path_file = path_file
39 47 self.mode = mode
48 self.channel = channel
40 49 self.range = range
41 50 self.grado = grado
42 51 self.r_min = r_min
@@ -44,40 +53,49 class Readsophy():
44 53 self.save = save
45 54 self.type_ = type
46 55 self.list_file = self.read_files(path_file=self.path_file,mode=self.mode,grado=self.grado, variable=self.variable)
47 print("self.list_file",self.list_file)
56 #print("self.list_file",self.list_file)
48 57
49 58 def read_files(self,path_file,mode=None,grado=None, variable=None):
50 59 if mode =='PPI':
51 60 filter= "_E"+str(grado)+".0_"+variable
52 61 else:
53 62 filter= "_A"+str(grado)+".0_"+variable
54 print("Filter :",filter)
63 #print("Filter :",filter)
55 64 validFilelist = []
56 65 fileList= os.listdir(path_file)
57 66 for thisFile in fileList:
58 67 #print(thisFile)
59 68 if not os.path.splitext(thisFile)[0][-7:] in filter:
60 print("s_:",os.path.splitext(thisFile)[0][-7:])
69 #print("s_:",os.path.splitext(thisFile)[0][-7:])
61 70 continue
62 71 validFilelist.append(thisFile)
63 72 validFilelist.sort()
64 73 return validFilelist
65 74
66 def readAttributes(self,obj,variable):
75 def readAttributes(self,obj,variable,channel,type_):
67 76 var = PARAM[variable]['var']
68 77 unit = PARAM[variable]['unit']
69 78 cmap = PARAM[variable]['cmap']
70 79 vmin = PARAM[variable]['vmin']
71 80 vmax = PARAM[variable]['vmax']
72 81 label = PARAM[variable]['label']
73 var_ = 'Data/'+var+'/H'
74 data_arr = numpy.array(obj[var_]['data']) # data
82
75 83 utc_time = numpy.array(obj['Data/time']['data'])
76 84 data_azi = numpy.array(obj['Metadata/azimuth']['data']) # th
77 85 data_ele = numpy.array(obj["Metadata/elevation"]['data'])
78 86 heightList = numpy.array(obj["Metadata/range"]['data']) # r
87 if type_ =='Diagonal':
88 var_H = 'Data/'+var+'/'+str('H')
89 var_V = 'Data/'+var+'/'+str('V')
90 data_arr_H = numpy.array(obj[var_H]['data']) # data
91 data_arr_V = numpy.array(obj[var_V]['data']) # data
92 data_arr = numpy.array([data_arr_H ,data_arr_V])
93 else:
94 var_ = 'Data/'+var+'/'+str(channel)
95 data_arr = numpy.array(obj[var_]['data']) # data
79 96 return data_arr, utc_time, data_azi,data_ele, heightList,unit,cmap,vmin,vmax,label
80 97
98
81 99 def selectHeights(self,heightList,minHei,maxHei):
82 100
83 101 if minHei and maxHei:
@@ -162,18 +180,24 class Readsophy():
162 180 plt.xlim(-20,80)
163 181
164 182 def save_PIC(self,count,time_save):
183 print("save",count)
184 if self.channel=='H':
185 ch_='0'
186 else:
187 ch_='1'
165 188 if count ==1:
166 filename = "SOPHY"+"_"+time_save+"_"+self.mode+"_"+self.grado+"_"+self.variable+str(self.range)+".png"
167 dir =self.variable+"_"+self.mode+self.grado+"CH0/"
189 #filename = "SOPHY"+"_"+time_save+"_"+self.mode+"_"+self.grado+"_"+self.variable+str(self.range)+".png"
190 filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+" "+self.channel+" "+str(self.range)+".png"
191 dir =self.variable+"_"+self.mode+"_"+self.grado+"_"+"CH"+ch_+"/"
168 192 filesavepath = os.path.join(self.path_file,dir)
169 193 try:
170 194 os.mkdir(filesavepath)
171 195 except:
172 196 pass
173 197 else:
174 dir =self.variable+"_"+self.mode+self.grado+"CH0/"
198 dir =self.variable+"_"+self.mode+"_"+self.grado+"_"+"CH"+ch_+"/"
175 199 filesavepath = os.path.join(self.path_file,dir)
176 filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+str(self.range)+".png"
200 filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+" "+self.channel+" "+str(self.range)+".png"
177 201 plt.savefig(filesavepath+filename)
178 202
179 203 def seleccion_roHV_min(self,count,z,y,arr_):
@@ -196,14 +220,14 class Readsophy():
196 220 for i in range(len_Z):
197 221 if min_CC[i]>moda_[0]+0.15 or min_CC[i]<moda_[0]-0.15:
198 222 min_CC[i]=numpy.nan
199 print("MIN_CC",min_CC)
200 print("y[0]",y[0])
223 #print("MIN_CC",min_CC)
224 #print("y[0]",y[0])
201 225 min_index_CC=((min_CC-y[0])/0.06)
202 226 if count == 0:
203 227 arr_ = min_index_CC
204 228 else:
205 229 arr_ = numpy.append(arr_,min_index_CC)
206 print("arr_",min_index_CC)
230 #print("arr_",min_index_CC)
207 231 return arr_
208 232 else:
209 233 print("Operation JUST for roHV - EXIT ")
@@ -219,8 +243,6 class Readsophy():
219 243 print("There is no file")
220 244 exit()
221 245
222 #print(min_CC.shape,len_X)
223 #print(min_CC)
224 246 if count ==1:
225 247 c_min = 0
226 248 c_max = c_max+ len_X
@@ -248,6 +270,81 class Readsophy():
248 270 prom_List.append(numpy.nanmean(bb))
249 271 return c_max
250 272
273 def plot_WR(self,count,fig,z,r,az,rf,my_time,label,unit,cmap,vmin,vmax):
274 if count ==1:
275 plt.rcParams['axes.facecolor']='black'
276 cgax, pm = wradlib.vis.plot_ppi(data=z,r=r,az=az,rf=1,fig=fig,ax=111,proj='cg',cmap=cmap,vmin=vmin,vmax=vmax)
277 caax = cgax.parasites[0]
278 title = 'Sophy Plot'+"-"+label+"-"+ my_time+" "+self.mode+"_"+self.channel+"_"+self.grado+"_"+" NΒ° "+str(count)
279 t = plt.title(title, fontsize=10,y=1.05)
280 cbar = plt.gcf().colorbar(pm,ax=cgax,shrink=0.7)
281 plt.text(1.0, 1.05, 'azimuth', transform=caax.transAxes, va='bottom',ha='right')
282 cbar.set_label(label+'[' + unit + ']')
283 caax.set_xlabel('x_range [km]')
284 caax.set_ylabel('y_range [km]')
285 gh = cgax.get_grid_helper()
286
287 else:
288 cgax, pm = wradlib.vis.plot_ppi(data=z,r=r,az=az,rf=1,fig=fig,ax=111,proj='cg',cmap=cmap,vmin=vmin,vmax=vmax)
289 caax = cgax.parasites[0]
290 title = 'Sophy Plot'+"-"+label+"-"+ my_time+" "+self.mode+"_"+self.channel+"_"+self.grado+"_"+" NΒ° "+str(count)
291 t = plt.title(title, fontsize=10,y=1.05)
292 cbar = plt.gcf().colorbar(pm,ax=cgax,shrink=0.7)
293 plt.text(1.0, 1.05, 'azimuth', transform=caax.transAxes, va='bottom',ha='right')
294 cbar.set_label(label+'[' + unit + ']')
295 caax.set_xlabel('x_range [km]')
296 caax.set_ylabel('y_range [km]')
297 gh = cgax.get_grid_helper()
298
299 def plot_D(self,count,h,x,y,my_time,label,mode,grado):
300 if count==1:
301 fig =plt.figure(figsize=(16,8))
302 ax1=plt.subplot(1,2,1)
303 ax2=plt.subplot(1,2,2)
304 ax1.plot(h,x,"bo",color="red", linestyle="dotted", lw=3,label='Zh')
305 ax1.plot(h,y,"bo",color="blue", linestyle="dotted", lw=3,label='Zv')
306 title = 'Sophy Plot '+ "Zh Zv"+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
307 fig.suptitle(title, fontsize=18)
308 #plt.ylim(0,self.range+1)
309 ax1.legend(loc=1,prop={'size': 16})
310 ax1.set_title("Z- Reflectividad vs H(Km)", fontsize=15)
311 ax1.set_ylabel('Z Reflectivity')
312 ax1.set_xlabel('H(Km)')
313 ax1.set_ylim(-20,70)
314
315 m= numpy.arange(100)-20
316 ax2.plot(x,y,"bo",color="red", linestyle="dotted", lw=3,label='Zh')
317 ax2.plot(m,m,"bo",color="green", linestyle="dotted", lw=0.5,label='Zh')
318 ax2.set_title('ZV vs ZH', fontsize=16)
319 ax2.set_xlabel('Zh dBZ')
320 ax2.set_xlim(-20,70)
321 ax2.set_ylim(-20,70)
322 ax2.set_ylabel('Zv dBZ')
323 ax2.set_xlabel('Zh dBZ')
324 ax2.legend(loc=1,prop={'size': 16})
325 else:
326 ax1=plt.subplot(1,2,1)
327 ax2=plt.subplot(1,2,2)
328 ax1.plot(h,x,"bo",color="red", linestyle="dotted", lw=3,label='Zh')
329 ax1.plot(h,y,"bo",color="blue", linestyle="dotted", lw=3,label='Zv')
330 title = 'Sophy Plot '+ "Zh Zv"+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
331 plt.suptitle(title, fontsize=18)
332 ax1.legend(loc=1,prop={'size': 16})
333 ax1.set_title("Z- Reflectividad vs H(Km)", fontsize=15)
334 ax1.set_ylabel('Z Reflectivity')
335 ax1.set_xlabel('H(Km)')
336 ax1.set_ylim(-20,70)
337 m= numpy.arange(100)-20
338 ax2.plot(x,y,"bo",color="red", linestyle="dotted", lw=3,label='Zv vs Zh')
339 ax2.plot(m,m,"bo",color="green", linestyle="dotted", lw=0.5,label='Zh=Zv')
340 ax2.set_title('ZV vs ZH', fontsize=16)
341 ax2.set_xlim(-20,70)
342 ax2.set_ylim(-20,70)
343 ax2.set_ylabel('Zv dBZ')
344 ax2.set_xlabel('Zh dBZ')
345 ax2.legend(loc=1,prop={'size': 16})
346
347 #plt.gcf()
251 348
252 349 def run(self):
253 350 count = 0
@@ -260,8 +357,8 class Readsophy():
260 357 filename = get_wradlib_data_file(fullpathfile)
261 358 test_hdf5 = read_generic_hdf5(filename)
262 359 # LECTURA
263 data_arr, utc_time, data_azi,data_ele, heightList,unit,cmap,vmin,vmax,label = self.readAttributes(obj= test_hdf5,variable=self.variable)
264 len_X= data_arr.shape[0]
360 data_arr, utc_time, data_azi,data_ele, heightList,unit,cmap,vmin,vmax,label = self.readAttributes(obj= test_hdf5,variable=self.variable,channel=self.channel,type_=self.type_)
361
265 362 # SELECCION DE ALTURAS
266 363 if self.range==0:
267 364 self.range == heightList[-1]
@@ -272,12 +369,19 class Readsophy():
272 369 utc_time[0] = utc_time[0]+60*60*5
273 370 my_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(utc_time[0]))
274 371 time_save = time.strftime('%Y%m%d_%H%M%S',time.localtime(utc_time[0]))
275 data_arr= data_arr[:,minIndex:maxIndex].transpose()
276 372 # VARIABLES
373 if self.type_=='Diagonal':
374 x= numpy.nanmean(data_arr[0][:,minIndex:maxIndex].transpose(),1)
375 y= numpy.nanmean(data_arr[1][:,minIndex:maxIndex].transpose(),1)
376 h= new_heightList
377 else:
378 len_X= data_arr.shape[0]
379 data_arr_= data_arr[:,minIndex:maxIndex].transpose()
277 380 x=numpy.linspace(1,len_X,len_X)
278 381 y= new_heightList
279 z=data_arr
382 z=data_arr_
280 383 profile = numpy.mean(z,1)
384
281 385 if count ==1:
282 386 if self.type_ =="PROFILE":
283 387 self.plot_PROFILE(count=count ,z=z,y=y,my_time=my_time,label=label,mode=self.mode,grado=self.grado)
@@ -288,6 +392,11 class Readsophy():
288 392 if self.type_ =='pp_BB':
289 393 self.plot_RTI_PPI_RHI(count=count,x=x,y=y,z=z,cmap=cmap,my_time=my_time,vmin=vmin,vmax=vmax,label =label,unit=unit, mode=self.mode,grado=self.grado)
290 394 c_max = self.pp_BB(count=count,x=x,y=y,z=z,filename='index.npy',c_max=0,prom_List=SAVE_PARAM)
395 if self.type_ == "plot_WR":
396 fig =plt.figure(figsize=(10,8))
397 self.plot_WR(count=count,fig=fig,z=data_arr[:,minIndex:maxIndex],r=y,az=data_azi,rf=1,my_time=my_time,label=label,unit=unit,cmap=cmap,vmin=vmin,vmax=vmax)
398 if self.type_ =="Diagonal":
399 self.plot_D(count=count,h=h,x=x,y=y,my_time=my_time,label="Zv vs Zh",mode=self.mode,grado=self.grado)
291 400 else:
292 401 if self.type_=="RTI":
293 402 self.plot_RTI_PPI_RHI(count=count,x=x,y=y,z=z,cmap=cmap,my_time=my_time,vmin=vmin,vmax=vmax,label =label,unit=unit, mode=self.mode,grado=self.grado)
@@ -300,6 +409,10 class Readsophy():
300 409 c_max = self.pp_BB(count=count,x=x,y=y,z=z,filename='index.npy',c_max=c_max,prom_List=SAVE_PARAM)
301 410 if c_max ==0:
302 411 count=len_files
412 if self.type_ == "plot_WR":
413 self.plot_WR(count=count,fig=fig,z=data_arr[:,minIndex:maxIndex],r=y,az=data_azi,rf=1,my_time=my_time,label=label,unit=unit,cmap=cmap,vmin=vmin,vmax=vmax)
414 if self.type_ =="Diagonal":
415 self.plot_D(count=count,h=h,x=x,y=y,my_time=my_time,label="Zv vs Zh",mode=self.mode,grado=self.grado)
303 416
304 417 if self.save == 1:
305 418 self.save_PIC(count=count,time_save=time_save)
@@ -307,10 +420,10 class Readsophy():
307 420 plt.clf()
308 421 if count == len_files:
309 422 if self.type_ =='roHV_MIN':
310 numpy.save("/home/soporte/WRJAN2023/schain/schainpy/scripts/index.npy",arr_)
423 numpy.save("/media/soporte/DATA/soporte/WRJAN2023/schain/schainpy/scripts/index.npy",arr_)
311 424 if self.type_ =='pp_BB':
312 numpy.save("/home/soporte/WRJAN2023/schain/schainpy/scripts/index_"+self.variable+"_prom.npy",SAVE_PARAM)
313 print("-----ADIOS-------------------")
425 numpy.save("/media/soporte/DATA/soporte/WRJAN2023/schain/schainpy/scripts/index_"+self.variable+"_prom.npy",SAVE_PARAM)
426 print("---------------------END---------------------")
314 427 plt.close()
315 428 exit()
316 429 plt.show()
@@ -324,19 +437,26 def main(args):
324 437 range = args.range
325 438 mode = args.mode
326 439 type = args.type
440 channel = args.channel
327 441 obj = Readsophy()
442 print("------------------START-------------------")
328 443 print("MODE :", mode)
329 444 if not mode =='PPI' and not mode =='RHI':
330 445 print("Error - Choose Mode RHI or PPI")
331 446 return None
332 447 for param in parameters:
333 448 print("Parameters : ", param)
449 DIR_ = "NORMAL"
334 450 if mode =='PPI':
335 PATH = "/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/"+str(param)+"_PPI_EL_"+str(grado)+".0/"
451 #PATH = "/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/"+str(param)+"_PPI_EL_"+str(grado)+".0/"
452 #PATH = "/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-27T00-00-32/param-FIXIT/"+str(param)+"_PPI_EL_"+str(grado)+".0/"
453 PATH = "/media/soporte/DATA/sophy/HYO_CC4_CC64_COMB@2022-12-27T00-00-32/param-"+DIR_+"/"+str(param)+"_PPI_EL_"+str(grado)+".0/"
336 454 else:
337 PATH = "/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/"+str(param)+"_RHI_AZ_"+str(grado)+".0/"
455 #PATH = "/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/"+str(param)+"_RHI_AZ_"+str(grado)+".0/"
456 PATH = "/media/soporte/DATA/sophy/HYO_CC4_CC64_COMB@2022-12-27T00-00-32/param-"+DIR_+"/"+str(param)+"_PPI_EL_"+str(grado)+".0/"
457
338 458 print("Path : ",PATH)
339 obj.setup(path_file =PATH,mode=mode,type=type,grado = grado,range=range,r_min=r_min, variable=param,save=int(save))
459 obj.setup(path_file =PATH,mode=mode,channel=channel,type=type,grado = grado,range=range,r_min=r_min, variable=param,save=int(save))
340 460 print("SETUP OK")
341 461 obj.run()
342 462
@@ -357,6 +477,11 if __name__ == '__main__':
357 477 help='Min range to plot')
358 478 parser.add_argument('--type', default='RTI',
359 479 help='TYPE Profile or RTI')
480 parser.add_argument('--channel', default='H',
481 help='Choose H or V')
482
360 483 args = parser.parse_args()
361 484
362 485 main(args)
486
487 #python test_zdr.py --parameters Z --grado 90 --mode 'PPI' --range 6 --r_min 0.5 --type plot_WR --channel H --save 1 No newline at end of file
General Comments 1
note

Update para identificar canales si ha sido seleccionada la operacion plot_D, algunos directorios son estaticos, actualizar si se instala en otro equipo.

You need to be logged in to leave comments. Login now