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