##// END OF EJS Templates
Update para ploteo de Zh vs Zv , METODO plot_D, atributo Diagonal
avaldez -
r1591:d9024fd73e87
parent child
Show More
@@ -1,362 +1,487
1 import numpy,os,time
1 import numpy,os,time
2 import matplotlib
2 import matplotlib
3 import argparse
3 import argparse
4 import matplotlib.pyplot as plt
4 import matplotlib.pyplot as plt
5 from wradlib.io import read_generic_hdf5
5 from wradlib.io import read_generic_hdf5
6 from wradlib.util import get_wradlib_data_file
6 from wradlib.util import get_wradlib_data_file
7 from plotting_codes import sophy_cb_tables
7 from plotting_codes import sophy_cb_tables
8 from scipy import stats
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 for name, cb_table in sophy_cb_tables:
16 for name, cb_table in sophy_cb_tables:
11 ncmap = matplotlib.colors.ListedColormap(cb_table, name=name)
17 ncmap = matplotlib.colors.ListedColormap(cb_table, name=name)
12 matplotlib.pyplot.register_cmap(cmap=ncmap)
18 matplotlib.pyplot.register_cmap(cmap=ncmap)
13 '''
19 '''
14 NOTA:
20 NOTA:
21 #python test_zdr.py --parameters Z --grado 90 --mode 'PPI' --range 10 --type plot_WR --channel H
22
15 - python3.10
23 - python3.10
16 - Conda environment:
24 - Conda environment:
17 WR_CONDA_JUN14 * /home/soporte/anaconda3/envs/WR_CONDA_JUN14
25 WR_CONDA_JUN14 * /home/soporte/anaconda3/envs/WR_CONDA_JUN14
18 export WRADLIB_DATA = "/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/"
26 export WRADLIB_DATA="/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/"
19 - Update de plotting_codes
27 - Update de plotting_codes
20 '''
28 '''
21 PARAM = {
29 PARAM = {
22 'S': {'var': 'power','vmin': -45, 'vmax': -15, 'cmap': 'jet', 'label': 'Power','unit': 'dBm'},
30 'S': {'var': 'power' ,'vmin': -45, 'vmax': -15, 'cmap': 'jet' ,'label': 'Power' ,'unit': 'dBm'},
23 'V': {'var': 'velocity', 'vmin': -10, 'vmax': 10 , 'cmap': 'sophy_v', 'label': 'Velocity','unit': 'm/s'},
31 'V': {'var': 'velocity' ,'vmin': -10, 'vmax': 10 , 'cmap': 'sophy_v','label': 'Velocity' ,'unit': 'm/s'},
24 'Z': {'var': 'reflectivity','vmin': -20, 'vmax': 80 , 'cmap': 'sophy_z','label': 'Reflectivity','unit': 'dBZ'},
32 'Z': {'var': 'reflectivity' ,'vmin': -20, 'vmax': 80 , 'cmap': 'sophy_z','label': 'Reflectivity' ,'unit': 'dBZ'},
25 'W': {'var': 'spectral_width', 'vmin': 0 , 'vmax': 12 , 'cmap': 'sophy_w','label': 'Spectral Width','unit': 'm/s'},
33 'W': {'var': 'spectral_width' ,'vmin': 0 , 'vmax': 12 , 'cmap': 'sophy_w','label': 'Spectral Width','unit': 'm/s'},
26 'R': {'var':'rhoHV','vmin': 0.2, 'vmax': 1, 'cmap': 'sophy_r','label': 'RhoHV', 'unit': ' '},
34 'R': {'var': 'rhoHV' ,'vmin': 0.2, 'vmax': 1 , 'cmap': 'sophy_r','label': 'RhoHV' , 'unit': ' '},
27 'D': {'var': 'differential_reflectivity','vmin': -9, 'vmax': 12, 'cmap': 'sophy_d','label': 'ZDR' , 'unit': 'dB'}
35 'D': {'var': 'differential_reflectivity','vmin': -9 , 'vmax': 12 , 'cmap': 'sophy_d','label': 'ZDR' , 'unit': 'dB'}
28 }
36 }
29
37
30 class Readsophy():
38 class Readsophy():
31 def __init__(self):
39 def __init__(self):
32 self.list_file = None
40 self.list_file = None
33 self.grado = None
41 self.grado = None
34 self.variable = None
42 self.variable = None
35 self.save = None
43 self.save = None
36 self.range = None
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 self.path_file = path_file
46 self.path_file = path_file
39 self.mode = mode
47 self.mode = mode
48 self.channel = channel
40 self.range = range
49 self.range = range
41 self.grado = grado
50 self.grado = grado
42 self.r_min = r_min
51 self.r_min = r_min
43 self.variable = variable
52 self.variable = variable
44 self.save = save
53 self.save = save
45 self.type_ = type
54 self.type_ = type
46 self.list_file = self.read_files(path_file=self.path_file,mode=self.mode,grado=self.grado, variable=self.variable)
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 def read_files(self,path_file,mode=None,grado=None, variable=None):
58 def read_files(self,path_file,mode=None,grado=None, variable=None):
50 if mode =='PPI':
59 if mode =='PPI':
51 filter= "_E"+str(grado)+".0_"+variable
60 filter= "_E"+str(grado)+".0_"+variable
52 else:
61 else:
53 filter= "_A"+str(grado)+".0_"+variable
62 filter= "_A"+str(grado)+".0_"+variable
54 print("Filter :",filter)
63 #print("Filter :",filter)
55 validFilelist = []
64 validFilelist = []
56 fileList= os.listdir(path_file)
65 fileList= os.listdir(path_file)
57 for thisFile in fileList:
66 for thisFile in fileList:
58 #print(thisFile)
67 #print(thisFile)
59 if not os.path.splitext(thisFile)[0][-7:] in filter:
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 continue
70 continue
62 validFilelist.append(thisFile)
71 validFilelist.append(thisFile)
63 validFilelist.sort()
72 validFilelist.sort()
64 return validFilelist
73 return validFilelist
65
74
66 def readAttributes(self,obj,variable):
75 def readAttributes(self,obj,variable,channel,type_):
67 var = PARAM[variable]['var']
76 var = PARAM[variable]['var']
68 unit = PARAM[variable]['unit']
77 unit = PARAM[variable]['unit']
69 cmap = PARAM[variable]['cmap']
78 cmap = PARAM[variable]['cmap']
70 vmin = PARAM[variable]['vmin']
79 vmin = PARAM[variable]['vmin']
71 vmax = PARAM[variable]['vmax']
80 vmax = PARAM[variable]['vmax']
72 label = PARAM[variable]['label']
81 label = PARAM[variable]['label']
73 var_ = 'Data/'+var+'/H'
82
74 data_arr = numpy.array(obj[var_]['data']) # data
75 utc_time = numpy.array(obj['Data/time']['data'])
83 utc_time = numpy.array(obj['Data/time']['data'])
76 data_azi = numpy.array(obj['Metadata/azimuth']['data']) # th
84 data_azi = numpy.array(obj['Metadata/azimuth']['data']) # th
77 data_ele = numpy.array(obj["Metadata/elevation"]['data'])
85 data_ele = numpy.array(obj["Metadata/elevation"]['data'])
78 heightList = numpy.array(obj["Metadata/range"]['data']) # r
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 return data_arr, utc_time, data_azi,data_ele, heightList,unit,cmap,vmin,vmax,label
96 return data_arr, utc_time, data_azi,data_ele, heightList,unit,cmap,vmin,vmax,label
80
97
98
81 def selectHeights(self,heightList,minHei,maxHei):
99 def selectHeights(self,heightList,minHei,maxHei):
82
100
83 if minHei and maxHei:
101 if minHei and maxHei:
84 if (minHei < heightList[0]):
102 if (minHei < heightList[0]):
85 minHei = heightList[0]
103 minHei = heightList[0]
86 if (maxHei > heightList[-1]):
104 if (maxHei > heightList[-1]):
87 maxHei = heightList[-1]
105 maxHei = heightList[-1]
88 minIndex = 0
106 minIndex = 0
89 maxIndex = 0
107 maxIndex = 0
90 heights = heightList
108 heights = heightList
91
109
92 inda = numpy.where(heights >= minHei)
110 inda = numpy.where(heights >= minHei)
93 indb = numpy.where(heights <= maxHei)
111 indb = numpy.where(heights <= maxHei)
94
112
95 try:
113 try:
96 minIndex = inda[0][0]
114 minIndex = inda[0][0]
97 except:
115 except:
98 minIndex = 0
116 minIndex = 0
99
117
100 try:
118 try:
101 maxIndex = indb[0][-1]
119 maxIndex = indb[0][-1]
102 except:
120 except:
103 maxIndex = len(heights)
121 maxIndex = len(heights)
104
122
105 new_heightList= self.selectHeightsByIndex(heightList=heightList,minIndex=minIndex, maxIndex=maxIndex)
123 new_heightList= self.selectHeightsByIndex(heightList=heightList,minIndex=minIndex, maxIndex=maxIndex)
106
124
107 return new_heightList, minIndex,maxIndex
125 return new_heightList, minIndex,maxIndex
108
126
109 def selectHeightsByIndex(self,heightList,minIndex, maxIndex):
127 def selectHeightsByIndex(self,heightList,minIndex, maxIndex):
110
128
111 if (minIndex < 0) or (minIndex > maxIndex):
129 if (minIndex < 0) or (minIndex > maxIndex):
112 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
130 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
113
131
114 if (maxIndex >= len(heightList)):
132 if (maxIndex >= len(heightList)):
115 maxIndex = len(heightList)
133 maxIndex = len(heightList)
116
134
117 new_h = heightList[minIndex:maxIndex]
135 new_h = heightList[minIndex:maxIndex]
118 return new_h
136 return new_h
119
137
120 def plot_RTI_PPI_RHI(self,count,x,y,z,cmap,my_time,vmin,vmax,label,unit,mode,grado):
138 def plot_RTI_PPI_RHI(self,count,x,y,z,cmap,my_time,vmin,vmax,label,unit,mode,grado):
121 if count==1:
139 if count==1:
122 fig = plt.figure(figsize=(8,6))
140 fig = plt.figure(figsize=(8,6))
123 plt.pcolormesh(x,y,z,cmap =cmap, vmin = vmin, vmax = vmax)
141 plt.pcolormesh(x,y,z,cmap =cmap, vmin = vmin, vmax = vmax)
124 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
142 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
125 t = plt.title(title, fontsize=12,y=1.05)
143 t = plt.title(title, fontsize=12,y=1.05)
126 cbar = plt.colorbar()
144 cbar = plt.colorbar()
127 cbar.set_label(label+'[' + unit + ']')
145 cbar.set_label(label+'[' + unit + ']')
128 else:
146 else:
129 plt.pcolormesh(x,y,z, cmap =cmap, vmin = vmin, vmax = vmax)
147 plt.pcolormesh(x,y,z, cmap =cmap, vmin = vmin, vmax = vmax)
130 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
148 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
131 t = plt.title(title, fontsize=12,y=1.05)
149 t = plt.title(title, fontsize=12,y=1.05)
132 cbar = plt.colorbar()
150 cbar = plt.colorbar()
133 cbar.set_label(label+'[' + unit + ']')
151 cbar.set_label(label+'[' + unit + ']')
134
152
135 def plot_PROFILE(self,count,z,y,my_time,label,mode,grado):
153 def plot_PROFILE(self,count,z,y,my_time,label,mode,grado):
136 if count==1:
154 if count==1:
137 fig = plt.figure(figsize=(8,6))
155 fig = plt.figure(figsize=(8,6))
138 plt.plot(numpy.nanmean(z,1),y)
156 plt.plot(numpy.nanmean(z,1),y)
139 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
157 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
140 t = plt.title(title, fontsize=12,y=1.05)
158 t = plt.title(title, fontsize=12,y=1.05)
141 plt.ylim(0,self.range+1)
159 plt.ylim(0,self.range+1)
142 plt.xlabel(label)
160 plt.xlabel(label)
143 plt.ylabel('Height(Km)')
161 plt.ylabel('Height(Km)')
144 if self.variable=="R":
162 if self.variable=="R":
145 plt.xlim(-1,3)
163 plt.xlim(-1,3)
146 if self.variable=='D':
164 if self.variable=='D':
147 plt.xlim(-10,10)
165 plt.xlim(-10,10)
148 if self.variable=='Z':
166 if self.variable=='Z':
149 plt.xlim(-20,80)
167 plt.xlim(-20,80)
150 else:
168 else:
151 plt.plot(numpy.nanmean(z,1),y)
169 plt.plot(numpy.nanmean(z,1),y)
152 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
170 title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count)
153 t = plt.title(title, fontsize=12,y=1.05)
171 t = plt.title(title, fontsize=12,y=1.05)
154 plt.ylim(0,self.range+1)
172 plt.ylim(0,self.range+1)
155 plt.xlabel(label)
173 plt.xlabel(label)
156 plt.ylabel('Height(Km)')
174 plt.ylabel('Height(Km)')
157 if self.variable=="R":
175 if self.variable=="R":
158 plt.xlim(-1,3)
176 plt.xlim(-1,3)
159 if self.variable=='D':
177 if self.variable=='D':
160 plt.xlim(-10,10)
178 plt.xlim(-10,10)
161 if self.variable=='Z':
179 if self.variable=='Z':
162 plt.xlim(-20,80)
180 plt.xlim(-20,80)
163
181
164 def save_PIC(self,count,time_save):
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 if count ==1:
188 if count ==1:
166 filename = "SOPHY"+"_"+time_save+"_"+self.mode+"_"+self.grado+"_"+self.variable+str(self.range)+".png"
189 #filename = "SOPHY"+"_"+time_save+"_"+self.mode+"_"+self.grado+"_"+self.variable+str(self.range)+".png"
167 dir =self.variable+"_"+self.mode+self.grado+"CH0/"
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 filesavepath = os.path.join(self.path_file,dir)
192 filesavepath = os.path.join(self.path_file,dir)
169 try:
193 try:
170 os.mkdir(filesavepath)
194 os.mkdir(filesavepath)
171 except:
195 except:
172 pass
196 pass
173 else:
197 else:
174 dir =self.variable+"_"+self.mode+self.grado+"CH0/"
198 dir =self.variable+"_"+self.mode+"_"+self.grado+"_"+"CH"+ch_+"/"
175 filesavepath = os.path.join(self.path_file,dir)
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 plt.savefig(filesavepath+filename)
201 plt.savefig(filesavepath+filename)
178
202
179 def seleccion_roHV_min(self,count,z,y,arr_):
203 def seleccion_roHV_min(self,count,z,y,arr_):
180 ##print("y",y)
204 ##print("y",y)
181 if self.variable=='R':
205 if self.variable=='R':
182 len_Z= z.shape[1]
206 len_Z= z.shape[1]
183 min_CC=numpy.zeros(len_Z)
207 min_CC=numpy.zeros(len_Z)
184 min_index_CC = numpy.zeros(len_Z)
208 min_index_CC = numpy.zeros(len_Z)
185 for i in range(len_Z):
209 for i in range(len_Z):
186 tmp=numpy.nanmin(z[:,i])
210 tmp=numpy.nanmin(z[:,i])
187 tmp_index = numpy.nanargmin((z[:,i]))
211 tmp_index = numpy.nanargmin((z[:,i]))
188 if tmp <0.5:
212 if tmp <0.5:
189 tmp_index= numpy.nan
213 tmp_index= numpy.nan
190 value = numpy.nan
214 value = numpy.nan
191 else:
215 else:
192 value= y[tmp_index]
216 value= y[tmp_index]
193 min_CC[i] =value
217 min_CC[i] =value
194 moda_,count_m_ = stats.mode(min_CC)
218 moda_,count_m_ = stats.mode(min_CC)
195 #print("MODA",moda_)
219 #print("MODA",moda_)
196 for i in range(len_Z):
220 for i in range(len_Z):
197 if min_CC[i]>moda_[0]+0.15 or min_CC[i]<moda_[0]-0.15:
221 if min_CC[i]>moda_[0]+0.15 or min_CC[i]<moda_[0]-0.15:
198 min_CC[i]=numpy.nan
222 min_CC[i]=numpy.nan
199 print("MIN_CC",min_CC)
223 #print("MIN_CC",min_CC)
200 print("y[0]",y[0])
224 #print("y[0]",y[0])
201 min_index_CC=((min_CC-y[0])/0.06)
225 min_index_CC=((min_CC-y[0])/0.06)
202 if count == 0:
226 if count == 0:
203 arr_ = min_index_CC
227 arr_ = min_index_CC
204 else:
228 else:
205 arr_ = numpy.append(arr_,min_index_CC)
229 arr_ = numpy.append(arr_,min_index_CC)
206 print("arr_",min_index_CC)
230 #print("arr_",min_index_CC)
207 return arr_
231 return arr_
208 else:
232 else:
209 print("Operation JUST for roHV - EXIT ")
233 print("Operation JUST for roHV - EXIT ")
210 exit()
234 exit()
211
235
212 def pp_BB(self,count,x,y,z,filename,c_max,prom_List):
236 def pp_BB(self,count,x,y,z,filename,c_max,prom_List):
213 #print("z shape",z.shape)
237 #print("z shape",z.shape)
214 len_Z = z.shape[1]
238 len_Z = z.shape[1]
215 len_X = x.shape[0]
239 len_X = x.shape[0]
216 try:
240 try:
217 min_CC = numpy.load(filename)
241 min_CC = numpy.load(filename)
218 except:
242 except:
219 print("There is no file")
243 print("There is no file")
220 exit()
244 exit()
221
245
222 #print(min_CC.shape,len_X)
223 #print(min_CC)
224 if count ==1:
246 if count ==1:
225 c_min = 0
247 c_min = 0
226 c_max = c_max+ len_X
248 c_max = c_max+ len_X
227 plt.plot(x,y[0]+min_CC[c_min:c_max]*0.06,'yo')
249 plt.plot(x,y[0]+min_CC[c_min:c_max]*0.06,'yo')
228 else:
250 else:
229 c_min = c_max
251 c_min = c_max
230 c_max = c_min+len_X
252 c_max = c_min+len_X
231 try:
253 try:
232 plt.plot(x,y[0]+min_CC[c_min:c_max]*0.06,'yo')
254 plt.plot(x,y[0]+min_CC[c_min:c_max]*0.06,'yo')
233 except:
255 except:
234 print("Check number of file")
256 print("Check number of file")
235 return 0
257 return 0
236
258
237 bb = numpy.zeros(len_Z)
259 bb = numpy.zeros(len_Z)
238 min_READ_CC = min_CC[c_min:c_max]
260 min_READ_CC = min_CC[c_min:c_max]
239 #print(min_READ_CC[0:50])
261 #print(min_READ_CC[0:50])
240 for i in range(len_Z):
262 for i in range(len_Z):
241 if min_READ_CC[i]==numpy.nan:
263 if min_READ_CC[i]==numpy.nan:
242 bb[i]=numpy.nan
264 bb[i]=numpy.nan
243 try:
265 try:
244 bb[i]=z[int(min_READ_CC[i])][i]
266 bb[i]=z[int(min_READ_CC[i])][i]
245 except:
267 except:
246 bb[i]=numpy.nan
268 bb[i]=numpy.nan
247 print("bb _ prom_ZDR",numpy.nanmean(bb))
269 print("bb _ prom_ZDR",numpy.nanmean(bb))
248 prom_List.append(numpy.nanmean(bb))
270 prom_List.append(numpy.nanmean(bb))
249 return c_max
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 def run(self):
349 def run(self):
253 count = 0
350 count = 0
254 len_files = len(self.list_file)
351 len_files = len(self.list_file)
255 SAVE_PARAM= []
352 SAVE_PARAM= []
256 for thisFile in self.list_file:
353 for thisFile in self.list_file:
257 count= count +1
354 count= count +1
258 print("Count :", count)
355 print("Count :", count)
259 fullpathfile = self.path_file + thisFile
356 fullpathfile = self.path_file + thisFile
260 filename = get_wradlib_data_file(fullpathfile)
357 filename = get_wradlib_data_file(fullpathfile)
261 test_hdf5 = read_generic_hdf5(filename)
358 test_hdf5 = read_generic_hdf5(filename)
262 # LECTURA
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)
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_)
264 len_X= data_arr.shape[0]
361
265 # SELECCION DE ALTURAS
362 # SELECCION DE ALTURAS
266 if self.range==0:
363 if self.range==0:
267 self.range == heightList[-1]
364 self.range == heightList[-1]
268 if self.r_min==0:
365 if self.r_min==0:
269 self.r_min = 0.01
366 self.r_min = 0.01
270 new_heightList,minIndex,maxIndex = self.selectHeights(heightList,self.r_min,self.range)
367 new_heightList,minIndex,maxIndex = self.selectHeights(heightList,self.r_min,self.range)
271 # TIEMPO
368 # TIEMPO
272 utc_time[0] = utc_time[0]+60*60*5
369 utc_time[0] = utc_time[0]+60*60*5
273 my_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(utc_time[0]))
370 my_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(utc_time[0]))
274 time_save = time.strftime('%Y%m%d_%H%M%S',time.localtime(utc_time[0]))
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 # VARIABLES
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 x=numpy.linspace(1,len_X,len_X)
380 x=numpy.linspace(1,len_X,len_X)
278 y= new_heightList
381 y= new_heightList
279 z=data_arr
382 z=data_arr_
280 profile = numpy.mean(z,1)
383 profile = numpy.mean(z,1)
384
281 if count ==1:
385 if count ==1:
282 if self.type_ =="PROFILE":
386 if self.type_ =="PROFILE":
283 self.plot_PROFILE(count=count ,z=z,y=y,my_time=my_time,label=label,mode=self.mode,grado=self.grado)
387 self.plot_PROFILE(count=count ,z=z,y=y,my_time=my_time,label=label,mode=self.mode,grado=self.grado)
284 if self.type_ =="RTI":
388 if self.type_ =="RTI":
285 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)
389 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)
286 if self.type_ =='roHV_MIN':
390 if self.type_ =='roHV_MIN':
287 arr_= self.seleccion_roHV_min(count=count,z=z,y=y,arr_= 0)
391 arr_= self.seleccion_roHV_min(count=count,z=z,y=y,arr_= 0)
288 if self.type_ =='pp_BB':
392 if self.type_ =='pp_BB':
289 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)
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 c_max = self.pp_BB(count=count,x=x,y=y,z=z,filename='index.npy',c_max=0,prom_List=SAVE_PARAM)
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 else:
400 else:
292 if self.type_=="RTI":
401 if self.type_=="RTI":
293 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)
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)
294 if self.type_ =="PROFILE":
403 if self.type_ =="PROFILE":
295 self. plot_PROFILE(count=count,z=z,y=y,my_time=my_time,label=label,mode=self.mode,grado=self.grado)
404 self. plot_PROFILE(count=count,z=z,y=y,my_time=my_time,label=label,mode=self.mode,grado=self.grado)
296 if self.type_ =='roHV_MIN':
405 if self.type_ =='roHV_MIN':
297 arr_= self.seleccion_roHV_min(count=count,z=z,y=y,arr_= arr_)
406 arr_= self.seleccion_roHV_min(count=count,z=z,y=y,arr_= arr_)
298 if self.type_ =='pp_BB':
407 if self.type_ =='pp_BB':
299 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)
408 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 c_max = self.pp_BB(count=count,x=x,y=y,z=z,filename='index.npy',c_max=c_max,prom_List=SAVE_PARAM)
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 if c_max ==0:
410 if c_max ==0:
302 count=len_files
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 if self.save == 1:
417 if self.save == 1:
305 self.save_PIC(count=count,time_save=time_save)
418 self.save_PIC(count=count,time_save=time_save)
306 plt.pause(1)
419 plt.pause(1)
307 plt.clf()
420 plt.clf()
308 if count == len_files:
421 if count == len_files:
309 if self.type_ =='roHV_MIN':
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 if self.type_ =='pp_BB':
424 if self.type_ =='pp_BB':
312 numpy.save("/home/soporte/WRJAN2023/schain/schainpy/scripts/index_"+self.variable+"_prom.npy",SAVE_PARAM)
425 numpy.save("/media/soporte/DATA/soporte/WRJAN2023/schain/schainpy/scripts/index_"+self.variable+"_prom.npy",SAVE_PARAM)
313 print("-----ADIOS-------------------")
426 print("---------------------END---------------------")
314 plt.close()
427 plt.close()
315 exit()
428 exit()
316 plt.show()
429 plt.show()
317
430
318
431
319 def main(args):
432 def main(args):
320 grado = args.grado
433 grado = args.grado
321 parameters = args.parameters
434 parameters = args.parameters
322 r_min = args.r_min
435 r_min = args.r_min
323 save = args.save
436 save = args.save
324 range = args.range
437 range = args.range
325 mode = args.mode
438 mode = args.mode
326 type = args.type
439 type = args.type
440 channel = args.channel
327 obj = Readsophy()
441 obj = Readsophy()
442 print("------------------START-------------------")
328 print("MODE :", mode)
443 print("MODE :", mode)
329 if not mode =='PPI' and not mode =='RHI':
444 if not mode =='PPI' and not mode =='RHI':
330 print("Error - Choose Mode RHI or PPI")
445 print("Error - Choose Mode RHI or PPI")
331 return None
446 return None
332 for param in parameters:
447 for param in parameters:
333 print("Parameters : ", param)
448 print("Parameters : ", param)
449 DIR_ = "NORMAL"
334 if mode =='PPI':
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 else:
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 print("Path : ",PATH)
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 print("SETUP OK")
460 print("SETUP OK")
341 obj.run()
461 obj.run()
342
462
343 if __name__ == '__main__':
463 if __name__ == '__main__':
344
464
345 parser = argparse.ArgumentParser(description='Script to process SOPHy data.')
465 parser = argparse.ArgumentParser(description='Script to process SOPHy data.')
346 parser.add_argument('--parameters', nargs='*', default=['S'],
466 parser.add_argument('--parameters', nargs='*', default=['S'],
347 help='Variables to process: P, Z, V ,W,D')
467 help='Variables to process: P, Z, V ,W,D')
348 parser.add_argument('--grado', default=2,
468 parser.add_argument('--grado', default=2,
349 help='Angle in Elev to plot')
469 help='Angle in Elev to plot')
350 parser.add_argument('--mode',default='PPI',
470 parser.add_argument('--mode',default='PPI',
351 help='MODE PPI or RHI')
471 help='MODE PPI or RHI')
352 parser.add_argument('--save', default=0,
472 parser.add_argument('--save', default=0,
353 help='Save plot')
473 help='Save plot')
354 parser.add_argument('--range', default=0, type=float,
474 parser.add_argument('--range', default=0, type=float,
355 help='Max range to plot')
475 help='Max range to plot')
356 parser.add_argument('--r_min', default=0, type=float,
476 parser.add_argument('--r_min', default=0, type=float,
357 help='Min range to plot')
477 help='Min range to plot')
358 parser.add_argument('--type', default='RTI',
478 parser.add_argument('--type', default='RTI',
359 help='TYPE Profile or RTI')
479 help='TYPE Profile or RTI')
480 parser.add_argument('--channel', default='H',
481 help='Choose H or V')
482
360 args = parser.parse_args()
483 args = parser.parse_args()
361
484
362 main(args)
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