Beispiel #1
0
    def test_read_from_file_with_missing_crs(self, no_crs_gdal_path):
        """
        We need to be able to read from data files even when GDAL can't automatically gather all the metdata.

        The :class:`RasterFileDataSource` is able to override the nodata, CRS and transform attributes if necessary.
        """
        crs = epsg4326
        nodata = -999
        transform = Affine(0.01, 0.0, 111.975,
                           0.0, 0.01, -9.975)
        data_source = RasterFileDataSource(no_crs_gdal_path, bandnumber=1, nodata=nodata, crs=crs, transform=transform)
        with pytest.warns(DeprecationWarning):
            with data_source.open() as src:
                dest1 = src.read()
                assert dest1.shape == (10, 10)
Beispiel #2
0
    def test_read_with_rasterfiledatasource(self, make_sample_geotiff, dst_nodata):
        sample_geotiff_path, geobox, written_data = make_sample_geotiff(dst_nodata)

        source = RasterFileDataSource(str(sample_geotiff_path), 1)

        dest = np.zeros_like(written_data)
        dst_transform = geobox.transform
        dst_projection = epsg3577
        dst_resampling = Resampling.nearest

        # Read exactly the hunk of data that we wrote
        _read_from_source(source, dest, dst_transform, dst_nodata, dst_projection, dst_resampling)

        assert np.all(written_data == dest)

        # Try reading from partially outside of our area
        xoff = 50
        offset_transform = dst_transform * Affine.translation(xoff, 0)
        dest = np.zeros_like(written_data)

        _read_from_source(source, dest, offset_transform, dst_nodata, dst_projection, dst_resampling)
        assert np.all(written_data[:, xoff:] == dest[:, :xoff])

        # Try reading from complete outside of our area, should return nodata
        xoff = 300
        offset_transform = dst_transform * Affine.translation(xoff, 0)
        dest = np.zeros_like(written_data)

        _read_from_source(source, dest, offset_transform, dst_nodata, dst_projection, dst_resampling)
        if np.isnan(dst_nodata):
            assert np.all(np.isnan(dest))
        else:
            assert np.all(dst_nodata == dest)
 def _read(gbox,
           resampling='nearest',
           fallback_nodata=None,
           dst_nodata=-999):
     with RasterFileDataSource(mm.path, 1, nodata=fallback_nodata).open() as rdr:
         yy = np.full(gbox.shape, dst_nodata, dtype=rdr.dtype)
         roi = read_time_slice(rdr, yy, gbox, resampling, dst_nodata)
         return yy, roi
    def _read(gbox, resampling='nearest',
              fallback_nodata=-999,
              dst_nodata=-999,
              check_paste=False):
        with RasterFileDataSource(mm.path, 1, nodata=fallback_nodata).open() as rdr:
            if check_paste:
                # check that we are using paste
                paste_ok, reason = can_paste(compute_reproject_roi(rdr_geobox(rdr), gbox))
                assert paste_ok is True, reason

            yy = np.full(gbox.shape, dst_nodata, dtype=rdr.dtype)
            roi = read_time_slice(rdr, yy, gbox, resampling, dst_nodata)
            return yy, roi
Beispiel #5
0
    def test_read_data_from_outside_file_region(self, make_sample_netcdf, dst_transform):
        sample_nc, geobox, written_data = make_sample_netcdf

        source = RasterFileDataSource(sample_nc, 1)

        dest = np.zeros((200, 1000))
        dst_nodata = -999
        dst_projection = epsg3577
        dst_resampling = Resampling.nearest

        # Read exactly the hunk of data that we wrote
        _read_from_source(source, dest, dst_transform, dst_nodata, dst_projection, dst_resampling)

        assert np.all(dest == -999)
Beispiel #6
0
    def xtest_failed_data_read(self, make_sample_geotiff, dst_nodata):
        sample_geotiff_path, geobox, written_data = make_sample_geotiff(dst_nodata)

        src_transform = Affine(25.0, 0.0, 1200000.0,
                               0.0, -25.0, -4200000.0)
        source = RasterFileDataSource(sample_geotiff_path, 1, transform=src_transform)

        dest = np.zeros((20, 100))
        dst_nodata = -999
        dst_projection = epsg3577
        dst_resampling = Resampling.nearest

        # Read exactly the hunk of data that we wrote
        dst_transform = Affine(25.0, 0.0, 127327.0,
                               0.0, -25.0, -417232.0)
        _read_from_source(source, dest, dst_transform, dst_nodata, dst_projection, dst_resampling)

        assert np.all(written_data == dest)