def test_epsg_to_osr(self): self.assertEqual(georef.epsg_to_osr(4326).ExportToWkt(), 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]') self.assertEqual(georef.epsg_to_osr().ExportToWkt(), 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]')
def setUp(self): self.site = (7.0, 53.0, 100.) self.proj = georef.epsg_to_osr(31467) self.az = np.arange(0., 360., 1.) self.r = np.arange(0, 100000, 1000) self.el = 2.5 self.coords = vpr.volcoords_from_polar(self.site, self.el, self.az, self.r, self.proj)
def test_epsg_to_osr(self): self.assertEqual( georef.epsg_to_osr(4326).ExportToWkt(), 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]') self.assertEqual( georef.epsg_to_osr().ExportToWkt(), 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]')
def test_create_xarray_dataarray(self): img = np.zeros((360, 10), dtype=np.float32) r = np.arange(0, 100000, 10000) az = np.arange(0, 360) th = np.zeros_like(az) proj = georef.epsg_to_osr(4326) with pytest.raises(TypeError): georef.create_xarray_dataarray(img) georef.create_xarray_dataarray(img, r, az, th, proj=proj)
def setUp(self): self.r = np.arange(1, 100, 10) self.az = np.arange(0, 360, 90) self.site = (9.7839, 48.5861) self.proj = georef.epsg_to_osr(31467) # Coordinates of the rain gages in Gauss-Krueger 3 coordinates self.x, self.y = (np.array([3557880, 3557890]), np.array([5383379, 5383375])) np.random.seed(42) self.data = np.random.random((len(self.az), len(self.r)))
def test_reproject_raster_dataset(self): georef.reproject_raster_dataset(self.ds, spacing=0.005, resample=gdal.GRA_Bilinear, align=True) georef.reproject_raster_dataset(self.ds, size=(1000, 1000), resample=gdal.GRA_Bilinear, align=True) self.assertRaises(NameError, lambda: georef.reproject_raster_dataset(self.ds)) dst = georef.epsg_to_osr(31466) georef.reproject_raster_dataset(self.ds, spacing=100., resample=gdal.GRA_Bilinear, align=True, projection_target=dst)
def test_reproject_raster_dataset(self): georef.reproject_raster_dataset( self.ds, spacing=0.005, resample=gdal.GRA_Bilinear, align=True ) georef.reproject_raster_dataset( self.ds, size=(1000, 1000), resample=gdal.GRA_Bilinear, align=True ) with pytest.raises(NameError): georef.reproject_raster_dataset(self.ds) dst = georef.epsg_to_osr(25832) georef.reproject_raster_dataset( self.ds, spacing=100.0, resample=gdal.GRA_Bilinear, align=True, projection_target=dst, )
def ex_georef(): # -------------------------------------------------------------------------- # EXAMPLE 1: Full workflow for georeferencing radar data # 1st step: generate the centroid coordinates of the radar bins # define the polar coordinates and the site coordinates in lat/lon r = np.arange(1, 129) * 1000 az = np.linspace(0, 360, 361)[0:-1] # drs: 51.12527778 ; fbg: 47.87444444 ; tur: 48.58611111 ; muc: 48.3372222 # drs: 13.76972222 ; fbg: 8.005 ; tur: 9.783888889 ; muc: 11.61277778 sitecoords = (9.7839, 48.5861) # these are the polgon vertices of the radar bins polygons = georef.polar2polyvert(r, az, sitecoords) # these are the corresponding centroids cent_lon, cent_lat = georef.polar2centroids(r, az, sitecoords) # plot the vertices and the centroids in one plot fig = pl.figure(figsize=(8, 8)) ax = fig.add_subplot(111) polycoll = mpl.collections.PolyCollection(polygons, closed=True, facecolors='None') ax.add_collection(polycoll, autolim=True) ax.plot(cent_lon, cent_lat, 'r+') ax.axis('tight') pl.title('Zoom in to compare polygons and centroids.') pl.show() # 2nd step: reproject the centroid coordinates to Gauss-Krueger Zone 3 # by using the EPSG-Number 31467 # use it for projecting the centroids to Gauss-Krueger 3 proj_gk3 = georef.epsg_to_osr(31467) x, y = georef.reproject(cent_lon, cent_lat, projection_targe=proj_gk3) # export the projected centroid coordinates # f = open('centroids.tab', 'w') f = 'centroids.tab' # f.write('x\ty\n') np.savetxt(f, np.hstack((x.reshape((-1, 1)), y.reshape((-1, 1)))), fmt='%.2f', header='x\ty', delimiter='\t') # f.close() print('Exit.')
def setUp(self): # polar grid settings self.site = (7.0, 53.0, 100.) self.proj = georef.epsg_to_osr(31467) self.az = np.arange(0., 360., 2.) + 1. self.r = np.arange(0., 50000., 1000.) self.elev = np.array([1., 3., 5., 10.]) # cartesian grid settings self.maxrange = 50000. self.minelev = 1. self.maxelev = 10. self.maxalt = 8000. self.horiz_res = 4000. self.vert_res = 1000. self.xyz = vpr.volcoords_from_polar(self.site, self.elev, self.az, self.r, self.proj) self.data = vpr.synthetic_polar_volume(self.xyz) self.trgxyz, self.trgshape = vpr.make_3d_grid(self.site, self.proj, self.maxrange, self.maxalt, self.horiz_res, self.vert_res)
class TestPolarNeighbours: r = np.arange(1, 100, 10) az = np.arange(0, 360, 90) site = (9.7839, 48.5861) proj = georef.epsg_to_osr(31467) # Coordinates of the rain gages in Gauss-Krueger 3 coordinates x, y = (np.array([3557880, 3557890]), np.array([5383379, 5383375])) np.random.seed(42) data = np.random.random((len(az), len(r))) def test___init__(self): verify.PolarNeighbours(self.r, self.az, self.site, self.proj, self.x, self.y, nnear=9) def test_extract(self): pn = verify.PolarNeighbours(self.r, self.az, self.site, self.proj, self.x, self.y, nnear=4) neighbours = pn.extract(self.data) res0 = np.array([0.59241457, 0.04645041, 0.51423444, 0.19967378]) res1 = np.array([0.04645041, 0.59241457, 0.51423444, 0.19967378]) np.testing.assert_allclose(neighbours[0], res0) np.testing.assert_allclose(neighbours[1], res1) def test_get_bincoords(self): pn = verify.PolarNeighbours(self.r, self.az, self.site, self.proj, self.x, self.y, nnear=4) bx, by = pn.get_bincoords() np.testing.assert_allclose(bx[0], 3557908.88665658, rtol=1e-6) np.testing.assert_allclose(by[0], 5383452.639404042, rtol=1e-6) def test_get_bincoords_at_points(self): pn = verify.PolarNeighbours(self.r, self.az, self.site, self.proj, self.x, self.y, nnear=4) bx, by = pn.get_bincoords_at_points() resx0 = np.array([ 3557909.62605379, 3557909.72874732, 3557909.52336013, 3557909.42066632 ]) resx1 = np.array([ 3557909.72874732, 3557909.62605379, 3557909.52336013, 3557909.42066632 ]) resy0 = np.array([ 5383380.64013055, 5383370.64023136, 5383390.64002972, 5383400.6399289 ]) resy1 = np.array([ 5383370.64023136, 5383380.64013055, 5383390.64002972, 5383400.6399289 ]) np.testing.assert_allclose(bx[0], resx0, rtol=1e-6) np.testing.assert_allclose(bx[1], resx1, rtol=1e-6) np.testing.assert_allclose(by[0], resy0, rtol=1e-6) np.testing.assert_allclose(by[1], resy1, rtol=1e-6)
def test_epsg_to_osr(self): self.assertEqual(georef.epsg_to_osr(4326).ExportToWkt(), self.wgs84) self.assertEqual(georef.epsg_to_osr().ExportToWkt(), self.wgs84)
proj = Transformer.from_crs(crs.geodetic_crs, crs) df = pd.read_csv(filename, delimiter=",") ######################################## loop sobre el satelite lat long for i in range(0, df.shape[0]): a, b = proj.transform(df.Latitude[i], df.Longitude[i]) #radar x.append(a) y.append(b) x = np.array(x) y = np.array(y) az = np.linspace(0, 360, 361)[0:-1] proj = georef.epsg_to_osr(4326) ###################### os.chdir('/home/arielcg/QRO_2015/') print(os.getcwd()) path = r'/home/arielcg/QRO_2015/' d1 = date(2015, 6, 1) # start date d2 = date(2015, 6, 8) # end date delta = d2 - d1 # timedelta for i in range(delta.days + 1): dat = d1 + timedelta(days=i) ase = "RAW_NA_000_236*" + '%02d' % dat.month + '%02d' % dat.day + "*" ase2 = '%02d' % dat.month + '%02d' % dat.day + ".tiff"
def setUp(self): self.site = (7.0, 53.0, 100.) self.proj = georef.epsg_to_osr(31467) self.az = np.arange(0., 360., 2.) self.r = np.arange(0, 50000, 1000) self.el = 2.5
class TestCartesianVolume: # polar grid settings site = (7.0, 53.0, 100.0) proj = georef.epsg_to_osr(31467) az = np.arange(0.0, 360.0, 2.0) + 1.0 r = np.arange(0.0, 50000.0, 1000.0) elev = np.array([1.0, 3.0, 5.0, 10.0]) # cartesian grid settings maxrange = 50000.0 minelev = 1.0 maxelev = 10.0 maxalt = 8000.0 horiz_res = 4000.0 vert_res = 1000.0 xyz = vpr.volcoords_from_polar(site, elev, az, r, proj) data = vpr.synthetic_polar_volume(xyz) trgxyz, trgshape = vpr.make_3d_grid( site, proj, maxrange, maxalt, horiz_res, vert_res, ) def test_CartesianVolume(self): gridder = vpr.CartesianVolume( self.xyz, self.trgxyz, self.trgshape, self.maxrange, self.minelev, self.maxelev, ) out = gridder(self.data) assert out.shape == (6084, ) assert len(np.where(np.isnan(out))[0]) == 0 def test_CAPPI(self): gridder = vpr.CAPPI( self.xyz, self.trgxyz, self.trgshape, self.maxrange, self.minelev, self.maxelev, ) out = gridder(self.data) assert out.shape == (6084, ) # Todo: find out where this discrepancy comes from from osgeo import gdal if gdal.VersionInfo()[0] >= "3": size = 3528 else: size = 3512 assert len(np.where(np.isnan(out))[0]) == size def test_PseudoCAPPI(self): # interpolate to Cartesian 3-D volume grid gridder = vpr.PseudoCAPPI( self.xyz, self.trgxyz, self.trgshape, self.maxrange, self.minelev, self.maxelev, ) out = gridder(self.data) assert out.shape == (6084, ) assert len(np.where(np.isnan(out))[0]) == 1744
class TestVPRHelperFunctions: site = (7.0, 53.0, 100.0) proj = georef.epsg_to_osr(31467) az = np.arange(0.0, 360.0, 2.0) r = np.arange(0, 50000, 1000) el = 2.5 def test_out_of_range(self): pass def test_blindspots(self): pass def test_volcoords_from_polar(self): coords = vpr.volcoords_from_polar(self.site, self.el, self.az, self.r, self.proj) assert coords.shape == (9000, 3) def test_volcoords_from_polar_irregular(self): # oneazforall, onerange4all, one elev coords = vpr.volcoords_from_polar_irregular(self.site, [self.el], self.az, self.r, self.proj) assert coords.shape == (9000, 3) # oneazforall, onerange4all, two elev coords = vpr.volcoords_from_polar_irregular(self.site, [self.el, 5.0], self.az, self.r, self.proj) assert coords.shape == (18000, 3) # onerange4all, two elev coords = vpr.volcoords_from_polar_irregular(self.site, [self.el, 5.0], [self.az, self.az], self.r, self.proj) assert coords.shape == (18000, 3) # oneazforall, two elev coords = vpr.volcoords_from_polar_irregular(self.site, [self.el, 5.0], self.az, [self.r, self.r], self.proj) assert coords.shape == (18000, 3) def test_synthetic_polar_volume(self): nbins = [320, 240, 340, 300] rscale = [1000, 1000, 500, 500] elev = [0.3, 0.4, 3.0, 4.5] xyz = np.array([]).reshape((-1, 3)) for i, vals in enumerate(zip(nbins, rscale, elev)): az = np.arange(0.0, 360.0, 2.0) r = np.arange(0, vals[0] * vals[1], vals[1]) xyz_ = vpr.volcoords_from_polar(self.site, vals[2], az, r, self.proj) xyz = np.vstack((xyz, xyz_)) vol = vpr.synthetic_polar_volume(xyz) assert vol.shape == (216000, ) def test_norm_vpr_stats(self): vol = np.arange(2 * 3 * 4).astype("f4").reshape((4, 3, 2))**2 prof = vpr.norm_vpr_stats(vol, 1) np.allclose(prof, np.array([0.09343848, 1.0, 3.0396144, 6.2122827])) def test_make_3d_grid(self): maxrange = 50000.0 maxalt = 5000.0 horiz_res = 4000.0 vert_res = 1000.0 outxyz, outshape = vpr.make_3d_grid(self.site, self.proj, maxrange, maxalt, horiz_res, vert_res) assert outshape == (6, 26, 26) assert outxyz.shape == (4056, 3)
def test_epsg_to_osr(self): assert georef.epsg_to_osr(4326).ExportToWkt() == self.wgs84 assert georef.epsg_to_osr().ExportToWkt() == self.wgs84