def test_spherical_to_xyz(self): def check(rc, azc, elc, outc, squeeze=False, strict_dims=False): assert ( georef.spherical_to_xyz( rc, azc, elc, self.csite, squeeze=squeeze, strict_dims=strict_dims, )[0].shape == outc ) check(np.arange(10), np.arange(36), 10.0, (1, 36, 10, 3)) check(np.arange(10), np.arange(36), np.arange(36), (1, 36, 10, 3,)) check(np.arange(10), np.arange(36), np.arange(36), (36, 10, 3,), squeeze=True) check( np.arange(10), np.arange(36), np.arange(36), (36, 36, 10, 3), squeeze=None, strict_dims=True, ) check(np.arange(10), np.arange(36), np.arange(18), (18, 36, 10, 3)) r, phi = np.meshgrid(np.arange(10), np.arange(36)) check(r, phi, 10, (1, 36, 10, 3)) r, phi = np.meshgrid(np.arange(10), np.arange(36)) check(r, phi, np.arange(36), (1, 36, 10, 3)) r, phi = np.meshgrid(np.arange(10), np.arange(36)) check(r, phi, np.arange(18), (18, 36, 10, 3)) r, phi = np.meshgrid(np.arange(10), np.arange(36)) check(r, phi, np.arange(36), (36, 36, 10, 3,), strict_dims=True) check(10, 36, 10.0, (1, 1, 1, 3)) check(np.arange(10), 36, 10.0, (1, 1, 10, 3)) check(10, np.arange(36), 10.0, (1, 36, 1, 3)) check(10, 36.0, np.arange(10), (10, 1, 1, 3)) check(10, np.arange(36), np.arange(10), (10, 36, 1, 3)) coords, rad = georef.spherical_to_xyz( self.r, self.az, self.th, self.csite, squeeze=True ) np.testing.assert_allclose( coords[..., 0], self.result_xyz[0], rtol=2e-10, atol=3e-5 ) np.testing.assert_allclose( coords[..., 1], self.result_xyz[1], rtol=2e-10, atol=3e-5 ) np.testing.assert_allclose( coords[..., 2], self.result_xyz[2], rtol=2e-10, atol=3e-5 ) re = georef.get_earth_radius(self.csite[1]) coords, rad = georef.spherical_to_xyz( self.r, self.az, self.th, self.csite, re=re, squeeze=True, ) np.testing.assert_allclose( coords[..., 0], self.result_xyz[0], rtol=2e-10, atol=3e-5 ) np.testing.assert_allclose( coords[..., 1], self.result_xyz[1], rtol=2e-10, atol=3e-5 ) np.testing.assert_allclose( coords[..., 2], self.result_xyz[2], rtol=2e-10, atol=3e-5 )
def check(rc, azc, elc, outc, squeeze=False, strict_dims=False): assert ( georef.spherical_to_xyz( rc, azc, elc, self.csite, squeeze=squeeze, strict_dims=strict_dims, )[0].shape == outc )
def test_spherical_to_xyz(self): coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite) self.assertTrue(np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03))
def test_spherical_to_xyz(self): coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite) self.assertTrue(np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03)) re = georef.get_earth_radius(self.csite[1]) coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite, re=re) self.assertTrue(np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03))
def plot_scan_strategy(ranges, elevs, site, vert_res=500., maxalt=10000., ax=None): """Plot the vertical scanning strategy Parameters ---------- ranges : array of ranges elevs : array of elevation angles site : tuple of site coordinates (longitude, latitude, altitude) vert_res : float Vertical resolution in [m] maxalt : float Maximum altitude in [m] ax : :class:`matplotlib:matplotlib.axes.Axes` The axes object to be plotted to. """ # just a dummy az = np.array([90.]) coords, _ = georef.spherical_to_xyz(ranges, az, elevs, site, squeeze=True) alt = coords[..., 2] if ax is None: returnax = False fig = pl.figure() ax = fig.add_subplot(111) else: returnax = True # actual plotting for y in np.arange(0, 10000., vert_res): ax.axhline(y=y, color="grey") for x in ranges: ax.axvline(x=x, color="grey") for i in range(len(elevs)): ax.plot(ranges, alt[i, :], lw=2, color="black") pl.ylim(top=maxalt) ax.tick_params(labelsize="large") pl.xlabel("Range (m)", size="large") pl.ylabel("Height over radar (m)", size="large") for i, elev in enumerate(elevs): x = ranges[-1] + 1500. y = alt[i, :][-1] if y > maxalt: ix = np.where(alt[i, :] < maxalt)[0][-1] x = ranges[ix] y = maxalt + 100. pl.text(x, y, str(elev), fontsize="large") if returnax: return ax pl.show()
def setUp(self): filename = 'dx/raa00-dx_10908-0806021655-fbg---bin.gz' dx_file = util.get_wradlib_data_file(filename) self.data, metadata = io.read_dx(dx_file) radar_location = (8.005, 47.8744, 1517) elevation = 0.5 # in degree azimuths = np.arange(0, 360) # in degrees ranges = np.arange(0, 128000., 1000.) # in meters polargrid = np.meshgrid(ranges, azimuths) coords, rad = georef.spherical_to_xyz(polargrid[0], polargrid[1], elevation, radar_location) self.x = coords[..., 0] self.y = coords[..., 1]
def setUp(self): # read the radar volume scan filename = 'hdf5/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf' filename = util.get_wradlib_data_file(filename) pvol = io.read_opera_hdf5(filename) nrays = int(pvol["dataset1/where"]["nrays"]) nbins = int(pvol["dataset1/where"]["nbins"]) val = pvol["dataset%d/data1/data" % (1)] gain = float(pvol["dataset1/data1/what"]["gain"]) offset = float(pvol["dataset1/data1/what"]["offset"]) self.val = val * gain + offset self.rscale = int(pvol["dataset1/where"]["rscale"]) elangle = pvol["dataset%d/where" % (1)]["elangle"] coord = georef.sweep_centroids(nrays, self.rscale, nbins, elangle) sitecoords = (pvol["where"]["lon"], pvol["where"]["lat"], pvol["where"]["height"]) coord, proj_radar = georef.spherical_to_xyz(coord[..., 0], coord[..., 1], coord[..., 2], sitecoords, re=6370040., ke=4. / 3.) filename = 'hdf5/SAFNWC_MSG3_CT___201304290415_BEL_________.h5' filename = util.get_wradlib_data_file(filename) sat_gdal = io.read_safnwc(filename) val_sat = georef.read_gdal_values(sat_gdal) coord_sat = georef.read_gdal_coordinates(sat_gdal) proj_sat = georef.read_gdal_projection(sat_gdal) coord_sat = georef.reproject(coord_sat, projection_source=proj_sat, projection_target=proj_radar) coord_radar = coord interp = ipol.Nearest(coord_sat[..., 0:2].reshape(-1, 2), coord_radar[..., 0:2].reshape(-1, 2)) self.val_sat = interp(val_sat.ravel()).reshape(val.shape) timelag = 9 * 60 wind = 10 self.error = np.absolute(timelag) * wind
def test_spherical_to_xyz(self): self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), 10., self.csite, squeeze=False)[0].shape) self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(36), self.csite, squeeze=False)[0].shape) self.assertTrue((36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(36), self.csite, squeeze=True, strict_dims=False)[0].shape) self.assertTrue((36, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(36), self.csite, strict_dims=True)[0].shape) self.assertTrue((18, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(18), self.csite, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz(r, phi, 10, self.csite, squeeze=False, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz(r, phi, np.arange(36), self.csite, squeeze=False, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue((18, 36, 10, 3) == georef.spherical_to_xyz(r, phi, np.arange(18), self.csite, squeeze=False, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue((36, 36, 10, 3) == georef.spherical_to_xyz(r, phi, np.arange(36), self.csite, squeeze=False, strict_dims=True)[0].shape) self.assertTrue((1, 1, 1, 3) == georef.spherical_to_xyz(10, 36, 10., self.csite, squeeze=False)[0].shape) self.assertTrue((1, 1, 10, 3) == georef.spherical_to_xyz(np.arange(10), 36, 10., self.csite, squeeze=False)[0].shape) self.assertTrue((1, 36, 1, 3) == georef.spherical_to_xyz(10, np.arange(36), 10., self.csite, squeeze=False)[0].shape) self.assertTrue((10, 1, 1, 3) == georef.spherical_to_xyz(10, 36., np.arange(10), self.csite, squeeze=False)[0].shape) self.assertTrue((10, 36, 1, 3) == georef.spherical_to_xyz(10, np.arange(36), np.arange(10), self.csite, squeeze=False)[0].shape) coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite, squeeze=True, strict_dims=False) self.assertTrue(np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03)) re = georef.get_earth_radius(self.csite[1]) coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite, re=re) self.assertTrue(np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue(np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03))
def test_spherical_to_xyz(self): self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz( np.arange(10), np.arange(36), 10., self.csite, squeeze=False) [0].shape) self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(36), self.csite, squeeze=False)[0].shape) self.assertTrue( (36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(36), self.csite, squeeze=True, strict_dims=False)[0].shape) self.assertTrue( (36, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(36), self.csite, strict_dims=True)[0].shape) self.assertTrue( (18, 36, 10, 3) == georef.spherical_to_xyz(np.arange(10), np.arange(36), np.arange(18), self.csite, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue((1, 36, 10, 3) == georef.spherical_to_xyz( r, phi, 10, self.csite, squeeze=False, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue( (1, 36, 10, 3) == georef.spherical_to_xyz(r, phi, np.arange(36), self.csite, squeeze=False, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue( (18, 36, 10, 3) == georef.spherical_to_xyz(r, phi, np.arange(18), self.csite, squeeze=False, strict_dims=False)[0].shape) r, phi = np.meshgrid(np.arange(10), np.arange(36)) self.assertTrue((36, 36, 10, 3) == georef.spherical_to_xyz( r, phi, np.arange(36), self.csite, squeeze=False, strict_dims=True) [0].shape) self.assertTrue((1, 1, 1, 3) == georef.spherical_to_xyz( 10, 36, 10., self.csite, squeeze=False)[0].shape) self.assertTrue((1, 1, 10, 3) == georef.spherical_to_xyz( np.arange(10), 36, 10., self.csite, squeeze=False)[0].shape) self.assertTrue((1, 36, 1, 3) == georef.spherical_to_xyz( 10, np.arange(36), 10., self.csite, squeeze=False)[0].shape) self.assertTrue((10, 1, 1, 3) == georef.spherical_to_xyz( 10, 36., np.arange(10), self.csite, squeeze=False)[0].shape) self.assertTrue((10, 36, 1, 3) == georef.spherical_to_xyz( 10, np.arange(36), np.arange(10), self.csite, squeeze=False) [0].shape) coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite, squeeze=True, strict_dims=False) self.assertTrue( np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue( np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue( np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03)) re = georef.get_earth_radius(self.csite[1]) coords, rad = georef.spherical_to_xyz(self.r, self.az, self.th, self.csite, re=re) self.assertTrue( np.allclose(coords[..., 0], self.result_xyz[0], rtol=1e-03)) self.assertTrue( np.allclose(coords[..., 1], self.result_xyz[1], rtol=1e-03)) self.assertTrue( np.allclose(coords[..., 2], self.result_xyz[2], rtol=1e-03))
def plot_scan_strategy( ranges, elevs, sitecoords, beamwidth=1.0, vert_res=500.0, maxalt=10000.0, range_res=None, maxrange=None, units="m", terrain=None, az=0.0, cg=False, ax=111, cmap="tab10", ): """Plot the vertical scanning strategy. Parameters ---------- ranges : sequence of floats array of ranges elevs : sequence of floats elevation angles sitecoords : sequence of floats radar site coordinates (longitude, latitude, altitude) beamwidth : float 3dB width of the radar beam, defaults to 1.0 deg. vert_res : float Vertical resolution in [m]. maxalt : float Maximum altitude in [m]. range_res : float Horizontal resolution in [m]. maxrange : float Maximum range in [m]. units : str Units to plot in, can be 'm' or 'km'. Defaults to 'm'. terrain : bool | :class:`numpy:numpy.ndarray` If True, downloads srtm data and add orography for given `az`. az : float Used to specify azimuth for terrain plots. cg : bool If True, plot in curvelinear grid, defaults to False (cartesian grid). ax : :class:`matplotlib:matplotlib.axes.Axes` | matplotlib grid definition If matplotlib Axes object is given, the scan strategy will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to '111', only one subplot/axis. cmap : str matplotlib colormap string. Returns ------- ax : :class:`matplotlib:matplotlib.axes.Axes` | matplotlib toolkit axisartist Axes object matplotlib Axes or curvelinear Axes (r-theta-grid) depending on keyword argument `cg`. """ if units == "m": scale = 1.0 elif units == "km": scale = 1000.0 else: raise ValueError( f"wradlib: unknown value for keyword argument units={units}") az = np.array([az]) if maxrange is None: maxrange = ranges.max() xyz, rad = georef.spherical_to_xyz(ranges, az, elevs, sitecoords, squeeze=True) add_title = "" if terrain is True: add_title += f" - Azimuth {az[0]}°" ll = georef.reproject(xyz, projection_source=rad) # (down-)load srtm data ds = io.get_srtm( [ ll[..., 0].min(), ll[..., 0].max(), ll[..., 1].min(), ll[..., 1].max() ], download={}, ) rastervalues, rastercoords, proj = georef.extract_raster_dataset( ds, nodata=-32768.0) # map rastervalues to polar grid points terrain = ipol.cart_to_irregular_spline(rastercoords, rastervalues, ll[-1, ..., :2], order=3, prefilter=False) if ax == 111: fig = pl.figure(figsize=(16, 8)) else: fig = pl.gcf() legend2 = {} if cg is True: ax, caax, paax = create_cg(fig=fig, subplot=ax, rot=0, scale=1) # for nice plotting we assume earth_radius = 6370000 m er = 6370000 # calculate beam_height and arc_distance for ke=1 # means line of sight ade = georef.bin_distance(ranges, 0, sitecoords[2], re=er, ke=1.0) nn0 = np.zeros_like(ranges) ecp = nn0 + er # theta (arc_distance sector angle) thetap = -np.degrees(ade / er) + 90.0 # zero degree elevation with standard refraction (bes, ) = paax.plot(thetap, ecp, "-k", linewidth=3, label="_MSL", zorder=3) legend2["MSL"] = bes if terrain is not None: paax.fill_between(thetap, ecp.min() - 2500, ecp + terrain, color="0.75", zorder=2) # axes layout ax.set_xlim(0, np.max(ade)) ax.set_ylim([ecp.min() - maxalt / 5, ecp.max() + maxalt]) caax.grid(True, axis="x") ax.grid(True, axis="y") ax.axis["top"].toggle(all=False) gh = ax.get_grid_helper() yrange = maxalt + maxalt / 5 nbins = ((yrange // vert_res) * 2 + 1) // np.sqrt(2) gh.grid_finder.grid_locator2._nbins = nbins else: ax = fig.add_subplot(ax) paax = ax caax = ax if terrain is not None: paax.fill_between(ranges, 0, terrain, color="0.75", zorder=2) ax.set_xlim(0.0, maxrange) ax.set_ylim(0.0, maxalt) ax.grid() # axes ticks and formatting if range_res is not None: xloc = range_res caax.xaxis.set_major_locator(MultipleLocator(xloc)) else: caax.xaxis.set_major_locator(MaxNLocator()) yloc = vert_res caax.yaxis.set_major_locator(MultipleLocator(yloc)) import functools hform = functools.partial(_height_formatter, cg=cg, scale=scale) rform = functools.partial(_range_formatter, scale=scale) caax.yaxis.set_major_formatter(FuncFormatter(hform)) caax.xaxis.set_major_formatter(FuncFormatter(rform)) # color management from cycler import cycler NUM_COLORS = len(elevs) cmap = pl.get_cmap(cmap) if cmap.N >= 256: colors = [cmap(1.0 * i / NUM_COLORS) for i in range(NUM_COLORS)] else: colors = cmap.colors cycle = cycler(color=colors) paax.set_prop_cycle(cycle) # plot beams for i, el in enumerate(elevs): alt = xyz[i, ..., 2] groundrange = np.sqrt(xyz[i, ..., 0]**2 + xyz[i, ..., 1]**2) if cg: plrange = thetap plalt = ecp + alt beamradius = util.half_power_radius(ranges, beamwidth) else: plrange = np.insert(groundrange, 0, 0) plalt = np.insert(alt, 0, sitecoords[2]) beamradius = util.half_power_radius(plrange, beamwidth) _, center, edge = _plot_beam(plrange, plalt, beamradius, label=f"{el:4.1f}°", ax=paax) # legend 1 handles, labels = ax.get_legend_handles_labels() leg1 = ax.legend( handles, labels, prop={"family": "monospace"}, loc="upper left", bbox_to_anchor=(1.04, 1), borderaxespad=0, ) # legend 2 legend2["Center"] = center[0] legend2["3 dB"] = edge[0] ax.legend( legend2.values(), legend2.keys(), prop={"family": "monospace"}, loc="lower left", bbox_to_anchor=(1.04, 0), borderaxespad=0, ) # add legend 1 ax.add_artist(leg1) # set axes labels ax.set_title(f"Radar Scan Strategy - {sitecoords}" + add_title) caax.set_xlabel(f"Range ({units})") caax.set_ylabel(f"Altitude ({units})") return ax
class TestCompose: if has_data: filename = "dx/raa00-dx_10908-0806021655-fbg---bin.gz" dx_file = util.get_wradlib_data_file(filename) data, metadata = io.read_dx(dx_file) radar_location = (8.005, 47.8744, 1517) elevation = 0.5 # in degree azimuths = np.arange(0, 360) # in degrees ranges = np.arange(0, 128000.0, 1000.0) # in meters polargrid = np.meshgrid(ranges, azimuths) coords, rad = georef.spherical_to_xyz(polargrid[0], polargrid[1], elevation, radar_location) x = coords[..., 0] y = coords[..., 1] @requires_data def test_extract_circle(self): xgrid = np.linspace(self.x.min(), self.x.mean(), 100) ygrid = np.linspace(self.y.min(), self.y.mean(), 100) grid_xy = np.meshgrid(xgrid, ygrid) grid_xy = np.vstack( (grid_xy[0].ravel(), grid_xy[1].ravel())).transpose() comp.extract_circle(np.array([self.x.mean(), self.y.mean()]), 128000.0, grid_xy) @requires_data def test_togrid(self): xgrid = np.linspace(self.x.min(), self.x.mean(), 100) ygrid = np.linspace(self.y.min(), self.y.mean(), 100) grid_xy = np.meshgrid(xgrid, ygrid) grid_xy = np.vstack( (grid_xy[0].ravel(), grid_xy[1].ravel())).transpose() xy = np.concatenate([self.x.ravel()[:, None], self.y.ravel()[:, None]], axis=1) comp.togrid( xy, grid_xy, 128000.0, np.array([self.x.mean(), self.y.mean()]), self.data.ravel(), ipol.Nearest, ) def test_compose(self): g1 = np.array([ np.nan, np.nan, 10.0, np.nan, np.nan, np.nan, 10.0, 10.0, 10.0, np.nan, 10.0, 10.0, 10.0, 10.0, np.nan, np.nan, 10.0, 10.0, 10.0, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, ]) g2 = np.array([ np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 11.0, 11.0, 11.0, np.nan, np.nan, 11.0, 11.0, 11.0, 11.0, np.nan, 11.0, 11.0, 11.0, np.nan, np.nan, np.nan, 11.0, np.nan, np.nan, ]) q1 = np.array([ np.nan, np.nan, 3.47408756e09, np.nan, np.nan, np.nan, 8.75744493e08, 8.75744493e08, 1.55045236e09, np.nan, 3.47408756e09, 8.75744493e08, 5.98145272e04, 1.55045236e09, np.nan, np.nan, 1.55045236e09, 1.55045236e09, 1.55045236e09, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, ]) q2 = np.array([ np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 1.55045236e09, 1.55045236e09, 1.55045236e09, np.nan, np.nan, 1.55045236e09, 5.98145272e04, 8.75744493e08, 3.47408756e09, np.nan, 1.55045236e09, 8.75744493e08, 8.75744493e08, np.nan, np.nan, np.nan, 3.47408756e09, np.nan, np.nan, ]) composite = comp.compose_weighted( [g1, g2], [1.0 / (q1 + 0.001), 1.0 / (q2 + 0.001)]) composite1 = comp.compose_ko([g1, g2], [1.0 / (q1 + 0.001), 1.0 / (q2 + 0.001)]) res = np.array([ np.nan, np.nan, 10.0, np.nan, np.nan, np.nan, 10.3609536, 10.3609536, 10.5, np.nan, 10.0, 10.3609536, 10.5, 10.6390464, 11.0, np.nan, 10.5, 10.6390464, 10.6390464, np.nan, np.nan, np.nan, 11.0, np.nan, np.nan, ]) res1 = np.array([ np.nan, np.nan, 10.0, np.nan, np.nan, np.nan, 10.0, 10.0, 10.0, np.nan, 10.0, 10.0, 10.0, 11.0, 11.0, np.nan, 10.0, 11.0, 11.0, np.nan, np.nan, np.nan, 11.0, np.nan, np.nan, ]) np.testing.assert_allclose(composite, res) np.testing.assert_allclose(composite1, res1)
class TestFilterCloudtype: if has_data: # read the radar volume scan filename = "hdf5/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf" filename = util.get_wradlib_data_file(filename) pvol = io.read_opera_hdf5(filename) nrays = int(pvol["dataset1/where"]["nrays"]) nbins = int(pvol["dataset1/where"]["nbins"]) val = pvol["dataset%d/data1/data" % (1)] gain = float(pvol["dataset1/data1/what"]["gain"]) offset = float(pvol["dataset1/data1/what"]["offset"]) val = val * gain + offset rscale = int(pvol["dataset1/where"]["rscale"]) elangle = pvol["dataset%d/where" % (1)]["elangle"] coord = georef.sweep_centroids(nrays, rscale, nbins, elangle) sitecoords = ( pvol["where"]["lon"], pvol["where"]["lat"], pvol["where"]["height"], ) coord, proj_radar = georef.spherical_to_xyz( coord[..., 0], coord[..., 1], coord[..., 2], sitecoords, re=6370040.0, ke=4.0 / 3.0, ) filename = "hdf5/SAFNWC_MSG3_CT___201304290415_BEL_________.h5" filename = util.get_wradlib_data_file(filename) sat_gdal = io.read_safnwc(filename) val_sat = georef.read_gdal_values(sat_gdal) coord_sat = georef.read_gdal_coordinates(sat_gdal) proj_sat = georef.read_gdal_projection(sat_gdal) coord_sat = georef.reproject(coord_sat, projection_source=proj_sat, projection_target=proj_radar) coord_radar = coord interp = ipol.Nearest(coord_sat[..., 0:2].reshape(-1, 2), coord_radar[..., 0:2].reshape(-1, 2)) val_sat = interp(val_sat.ravel()).reshape(val.shape) timelag = 9 * 60 wind = 10 error = np.absolute(timelag) * wind @requires_data def test_filter_cloudtype(self): nonmet = clutter.filter_cloudtype(self.val, self.val_sat, scale=self.rscale, smoothing=self.error) nclutter = np.sum(nonmet) assert nclutter == 8141 nonmet = clutter.filter_cloudtype(self.val, self.val_sat, scale=self.rscale, smoothing=self.error, low=True) nclutter = np.sum(nonmet) assert nclutter == 17856