##// END OF EJS Templates
Add new colormaps for sophy
Juan C. Espinoza -
r1563:dfed7990a42c
parent child
Show More
@@ -20,7 +20,7 import matplotlib,re
20 if 'BACKEND' in os.environ:
20 if 'BACKEND' in os.environ:
21 matplotlib.use(os.environ['BACKEND'])
21 matplotlib.use(os.environ['BACKEND'])
22 elif 'linux' in sys.platform:
22 elif 'linux' in sys.platform:
23 matplotlib.use("Agg")
23 matplotlib.use("TkAgg")
24 elif 'darwin' in sys.platform:
24 elif 'darwin' in sys.platform:
25 matplotlib.use('MacOSX')
25 matplotlib.use('MacOSX')
26 else:
26 else:
@@ -33,18 +33,17 from matplotlib.patches import Polygon
33 from mpl_toolkits.axes_grid1 import make_axes_locatable
33 from mpl_toolkits.axes_grid1 import make_axes_locatable
34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
35
35
36 from .plotting_codes import *
36 from .plotting_codes import register_cmap
37
37
38 from schainpy.model.data.jrodata import PlotterData
38 from schainpy.model.data.jrodata import PlotterData
39 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
39 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
40 from schainpy.utils import log
40 from schainpy.utils import log
41
41
42 for name, cb_table in sophy_cb_tables:
43 ncmap = matplotlib.colors.ListedColormap(cb_table, name=name)
44 matplotlib.pyplot.register_cmap(cmap=ncmap)
45
42
46 EARTH_RADIUS = 6.3710e3
43 EARTH_RADIUS = 6.3710e3
47
44
45 register_cmap()
46
48 def ll2xy(lat1, lon1, lat2, lon2):
47 def ll2xy(lat1, lon1, lat2, lon2):
49
48
50 p = 0.017453292519943295
49 p = 0.017453292519943295
@@ -293,7 +292,7 class Plot(Operation):
293 fig_p = plt.figure(figsize=(self.width, self.height),
292 fig_p = plt.figure(figsize=(self.width, self.height),
294 edgecolor='k',
293 edgecolor='k',
295 facecolor='w')
294 facecolor='w')
296 fig_r = plt.figure(figsize=(self.width, self.height),
295 fig_r = plt.figure(figsize=(self.width, 4),
297 edgecolor='k',
296 edgecolor='k',
298 facecolor='w')
297 facecolor='w')
299 self.figures['PPI'].append(fig_p)
298 self.figures['PPI'].append(fig_p)
@@ -342,13 +341,13 class Plot(Operation):
342 cax.tick_params(labelsize=8)
341 cax.tick_params(labelsize=8)
343 self.pf_axes.append(cax)
342 self.pf_axes.append(cax)
344
343
345 for n in range(self.nrows):
344 # for n in range(self.nrows):
346 if self.colormaps is not None:
345 # if self.colormaps is not None:
347 cmap = plt.get_cmap(self.colormaps[n])
346 # cmap = plt.get_cmap(self.colormaps[n])
348 else:
347 # else:
349 cmap = plt.get_cmap(self.colormap)
348 # cmap = plt.get_cmap(self.colormap)
350 cmap.set_bad(self.bgcolor, 1.)
349 # cmap.set_bad(self.bgcolor, 1.)
351 self.cmaps.append(cmap)
350 # self.cmaps.append(cmap)
352
351
353 def __add_axes(self, ax, size='30%', pad='8%'):
352 def __add_axes(self, ax, size='30%', pad='8%'):
354 '''
353 '''
@@ -431,6 +430,8 class Plot(Operation):
431 if self.colorbar:
430 if self.colorbar:
432 ax.cbar = plt.colorbar(
431 ax.cbar = plt.colorbar(
433 ax.plt, ax=ax, fraction=0.05, pad=0.06, aspect=10)
432 ax.plt, ax=ax, fraction=0.05, pad=0.06, aspect=10)
433 if self.colormap=='sophy_r':
434 ax.cbar.set_ticks([0.2, 0.73, 0.83, 0.93, 0.96, 0.99, 1.02, 1.05])
434 ax.cbar.ax.tick_params(labelsize=8)
435 ax.cbar.ax.tick_params(labelsize=8)
435 ax.cbar.ax.press = None
436 ax.cbar.ax.press = None
436 if self.cb_label:
437 if self.cb_label:
@@ -11,6 +11,7 import cartopy.io.shapereader as shpreader
11 from schainpy.model.graphics.jroplot_base import Plot, plt
11 from schainpy.model.graphics.jroplot_base import Plot, plt
12 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
12 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
13 from schainpy.utils import log
13 from schainpy.utils import log
14 from schainpy.model.graphics.plotting_codes import cb_tables
14
15
15
16
16 EARTH_RADIUS = 6.3710e3
17 EARTH_RADIUS = 6.3710e3
@@ -525,8 +526,8 class WeatherParamsPlot(Plot):
525 self.ncols = 1
526 self.ncols = 1
526 self.nrows = 1
527 self.nrows = 1
527 self.nplots= 1
528 self.nplots= 1
528 self.ylabel= 'Range [km]'
529 self.ylabel= 'Height [km]'
529 self.xlabel= 'Range [km]'
530 self.xlabel= 'Distance from radar [km]'
530
531
531 if self.channels is not None:
532 if self.channels is not None:
532 self.nplots = len(self.channels)
533 self.nplots = len(self.channels)
@@ -546,7 +547,7 class WeatherParamsPlot(Plot):
546 self.len_azi =0
547 self.len_azi =0
547 self.buffer_ini = None
548 self.buffer_ini = None
548 self.buffer_ele = None
549 self.buffer_ele = None
549 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
550 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.1})
550 self.flag =0
551 self.flag =0
551 self.indicador= 0
552 self.indicador= 0
552 self.last_data_ele = None
553 self.last_data_ele = None
@@ -649,11 +650,19 class WeatherParamsPlot(Plot):
649 else:
650 else:
650 axes = self.axes['RHI']
651 axes = self.axes['RHI']
651
652
653 if self.colormap in cb_tables:
654 norm = cb_tables[self.colormap]['norm']
655 else:
656 norm = None
657
652 for i, ax in enumerate(axes):
658 for i, ax in enumerate(axes):
653 if data['mode_op'] == 'PPI':
659 if data['mode_op'] == 'PPI':
654 ax.set_extent([-75.745893, -74.845893, -12.490436, -11.590436])
660 ax.set_extent([-75.745893, -74.845893, -12.490436, -11.590436])
655
661
656 ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
662 if norm is None:
663 ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
664 else:
665 ax.plt = ax.pcolormesh(x, y, z[i], cmap=self.colormap, norm=norm)
657
666
658 if data['mode_op'] == 'RHI':
667 if data['mode_op'] == 'RHI':
659 len_aux = int(data['azi'].shape[0]/4)
668 len_aux = int(data['azi'].shape[0]/4)
@@ -691,7 +700,7 class WeatherParamsPlot(Plot):
691 provs = [x for x in reader_p.records() if x.attributes["NAME"] in ("JunΓ­n", "Lima")]
700 provs = [x for x in reader_p.records() if x.attributes["NAME"] in ("JunΓ­n", "Lima")]
692 vias = [x for x in reader_v.records() if x.attributes["DEP"] in ("JUNIN", "LIMA")]
701 vias = [x for x in reader_v.records() if x.attributes["DEP"] in ("JUNIN", "LIMA")]
693
702
694 # Display Kenya's shape
703 # Display limits and streets
695 shape_feature = ShapelyFeature([x.geometry for x in districts], ccrs.PlateCarree(), facecolor="none", edgecolor='grey', lw=0.5)
704 shape_feature = ShapelyFeature([x.geometry for x in districts], ccrs.PlateCarree(), facecolor="none", edgecolor='grey', lw=0.5)
696 ax.add_feature(shape_feature)
705 ax.add_feature(shape_feature)
697 shape_feature = ShapelyFeature([x.geometry for x in provs], ccrs.PlateCarree(), facecolor="none", edgecolor='white', lw=1)
706 shape_feature = ShapelyFeature([x.geometry for x in provs], ccrs.PlateCarree(), facecolor="none", edgecolor='white', lw=1)
@@ -1,6 +1,9
1 '''
1 '''
2 @author: roj-idl71
2 @author: roj-idl71
3 '''
3 '''
4
5 import matplotlib
6
4 #USED IN jroplot_spectra.py
7 #USED IN jroplot_spectra.py
5 RTI_CODE = 0 #Range time intensity (RTI).
8 RTI_CODE = 0 #Range time intensity (RTI).
6 SPEC_CODE = 1 #Spectra (and Cross-spectra) information.
9 SPEC_CODE = 1 #Spectra (and Cross-spectra) information.
@@ -30,48 +33,81 EWDRIFT_CODE = 28
30
33
31 #COLOR TABLES
34 #COLOR TABLES
32
35
33 reflectivity = [
36 refl = [
34 "#000000", # -30
37 "#2a323b", "#3f4c59", "#556576", "#6a7f94", "#7f99b2",
35 "#15191d", # -25
38 "#00ffff", "#007fff", "#0000ff", "#00ff00", "#00bf00",
36 "#2a323b", # -20
39 "#007f00", "#ffff00", "#ffbf00", "#ff7f00", "#ff0000",
37 "#3f4c59", # -15
40 "#bf0000", "#7f0000", "#fe00fe", "#8e59ff", "#f0f0f0",
38 "#556576", # -10
39 "#6a7f94", # -5
40 "#7f99b2", # 0
41 "#00ffff", # 5
42 "#007fff", # 10
43 "#0000ff", # 15
44 "#00ff00", # 20
45 "#00bf00", # 25
46 "#007f00", # 30
47 "#ffff00", # 35
48 "#ffbf00", # 40
49 "#ff7f00", # 45
50 "#ff0000", # 50
51 "#bf0000", # 55
52 "#7f0000", # 60
53 "#fe00fe", # 65
54 "#8e59ff", # 70
55 "#f0f0f0", # 75
56 ]
41 ]
57
42
58 velocity = [
43 refl_bounds = [-20, -15, -10, -5, 0, 5, 10 ,15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]
44
45 doppler = [
59 "#003300", "#005500", "#007700", "#009900", "#00bb00", "#24ce24", "#6cd26c", "#b4d6b4",
46 "#003300", "#005500", "#007700", "#009900", "#00bb00", "#24ce24", "#6cd26c", "#b4d6b4",
60 "#d6b4b4", "#d26c6c", "#ce2424", "#bb0000", "#980000", "#760000", "#540000", "#330000",
47 "#d6b4b4", "#d26c6c", "#ce2424", "#bb0000", "#980000", "#760000", "#540000", "#330000",
61 ]
48 ]
62
49
63 spc_width = [
50 width = [
64 "#00ffff", "#00aaf2", "#0055e5", "#0000d8",
51 "#00ffff", "#00aaf2", "#0055e5", "#0000d8",
65 "#007f00", "#00aa00", "#00d400", "#00ff00",
52 "#007f00", "#00aa00", "#00d400", "#00ff00",
66 "#ffff00", "#ffd400", "#ffaa00", "#ff7f00",
53 "#ffff00", "#ffd400", "#ffaa00", "#ff7f00",
67 "#ff0000", "#d40000", "#aa0000", "#7f0000",
54 "#ff0000", "#d40000", "#aa0000", "#7f0000",
68 "#ff00ff", "#d400d4", "#aa00aa", "#7f007f",
55 "#ff00ff", "#d400d4", "#aa00aa", "#7f007f",
69 "#9938ff", "#832ed8", "#6e25b2", "#591c8c",
56 "#9938ff", "#832ed8", "#6e25b2", "#591c8c",
70 "#aaaaaa", "#8e8e8e"
71 ]
57 ]
72
58
73 sophy_cb_tables = [
59 zdr = [
74 ('sophy_r', reflectivity),
60 "#7333cc", "#7e3cd5", "#8945de", "#944ee7", "#9f57f0", "#aa5ff8",
75 ('sophy_v', velocity),
61 "#82345c", "#984272", "#ae4f88", "#c55c9f", "#db6ab5", "#db6ab5",
76 ('sophy_w', spc_width),
62 "#b5842d", "#c29a4c", "#d0b16b", "#ddc78a", "#ebddaa", "#f8f4c9",
77 ] No newline at end of file
63 "#f0f5ff", "#c4d8ff", "#97bbff", "#6a9eff", "#3e81ff", "#1164ff",
64 "#17f576", "#13df60", "#0ec949", "#0ab233", "#059c1d", "#018606",
65 "#fff300", "#ffdd00", "#ffc700", "#ffb000", "#ff9a00", "#ff8400",
66 "#f10000", "#db0000", "#c40000", "#ae0000", "#980000", "#810000",
67 ]
68
69 phi = [
70 "#ff3f40", "#ec3b6d", "#bf2f7e", "#92247c", "#7b1f7f", "#732492", "#782fbf", "#6f3bec",
71 "#513fff", "#3b4bec", "#2f57bf", "#245592", "#1f5a7f", "#247992", "#2fb4bf", "#3bece0",
72 "#3fffd8", "#3becb1", "#2fbf7d", "#249253", "#1f7f3d", "#24923b", "#2fbf3e", "#3bec3b",
73 "#50ff3f", "#5aec3b", "#55bf2f", "#4a9224", "#487f1f", "#5a9224", "#80bf2f", "#aaec3b",
74 "#c4ff3f", "#c0ec3b", "#a4bf2f", "#839224", "#777f1f", "#8e9224", "#bfbc2f", "#ece03b",
75 "#ffea3f", "#ecd13b", "#bfa42f", "#927924", "#7f661f", "#927124", "#bf8f2f", "#ecac3b",
76 "#ffb43f", "#eca23b", "#bf7f2f", "#925e24", "#7f501f", "#925924", "#bf712f", "#ec883b",
77 "#ff8f3f", "#ec813b", "#bf662f", "#924c24", "#7f401f", "#924824", "#bf5c2f", "#ec6f3b",
78 ]
79
80 rho = [
81 "#2a323b", "#3f4c59", "#556576", "#6a7f94", "#7f99b2",
82 "#00ffff", "#00bff5", "#007feb", "#003fe2", "#0000d8",
83 "#00ff00", "#00df00", "#00bf00", "#009f00", "#007f00",
84 "#ffff00", "#ffdf00", "#ffbf00", "#ff9f00", "#ff7f00",
85 "#ff0000", "#df0000", "#bf0000", "#9f0000", "#7f0000",
86 "#ff00ff", "#df00df", "#bf00bf", "#9f009f", "#7f007f",
87 "#9938ff", "#8931e2", "#792ac5", "#6923a8", "#591c8c",
88 ]
89
90 rho_bounds = [0.2, 0.306, 0.412, 0.518, 0.624, 0.73,
91 0.75, 0.77, 0.79, 0.81, 0.83,
92 0.85, 0.87, 0.89, 0.91, 0.93,
93 0.936, 0.942, 0.948, 0.954, 0.96,
94 0.966, 0.972, 0.978, 0.984, 0.99,
95 0.996, 1.002, 1.008, 1.014, 1.02,
96 1.026, 1.032, 1.038, 1.044, 1.05, 1.056]
97
98 cb_tables = {
99 'sophy_z': {'colors': refl, 'norm': None },
100 'sophy_v': {'colors': doppler, 'norm': None },
101 'sophy_w': {'colors': width, 'norm': None },
102 'sophy_d': {'colors': zdr, 'norm': None },
103 'sophy_p': {'colors': phi, 'norm': None },
104 'sophy_r': {'colors': rho, 'norm': matplotlib.colors.BoundaryNorm(rho_bounds, 37), 'extremes': ['#15191d', '#333899']},
105 }
106
107 def register_cmap():
108
109 for colormap in cb_tables:
110 cmap = matplotlib.colors.ListedColormap(cb_tables[colormap]['colors'], name=colormap)
111 if 'extremes' in cb_tables[colormap]:
112 cmap = cmap.with_extremes(under=cb_tables[colormap]['extremes'][0], over=cb_tables[colormap]['extremes'][1])
113 matplotlib.pyplot.register_cmap(cmap=cmap)
@@ -4027,12 +4027,8 class WeatherRadar(Operation):
4027
4027
4028 Pr = dataOut.data_param[:,0,:]
4028 Pr = dataOut.data_param[:,0,:]
4029 '''---------------------------- Calculo de Noise y threshold para Reflectividad---------'''
4029 '''---------------------------- Calculo de Noise y threshold para Reflectividad---------'''
4030 # noise = numpy.zeros(self.nCh)
4030
4031 # for i in range(self.nCh):
4031 Pr = Pr/1000.0 # Conversion Watt
4032 # noise[i] = hildebrand_sekhon(Pr[i,:], 1)
4033 # window = numpy.where(Pr[i,:]<1.3*noise[i])
4034 # Pr[i,window]= 1e-10
4035 Pr = Pr/1000.0 # Conversion Watt
4036 '''-----------2 Reflectividad del Radar y Factor de Reflectividad------'''
4032 '''-----------2 Reflectividad del Radar y Factor de Reflectividad------'''
4037 self.n_radar = numpy.zeros((self.nCh,self.nHeis))
4033 self.n_radar = numpy.zeros((self.nCh,self.nHeis))
4038 self.Z_radar = numpy.zeros((self.nCh,self.nHeis))
4034 self.Z_radar = numpy.zeros((self.nCh,self.nHeis))
@@ -4044,12 +4040,7 class WeatherRadar(Operation):
4044
4040
4045 '''----------- Factor de Reflectividad Equivalente lamda_ < 10 cm , lamda_= 3.2cm-------'''
4041 '''----------- Factor de Reflectividad Equivalente lamda_ < 10 cm , lamda_= 3.2cm-------'''
4046 Zeh = self.Z_radar
4042 Zeh = self.Z_radar
4047 #print("---------------------------------------------------------------------")
4043
4048 #print("RangedBz",10*numpy.log10((self.Range[0,-10:]*(10**3))**2))
4049 #print("CTE",10*numpy.log10(self.RadarConstant))
4050 #print("Pr first10",10*numpy.log10(Pr[0,:20]))
4051 #print("Pr last10",10*numpy.log10(Pr[0,-20:]))
4052 #print("LCTE",10*numpy.log10(self.lambda_**4/( numpy.pi**5 * self.Km**2)))
4053 if self.Pt<0.3:
4044 if self.Pt<0.3:
4054 factor=10.072
4045 factor=10.072
4055 else:
4046 else:
@@ -4164,45 +4155,6 class PedestalInformation(Operation):
4164 log.error('No new position files found in {}'.format(path))
4155 log.error('No new position files found in {}'.format(path))
4165 raise IOError('No new position files found in {}'.format(path))
4156 raise IOError('No new position files found in {}'.format(path))
4166
4157
4167
4168 def find_mode(self, index):
4169 sample_max = 20
4170 start = index
4171 flag_mode = None
4172
4173 while True:
4174 print(start, sample_max, numpy.shape(self.ele))
4175 if start+sample_max > numpy.shape(self.ele)[0]:
4176 if sample_max == 10:
4177 print("CANNOT KNOW IF MODE IS PPI OR RHI, ANALIZE NEXT FILE")
4178 break
4179 else:
4180 sample_max = 10
4181 continue
4182 sigma_ele = numpy.nanstd(self.ele[start:start+sample_max])
4183 sigma_azi = numpy.nanstd(self.azi[start:start+sample_max])
4184 print("ele",self.ele[start-sample_max:start+sample_max])
4185 print("azi",self.azi[start-sample_max:start+sample_max])
4186 print(sigma_azi, sigma_ele)
4187
4188 if sigma_ele<.5 and sigma_azi<.5:
4189 if sigma_ele<sigma_azi:
4190 flag_mode = 'PPI'
4191 break
4192 else:
4193 flag_mode = 'RHI'
4194 break
4195 elif sigma_ele < .5:
4196 flag_mode = 'PPI'
4197 break
4198 elif sigma_azi < .5:
4199 flag_mode = 'RHI'
4200 break
4201
4202 start += sample_max
4203
4204 return flag_mode
4205
4206 def get_values(self):
4158 def get_values(self):
4207
4159
4208 if self.flagNoData:
4160 if self.flagNoData:
@@ -4210,22 +4162,10 class PedestalInformation(Operation):
4210 else:
4162 else:
4211 index = int((self.utctime-self.utcfile)/self.interval)
4163 index = int((self.utctime-self.utcfile)/self.interval)
4212 try:
4164 try:
4213 #print( self.azi[index], self.ele[index], None)
4214 return self.azi[index], self.ele[index], None
4165 return self.azi[index], self.ele[index], None
4215 except:
4166 except:
4216 return numpy.nan, numpy.nan, numpy.nan
4167 return numpy.nan, numpy.nan, numpy.nan
4217
4168
4218 if self.flagAskMode:
4219 mode = self.find_mode(index)
4220 print('MODE: ', mode)
4221 else:
4222 mode = self.mode
4223
4224 if mode is not None:
4225 return self.azi[index], self.ele[index], mode
4226 else:
4227 return numpy.nan, numpy.nan, numpy.nan
4228
4229 def setup(self, dataOut, path, conf, samples, interval, mode):
4169 def setup(self, dataOut, path, conf, samples, interval, mode):
4230
4170
4231 self.path = path
4171 self.path = path
@@ -4294,8 +4234,6 class Block360(Operation):
4294 __buffer = None
4234 __buffer = None
4295 __dataReady = False
4235 __dataReady = False
4296 n = None
4236 n = None
4297 __nch = 0
4298 __nHeis = 0
4299 index = 0
4237 index = 0
4300 mode = None
4238 mode = None
4301
4239
@@ -4311,11 +4249,7 class Block360(Operation):
4311 self.__dataReady = False
4249 self.__dataReady = False
4312 self.__buffer = 0
4250 self.__buffer = 0
4313 self.index = 0
4251 self.index = 0
4314 self.__nch = dataOut.nChannels
4315 self.__nHeis = dataOut.nHeights
4316
4317 self.attr = attr
4252 self.attr = attr
4318
4319 self.__buffer = []
4253 self.__buffer = []
4320 self.azi = []
4254 self.azi = []
4321 self.ele = []
4255 self.ele = []
General Comments 0
You need to be logged in to leave comments. Login now