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