def calc_DWR(datalist): var = h.lin2z(datalist[0]['var']) - h.lin2z(datalist[1]['var']) mask = np.logical_or(datalist[0]['mask'], datalist[1]['mask']) return var, mask
def filter_ghost_echos_RPG94GHz_FMCW(data, **kwargs): ###################################################################### # # 2nd and 3rd chirp ghost echo filter if 'clean_spectra' in kwargs and kwargs['clean_spectra']: sensitivity_limit = kwargs['SL'] if 'SL' in kwargs else sys.exit( 'Error in clean_spectra ghost echo filter :: Sensitivity Limit missing!') Ze = kwargs['Ze'] if 'Ze' in kwargs else sys.exit( 'Error in clean_spectra ghost echo filter :: Ze values missing!') for ichirp in [0, 1, 2]: # threholds for 3rd chrip ghost echo filter new_ny_vel = data[ichirp]['vel'].max() - 2.5 ic_Ze_max = h.z2lin(-22.5) idx_left = np.argwhere(-new_ny_vel > data[ichirp]['vel']).max() idx_right = np.argwhere(new_ny_vel < data[ichirp]['vel']).min() Ze_lin_left = data[ichirp]['var'][:, :, :idx_left].copy() Ze_lin_right = data[ichirp]['var'][:, :, idx_right:].copy() # if noise was already removed by the RPG software, replace the ghost with -999., # if noise factor 0 was selected in the RPG software, replace the ghost by the minimum spectrum value, # to avoid wrong noise estimations (to much signal would be lost otherwise), idx_ts_nf0 = np.argwhere(data[ichirp]['var'][:, 0, 0] != -999.0) if idx_ts_nf0.size > 0: mask_left, mask_right = Ze_lin_left < ic_Ze_max, Ze_lin_right < ic_Ze_max min_left, min_right = np.amin(Ze_lin_left, axis=2), np.amin(Ze_lin_right, axis=2) for i_bin in range(mask_left.shape[2]): Ze_lin_left[mask_left[:, :, i_bin], i_bin] = min_left[mask_left[:, :, i_bin]] for i_bin in range(mask_right.shape[2]): Ze_lin_right[mask_right[:, :, i_bin], i_bin] = min_right[mask_right[:, :, i_bin]] else: Ze_lin_left[Ze_lin_left < ic_Ze_max] = -999.0 Ze_lin_right[Ze_lin_right < ic_Ze_max] = -999.0 data[ichirp]['var'][:, :, :idx_left] = Ze_lin_left.copy() data[ichirp]['var'][:, :, idx_right:] = Ze_lin_right.copy() ###################################################################### # # 2nd and 3rd chirp ghost echo filter if 'C2C3' in kwargs and kwargs['C2C3']: for ichirp in [0, 1, 2]: # threholds for 3rd chrip ghost echo filter new_ny_vel = data[ichirp]['vel'].max() - 2.5 ic_Ze_max = h.z2lin(-22.5) idx_left = np.argwhere(-new_ny_vel > data[ichirp]['vel']).max() idx_right = np.argwhere(new_ny_vel < data[ichirp]['vel']).min() Ze_lin_left = data[ichirp]['var'][:, :, :idx_left].copy() Ze_lin_right = data[ichirp]['var'][:, :, idx_right:].copy() # if noise was already removed by the RPG software, replace the ghost with -999., # if noise factor 0 was selected in the RPG software, replace the ghost by the minimum spectrum value, # to avoid wrong noise estimations (to much signal would be lost otherwise), idx_ts_nf0 = np.argwhere(data[ichirp]['var'][:, 0, 0] != -999.0) if idx_ts_nf0.size > 0: mask_left, mask_right = Ze_lin_left < ic_Ze_max, Ze_lin_right < ic_Ze_max min_left, min_right = np.amin(Ze_lin_left, axis=2), np.amin(Ze_lin_right, axis=2) for i_bin in range(mask_left.shape[2]): Ze_lin_left[mask_left[:, :, i_bin], i_bin] = min_left[mask_left[:, :, i_bin]] for i_bin in range(mask_right.shape[2]): Ze_lin_right[mask_right[:, :, i_bin], i_bin] = min_right[mask_right[:, :, i_bin]] else: Ze_lin_left[Ze_lin_left < ic_Ze_max] = -999.0 Ze_lin_right[Ze_lin_right < ic_Ze_max] = -999.0 data[ichirp]['var'][:, :, :idx_left] = Ze_lin_left.copy() data[ichirp]['var'][:, :, idx_right:] = Ze_lin_right.copy() ###################################################################### # # 1st chirp ghost echo filter if 'C1' in kwargs and kwargs['C1']: # invalid mask has to be provided via kwarg for this filter invalid_mask = kwargs['inv_mask'] rg_offsets = kwargs['offset'] SL = kwargs['SL'] # setting higher threshold if chirp 2 contains high reflectivity values # sum_over_heightC1 = np.ma.sum(data['Ze'][:rg_offsets[1], :], axis=0) sum_over_heightC2 = np.ma.sum(data['Ze'][rg_offsets[1]:rg_offsets[2], :], axis=0) # load sensitivity limits (time, height) and calculate the mean over time sens_reduction = 15.0 # sensitivity in chirp 1 is reduced by 12.0 dBZ C2_Ze_threshold = 18.0 # if sum(C2_Ze) > this threshold, ghost echo in C1 is assumed sens_lim = h.z2lin(h.lin2z(np.mean(SL, axis=0)) + sens_reduction) ts_to_mask = np.argwhere(h.lin2z(sum_over_heightC2) > C2_Ze_threshold)[:, 0] m1 = invalid_mask[:rg_offsets[1], :].copy() for idx_ts in ts_to_mask: m1[:, idx_ts] = data['Ze'][:rg_offsets[1], idx_ts] < sens_lim # a = data['Ze'][:rg_offsets[1], idx_ts] < sens_lim # b = data['VEL'][:rg_offsets[1], idx_ts] < -0.5 # m1[:, idx_ts] = a == b invalid_mask[:rg_offsets[1], :] = m1.copy() for mom in ['Ze', 'VEL', 'sw', 'skew', 'kurt']: data[mom][:rg_offsets[1], :] = np.ma.masked_where(m1, data[mom][:rg_offsets[1], :]) return invalid_mask
fig, ax = pyLARDA.Transformations.plot_timeheight(LIMRAD94_Z_interp, range_interval=plot_range, z_converter='lin2z') fig.savefig('limrad_Z_interp.png', dpi=250) def calc_DWR(datalist): var = h.lin2z(datalist[0]['var']) - h.lin2z(datalist[1]['var']) mask = np.logical_or(datalist[0]['mask'], datalist[1]['mask']) return var, mask new_keys = { 'system': '', 'name': 'DWR', 'colormap': 'gist_rainbow', 'rg_unit': 'm', 'var_lims': [-7, 2] } DWR = pyLARDA.Transformations.combine(calc_DWR, [MIRA_Zg, LIMRAD94_Z_interp], new_keys) fig, ax = pyLARDA.Transformations.plot_timeheight(DWR, range_interval=plot_range) fig.savefig('DWR_MIRA_LIMRAD.png', dpi=250) MRR_Z = larda.read("MRRPRO", "Ze", [begin_dt, end_dt], [0, 'max']) MRR_Z['var'] = h.lin2z(MRR_Z['var']) fig, ax = pyLARDA.Transformations.plot_timeheight(MRR_Z, range_interval=plot_range) fig.savefig('mrr_Z.png', dpi=250)
range_interval=plot_range, z_converter='lin2z') fig.savefig(case_prefix + 'limrad_Z.png', dpi=250) LIMRAD94_Z_interp = pyLARDA.Transformations.interpolate2d( LIMRAD94_Z, new_time=MIRA_Zg['ts'], new_range=MIRA_Zg['rg']) fig, ax = pyLARDA.Transformations.plot2d(LIMRAD94_Z_interp, range_interval=plot_range, z_converter='lin2z') fig.savefig(case_prefix + 'limrad_Z_interp.png', dpi=250) # Z scatterplot combined_mask = np.logical_or(MIRA_Zg['mask'], LIMRAD94_Z_interp['mask']) Mira_Z_scatter = h.lin2z(MIRA_Zg['var'][~combined_mask].ravel()) #+4.5 Limrad_Z_scatter = h.lin2z(LIMRAD94_Z_interp['var'][~combined_mask].ravel()) s, i, r, p, std_err = stats.linregress(Mira_Z_scatter, Limrad_Z_scatter) H, xedges, yedges = np.histogram2d(Mira_Z_scatter, Limrad_Z_scatter, bins=120, range=[[-75, 30], [-75, 30]]) X, Y = np.meshgrid(xedges, yedges) fig, ax = plt.subplots(1, figsize=(5.7, 5.7)) ax.pcolormesh( X, Y, np.transpose(H), norm=matplotlib.colors.LogNorm(), )