Пример #1
0
    def test_to_cartopy(self):

        import cartopy.crs as ccrs
        from salem import GeoNetcdf, GeoTiff

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000000, 2000000))
        p = gis.proj_to_cartopy(grid.proj)
        assert isinstance(p, ccrs.TransverseMercator)
        fuzzy_proj_tester(grid.proj, pyproj.Proj(p.proj4_params))

        ds = GeoNetcdf(get_demo_file('wrfout_d01.nc'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.LambertConformal)
        fuzzy_proj_tester(ds.grid.proj, pyproj.Proj(p.proj4_params))

        ds = GeoNetcdf(get_demo_file('wrf_mercator.nc'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.Mercator)
        fuzzy_proj_tester(ds.grid.proj, pyproj.Proj(p.proj4_params))

        ds = GeoTiff(get_demo_file('himalaya.tif'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.PlateCarree)

        ds = GeoTiff(get_demo_file('hef_roi.tif'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.PlateCarree)
        fuzzy_proj_tester(ds.grid.proj, pyproj.Proj(p.proj4_params))

        p = gis.proj_to_cartopy(wgs84)
        assert isinstance(p, ccrs.PlateCarree)

        p = gis.proj_to_cartopy(pyproj.Proj('+proj=utm +zone=15'))
        assert isinstance(p, ccrs.UTM)

        # this needs gdal
        if gis.has_gdal:
            p = gis.proj_to_cartopy(pyproj.Proj(init='epsg:26915'))
            assert isinstance(p, ccrs.UTM)
Пример #2
0
    def test_to_cartopy(self):

        import cartopy.crs as ccrs
        from salem import GeoNetcdf, GeoTiff

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000000, 2000000))
        p = gis.proj_to_cartopy(grid.proj)
        assert isinstance(p, ccrs.TransverseMercator)
        fuzzy_proj_tester(grid.proj, pyproj.Proj(p.proj4_params))

        ds = GeoNetcdf(get_demo_file('wrfout_d01.nc'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.LambertConformal)
        fuzzy_proj_tester(ds.grid.proj, pyproj.Proj(p.proj4_params))

        ds = GeoNetcdf(get_demo_file('wrf_mercator.nc'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.Mercator)
        fuzzy_proj_tester(ds.grid.proj, pyproj.Proj(p.proj4_params))

        ds = GeoTiff(get_demo_file('himalaya.tif'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.PlateCarree)

        ds = GeoTiff(get_demo_file('hef_roi.tif'))
        p = gis.proj_to_cartopy(ds.grid.proj)
        assert isinstance(p, ccrs.PlateCarree)
        fuzzy_proj_tester(ds.grid.proj, pyproj.Proj(p.proj4_params))

        p = gis.proj_to_cartopy(wgs84)
        assert isinstance(p, ccrs.PlateCarree)

        p = gis.proj_to_cartopy(pyproj.Proj('+proj=utm +zone=15'))
        assert isinstance(p, ccrs.UTM)

        # this needs gdal
        if gis.has_gdal:
            p = gis.proj_to_cartopy(pyproj.Proj(init='epsg:26915'))
            assert isinstance(p, ccrs.UTM)
Пример #3
0
    def test_mercatorgrid(self):

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000000, 2000000))
        lon1, lat1 = grid.center_grid.ll_coordinates
        e1 = grid.extent
        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000000, 2000000),
                                 origin='upper-left')
        lon2, lat2 = grid.center_grid.ll_coordinates
        e2 = grid.extent

        assert_allclose(e1, e2)
        assert_allclose(lon1, lon2[::-1, :])
        assert_allclose(lat1, lat2[::-1, :])

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000, 2000),
                                 nx=100)
        lon1, lat1 = grid.pixcorner_ll_coordinates
        e1 = grid.extent
        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000, 2000),
                                 origin='upper-left',
                                 nx=100)
        lon2, lat2 = grid.pixcorner_ll_coordinates
        e2 = grid.extent

        assert_allclose(e1, e2)
        assert_allclose(lon1, lon2[::-1, :])
        assert_allclose(lat1, lat2[::-1, :])

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000, 2000),
                                 nx=10)
        e1 = grid.extent
        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                 extent=(2000, 2000),
                                 origin='upper-left',
                                 nx=9)
        e2 = grid.extent
        assert_allclose(e1, e2)
Пример #4
0
    def test_mercatorgrid(self):

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                         extent=(2000000, 2000000))
        lon1, lat1 = grid.center_grid.ll_coordinates
        e1 = grid.extent
        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                         extent=(2000000, 2000000),
                                         order='ul')
        lon2, lat2 = grid.center_grid.ll_coordinates
        e2 = grid.extent

        assert_allclose(e1, e2)
        assert_allclose(lon1, lon2[::-1, :])
        assert_allclose(lat1, lat2[::-1, :])

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                         extent=(2000, 2000),
                                         nx=100)
        lon1, lat1 = grid.pixcorner_ll_coordinates
        e1 = grid.extent
        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                         extent=(2000, 2000),
                                         order='ul',
                                         nx=100)
        lon2, lat2 = grid.pixcorner_ll_coordinates
        e2 = grid.extent

        assert_allclose(e1, e2)
        assert_allclose(lon1, lon2[::-1, :])
        assert_allclose(lat1, lat2[::-1, :])

        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                         extent=(2000, 2000),
                                         nx=10)
        e1 = grid.extent
        grid = gis.mercator_grid(center_ll=(11.38, 47.26),
                                         extent=(2000, 2000),
                                         order='ul',
                                         nx=9)
        e2 = grid.extent
        assert_allclose(e1, e2)