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_create_osr(self): self.maxDiff = None radolan_wkt = ('PROJCS["Radolan projection",' 'GEOGCS["Radolan Coordinate System",' 'DATUM["Radolan Kugel",' 'SPHEROID["Erdkugel",6370040.0,0.0]],' 'PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.017453292519943295],' 'AXIS["Longitude",EAST],' 'AXIS["Latitude",NORTH]],' 'PROJECTION["polar_stereographic"],' 'PARAMETER["central_meridian",10.0],' 'PARAMETER["latitude_of_origin",60.0],' 'PARAMETER["scale_factor",{0:8.10f}],' 'PARAMETER["false_easting",0.0],' 'PARAMETER["false_northing",0.0],' 'UNIT["m*1000.0",1000.0],' 'AXIS["X",EAST],' 'AXIS["Y",NORTH]]'. format((1. + np.sin(np.radians(60.))) / (1. + np.sin(np.radians(90.))))) self.assertEqual(georef.create_osr('dwd-radolan').ExportToWkt(), radolan_wkt) aeqd_wkt = ('PROJCS["unnamed",' 'GEOGCS["WGS 84",' 'DATUM["unknown",' 'SPHEROID["WGS84",6378137,298.257223563]],' 'PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],' 'PROJECTION["Azimuthal_Equidistant"],' 'PARAMETER["latitude_of_center",{0:-f}],' 'PARAMETER["longitude_of_center",{1:-f}],' 'PARAMETER["false_easting",{2:-f}],' 'PARAMETER["false_northing",{3:-f}]]'. format(49., 5., 0, 0)) self.assertEqual(georef.create_osr('aeqd', lon_0=5., lat_0=49).ExportToWkt(), aeqd_wkt) self.assertEqual(georef.create_osr('aeqd', lon_0=5., lat_0=49, x_0=0, y_0=0).ExportToWkt(), aeqd_wkt) self.assertRaises(ValueError, lambda: georef.create_osr('lambert'))
def setUp(self): img = np.zeros((360, 10), dtype=np.float32) img[2, 2] = 10 # isolated pixel img[5, 6:8] = 10 # line img[20, :] = 5 # spike img[60:120, 2:7] = 11 # precip field self.img = img self.proj = georef.create_osr("dwd-radolan")
def test_create_osr(self): self.maxDiff = None radolan_wkt = ('PROJCS["Radolan projection",' 'GEOGCS["Radolan Coordinate System",' 'DATUM["Radolan Kugel",' 'SPHEROID["Erdkugel",6370040.0,0.0]],' 'PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.017453292519943295],' 'AXIS["Longitude",EAST],' 'AXIS["Latitude",NORTH]],' 'PROJECTION["polar_stereographic"],' 'PARAMETER["central_meridian",10.0],' 'PARAMETER["latitude_of_origin",60.0],' 'PARAMETER["scale_factor",{0:8.10f}],' 'PARAMETER["false_easting",0.0],' 'PARAMETER["false_northing",0.0],' 'UNIT["m*1000.0",1000.0],' 'AXIS["X",EAST],' 'AXIS["Y",NORTH]]'.format( (1. + np.sin(np.radians(60.))) / (1. + np.sin(np.radians(90.))))) self.assertEqual( georef.create_osr('dwd-radolan').ExportToWkt(), radolan_wkt) aeqd_wkt = ('PROJCS["unnamed",' 'GEOGCS["WGS 84",' 'DATUM["unknown",' 'SPHEROID["WGS84",6378137,298.257223563]],' 'PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],' 'PROJECTION["Azimuthal_Equidistant"],' 'PARAMETER["latitude_of_center",{0:-f}],' 'PARAMETER["longitude_of_center",{1:-f}],' 'PARAMETER["false_easting",{2:-f}],' 'PARAMETER["false_northing",{3:-f}]]'.format( 49., 5., 0, 0)) self.assertEqual( georef.create_osr('aeqd', lon_0=5., lat_0=49).ExportToWkt(), aeqd_wkt) self.assertEqual( georef.create_osr('aeqd', lon_0=5., lat_0=49, x_0=0, y_0=0).ExportToWkt(), aeqd_wkt) with self.assertRaises(ValueError): georef.create_osr('lambert')
def setUp(self): img = np.zeros((360, 10), dtype=np.float32) img[2, 2] = 10 # isolated pixel img[5, 6:8] = 10 # line img[20, :] = 5 # spike img[60:120, 2:7] = 11 # precip field self.r = np.arange(0, 100000, 10000) self.az = np.arange(0, 360) self.el = np.arange(0, 90) self.th = np.zeros_like(self.az) self.az1 = np.ones_like(self.el) * 225 self.img = img self.proj = georef.create_osr("dwd-radolan") self.da_ppi = io.create_xarray_dataarray(img, self.r, self.az, self.th) self.da_rhi = io.create_xarray_dataarray(img[0:90], self.r, self.az1, self.el)
def test_plot_ppi(self): pl.figure() proj = georef.create_osr("dwd-radolan") ax, pm = vis.plot_ppi(self.img, re=6371000., ke=4./3.) ax, pm = vis.plot_ppi(self.img, autoext=False) vis.plot_ppi_crosshair(site=(0, 0), ranges=[2, 4, 8], angles=[0, 45, 90, 180, 270], line=dict(color='white', linestyle='solid')) pl.figure() ax, pm = vis.plot_ppi(self.img, site=(10., 45.), autoext=False, proj=proj) vis.plot_ppi_crosshair(site=(0, 0), ranges=[2, 4, 8], angles=[0, 45, 90, 180, 270], proj=proj, line=dict(color='white', linestyle='solid'))
def test_plot_ppi(self): pl.figure() proj = georef.create_osr("dwd-radolan") ax, pm = vis.plot_ppi(self.img, re=6371000., ke=4. / 3.) ax, pm = vis.plot_ppi(self.img, autoext=False) vis.plot_ppi_crosshair(site=(0, 0), ranges=[2, 4, 8], angles=[0, 45, 90, 180, 270], line=dict(color='white', linestyle='solid')) pl.figure() ax, pm = vis.plot_ppi(self.img, site=(10., 45.), autoext=False, proj=proj) vis.plot_ppi_crosshair(site=(0, 0), ranges=[2, 4, 8], angles=[0, 45, 90, 180, 270], proj=proj, line=dict(color='white', linestyle='solid'))
def test_create_osr(self): self.maxDiff = None radolan_wkt = 'PROJCS["Radolan projection",' \ 'GEOGCS["Radolan Coordinate System",' \ 'DATUM["Radolan Kugel",' \ 'SPHEROID["Erdkugel",6370040.0,0.0]],' \ 'PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],' \ 'UNIT["degree",0.017453292519943295],' \ 'AXIS["Longitude",EAST],' \ 'AXIS["Latitude",NORTH]],' \ 'PROJECTION["polar_stereographic"],' \ 'PARAMETER["central_meridian",10.0],' \ 'PARAMETER["latitude_of_origin",60.0],' \ 'PARAMETER["scale_factor",{0:8.10f}],' \ 'PARAMETER["false_easting",0.0],' \ 'PARAMETER["false_northing",0.0],' \ 'UNIT["m*1000.0",1000.0],' \ 'AXIS["X",EAST],' \ 'AXIS["Y",NORTH]]'.format((1. + np.sin(np.radians(60.))) / (1. + np.sin(np.radians(90.)))) self.assertEqual(georef.create_osr('dwd-radolan').ExportToWkt(), radolan_wkt)
def test_create_osr(self): self.maxDiff = None radolan_wkt = 'PROJCS["Radolan projection",' \ 'GEOGCS["Radolan Coordinate System",' \ 'DATUM["Radolan Kugel",' \ 'SPHEROID["Erdkugel",6370040.0,0.0]],' \ 'PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],' \ 'UNIT["degree",0.017453292519943295],' \ 'AXIS["Longitude",EAST],' \ 'AXIS["Latitude",NORTH]],' \ 'PROJECTION["polar_stereographic"],' \ 'PARAMETER["central_meridian",10.0],' \ 'PARAMETER["latitude_of_origin",60.0],' \ 'PARAMETER["scale_factor",{0:8.10f}],' \ 'PARAMETER["false_easting",0.0],' \ 'PARAMETER["false_northing",0.0],' \ 'UNIT["m*1000.0",1000.0],' \ 'AXIS["X",EAST],' \ 'AXIS["Y",NORTH]]'.format((1. + np.sin(np.radians(60.))) / (1. + np.sin(np.radians(90.)))) self.assertEqual( georef.create_osr('dwd-radolan').ExportToWkt(), radolan_wkt)
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_create_osr(self): self.maxDiff = None radolan_wkt = ( 'PROJCS["Radolan projection",' 'GEOGCS["Radolan Coordinate System",' 'DATUM["Radolan Kugel",' 'SPHEROID["Erdkugel",6370040.0,0.0]],' 'PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.017453292519943295],' 'AXIS["Longitude",EAST],' 'AXIS["Latitude",NORTH]],' 'PROJECTION["polar_stereographic"],' 'PARAMETER["central_meridian",10.0],' 'PARAMETER["latitude_of_origin",90.0],' 'PARAMETER["scale_factor",{0:8.10f}],' 'PARAMETER["false_easting",0.0],' 'PARAMETER["false_northing",0.0],' 'UNIT["m*1000.0",1000.0],' 'AXIS["X",EAST],' 'AXIS["Y",NORTH]]' ) radolan_wkt3 = ( 'PROJCS["Radolan Projection",' 'GEOGCS["Radolan Coordinate System",' 'DATUM["Radolan_Kugel",' 'SPHEROID["Erdkugel",6370040,0]],' 'PRIMEM["Greenwich",0,' 'AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,' 'AUTHORITY["EPSG","9122"]]],' 'PROJECTION["Polar_Stereographic"],' 'PARAMETER["latitude_of_origin",90],' 'PARAMETER["central_meridian",10],' 'PARAMETER["scale_factor",{0:8.12f}],' 'PARAMETER["false_easting",0],' 'PARAMETER["false_northing",0],' 'UNIT["kilometre",1000,' 'AUTHORITY["EPSG","9036"]],' 'AXIS["Easting",SOUTH],' 'AXIS["Northing",SOUTH]]' ) scale = (1.0 + np.sin(np.radians(60.0))) / (1.0 + np.sin(np.radians(90.0))) aeqd_wkt = ( 'PROJCS["unnamed",' 'GEOGCS["WGS 84",' 'DATUM["unknown",' 'SPHEROID["WGS84",6378137,298.257223563]],' 'PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],' 'PROJECTION["Azimuthal_Equidistant"],' 'PARAMETER["latitude_of_center",{0:-f}],' 'PARAMETER["longitude_of_center",{1:-f}],' 'PARAMETER["false_easting",{2:-f}],' 'PARAMETER["false_northing",{3:-f}],' 'UNIT["Meter",1]]' ) aeqd_wkt3 = ( 'PROJCS["unnamed",' 'GEOGCS["WGS 84",' 'DATUM["unknown",' 'SPHEROID["WGS84",6378137,298.257223563]],' 'PRIMEM["Greenwich",0],' 'UNIT["degree",0.0174532925199433]],' 'PROJECTION["Azimuthal_Equidistant"],' 'PARAMETER["latitude_of_center",{0:d}],' 'PARAMETER["longitude_of_center",{1:d}],' 'PARAMETER["false_easting",{2:d}],' 'PARAMETER["false_northing",{3:d}],' 'UNIT["Meter",1],' 'AXIS["Easting",EAST],' 'AXIS["Northing",NORTH]]' ) if gdal.VersionInfo()[0] >= "3": radolan_wkt = radolan_wkt3.format(scale) aeqd_wkt = aeqd_wkt3.format(49, 5, 0, 0) else: radolan_wkt = radolan_wkt.format(scale) aeqd_wkt = aeqd_wkt.format(49, 5, 0, 0) assert georef.create_osr("dwd-radolan").ExportToWkt() == radolan_wkt assert georef.create_osr("aeqd", lon_0=5, lat_0=49).ExportToWkt() == aeqd_wkt assert ( georef.create_osr("aeqd", lon_0=5, lat_0=49, x_0=0, y_0=0).ExportToWkt() == aeqd_wkt ) with pytest.raises(ValueError): georef.create_osr("lambert")
class TestPolarPlot: img = np.zeros((360, 10), dtype=np.float32) img[2, 2] = 10 # isolated pixel img[5, 6:8] = 10 # line img[20, :] = 5 # spike img[60:120, 2:7] = 11 # precip field r = np.arange(0, 100000, 10000) az = np.arange(0, 360) el = np.arange(0, 90) th = np.zeros_like(az) az1 = np.ones_like(el) * 225 img = img proj = georef.create_osr("dwd-radolan") da_ppi = georef.create_xarray_dataarray(img, r, az, th) da_ppi = georef.georeference_dataset(da_ppi, proj=None) da_rhi = georef.create_xarray_dataarray(img[0:90], r, az1, el) da_rhi = georef.georeference_dataset(da_rhi, proj=None) def test_plot_ppi(self): ax, pm = vis.plot_ppi(self.img, re=6371000.0, ke=(4.0 / 3.0)) ax, pm = vis.plot_ppi(self.img, self.r, self.az, re=6371000.0, ke=(4.0 / 3.0)) ax, pm = vis.plot_ppi( self.img, self.r, self.az, re=6371000.0, ke=(4.0 / 3.0), ax=ax ) ax, pm = vis.plot_ppi( self.img, self.r, self.az, re=6371000.0, ke=(4.0 / 3.0), ax=212 ) ax, pm = vis.plot_ppi(self.img) vis.plot_ppi_crosshair(site=(0, 0, 0), ranges=[2, 4, 8]) vis.plot_ppi_crosshair( site=(0, 0, 0), ranges=[2, 4, 8], angles=[0, 45, 90, 180, 270], line=dict(color="white", linestyle="solid"), ) ax, pm = vis.plot_ppi(self.img, self.r, site=(10.0, 45.0, 0.0), proj=self.proj) vis.plot_ppi_crosshair( site=(10.0, 45.0, 0.0), ranges=[2, 4, 8], angles=[0, 45, 90, 180, 270], proj=self.proj, line=dict(color="white", linestyle="solid"), ) ax, pm = vis.plot_ppi(self.img, func="contour") ax, pm = vis.plot_ppi(self.img, func="contourf") ax, pm = vis.plot_ppi(self.img, self.r, self.az, proj=self.proj, site=(0, 0, 0)) with pytest.warns(UserWarning): ax, pm = vis.plot_ppi(self.img, site=(10.0, 45.0, 0.0), proj=self.proj) with pytest.warns(UserWarning): ax, pm = vis.plot_ppi(self.img, proj=None, site=(0, 0, 0)) with pytest.raises(TypeError): ax, pm = vis.plot_ppi(self.img, proj=self.proj) with pytest.raises(ValueError): ax, pm = vis.plot_ppi(self.img, site=(0, 0), proj=self.proj) with pytest.raises(ValueError): vis.plot_ppi_crosshair(site=(0, 0), ranges=[2, 4, 8]) def test_plot_ppi_xarray(self): self.da_ppi.wradlib.rays self.da_ppi.wradlib.plot() self.da_ppi.wradlib.plot_ppi() self.da_ppi.wradlib.contour() self.da_ppi.wradlib.contourf() self.da_ppi.wradlib.pcolormesh() self.da_ppi.wradlib.plot(proj="cg") self.da_ppi.wradlib.plot_ppi(proj="cg") self.da_ppi.wradlib.contour(proj="cg") self.da_ppi.wradlib.contourf(proj="cg") self.da_ppi.wradlib.pcolormesh(proj="cg") with pytest.raises(TypeError): self.da_ppi.wradlib.pcolormesh(proj=self.proj) fig = pl.figure() ax = fig.add_subplot(111) with pytest.raises(TypeError): self.da_ppi.wradlib.pcolormesh(proj={"rot": 0, "scale": 1}, ax=ax) @pytest.mark.skipif("cartopy" not in sys.modules, reason="without Cartopy") def test_plot_ppi_cartopy(self): if cartopy: if (LooseVersion(cartopy.__version__) < LooseVersion("0.18.0")) and ( LooseVersion(mpl.__version__) >= LooseVersion("3.3.0") ): pytest.skip("fails for cartopy < 0.18.0 and matplotlib >= 3.3.0") site = (7, 45, 0.0) map_proj = cartopy.crs.Mercator(central_longitude=site[1]) ax, pm = vis.plot_ppi(self.img, self.r, self.az, proj=map_proj) assert isinstance(ax, cartopy.mpl.geoaxes.GeoAxes) fig = pl.figure(figsize=(10, 10)) ax = fig.add_subplot(111, projection=map_proj) self.da_ppi.wradlib.plot_ppi(ax=ax) ax.gridlines(draw_labels=True) def test_plot_rhi(self): ax, pm = vis.plot_rhi(self.img[0:90, :]) ax, pm = vis.plot_rhi(self.img[0:90, :], th_res=0.5) ax, pm = vis.plot_rhi(self.img[0:90, :], th_res=0.5, ax=212) ax, pm = vis.plot_rhi(self.img[0:90, :], r=np.arange(10), th=np.arange(90)) ax, pm = vis.plot_rhi(self.img[0:90, :], func="contour") ax, pm = vis.plot_rhi(self.img[0:90, :], func="contourf") ax, pm = vis.plot_rhi( self.img[0:90, :], r=np.arange(10), th=np.arange(90), proj=self.proj, site=(0, 0, 0), ) def test_plot_rhi_xarray(self): assert ( repr(self.da_rhi.wradlib).split("\n", 1)[1] == repr(self.da_rhi).split("\n", 1)[1] ) self.da_rhi.wradlib.rays self.da_rhi.wradlib.plot() self.da_rhi.wradlib.plot_rhi() self.da_rhi.wradlib.contour() self.da_rhi.wradlib.contourf() self.da_rhi.wradlib.pcolormesh() self.da_rhi.wradlib.plot(proj="cg") self.da_rhi.wradlib.plot_rhi(proj="cg") self.da_rhi.wradlib.contour(proj="cg") self.da_rhi.wradlib.contourf(proj="cg") self.da_rhi.wradlib.pcolormesh(proj="cg") def test_plot_cg_ppi(self): cgax, pm = vis.plot_ppi(self.img, elev=2.0, proj="cg") cgax, pm = vis.plot_ppi(self.img, elev=2.0, proj="cg", site=(0, 0, 0)) cgax, pm = vis.plot_ppi(self.img, elev=2.0, proj="cg", ax=cgax) fig, ax = pl.subplots(2, 2) with pytest.raises(TypeError): vis.plot_ppi(self.img, elev=2.0, proj="cg", ax=ax[0, 0]) cgax, pm = vis.plot_ppi(self.img, elev=2.0, proj="cg", ax=111) cgax, pm = vis.plot_ppi(self.img, elev=2.0, proj="cg", ax=121) cgax, pm = vis.plot_ppi(self.img, proj="cg") cgax, pm = vis.plot_ppi(self.img, func="contour", proj="cg") cgax, pm = vis.plot_ppi(self.img, func="contourf", proj="cg") cgax, pm = vis.plot_ppi(self.img, func="contourf", proj="cg") def test_plot_cg_rhi(self): cgax, pm = vis.plot_rhi(self.img[0:90, :], proj="cg") cgax, pm = vis.plot_rhi(self.img[0:90, :], proj="cg", ax=cgax) fig, ax = pl.subplots(2, 2) with pytest.raises(TypeError): vis.plot_rhi(self.img[0:90, :], proj="cg", ax=ax[0, 0]) cgax, pm = vis.plot_rhi(self.img[0:90, :], th_res=0.5, proj="cg") cgax, pm = vis.plot_rhi(self.img[0:90, :], proj="cg") cgax, pm = vis.plot_rhi( self.img[0:90, :], r=np.arange(10), th=np.arange(90), proj="cg" ) cgax, pm = vis.plot_rhi(self.img[0:90, :], func="contour", proj="cg") cgax, pm = vis.plot_rhi(self.img[0:90, :], func="contourf", proj="cg") def test_create_cg(self): cgax, caax, paax = vis.create_cg() cgax, caax, paax = vis.create_cg(subplot=121)
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()