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)
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 setUp(self): f = 'gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5' # noqa gpm_file = util.get_wradlib_data_file(f) pr_data = read_generic_hdf5(gpm_file) pr_lon = pr_data['NS/Longitude']['data'] pr_lat = pr_data['NS/Latitude']['data'] zenith = pr_data['NS/PRE/localZenithAngle']['data'] wgs84 = georef.get_default_projection() a = wgs84.GetSemiMajor() b = wgs84.GetSemiMinor() rad = georef.proj4_to_osr( ('+proj=aeqd +lon_0={lon:f} ' + '+lat_0={lat:f} +a={a:f} +b={b:f}' + '').format(lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b)) pr_x, pr_y = georef.reproject(pr_lon, pr_lat, projection_source=wgs84, projection_target=rad) self.re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4. / 3. self.pr_xy = np.dstack((pr_x, pr_y)) self.alpha = zenith self.zt = 407000. self.dr = 125. self.bw_pr = 0.71 self.nbin = 176 self.nray = pr_lon.shape[1] self.pr_out = np.array([[[[-58533.78453556, 124660.60390174], [-58501.33048429, 124677.58873852]], [[-53702.13393133, 127251.83656509], [-53670.98686161, 127268.11882882]]], [[[-56444.00788528, 120205.5374491], [-56411.55421163, 120222.52300741]], [[-51612.2360682, 122796.78620764], [-51581.08938314, 122813.06920719]]]]) self.r_out = np.array( [0., 125., 250., 375., 500., 625., 750., 875., 1000., 1125.]) self.z_out = np.array([ 0., 119.51255112, 239.02510224, 358.53765337, 478.05020449, 597.56275561, 717.07530673, 836.58785786, 956.10040898, 1075.6129601 ])
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 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 setUp(self): f = 'gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5' # noqa gpm_file = util.get_wradlib_data_file(f) pr_data = read_generic_hdf5(gpm_file) pr_lon = pr_data['NS/Longitude']['data'] pr_lat = pr_data['NS/Latitude']['data'] zenith = pr_data['NS/PRE/localZenithAngle']['data'] wgs84 = georef.get_default_projection() a = wgs84.GetSemiMajor() b = wgs84.GetSemiMinor() rad = georef.proj4_to_osr(('+proj=aeqd +lon_0={lon:f} ' + '+lat_0={lat:f} +a={a:f} +b={b:f}' + '').format(lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b)) pr_x, pr_y = georef.reproject(pr_lon, pr_lat, projection_source=wgs84, projection_target=rad) self.re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4. / 3. self.pr_xy = np.dstack((pr_x, pr_y)) self.alpha = zenith self.zt = 407000. self.dr = 125. self.bw_pr = 0.71 self.nbin = 176 self.nray = pr_lon.shape[1] self.pr_out = np.array([[[[-58533.78453556, 124660.60390174], [-58501.33048429, 124677.58873852]], [[-53702.13393133, 127251.83656509], [-53670.98686161, 127268.11882882]]], [[[-56444.00788528, 120205.5374491], [-56411.55421163, 120222.52300741]], [[-51612.2360682, 122796.78620764], [-51581.08938314, 122813.06920719]]]]) self.r_out = np.array([0., 125., 250., 375., 500., 625., 750., 875., 1000., 1125.]) self.z_out = np.array([0., 119.51255112, 239.02510224, 358.53765337, 478.05020449, 597.56275561, 717.07530673, 836.58785786, 956.10040898, 1075.6129601])
def test_get_earth_radius(self): self.assertEqual(georef.get_earth_radius(50.), 6365631.51753728)
def test_get_earth_radius(self): self.assertEqual(georef.get_earth_radius(50.), 6365631.51753728)
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))
class TestSatellite: f = "gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5" # noqa gpm_file = util.get_wradlib_data_file(f) pr_data = wradlib.io.read_generic_hdf5(gpm_file) pr_lon = pr_data["NS/Longitude"]["data"] pr_lat = pr_data["NS/Latitude"]["data"] zenith = pr_data["NS/PRE/localZenithAngle"]["data"] wgs84 = georef.get_default_projection() a = wgs84.GetSemiMajor() b = wgs84.GetSemiMinor() rad = georef.proj4_to_osr( ("+proj=aeqd +lon_0={lon:f} " + "+lat_0={lat:f} +a={a:f} +b={b:f}" + "").format( lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b ) ) pr_x, pr_y = georef.reproject( pr_lon, pr_lat, projection_source=wgs84, projection_target=rad ) re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4.0 / 3.0 pr_xy = np.dstack((pr_x, pr_y)) alpha = zenith zt = 407000.0 dr = 125.0 bw_pr = 0.71 nbin = 176 nray = pr_lon.shape[1] pr_out = np.array( [ [ [ [-58533.78453556, 124660.60390174], [-58501.33048429, 124677.58873852], ], [ [-53702.13393133, 127251.83656509], [-53670.98686161, 127268.11882882], ], ], [ [ [-56444.00788528, 120205.5374491], [-56411.55421163, 120222.52300741], ], [ [-51612.2360682, 122796.78620764], [-51581.08938314, 122813.06920719], ], ], ] ) r_out = np.array( [0.0, 125.0, 250.0, 375.0, 500.0, 625.0, 750.0, 875.0, 1000.0, 1125.0] ) z_out = np.array( [ 0.0, 119.51255112, 239.02510224, 358.53765337, 478.05020449, 597.56275561, 717.07530673, 836.58785786, 956.10040898, 1075.6129601, ] ) def test_correct_parallax(self): xy, r, z = georef.correct_parallax(self.pr_xy, self.nbin, self.dr, self.alpha) pr_out = np.array( [ [ [ [-16582.50734831, 35678.47219358], [-16547.94607589, 35696.40777009], ], [ [-11742.02016667, 38252.32622057], [-11708.84553319, 38269.52268457], ], ], [ [ [-14508.62005182, 31215.98689653], [-14474.05905935, 31233.92329553], ], [ [-9667.99183645, 33789.86576047], [-9634.81750708, 33807.06305397], ], ], ] ) r_out = np.array( [0.0, 125.0, 250.0, 375.0, 500.0, 625.0, 750.0, 875.0, 1000.0, 1125.0] ) z_out = np.array( [ 0.0, 118.78164113, 237.56328225, 356.34492338, 475.1265645, 593.90820563, 712.68984675, 831.47148788, 950.25312901, 1069.03477013, ] ) np.testing.assert_allclose(xy[60:62, 0:2, 0:2, :], pr_out, rtol=1e-12) np.testing.assert_allclose(r[0:10], r_out, rtol=1e-12) np.testing.assert_allclose(z[0, 0, 0:10], z_out, rtol=1e-10) def test_dist_from_orbit(self): beta = abs(-17.04 + np.arange(self.nray) * self.bw_pr) xy, r, z = georef.correct_parallax(self.pr_xy, self.nbin, self.dr, self.alpha) dists = georef.dist_from_orbit(self.zt, self.alpha, beta, r, re=self.re) bd = np.array( [ 426553.58667772, 426553.50342119, 426553.49658156, 426553.51025979, 426553.43461609, 426553.42515894, 426553.46559985, 426553.37020786, 426553.44407286, 426553.42173696, ] ) sd = np.array( [ 426553.58667772, 424895.63462839, 423322.25176564, 421825.47714885, 420405.9414294, 419062.44208923, 417796.86827302, 416606.91482435, 415490.82582636, 414444.11587979, ] ) np.testing.assert_allclose(dists[0:10, 0, 0], bd, rtol=1e-12) np.testing.assert_allclose(dists[0, 0:10, 0], sd, rtol=1e-12)
def test_get_earth_radius(self): assert georef.get_earth_radius(50.0), 6365631.51753728