diff --git a/pyart/aux_io/rainbow_wrl.py b/pyart/aux_io/rainbow_wrl.py index d29a0c1b85..be2234796f 100755 --- a/pyart/aux_io/rainbow_wrl.py +++ b/pyart/aux_io/rainbow_wrl.py @@ -247,7 +247,7 @@ def read_rainbow_wrl( if single_slice: rays_per_sweep[0] = int(common_slice_info["slicedata"]["rawdata"]["@rays"]) - nbins = int(common_slice_info["slicedata"]["rawdata"]["@bins"]) + maxbin = int(common_slice_info["slicedata"]["rawdata"]["@bins"]) ssri = np.array([0], dtype="int32") seri = np.array([rays_per_sweep[0] - 1], dtype="int32") else: @@ -263,8 +263,12 @@ def read_rainbow_wrl( # all sweeps have to have the same number of range bins if any(nbins_sweep != nbins_sweep[0]): - raise ValueError("number of range bins changes between sweeps") - nbins = nbins_sweep[0] + # raise ValueError("number of range bins changes between sweeps") + print( + "WARNING: number of range bins changes between sweeps " + + "max number of bins will be used" + ) + maxbin = nbins_sweep.max() ssri = np.cumsum(np.append([0], rays_per_sweep[:-1])).astype("int32") seri = np.cumsum(rays_per_sweep).astype("int32") - 1 @@ -274,14 +278,23 @@ def read_rainbow_wrl( sweep_end_ray_index["data"] = seri # range + if not single_slice: + # all sweeps have to have the same range resolution + for i in range(nslices): + slice_info = rbf["volume"]["scan"]["slice"][i] + if slice_info["rangestep"] != common_slice_info["rangestep"]: + raise ValueError("range resolution changes between sweeps") + r_res = float(common_slice_info["rangestep"]) * 1000.0 if "start_range" in common_slice_info.keys(): start_range = float(common_slice_info["start_range"]) * 1000.0 else: start_range = 0.0 _range["data"] = np.linspace( - start_range + r_res / 2.0, float(nbins - 1.0) * r_res + r_res / 2.0, nbins + start_range + r_res / 2.0, float(maxbin - 1.0) * r_res + r_res / 2.0, maxbin ).astype("float32") + _range["meters_between_gates"] = r_res + _range["meters_to_center_of_first_gate"] = _range["data"][0] # containers for data t_fixed_angle = np.empty(nslices, dtype="float64") @@ -289,7 +302,7 @@ def read_rainbow_wrl( static_angle = np.empty(total_rays, dtype="float64") time_data = np.empty(total_rays, dtype="float64") fdata = np.ma.zeros( - (total_rays, nbins), dtype="float32", fill_value=get_fillvalue() + (total_rays, maxbin), dtype="float32", fill_value=get_fillvalue() ) # read data from file @@ -338,7 +351,10 @@ def read_rainbow_wrl( # data fdata[ssri[i] : seri[i] + 1, :] = _get_data( - slice_info["slicedata"]["rawdata"], rays_per_sweep[i], nbins + slice_info["slicedata"]["rawdata"], + rays_per_sweep[i], + nbins_sweep[i], + maxbin, ) if bfile.endswith(".vol") or bfile.endswith(".azi"): @@ -439,7 +455,7 @@ def _extract_angles(data): return moving_angle, angle_start, angle_stop -def _get_data(rawdata, nrays, nbins): +def _get_data(rawdata, nrays, nbins, maxbin): """ Obtains the raw data @@ -480,7 +496,12 @@ def _get_data(rawdata, nrays, nbins): data = np.reshape(data, [nrays, nbins]) mask = np.reshape(mask, [nrays, nbins]) - masked_data = np.ma.array(data, mask=mask, fill_value=get_fillvalue()) + data_tmp = np.full((nrays, maxbin), get_fillvalue()) + data_tmp[:nrays, :nbins] = data + mask_tmp = np.full((nrays, maxbin), True) + mask_tmp[:nrays, :nbins] = mask + + masked_data = np.ma.array(data_tmp, mask=mask_tmp, fill_value=get_fillvalue()) return masked_data