def ex_coord(): pvol = io.read_OPERA_hdf5(os.path.dirname(__file__) + '/' + 'data/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf') # Count the number of dataset ntilt = 1 for i in range(100): try: pvol["dataset%d/what" % ntilt] ntilt += 1 except Exception: ntilt -= 1 break nrays = int(pvol["dataset1/where"]["nrays"]) nbins = int(pvol["dataset1/where"]["nbins"]) rscale = int(pvol["dataset1/where"]["rscale"]) coord = np.empty((ntilt, nrays, nbins, 3)) for t in range(ntilt): elangle = pvol["dataset%d/where" % (t + 1)]["elangle"] coord[t, ...] = georef.sweep_centroids(nrays, rscale, nbins, elangle) ascale = math.pi / nrays sitecoords = (pvol["where"]["lon"], pvol["where"]["lat"], pvol["where"]["height"]) proj_radar = georef.create_osr("aeqd", lat_0=pvol["where"]["lat"], lon_0=pvol["where"]["lon"]) radius = georef.get_earth_radius(pvol["where"]["lat"], proj_radar) lon, lat, height = georef.polar2lonlatalt_n(coord[..., 0], np.degrees(coord[..., 1]), coord[..., 2], sitecoords, re=radius, ke=4. / 3.) x, y = georef.reproject(lon, lat, projection_target=proj_radar) test = x[0, 90, 0:960:60] print(test)
class TestRegularToIrregular: NX = 2 nx = np.linspace(-NX + 0.5, NX - 0.5, num=2 * NX, endpoint=True) vx = np.linspace(-NX, NX, num=2 * NX, endpoint=True) meshx, meshy = np.meshgrid(nx, nx) cartgrid = np.dstack((meshx, meshy)) values = np.repeat(vx[:, np.newaxis], 2 * NX, 1) coord = georef.sweep_centroids(4, 1, NX, 0.0) xx = coord[..., 0] yy = coord[..., 1] xxx = xx * np.cos(np.radians(90.0 - yy)) x = xx * np.sin(np.radians(90.0 - yy)) y = xxx newgrid = np.dstack((x, y)) result = np.array([ [0.47140452, 1.41421356], [0.47140452, 1.41421356], [-0.47140452, -1.41421356], [-0.47140452, -1.41421356], ]) def test_cart_to_irregular_interp(self): newvalues = ipol.cart_to_irregular_interp(self.cartgrid, self.values, self.newgrid, method="linear") assert np.allclose(newvalues, self.result) def test_cart_to_irregular_spline(self): newvalues = ipol.cart_to_irregular_spline(self.cartgrid, self.values, self.newgrid, order=1, prefilter=False) assert np.allclose(newvalues, self.result) def test_cart_to_irregular_equality(self): assert np.allclose( ipol.cart_to_irregular_interp(self.cartgrid, self.values, self.newgrid, method="linear"), ipol.cart_to_irregular_spline(self.cartgrid, self.values, self.newgrid, order=1, prefilter=False), )
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 setUp(self): NX = 2 nx = np.linspace(-NX + 0.5, NX - 0.5, num=2 * NX, endpoint=True) vx = np.linspace(-NX, NX, num=2 * NX, endpoint=True) meshx, meshy = np.meshgrid(nx, nx) self.cartgrid = np.dstack((meshx, meshy)) self.values = np.repeat(vx[:, np.newaxis], 2 * NX, 1) coord = georef.sweep_centroids(4, 1, NX, 0.) xx = coord[..., 0] yy = np.degrees(coord[..., 1]) xxx = xx * np.cos(np.radians(90. - yy)) x = xx * np.sin(np.radians(90. - yy)) y = xxx self.newgrid = np.dstack((x, y)) self.result = np.array([[0.47140452, 1.41421356], [0.47140452, 1.41421356], [-0.47140452, -1.41421356], [-0.47140452, -1.41421356]])
def test_sweep_centroids(self): self.assertTrue(np.allclose(georef.sweep_centroids(1,100.,1,2.0), np.array([[[50., 1.57079633, 2.]]])))
def test_sweep_centroids(self): self.assertTrue(np.allclose(georef.sweep_centroids(1, 100., 1, 2.0), np.array([[[50., 3.14159265, 2.]]])))
def ex_clutter_cloud(): # read the radar volume scan path = os.path.dirname(__file__) + '/' pvol = io.read_OPERA_hdf5(path + 'data/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf') # Count the number of dataset ntilt = 1 for i in range(100): try: pvol["dataset%d/what" % ntilt] ntilt += 1 except Exception: ntilt -= 1 break # Construct radar values nrays = int(pvol["dataset1/where"]["nrays"]) nbins = int(pvol["dataset1/where"]["nbins"]) val = np.empty((ntilt, nrays, nbins)) for t in range(ntilt): val[t, ...] = pvol["dataset%d/data1/data" % (t + 1)] gain = float(pvol["dataset1/data1/what"]["gain"]) offset = float(pvol["dataset1/data1/what"]["offset"]) val = val * gain + offset # Construct radar coordinates rscale = int(pvol["dataset1/where"]["rscale"]) coord = np.empty((ntilt, nrays, nbins, 3)) for t in range(ntilt): elangle = pvol["dataset%d/where" % (t + 1)]["elangle"] coord[t, ...] = georef.sweep_centroids(nrays, rscale, nbins, elangle) ascale = math.pi / nrays sitecoords = (pvol["where"]["lon"], pvol["where"]["lat"], pvol["where"]["height"]) proj_radar = georef.create_osr("aeqd", lat_0=pvol["where"]["lat"], lon_0=pvol["where"]["lon"]) coord[..., 0], coord[..., 1], coord[..., 2] = georef.polar2lonlatalt_n(coord[..., 0], np.degrees(coord[..., 1]), coord[..., 2], sitecoords, re=6370040., ke=4. / 3.) coord = georef.reproject(coord, projection_target=proj_radar) # Construct collocated satellite data sat_gdal = io.read_safnwc(path + 'data/SAFNWC_MSG3_CT___201304290415_BEL_________.h5') 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) # Estimate localisation errors timelag = 9 * 60 wind = 10 error = np.absolute(timelag) * wind # Identify clutter based on collocated cloudtype clutter = cl.filter_cloudtype(val[0, ...], val_sat[0, ...], scale=rscale, smoothing=error) # visualize the result plt.figure() vis.plot_ppi(clutter) plt.suptitle('clutter') plt.savefig('clutter_cloud_example_1.png') plt.figure() vis.plot_ppi(val_sat[0, ...]) plt.suptitle('satellite') plt.savefig('clutter_cloud_example_2.png') plt.show()
def test_sweep_centroids(self): np.testing.assert_array_equal( georef.sweep_centroids(1, 100.0, 1, 2.0), np.array([[[50.0, 180.0, 2.0]]]) )
def ex_clutter_cloud(): # read the radar volume scan path = os.path.dirname(__file__) + '/' pvol = io.read_OPERA_hdf5( path + 'data/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf') # Count the number of dataset ntilt = 1 for i in range(100): try: pvol["dataset%d/what" % ntilt] ntilt += 1 except Exception: ntilt -= 1 break # Construct radar values nrays = int(pvol["dataset1/where"]["nrays"]) nbins = int(pvol["dataset1/where"]["nbins"]) val = np.empty((ntilt, nrays, nbins)) for t in range(ntilt): val[t, ...] = pvol["dataset%d/data1/data" % (t + 1)] gain = float(pvol["dataset1/data1/what"]["gain"]) offset = float(pvol["dataset1/data1/what"]["offset"]) val = val * gain + offset # Construct radar coordinates rscale = int(pvol["dataset1/where"]["rscale"]) coord = np.empty((ntilt, nrays, nbins, 3)) for t in range(ntilt): elangle = pvol["dataset%d/where" % (t + 1)]["elangle"] coord[t, ...] = georef.sweep_centroids(nrays, rscale, nbins, elangle) ascale = math.pi / nrays sitecoords = (pvol["where"]["lon"], pvol["where"]["lat"], pvol["where"]["height"]) proj_radar = georef.create_osr("aeqd", lat_0=pvol["where"]["lat"], lon_0=pvol["where"]["lon"]) coord[..., 0], coord[..., 1], coord[..., 2] = georef.polar2lonlatalt_n( coord[..., 0], np.degrees(coord[..., 1]), coord[..., 2], sitecoords, re=6370040., ke=4. / 3.) coord = georef.reproject(coord, projection_target=proj_radar) # Construct collocated satellite data sat_gdal = io.read_safnwc( path + 'data/SAFNWC_MSG3_CT___201304290415_BEL_________.h5') 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) # Estimate localisation errors timelag = 9 * 60 wind = 10 error = np.absolute(timelag) * wind # Identify clutter based on collocated cloudtype clutter = cl.filter_cloudtype(val[0, ...], val_sat[0, ...], scale=rscale, smoothing=error) # visualize the result plt.figure() vis.plot_ppi(clutter) plt.suptitle('clutter') plt.savefig('clutter_cloud_example_1.png') plt.figure() vis.plot_ppi(val_sat[0, ...]) plt.suptitle('satellite') plt.savefig('clutter_cloud_example_2.png') plt.show()
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