def scatter_off_2dvd_packed(dicc): def drop_ar(D_eq): if D_eq < 0.7: return 1.0 elif D_eq < 1.5: return 1.173 - 0.5165*D_eq + 0.4698*D_eq**2 - 0.1317*D_eq**3 - \ 8.5e-3*D_eq**4 else: return 1.065 - 6.25e-2*D_eq - 3.99e-3*D_eq**2 + 7.66e-4*D_eq**3 - \ 4.095e-5*D_eq**4 d_diameters = dicc['1'] d_densities = dicc['2'] mypds = interpolate.interp1d(d_diameters, d_densities, bounds_error=False, fill_value=0.0) scatterer = Scatterer(wavelength=tmatrix_aux.wl_C, m=refractive.m_w_10C[tmatrix_aux.wl_C]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / drop_ar(D) scatterer.psd_integrator.D_max = 10.0 scatterer.psd_integrator.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(20.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) scatterer.psd = mypds # GammaPSD(D0=2.0, Nw=1e3, mu=4) radar.refl(scatterer) zdr = radar.Zdr(scatterer) z = radar.refl(scatterer) scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) kdp = radar.Kdp(scatterer) A = radar.Ai(scatterer) return z, zdr, kdp, A
def cal_tm4(n0,lamda,u,scatterer): rain_zdr=[] rain_zv=[] rain_ldr=[] rain_rhv=[] rain_zh=[] length=len(n0) for i in range(length): scatterer.psd=UnnormalizedGammaPSD(N0=n0[i],Lambda=lamda[i],mu=u) rain_zh.append(radar.refl(scatterer)) rain_zdr.append(radar.Zdr(scatterer)) rain_zv.append(radar.refl(scatterer,h_pol=False)) rain_ldr.append(radar.ldr(scatterer)) rain_rhv.append(radar.rho_hv(scatterer)) if i%1000==0: print '\r|'+'='*(50*i/length)+' '*(50-50*i/length)+'|'+'%1.2f%%' %(100.0*i/length), print ' ' rain_zh = np.array(rain_zh) rain_zdr = np.array(rain_zdr) rain_zv = np.array(rain_zv) rain_ldr = np.array(rain_ldr) rain_rhv = np.array(rain_rhv) return rain_zh,rain_zdr,rain_zv,rain_ldr,rain_rhv
def tmatrix(self, wl, pluvio_filter=True, pip_filter=False, density=None): """Calculate radar reflectivity at requested wavelength wl [mm] using T-matrix""" name = switch_wl(wl) + "reflTM" if density is None: density = self.density(pluvio_filter=pluvio_filter, pip_filter=pip_filter) z_serie = pd.Series(density) dBin = self.instr['dsd'].bin_width() edges = self.instr['dsd'].bin_cen() + 0.5 * dBin grp = self.instr['dsd'].grouped(rule=self.rule, varinterval=self.varinterval, col=self.dsd.bin_cen()) psd_values = grp.mean() for item in density.iteritems(): if item[1] > 0.0: ref = refractive.mi(wl, 0.001 * item[1]) print(ref) flake = tmatrix.Scatterer(wavelength=wl, m=ref, axis_ratio=1.0 / 1.0) flake.psd_integrator = psd.PSDIntegrator() flake.psd_integrator.D_max = 35.0 flake.psd = psd.BinnedPSD( bin_edges=edges, bin_psd=psd_values.loc[item[0]].values) flake.psd_integrator.init_scatter_table(flake) Z = 10.0 * np.log10(radar.refl(flake)) else: Z = np.nan z_serie.loc[item[0]] = Z z_serie.name = name return z_serie
def calculate_radar_parameters(self, wavelength=tmatrix_aux.wl_X): ''' Calculates radar parameters for the Drop Size Distribution. Calculates the radar parameters and stores them in the object. Defaults to X-Band,Beard and Chuang 10C setup. Sets the dictionary parameters in fields dictionary: Zh, Zdr, Kdp, Ai(Attenuation) Parameters: ---------- wavelength = pytmatrix supported wavelength. ''' self._setup_scattering(wavelength) self._setup_empty_fields() for t in range(0, len(self.time)): BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges, self.Nd[t]) self.scatterer.psd = BinnedDSD self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back) self.fields['Zh']['data'][t] = 10 * \ np.log10(radar.refl(self.scatterer)) self.fields['Zdr']['data'][t] = 10 * \ np.log10(radar.Zdr(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) self.fields['Kdp']['data'][t] = radar.Kdp(self.scatterer) self.fields['Ai']['data'][t] = radar.Ai(self.scatterer) self.fields['Ad']['data'][t] = radar.Ai(self.scatterer) -radar.Ai(self.scatterer, h_pol=False)
def tmatrix(self, wl, pluvio_filter=True, pip_filter=False, density=None): """Calculate radar reflectivity at requested wavelength wl [mm] using T-matrix""" name = switch_wl(wl) + "reflTM" if density is None: density = self.density(pluvio_filter=pluvio_filter, pip_filter=pip_filter) z_serie = pd.Series(density) dBin = self.instr['dsd'].bin_width() edges = d_corr_pip(self.instr['dsd'].bin_cen())+0.5*dBin grp = self.instr['dsd'].grouped(rule=self.rule, varinterval=self.varinterval, col=self.dsd.bin_cen()) psd_values = grp.mean() for item in density.iteritems(): if item[1] > 0.0: ref = refractive.mi(wl, 0.001*item[1]) print(ref) flake = tmatrix.Scatterer(wavelength=wl, m=ref, axis_ratio=1.0/1.0) flake.psd_integrator = psd.PSDIntegrator() flake.psd_integrator.D_max = 35.0 flake.psd = psd.BinnedPSD(bin_edges=edges, bin_psd=psd_values.loc[item[0]].values) flake.psd_integrator.init_scatter_table(flake) Z = 10.0*np.log10(radar.refl(flake)) else: Z = np.nan z_serie.loc[item[0]] = Z z_serie.name = name return z_serie
def get_radar_variables_cloudPSD(N0=None, Lambda=None, D_max=None): scatterer.psd = NEWhybridPSD(N0=N0, Lambda=Lambda, D_max=D_max) #return [10.*np.log10(radar.refl(scatterer)), 10.*np.log10(radar.Zdr(scatterer)), radar.Kdp(scatterer), radar.Ai(scatterer)] return [ 10. * np.log10(radar.refl(scatterer)), 10. * np.log10(radar.Zdr(scatterer)) ]
def get_radar_variables_unnormalizedGamma(N0=None, Lambda=None, mu=None, D_max=None): scatterer.psd = psd.UnnormalizedGammaPSD(N0=N0, Lambda=Lambda, mu=mu, D_max=D_max) return [radar.refl(scatterer), radar.Zdr(scatterer), radar.ldr(scatterer)]
def calculate_radar_parameters(self, dsr_func = DSR.bc, scatter_time_range = None ): ''' Calculates radar parameters for the Drop Size Distribution. Calculates the radar parameters and stores them in the object. Defaults to X-Band,Beard and Chuang 10C setup. Sets the dictionary parameters in fields dictionary: Zh, Zdr, Kdp, Ai(Attenuation) Parameters: ---------- wavelength: optional, pytmatrix wavelength Wavelength to calculate scattering coefficients at. dsr_func: optional, function Drop Shape Relationship function. Several are availab le in the `DSR` module. Defaults to Beard and Chuang scatter_time_range: optional, tuple Parameter to restrict the scattering to a time interval. The first element is the start time, while the second is the end time. ''' self._setup_scattering(SPEED_OF_LIGHT/self.scattering_freq*1000.0, dsr_func) self._setup_empty_fields() if scatter_time_range is None: self.scatter_start_time = 0 self.scatter_end_time = self.numt else: if scatter_time_range[0] < 0: print("Invalid Start time specified, aborting") return self.scatter_start_time = scatter_time_range[0] self.scatter_end_time = scatter_time_range[1] if scatter_time_range[1] > self.numt: print("End of Scatter time is greater than end of file. Scattering to end of included time.") self.scatter_end_time = self.numt self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back) # We break up scattering to avoid regenerating table. for t in range(self.scatter_start_time, self.scatter_end_time): if np.sum(self.Nd['data'][t]) is 0: continue BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges['data'], self.Nd['data'][t]) self.scatterer.psd = BinnedDSD self.fields['Zh']['data'][t] = 10 * \ np.log10(radar.refl(self.scatterer)) self.fields['Zdr']['data'][t] = 10 * \ np.log10(radar.Zdr(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) for t in range(self.scatter_start_time, self.scatter_end_time): BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges['data'], self.Nd['data'][t]) self.scatterer.psd = BinnedDSD self.fields['Kdp']['data'][t] = radar.Kdp(self.scatterer) self.fields['Ai']['data'][t] = radar.Ai(self.scatterer) self.fields['Adr']['data'][t] = radar.Ai(self.scatterer) -radar.Ai(self.scatterer, h_pol=False)
def test_radar(self): """Test that the radar properties are computed correctly """ tm = TMatrixPSD(lam=tmatrix_aux.wl_C, m=refractive.m_w_10C[tmatrix_aux.wl_C], suppress_warning=True) tm.psd = psd.GammaPSD(D0=2.0, Nw=1e3, mu=4) tm.psd_eps_func = lambda D: 1.0 / drop_ar(D) tm.D_max = 10.0 tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_fixed tm.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) tm.init_scatter_table() radar_xsect_h = radar.radar_xsect(tm) Z_h = radar.refl(tm) Z_v = radar.refl(tm, False) ldr = radar.ldr(tm) Zdr = radar.Zdr(tm) delta_hv = radar.delta_hv(tm) rho_hv = radar.rho_hv(tm) tm.set_geometry(tmatrix_aux.geom_horiz_forw) Kdp = radar.Kdp(tm) A_h = radar.Ai(tm) A_v = radar.Ai(tm, False) radar_xsect_h_ref = 0.22176446239750278 Z_h_ref = 6383.7337897299258 Z_v_ref = 5066.721040036321 ldr_ref = 0.0021960626647629547 Zdr_ref = 1.2599339374097778 delta_hv_ref = -0.00021227778705544846 rho_hv_ref = 0.99603080460983828 Kdp_ref = 0.19334678024367824 A_h_ref = 0.018923976733777458 A_v_ref = 0.016366340549483317 for (val, ref) in zip( (radar_xsect_h, Z_h, Z_v, ldr, Zdr, delta_hv, rho_hv, Kdp, A_h, A_v), (radar_xsect_h_ref, Z_h_ref, Z_v_ref, ldr_ref, Zdr_ref, delta_hv_ref, rho_hv_ref, Kdp_ref, A_h_ref, A_v_ref)): test_relative(self, val, ref)
def test_radar(self): """Test that the radar properties are computed correctly """ tm = TMatrixPSD(lam=tmatrix_aux.wl_C, m=refractive.m_w_10C[tmatrix_aux.wl_C], suppress_warning=True) tm.psd = psd.GammaPSD(D0=2.0, Nw=1e3, mu=4) tm.psd_eps_func = lambda D: 1.0/drop_ar(D) tm.D_max = 10.0 tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_fixed tm.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) tm.init_scatter_table() radar_xsect_h = radar.radar_xsect(tm) Z_h = radar.refl(tm) Z_v = radar.refl(tm, False) ldr = radar.ldr(tm) Zdr = radar.Zdr(tm) delta_hv = radar.delta_hv(tm) rho_hv = radar.rho_hv(tm) tm.set_geometry(tmatrix_aux.geom_horiz_forw) Kdp = radar.Kdp(tm) A_h = radar.Ai(tm) A_v = radar.Ai(tm, False) radar_xsect_h_ref = 0.22176446239750278 Z_h_ref = 6383.7337897299258 Z_v_ref = 5066.721040036321 ldr_ref = 0.0021960626647629547 Zdr_ref = 1.2599339374097778 delta_hv_ref = -0.00021227778705544846 rho_hv_ref = 0.99603080460983828 Kdp_ref = 0.19334678024367824 A_h_ref = 0.018923976733777458 A_v_ref = 0.016366340549483317 for (val, ref) in zip( (radar_xsect_h, Z_h, Z_v, ldr, Zdr, delta_hv, rho_hv, Kdp, A_h, A_v), (radar_xsect_h_ref, Z_h_ref, Z_v_ref, ldr_ref, Zdr_ref, delta_hv_ref, rho_hv_ref, Kdp_ref, A_h_ref, A_v_ref)): test_relative(self, val, ref)
def tmatrix_stuffses(dsd): drops = tmatrix.Scatterer(wavelength=aux.wl_C, m=ref.m_w_10C[aux.wl_C]) drops.Kw_sqr = aux.K_w_sqr[aux.wl_C] drops.or_pdf = ori.gaussian_pdf(std=7.0) drops.orient = ori.orient_averaged_fixed drops.psd_integrator = psd.PSDIntegrator() drops.psd_integrator.D_max = 10.0 drops.psd_integrator.axis_ratio_func = read.ar back = aux.geom_horiz_back forw = aux.geom_horiz_forw drops.psd_integrator.geometries = (back, forw) drops.psd_integrator.init_scatter_table(drops) psds = dsd.to_tm_series(resample=None) drops.set_geometry(back) zh = [] zv = [] zdr = [] rho_hv = [] ldr = [] for tm_psd in psds: drops.psd = tm_psd zh.append(db(radar.refl(drops))) zv.append(db(radar.refl(drops, False))) zdr.append(db(radar.Zdr(drops))) rho_hv.append(radar.rho_hv(drops)) ldr.append(db(radar.ldr(drops))) d = { 'R': dsd.intensity(), 'Zh': zh, 'Zv': zv, 'Zdr': zdr, 'rho_hv': rho_hv, 'LDR': ldr } return pd.DataFrame(data=d, index=psds.index)
def get_radar_variables_ThomPSD(N1=None, N2=None, Lambda1=None, Lambda2=None, mu=None, D_max=None): scatterer.psd = ThomPSD(N1=N1, N2=N2, Lambda1=Lambda1, Lambda2=Lambda2, mu=mu, D_max=D_max) return [radar.refl(scatterer), radar.Zdr(scatterer), radar.ldr(scatterer)]
def tmatrix_stuffses(dsd): drops = tmatrix.Scatterer(wavelength=aux.wl_C,m=ref.m_w_10C[aux.wl_C]) drops.Kw_sqr = aux.K_w_sqr[aux.wl_C] drops.or_pdf = ori.gaussian_pdf(std=7.0) drops.orient = ori.orient_averaged_fixed drops.psd_integrator = psd.PSDIntegrator() drops.psd_integrator.D_max = 10.0 drops.psd_integrator.axis_ratio_func = read.ar back = aux.geom_horiz_back forw = aux.geom_horiz_forw drops.psd_integrator.geometries = (back,forw) drops.psd_integrator.init_scatter_table(drops) psds = dsd.to_tm_series(resample=None) drops.set_geometry(back) zh = [] zv = [] zdr = [] rho_hv = [] ldr = [] for tm_psd in psds: drops.psd = tm_psd zh.append(db(radar.refl(drops))) zv.append(db(radar.refl(drops,False))) zdr.append(db(radar.Zdr(drops))) rho_hv.append(radar.rho_hv(drops)) ldr.append(db(radar.ldr(drops))) d = {'R':dsd.intensity(), 'Zh': zh, 'Zv': zv, 'Zdr': zdr, 'rho_hv': rho_hv, 'LDR': ldr} return pd.DataFrame(data=d, index=psds.index)
def calcParameters(self,D0, Nw, mu): self.moments = {} self.scatterer.psd = GammaPSD(D0=D0, Nw=10**(Nw), mu=mu) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back) self.moments['Zh'] = 10*np.log10(radar.refl(self.scatterer)) self.moments['Zdr'] = 10*np.log10(radar.Zdr(self.scatterer)) self.moments['delta_hv'] = radar.delta_hv(self.scatterer) self.moments['ldr_h'] = radar.ldr(self.scatterer) self.moments['ldr_v'] = radar.ldr(self.scatterer, h_pol=False) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) self.moments['Kdp'] = radar.Kdp(self.scatterer) self.moments['Ah'] = radar.Ai(self.scatterer) self.moments['Adr'] = self.moments['Ah']-radar.Ai(self.scatterer, h_pol=False) return self.moments
def scatter_off_2dvd_packed(d_diameters, d_densities, scatterer): """ Computing the scattering properties of homogeneous nonspherical scatterers with the T-Matrix method. Parameters: =========== d_diameters: array Drop diameters in mm! (or else returns values won't be with proper units.) d_densities: array Drop densities. Returns: ======== dbz: array Horizontal reflectivity. zdr: array Differential reflectivity. kdp: array Specific differential phase (deg/km). atten_spec: array Specific attenuation (dB/km). """ # Function interpolation. mypds = interpolate.interp1d(d_diameters, d_densities, bounds_error=False, fill_value=0.0) scatterer.psd = mypds # GammaPSD(D0=2.0, Nw=1e3, mu=4) # Obtaining reflectivity and ZDR. print(scatterer) print(np.shape(mypds)) print(d_diameters) print(d_densities) dbz = 10 * np.log10(radar.refl(scatterer)) # in dBZ zdr = radar.Zdr(scatterer) # in dB # Specific attenuation and KDP. scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) atten_spec = radar.Ai(scatterer) # in dB/km kdp = radar.Kdp(scatterer) # in deg/km return dbz, zdr, kdp, atten_spec
def calc_radar_parameters(self, wavelength=tmatrix_aux.wl_X): ''' Calculates the radar parameters and stores them in the object. Defaults to X-Band,Beard and Chuang setup. Sets object radar parameters: Zh, Zdr, Kdp, Ai Parameter: wavelength = tmatrix supported wavelength. ''' self._setup_scattering(wavelength) for t in range(0, len(self.time)): BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges, self.Nd[t]) self.scatterer.psd = BinnedDSD self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back) self.Zdr[t] = 10 * np.log10(radar.Zdr(self.scatterer)) self.Zh[t] = 10 * np.log10(radar.refl(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) self.Kdp[t] = radar.Kdp(self.scatterer) self.Ai[t] = radar.Ai(self.scatterer)
def calc_radar_parameters(self, wavelength=tmatrix_aux.wl_X): ''' Calculates the radar parameters and stores them in the object. Defaults to X-Band wavelength and Thurai et al. 2007 axis ratio setup. Sets object radar parameters: Zh, Zdr, Kdp, Ai Parameter: wavelength = tmatrix supported wavelength. ''' self._setup_scattering(wavelength) print self.bin_edges/1000. print self.Nt.min(),self.Nt.max() for t in range(0, len(self.time)): BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges/1000., self.Nt[t]/1E9) self.scatterer.psd = BinnedDSD self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back) self.Zdr[t] = 10 * np.log10(radar.Zdr(self.scatterer)) self.Zh[t] = 10 * np.log10(radar.refl(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) self.Kdp[t] = radar.Kdp(self.scatterer) self.Ai[t] = radar.Ai(self.scatterer)
def get_radar_variables_Exponential(N0=None, Lambda=None, D_max=None): scatterer.psd = psd.ExponentialPSD(N0=N0, Lambda=Lambda, D_max=D_max) return [ 10. * np.log10(radar.refl(scatterer)), 10. * np.log10(radar.Zdr(scatterer)) ]
m = refractive.m_w_10C[wl] scatterer = tmatrix.Scatterer(wavelength=wl, m=m, axis_ratio=1.0, radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM, thet0=90.0 - el, thet=90.0 + el) Dmax = np.linspace(0.1, 2.7, 100) Zhh = 0.0 * Dmax Zvv = 0.0 * Dmax Zdr = 0.0 * Dmax for i, D in enumerate(Dmax): scatterer.radius = 0.5 * D Zdr[i] = 10.0 * np.log10(radar.Zdr(scatterer)) Zhh[i] = 10.0 * np.log10(radar.refl(scatterer, h_pol=True)) Zvv[i] = 10.0 * np.log10(radar.refl(scatterer, h_pol=False)) plt.figure() ax0 = plt.gca() ax0.plot(Dmax, Zhh, label='Zhh') ax0.plot(Dmax, Zvv, label='Zvv') ax0.vlines(wl * 0.5, ymin=-14, ymax=0) ax0.legend() ax0.grid() ax0.set_ylabel('Z [dbZ]') ax0.set_xlabel('Dmax [mm]') ax1 = ax0.twinx() ax1.plot(Dmax, Zdr, c='C3', label='Zdr') ax1.legend() ax1.set_ylabel('Zdr [dB]')
Ai = 0.0 * D0s wl = tmatrix_aux.wl_W el = 0. scatterer = tmatrix.Scatterer( wavelength=wl, m=refractive.m_w_10C[wl], #kw_sqr=tmatrix_aux.K_w_sqr[wl], radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM, #or_pdf=orientation.gaussian_pdf(std=1.0), #orient=orientation.orient_averaged_fixed, thet0=90.0 - el, thet=90.0 + el) Nw = 8000.0 # mm-2 m-3 mu = 5 scatterer.psd_integrator = psd.PSDIntegrator( D_max=8.0, geometries=(tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw)) scatterer.psd_integrator.init_scatter_table(scatterer) for i, D0 in enumerate(D0s): scatterer.psd = genGamma(Nw, D0, mu) #psd.GammaPSD(D0=D0, mu=mu, Nw=Nw) scatterer.set_geometry(tmatrix_aux.geom_horiz_back) Zhh[i] = 10.0 * np.log10(radar.refl(scatterer)) scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) Ai[i] = radar.Ai(scatterer) plt.plot(D0s, Zhh) plt.plot(D0s, Zhh - 2.0 * Ai * 0.25) plt.ylim([11, 26]) plt.grid()
d = np.logspace(-2, 2, num = 1000) #mm wave = (8.5714, 21.4286) backscatter = Dataset('scatsout_a.cdf', 'w') AR = backscatter.createDimension('Area Ratio', len(ar.tolist())) B = backscatter.createDimension('Mass Parameter b', len(b.tolist())) A = backscatter.createDimension('Mass Parameter a', len(a.tolist())) D = backscatter.createDimension('Maximum Diameter', len(d.tolist())) WAVE = backscatter.createDimension('Wavelength', len(wave)) xsections = backscatter.createVariable('backscat', 'f4', ('Area Ratio', 'Mass Parameter b', 'Mass Parameter a', 'Maximum Diameter', 'Wavelength')) for i in range(len(a)): print(a[i]) for j in range(len(b)): print(b[j]) for k in range(len(ar)): print(ar[k]) for l in range(len(d)): for n in range(len(wave)): if wave[n]/d[l] > 0.15: dmod = d[l] * (ar[k]**(1./3.)) newm = mix(a[i], b[j], d[l]*0.1, ar[k]) oblate = Scatterer(radius = dmod/2., wavelength = wave[n], m = newm, axis_ratio = 1/ar[k]) xsection = 10*np.log10(radar.refl(oblate)) xsections[i,j,k,l,n] = 10*np.log10(radar.refl(oblate)) else: xsections[i,j,k,l,n] = np.nan backscatter.close()
def calculate_radar_parameters(self, wavelength=tmatrix_aux.wl_X, dsr_func=DSR.bc, scatter_time_range=None): ''' Calculates radar parameters for the Drop Size Distribution. Calculates the radar parameters and stores them in the object. Defaults to X-Band,Beard and Chuang 10C setup. Sets the dictionary parameters in fields dictionary: Zh, Zdr, Kdp, Ai(Attenuation) Parameters: ---------- wavelength: optional, pytmatrix wavelength Wavelength to calculate scattering coefficients at. dsr_func: optional, function Drop Shape Relationship function. Several are availab le in the `DSR` module. Defaults to Beard and Chuang scatter_time_range: optional, tuple Parameter to restrict the scattering to a time interval. The first element is the start time, while the second is the end time. ''' self._setup_scattering(wavelength, dsr_func) self._setup_empty_fields() if scatter_time_range is None: self.scatter_start_time = 0 self.scatter_end_time = len(self.time) else: if scatter_time_range[0] < 0: print("Invalid Start time specified, aborting") return self.scatter_start_time = scatter_time_range[0] self.scatter_end_time = scatter_time_range[1] if scatter_time_range[1] > len(self.time): print( "End of Scatter time is greater than end of file. Scattering to end of included time." ) self.scatter_end_time = len(self.time) self.scatterer.set_geometry( tmatrix_aux.geom_horiz_back ) # We break up scattering to avoid regenerating table. for t in range(self.scatter_start_time, self.scatter_end_time): if np.sum(self.Nd[t]) is 0: continue BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges, self.Nd[t]) self.scatterer.psd = BinnedDSD self.fields['Zh']['data'][t] = 10 * \ np.log10(radar.refl(self.scatterer)) self.fields['Zdr']['data'][t] = 10 * \ np.log10(radar.Zdr(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) for t in range(self.scatter_start_time, self.scatter_end_time): self.fields['Kdp']['data'][t] = radar.Kdp(self.scatterer) self.fields['Ai']['data'][t] = radar.Ai(self.scatterer) self.fields['Ad']['data'][t] = radar.Ai(self.scatterer) - radar.Ai( self.scatterer, h_pol=False)
def calculate_radar_parameters(self, dsr_func=DSR.bc, scatter_time_range=None): ''' Calculates radar parameters for the Drop Size Distribution. Calculates the radar parameters and stores them in the object. Defaults to X-Band,Beard and Chuang 10C setup. Sets the dictionary parameters in fields dictionary: Zh, Zv, Zdr, Kdp, Ai, Av(hor. and vert. Attenuation), Adr (diff. attenuation), cross_correlation_ratio_hv (rhohv), LDR, Kdp Parameters: ---------- wavelength: optional, pytmatrix wavelength Wavelength to calculate scattering coefficients at. dsr_func: optional, function Drop Shape Relationship function. Several are available in the `DSR` module. Defaults to Beard and Chuang scatter_time_range: optional, tuple Parameter to restrict the scattering to a time interval. The first element is the start time, while the second is the end time. ''' self._setup_scattering(SPEED_OF_LIGHT / self.scattering_freq * 1000.0, dsr_func) self._setup_empty_fields() if scatter_time_range is None: self.scatter_start_time = 0 self.scatter_end_time = self.numt else: if scatter_time_range[0] < 0: print("Invalid Start time specified, aborting") return self.scatter_start_time = scatter_time_range[0] self.scatter_end_time = scatter_time_range[1] if scatter_time_range[1] > self.numt: print("End of Scatter time is greater than end of file. " + "Scattering to end of included time.") self.scatter_end_time = self.numt # We break up scattering to avoid regenerating table. self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back) print('Calculating backward scattering parameters ...') for t in range(self.scatter_start_time, self.scatter_end_time): if np.sum(self.Nd['data'][t]) is 0: continue BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges['data'], self.Nd['data'][t]) self.scatterer.psd = BinnedDSD self.fields['Zh']['data'][t] = 10 * \ np.log10(radar.refl(self.scatterer)) self.fields['Zv']['data'][t] = 10 * \ np.log10(radar.refl(self.scatterer, h_pol=False)) self.fields['Zdr']['data'][t] = 10 * \ np.log10(radar.Zdr(self.scatterer)) self.fields['cross_correlation_ratio_hv']['data'][t] = \ radar.rho_hv(self.scatterer) self.fields['specific_differential_phase_hv']['data'][t] = \ radar.delta_hv(self.scatterer) self.fields['LDR']['data'][t] = 10 * \ np.log10(radar.ldr(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) print('Calculating forward scattering parameters ...') for t in range(self.scatter_start_time, self.scatter_end_time): BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges['data'], self.Nd['data'][t]) self.scatterer.psd = BinnedDSD self.fields['Kdp']['data'][t] = radar.Kdp(self.scatterer) self.fields['Ai']['data'][t] = radar.Ai(self.scatterer) self.fields['Av']['data'][t] = radar.Ai(self.scatterer, h_pol=False) self.fields['Adr']['data'][t] = radar.Ai(self.scatterer) - \ radar.Ai(self.scatterer, h_pol=False) # Mask all values where no precipitation present or when ice present params_list = [ 'Zh', 'Zv', 'Zdr', 'Kdp', 'Ai', 'Av', 'Adr', 'cross_correlation_ratio_hv', 'LDR', 'specific_differential_phase_hv' ] l = np.empty(len(self.fields['Precip_Code']['data']), dtype=bool) j = 0 for i in self.fields['Precip_Code']['data']: l[j] = 'N' in i or 'G' in i j += 1 for param in params_list: self.fields[param]['data'] = \ np.ma.masked_where(l, self.fields[param]['data'])
A = backscatter.createDimension('Mass Parameter a', len(a.tolist())) D = backscatter.createDimension('Maximum Diameter', len(d.tolist())) WAVE = backscatter.createDimension('Wavelength', len(wave)) xsections = backscatter.createVariable( 'backscat', 'f4', ('Area Ratio', 'Mass Parameter b', 'Mass Parameter a', 'Maximum Diameter', 'Wavelength')) for i in range(len(a)): print(a[i]) for j in range(len(b)): print(b[j]) for k in range(len(ar)): print(ar[k]) for l in range(len(d)): for n in range(len(wave)): if wave[n] / d[l] > 0.15: dmod = d[l] * (ar[k]**(1. / 3.)) newm = mix(a[i], b[j], d[l] * 0.1, ar[k]) oblate = Scatterer(radius=dmod / 2., wavelength=wave[n], m=newm, axis_ratio=1 / ar[k]) xsection = 10 * np.log10(radar.refl(oblate)) xsections[i, j, k, l, n] = 10 * np.log10(radar.refl(oblate)) else: xsections[i, j, k, l, n] = np.nan backscatter.close()
def calculate_radar_parameters(self, dsr_func=DSR.bc, scatter_time_range=None, max_diameter=9.0): """ Calculates radar parameters for the Drop Size Distribution. Calculates the radar parameters and stores them in the object. Defaults to X-Band,Beard and Chuang 10C setup. Sets the dictionary parameters in fields dictionary: Zh, Zdr, Kdp, Ai(Attenuation) Parameters: ---------- wavelength: optional, pytmatrix wavelength Wavelength to calculate scattering coefficients at. dsr_func: optional, function Drop Shape Relationship function. Several are availab le in the `DSR` module. Defaults to Beard and Chuang scatter_time_range: optional, tuple Parameter to restrict the scattering to a time interval. The first element is the start time, while the second is the end time. """ if self.scattering_table_consistent is False: self._setup_scattering( SPEED_OF_LIGHT / self.scattering_params["scattering_freq"] * 1000.0, dsr_func, max_diameter, ) self._setup_empty_fields() if scatter_time_range is None: self.scatter_start_time = 0 self.scatter_end_time = self.numt else: if scatter_time_range[0] < 0: print("Invalid Start time specified, aborting") return self.scatter_start_time = scatter_time_range[0] self.scatter_end_time = scatter_time_range[1] if scatter_time_range[1] > self.numt: print("End of Scatter time is greater than end of file." + "Scattering to end of included time.") self.scatter_end_time = self.numt self.scatterer.set_geometry( tmatrix_aux.geom_horiz_back ) # We break up scattering to avoid regenerating table. for t in range(self.scatter_start_time, self.scatter_end_time): if np.sum(self.Nd["data"][t]) is 0: continue BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges["data"], self.Nd["data"][t]) self.scatterer.psd = BinnedDSD self.fields["Zh"]["data"][t] = 10 * np.log10( radar.refl(self.scatterer)) self.fields["Zdr"]["data"][t] = 10 * np.log10( radar.Zdr(self.scatterer)) self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) for t in range(self.scatter_start_time, self.scatter_end_time): BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges["data"], self.Nd["data"][t]) self.scatterer.psd = BinnedDSD self.fields["Kdp"]["data"][t] = radar.Kdp(self.scatterer) self.fields["Ai"]["data"][t] = radar.Ai(self.scatterer) self.fields["Adr"]["data"][t] = radar.Ai( self.scatterer) - radar.Ai(self.scatterer, h_pol=False)
def get_radar_variables_Exponential(N0=None,Lambda=None,D_max=None): scatterer.psd = psd.ExponentialPSD(N0=N0, Lambda=Lambda, D_max=D_max) return [radar.refl(scatterer), radar.Zdr(scatterer), radar.ldr(scatterer)]