##// END OF EJS Templates
test
avaldezp -
r1520:277c0ca243e2
parent child
Show More
@@ -1,217 +1,220
1 1 #!/usr/bin/env python
2 # Ing. AVP
3 # 22/06/2022
4 # ARCHIVO DE LECTURA y PLOT
2 5 import matplotlib.pyplot as pl
3 6 import matplotlib
4 7 import wradlib
5 8 import numpy
6 9 import warnings
7 10 import argparse
8 11 from wradlib.io import read_generic_hdf5
9 12 from wradlib.util import get_wradlib_data_file
10 13 from plotting_codes import sophy_cb_tables
11 14 import os,time
12 15
13 16 for name, cb_table in sophy_cb_tables:
14 17 ncmap = matplotlib.colors.ListedColormap(cb_table, name=name)
15 18 matplotlib.pyplot.register_cmap(cmap=ncmap)
16 19 #LINUX bash: export WRADLIB_DATA=/path/to/wradlib-data
17 20 warnings.filterwarnings('ignore')
18 21 PARAM = {
19 22 'S': {'var': 'power','vmin': -45, 'vmax': -15, 'cmap': 'jet', 'label': 'Power','unit': 'dBm'},
20 23 'V': {'var': 'velocity', 'vmin': -10, 'vmax': 10 , 'cmap': 'sophy_v', 'label': 'Velocity','unit': 'm/s'},
21 24 'Z': {'var': 'reflectivity','vmin': -30, 'vmax': 80 , 'cmap': 'sophy_r','label': 'Reflectivity','unit': 'dBZ'},
22 25 'W': {'var': 'spectral_width', 'vmin': 0 , 'vmax': 12 , 'cmap': 'sophy_w','label': 'Spectral Width','unit': 'hz'}
23 26 }
24 27 class Readsophy():
25 28 def __init__(self):
26 29 self.list_file = None
27 30 self.grado = None
28 31 self.variable = None
29 32 self.save = None
30 33 self.range = None
31 34
32 35 def read_files(self,path_file,grado=None, variable=None):
33 36 filter= "_E"+str(grado)+".0_"+variable
34 37 validFilelist = []
35 38 fileList= os.listdir(path_file)
36 39 for thisFile in fileList:
37 40 if (os.path.splitext(thisFile)[0][-7:] != filter):
38 41 #print("s_:",os.path.splitext(thisFile)[0][-7:])
39 42 continue
40 43 validFilelist.append(thisFile)
41 44 validFilelist.sort()
42 45 return validFilelist
43 46
44 47 def setup(self, path_file,grado,range,variable,save):
45 48 self.path_file = path_file
46 49 self.range = range
47 50 self.grado = grado
48 51 self.variable = variable
49 52 self.save = save
50 53 self.list_file = self.read_files(path_file=self.path_file,grado=self.grado, variable=self.variable)
51 54
52 55 def selectHeights(self,heightList,minHei,maxHei):
53 56
54 57 if minHei and maxHei:
55 58 if (minHei < heightList[0]):
56 59 minHei = heightList[0]
57 60 if (maxHei > heightList[-1]):
58 61 maxHei = heightList[-1]
59 62 minIndex = 0
60 63 maxIndex = 0
61 64 heights = heightList
62 65
63 66 inda = numpy.where(heights >= minHei)
64 67 indb = numpy.where(heights <= maxHei)
65 68
66 69 try:
67 70 minIndex = inda[0][0]
68 71 except:
69 72 minIndex = 0
70 73
71 74 try:
72 75 maxIndex = indb[0][-1]
73 76 except:
74 77 maxIndex = len(heights)
75 78
76 79 new_heightList= self.selectHeightsByIndex(heightList=heightList,minIndex=minIndex, maxIndex=maxIndex)
77 80
78 81 return new_heightList, minIndex,maxIndex
79 82
80 83 def selectHeightsByIndex(self,heightList,minIndex, maxIndex):
81 84
82 85 if (minIndex < 0) or (minIndex > maxIndex):
83 86 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
84 87
85 88 if (maxIndex >= len(heightList)):
86 89 maxIndex = len(heightList)
87 90
88 91 new_h = heightList[minIndex:maxIndex]
89 92 return new_h
90 93
91 94 def run(self):
92 95 count= 0
93 96 len_files = len(self.list_file)
94 97
95 98 for thisFile in self.list_file:
96 99 count = count +1
97 100 fullpathfile = self.path_file + thisFile
98 101 filename = get_wradlib_data_file(fullpathfile)
99 102 test_hdf5 = read_generic_hdf5(filename)
100 103
101 104 var = PARAM[self.variable]['var']
102 105 unit = PARAM[self.variable]['unit']
103 106 cmap = PARAM[self.variable]['cmap']
104 107 vmin = PARAM[self.variable]['vmin']
105 108 vmax = PARAM[self.variable]['vmax']
106 109 label = PARAM[self.variable]['label']
107 110 var_ = 'Data/'+var+'/H'
108 111 data_arr = numpy.array(test_hdf5[var_]['data']) # data
109 112 utc_time = numpy.array(test_hdf5['Data/time']['data'])
110 113 data_azi = numpy.array(test_hdf5['Metadata/azimuth']['data']) # th
111 114 data_ele = numpy.array(test_hdf5["Metadata/elevation"]['data'])
112 115 heightList = numpy.array(test_hdf5["Metadata/range"]['data']) # r
113 116
114 117 if self.range==0:
115 118 self.range == heightList[-1]
116 119 else:
117 120 print(self.range)
118 121 new_heightList,minIndex,maxIndex = self.selectHeights(heightList,0.06,self.range)
119 122
120 123
121 124 my_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(utc_time[0]))
122 125 time_save = time.strftime('%Y%m%d_%H%M%S',time.localtime(utc_time[0]))
123 126
124 127 # PLOT DATA WITH ANNOTATION
125 128 if count ==1:
126 129 fig = pl.figure(figsize=(10,8))
127 130 cgax, pm = wradlib.vis.plot_ppi(data_arr[:,minIndex:maxIndex],r=new_heightList,az=data_azi,rf=1,fig=fig, ax=111,proj='cg',cmap=cmap,vmin=vmin, vmax=vmax)
128 131 caax = cgax.parasites[0]
129 132 title = 'Simple PPI'+"-"+ my_time
130 133 t = pl.title(title, fontsize=12,y=1.05)
131 134 cbar = pl.gcf().colorbar(pm, pad=0.075)
132 135 pl.text(1.0, 1.05, 'azimuth', transform=caax.transAxes, va='bottom',ha='right')
133 136 cbar.set_label(label+'[' + unit + ']')
134 137 gh = cgax.get_grid_helper()
135 138 else:
136 139 cgax, pm = wradlib.vis.plot_ppi(data_arr[:,minIndex:maxIndex],r=new_heightList,az=data_azi,rf=1,fig=fig, ax=111,proj='cg',cmap=cmap,vmin=vmin, vmax=vmax)
137 140 caax = cgax.parasites[0]
138 141 title = 'Simple PPI'+"-"+my_time
139 142 t = pl.title(title, fontsize=12,y=1.05)
140 143 cbar = pl.gcf().colorbar(pm, pad=0.075)
141 144 pl.text(1.0, 1.05, 'azimuth', transform=caax.transAxes, va='bottom',ha='right')
142 145 cbar.set_label(label+'[' + unit + ']')
143 146 gh = cgax.get_grid_helper()
144 147 if self.save == 1:
145 148 if count ==1:
146 149 filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+".png"
147 150 dir =self.variable+"_"+"E."+self.grado+"CH0/"
148 151 filesavepath = os.path.join(self.path_file,dir)
149 152 try:
150 153 os.mkdir(filesavepath)
151 154 except:
152 155 pass
153 156 else:
154 157 filename = "SOPHY"+"_"+time_save+"_"+"E."+self.grado+"_"+self.variable+".png"
155 158 pl.savefig(filesavepath+filename)
156 159
157 160 pl.pause(1)
158 161 pl.clf()
159 162 if count==len_files:
160 163 pl.close()
161 164 pl.show()
162 165
163 166 PATH = "/home/soporte/Documents/EVENTO/HYO_PM@2022-06-09T15-05-12/paramC0N36.0/2022-06-09T18-00-00/"
164 167 PATH = "/home/soporte/Documents/EVENTO/HYO_PM@2022-06-09T15-05-12/paramC0N36.0/2022-06-09T19-00-00/"
165 168
166 169 #PATH = "/home/soporte/Documents/EVENTO/HYO_PM@2022-05-31T12-00-17/paramC0N36.0/2022-05-31T16-00-00/"
167 170
168 171 def main(args):
169 172 grado = args.grado
170 173 parameters = args.parameters
171 174 save = args.save
172 175 range = args.range
173 176 obj = Readsophy()
174 177 for param in parameters:
175 178 obj.setup(path_file = PATH,grado = grado,range=range, variable=param,save=int(save))
176 179 obj.run()
177 180
178 181 if __name__ == '__main__':
179 182
180 183 parser = argparse.ArgumentParser(description='Script to process SOPHy data.')
181 184 parser.add_argument('--parameters', nargs='*', default=['S'],
182 185 help='Variables to process: P, Z, V ,W')
183 186 parser.add_argument('--grado', default=2,
184 187 help='Angle in Elev to plot')
185 188 parser.add_argument('--save', default=0,
186 189 help='Save plot')
187 190 parser.add_argument('--range', default=0, type=float,
188 191 help='Max range to plot')
189 192 args = parser.parse_args()
190 193
191 194 main(args)
192 195
193 196 #python sophy_proc_rev006.py --parameters Z --grado 8 --save 1 --range 28
194 197 '''
195 198 def read_and_overview(filename):
196 199 """Read HDF5 using read_generic_hdf5 and print upper level dictionary keys
197 200 """
198 201 test = read_generic_hdf5(filename)
199 202 print("\nPrint keys for file %s" % os.path.basename(filename))
200 203 for key in test.keys():
201 204 print("\t%s" % key)
202 205 return test
203 206
204 207 file__ = "/home/soporte/Documents/EVENTO/HYO_PM@2022-06-09T15-05-12/paramC0_FD_PL_R15.0km/2022-06-09T18-00-00/SOPHY_20220609_180229_E2.0_Z.hdf5"
205 208
206 209
207 210 filename = get_wradlib_data_file(file__)
208 211
209 212 print("filename:\n",filename )
210 213
211 214 test= read_and_overview(filename)
212 215 # ANADIR INFORMACION
213 216 # informacion de los pulsos de TX
214 217 # informacion de los ruidos
215 218 # informacion de los SNR ¿?
216 219 # Aumentar la amplitud de la USRP
217 220 '''
General Comments 0
You need to be logged in to leave comments. Login now