Update para identificar canales si ha sido seleccionada la operacion plot_D, algunos directorios son estaticos, actualizar si se instala en otro equipo.
@@ -1,362 +1,487 | |||
|
1 | 1 | import numpy,os,time |
|
2 | 2 | import matplotlib |
|
3 | 3 | import argparse |
|
4 | 4 | import matplotlib.pyplot as plt |
|
5 | 5 | 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 |
|
18 |
export WRADLIB_DATA |
|
|
26 | export WRADLIB_DATA="/media/soporte/TOSHIBAEXT/sophy/HYO_CC4_CC64_COMB@2022-12-26T00-00-32/param-EVENTO/" | |
|
19 | 27 | - Update de plotting_codes |
|
20 | 28 | ''' |
|
21 | 29 | PARAM = { |
|
22 |
'S': {'var': 'power','vmin': -45, 'vmax': -15, 'cmap': 'jet', |
|
|
23 |
'V': {'var': 'velocity', |
|
|
24 | 'Z': {'var': 'reflectivity','vmin': -20, 'vmax': 80 , 'cmap': 'sophy_z','label': 'Reflectivity','unit': 'dBZ'}, | |
|
25 |
'W': {'var': 'spectral_width', |
|
|
26 |
'R': {'var':'rhoHV','vmin': 0.2, |
|
|
27 | 'D': {'var': 'differential_reflectivity','vmin': -9, 'vmax': 12, 'cmap': 'sophy_d','label': 'ZDR' , 'unit': 'dB'} | |
|
30 | 'S': {'var': 'power' ,'vmin': -45, 'vmax': -15, 'cmap': 'jet' ,'label': 'Power' ,'unit': 'dBm'}, | |
|
31 | 'V': {'var': 'velocity' ,'vmin': -10, 'vmax': 10 , 'cmap': 'sophy_v','label': 'Velocity' ,'unit': 'm/s'}, | |
|
32 | 'Z': {'var': 'reflectivity' ,'vmin': -20, 'vmax': 80 , 'cmap': 'sophy_z','label': 'Reflectivity' ,'unit': 'dBZ'}, | |
|
33 | 'W': {'var': 'spectral_width' ,'vmin': 0 , 'vmax': 12 , 'cmap': 'sophy_w','label': 'Spectral Width','unit': 'm/s'}, | |
|
34 | 'R': {'var': 'rhoHV' ,'vmin': 0.2, 'vmax': 1 , 'cmap': 'sophy_r','label': 'RhoHV' , 'unit': ' '}, | |
|
35 | 'D': {'var': 'differential_reflectivity','vmin': -9 , 'vmax': 12 , 'cmap': 'sophy_d','label': 'ZDR' , 'unit': 'dB'} | |
|
28 | 36 | } |
|
29 | 37 | |
|
30 | 38 | class Readsophy(): |
|
31 | 39 | def __init__(self): |
|
32 | 40 | self.list_file = None |
|
33 | 41 | self.grado = None |
|
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 |
|
43 | 52 | self.variable = variable |
|
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 |
|
97 | ||
|
80 | 98 | |
|
81 | 99 | def selectHeights(self,heightList,minHei,maxHei): |
|
82 | 100 | |
|
83 | 101 | if minHei and maxHei: |
|
84 | 102 | if (minHei < heightList[0]): |
|
85 | 103 | minHei = heightList[0] |
|
86 | 104 | if (maxHei > heightList[-1]): |
|
87 | 105 | maxHei = heightList[-1] |
|
88 | 106 | minIndex = 0 |
|
89 | 107 | maxIndex = 0 |
|
90 | 108 | heights = heightList |
|
91 | 109 | |
|
92 | 110 | inda = numpy.where(heights >= minHei) |
|
93 | 111 | indb = numpy.where(heights <= maxHei) |
|
94 | 112 | |
|
95 | 113 | try: |
|
96 | 114 | minIndex = inda[0][0] |
|
97 | 115 | except: |
|
98 | 116 | minIndex = 0 |
|
99 | 117 | |
|
100 | 118 | try: |
|
101 | 119 | maxIndex = indb[0][-1] |
|
102 | 120 | except: |
|
103 | 121 | maxIndex = len(heights) |
|
104 | 122 | |
|
105 | 123 | new_heightList= self.selectHeightsByIndex(heightList=heightList,minIndex=minIndex, maxIndex=maxIndex) |
|
106 | 124 | |
|
107 | 125 | return new_heightList, minIndex,maxIndex |
|
108 | 126 | |
|
109 | 127 | def selectHeightsByIndex(self,heightList,minIndex, maxIndex): |
|
110 | 128 | |
|
111 | 129 | if (minIndex < 0) or (minIndex > maxIndex): |
|
112 | 130 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
113 | 131 | |
|
114 | 132 | if (maxIndex >= len(heightList)): |
|
115 | 133 | maxIndex = len(heightList) |
|
116 | 134 | |
|
117 | 135 | new_h = heightList[minIndex:maxIndex] |
|
118 | 136 | return new_h |
|
119 | 137 | |
|
120 | 138 | def plot_RTI_PPI_RHI(self,count,x,y,z,cmap,my_time,vmin,vmax,label,unit,mode,grado): |
|
121 | 139 | if count==1: |
|
122 | 140 | fig = plt.figure(figsize=(8,6)) |
|
123 | 141 | plt.pcolormesh(x,y,z,cmap =cmap, vmin = vmin, vmax = vmax) |
|
124 | 142 | title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count) |
|
125 | 143 | t = plt.title(title, fontsize=12,y=1.05) |
|
126 | 144 | cbar = plt.colorbar() |
|
127 | 145 | cbar.set_label(label+'[' + unit + ']') |
|
128 | 146 | else: |
|
129 | 147 | plt.pcolormesh(x,y,z, cmap =cmap, vmin = vmin, vmax = vmax) |
|
130 | 148 | title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count) |
|
131 | 149 | t = plt.title(title, fontsize=12,y=1.05) |
|
132 | 150 | cbar = plt.colorbar() |
|
133 | 151 | cbar.set_label(label+'[' + unit + ']') |
|
134 | 152 | |
|
135 | 153 | def plot_PROFILE(self,count,z,y,my_time,label,mode,grado): |
|
136 | 154 | if count==1: |
|
137 | 155 | fig = plt.figure(figsize=(8,6)) |
|
138 | 156 | plt.plot(numpy.nanmean(z,1),y) |
|
139 | 157 | title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count) |
|
140 | 158 | t = plt.title(title, fontsize=12,y=1.05) |
|
141 | 159 | plt.ylim(0,self.range+1) |
|
142 | 160 | plt.xlabel(label) |
|
143 | 161 | plt.ylabel('Height(Km)') |
|
144 | 162 | if self.variable=="R": |
|
145 | 163 | plt.xlim(-1,3) |
|
146 | 164 | if self.variable=='D': |
|
147 | 165 | plt.xlim(-10,10) |
|
148 | 166 | if self.variable=='Z': |
|
149 | 167 | plt.xlim(-20,80) |
|
150 | 168 | else: |
|
151 | 169 | plt.plot(numpy.nanmean(z,1),y) |
|
152 | 170 | title = 'Sophy Plot '+label+"-"+ my_time+" "+mode+" "+grado+" NΒ° "+str(count) |
|
153 | 171 | t = plt.title(title, fontsize=12,y=1.05) |
|
154 | 172 | plt.ylim(0,self.range+1) |
|
155 | 173 | plt.xlabel(label) |
|
156 | 174 | plt.ylabel('Height(Km)') |
|
157 | 175 | if self.variable=="R": |
|
158 | 176 | plt.xlim(-1,3) |
|
159 | 177 | if self.variable=='D': |
|
160 | 178 | plt.xlim(-10,10) |
|
161 | 179 | if self.variable=='Z': |
|
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+" |
|
|
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_): |
|
180 | 204 | ##print("y",y) |
|
181 | 205 | if self.variable=='R': |
|
182 | 206 | len_Z= z.shape[1] |
|
183 | 207 | min_CC=numpy.zeros(len_Z) |
|
184 | 208 | min_index_CC = numpy.zeros(len_Z) |
|
185 | 209 | for i in range(len_Z): |
|
186 | 210 | tmp=numpy.nanmin(z[:,i]) |
|
187 | 211 | tmp_index = numpy.nanargmin((z[:,i])) |
|
188 | 212 | if tmp <0.5: |
|
189 | 213 | tmp_index= numpy.nan |
|
190 | 214 | value = numpy.nan |
|
191 | 215 | else: |
|
192 | 216 | value= y[tmp_index] |
|
193 | 217 | min_CC[i] =value |
|
194 | 218 | moda_,count_m_ = stats.mode(min_CC) |
|
195 | 219 | #print("MODA",moda_) |
|
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 ") |
|
210 | 234 | exit() |
|
211 | 235 | |
|
212 | 236 | def pp_BB(self,count,x,y,z,filename,c_max,prom_List): |
|
213 | 237 | #print("z shape",z.shape) |
|
214 | 238 | len_Z = z.shape[1] |
|
215 | 239 | len_X = x.shape[0] |
|
216 | 240 | try: |
|
217 | 241 | min_CC = numpy.load(filename) |
|
218 | 242 | except: |
|
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 |
|
227 | 249 | plt.plot(x,y[0]+min_CC[c_min:c_max]*0.06,'yo') |
|
228 | 250 | else: |
|
229 | 251 | c_min = c_max |
|
230 | 252 | c_max = c_min+len_X |
|
231 | 253 | try: |
|
232 | 254 | plt.plot(x,y[0]+min_CC[c_min:c_max]*0.06,'yo') |
|
233 | 255 | except: |
|
234 | 256 | print("Check number of file") |
|
235 | 257 | return 0 |
|
236 | 258 | |
|
237 | 259 | bb = numpy.zeros(len_Z) |
|
238 | 260 | min_READ_CC = min_CC[c_min:c_max] |
|
239 | 261 | #print(min_READ_CC[0:50]) |
|
240 | 262 | for i in range(len_Z): |
|
241 | 263 | if min_READ_CC[i]==numpy.nan: |
|
242 | 264 | bb[i]=numpy.nan |
|
243 | 265 | try: |
|
244 | 266 | bb[i]=z[int(min_READ_CC[i])][i] |
|
245 | 267 | except: |
|
246 | 268 | bb[i]=numpy.nan |
|
247 | 269 | print("bb _ prom_ZDR",numpy.nanmean(bb)) |
|
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 |
|
254 | 351 | len_files = len(self.list_file) |
|
255 | 352 | SAVE_PARAM= [] |
|
256 | 353 | for thisFile in self.list_file: |
|
257 | 354 | count= count +1 |
|
258 | 355 | print("Count :", count) |
|
259 | 356 | fullpathfile = self.path_file + thisFile |
|
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] |
|
268 | 365 | if self.r_min==0: |
|
269 | 366 | self.r_min = 0.01 |
|
270 | 367 | new_heightList,minIndex,maxIndex = self.selectHeights(heightList,self.r_min,self.range) |
|
271 | 368 | # TIEMPO |
|
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 |
|
277 | x=numpy.linspace(1,len_X,len_X) | |
|
278 | y= new_heightList | |
|
279 | z=data_arr | |
|
280 | profile = numpy.mean(z,1) | |
|
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() | |
|
380 | x=numpy.linspace(1,len_X,len_X) | |
|
381 | y= new_heightList | |
|
382 | z=data_arr_ | |
|
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) |
|
284 | 388 | if self.type_ =="RTI": |
|
285 | 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 | 390 | if self.type_ =='roHV_MIN': |
|
287 | 391 | arr_= self.seleccion_roHV_min(count=count,z=z,y=y,arr_= 0) |
|
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) |
|
294 | 403 | if self.type_ =="PROFILE": |
|
295 | 404 | self. plot_PROFILE(count=count,z=z,y=y,my_time=my_time,label=label,mode=self.mode,grado=self.grado) |
|
296 | 405 | if self.type_ =='roHV_MIN': |
|
297 | 406 | arr_= self.seleccion_roHV_min(count=count,z=z,y=y,arr_= arr_) |
|
298 | 407 | if self.type_ =='pp_BB': |
|
299 | 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 | 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 |
|
303 | ||
|
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) | |
|
416 | ||
|
304 | 417 | if self.save == 1: |
|
305 | 418 | self.save_PIC(count=count,time_save=time_save) |
|
306 | 419 | plt.pause(1) |
|
307 | 420 | plt.clf() |
|
308 | 421 | if count == len_files: |
|
309 | 422 | if self.type_ =='roHV_MIN': |
|
310 |
numpy.save("/ |
|
|
423 | numpy.save("/media/soporte/DATA/soporte/WRJAN2023/schain/schainpy/scripts/index.npy",arr_) | |
|
311 | 424 | if self.type_ =='pp_BB': |
|
312 |
numpy.save("/ |
|
|
313 |
print("----- |
|
|
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() |
|
317 | 430 | |
|
318 | 431 | |
|
319 | 432 | def main(args): |
|
320 | 433 | grado = args.grado |
|
321 | 434 | parameters = args.parameters |
|
322 | 435 | r_min = args.r_min |
|
323 | 436 | save = args.save |
|
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 | |
|
343 | 463 | if __name__ == '__main__': |
|
344 | 464 | |
|
345 | 465 | parser = argparse.ArgumentParser(description='Script to process SOPHy data.') |
|
346 | 466 | parser.add_argument('--parameters', nargs='*', default=['S'], |
|
347 | 467 | help='Variables to process: P, Z, V ,W,D') |
|
348 | 468 | parser.add_argument('--grado', default=2, |
|
349 | 469 | help='Angle in Elev to plot') |
|
350 | 470 | parser.add_argument('--mode',default='PPI', |
|
351 | 471 | help='MODE PPI or RHI') |
|
352 | 472 | parser.add_argument('--save', default=0, |
|
353 | 473 | help='Save plot') |
|
354 | 474 | parser.add_argument('--range', default=0, type=float, |
|
355 | 475 | help='Max range to plot') |
|
356 | 476 | parser.add_argument('--r_min', default=0, type=float, |
|
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
You need to be logged in to leave comments.
Login now