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