Beispiel #1
0
def test_window_shape_errors():
    # Positive height and width are needed when stop is None.
    with pytest.raises(ValueError):
        assert shape(((10, 20), (10, None)))

    with pytest.raises(ValueError):
        assert shape(((-1, 10), (10, 20)))
Beispiel #2
0
def test_window_shape_errors():
    # Positive height and width are needed when stop is None.
    with pytest.raises(ValueError):
        assert shape(((10, 20), (10, None)))

    with pytest.raises(ValueError):
        assert shape(((-1, 10), (10, 20)))
Beispiel #3
0
    def reproject_band(self, band, src_transform, bbox):
        # shift dst_transform
        # bbox --> (left, bottom, right, top)
        assert self.out_res in ["10", "30", "20", "60"
                                ], "output resolution must be 10, 20, 30 or 60"

        transform_out_res = self.transform_dict[self.out_res][0]

        dst_transform = rasterio.Affine(
            transform_out_res.a, transform_out_res.b,
            bbox[0] if transform_out_res.a > 0 else bbox[2],
            transform_out_res.d, transform_out_res.e,
            bbox[3] if transform_out_res.e < 0 else bbox[1])

        window_read = windows.from_bounds(*bbox, dst_transform)
        shape_new = tuple([int(round(s)) for s in windows.shape(window_read)])
        data_new_proj = np.ndarray(shape=shape_new, dtype=band.dtype)

        reproject(band,
                  data_new_proj,
                  src_transform=src_transform,
                  src_crs=self.crs,
                  dst_transform=dst_transform,
                  dst_crs=self.crs,
                  resampling=Resampling.cubic_spline)

        return data_new_proj
Beispiel #4
0
def fetch_raster_window(
    asset_entry: Optional[Tuple[Reader, windows.Window]],
    slices: Tuple[slice, ...],
) -> np.ndarray:
    current_window = windows.Window.from_slices(*slices)
    if asset_entry is not None:
        reader, asset_window = asset_entry

        # check that the window we're fetching overlaps with the asset
        if windows.intersect(current_window, asset_window):
            # backend: Backend = manager.acquire(needs_lock=False)
            data = reader.read(current_window)

            return data[None, None]

    # no dataset, or we didn't overlap it: return empty data.
    # use the broadcast trick for even fewer memz
    return np.broadcast_to(np.nan, (1, 1) + windows.shape(current_window))
Beispiel #5
0
def test_shape_negative_stop():
    assert shape(((None, -1), (None, -1)), 100, 90) == (99, 89)
Beispiel #6
0
def test_shape_positive():
    assert shape(((0, 4), (1, 102))) == (4, 101)
Beispiel #7
0
def test_shape_negative_start():
    assert shape(((-10, None), (-10, None)), 100, 90) == (10, 10)
    assert shape(((-1, None), (-1, None)), 100, 90) == (1, 1)
Beispiel #8
0
def test_window_shape_None_start():
    assert shape(((None, 4), (None, 102))) == (4, 102)
Beispiel #9
0
def test_shape_None_stop():
    assert shape(((10, None), (10, None)), 100, 90) == (90, 80)
Beispiel #10
0
def window_shape(*args, **kwargs):
    from rasterio.windows import shape
    warnings.warn("Deprecated; Use rasterio.windows instead", FutureWarning)
    return shape(*args, **kwargs)
Beispiel #11
0
def window_shape(*args, **kwargs):
    from rasterio.windows import shape
    warnings.warn("Deprecated; Use rasterio.windows instead", FutureWarning)
    return shape(*args, **kwargs)
def test_shape_negative_start():
    assert shape(((None, ~0), (None, ~0)), 100, 90) == (99, 89)
Beispiel #13
0
def test_shape_negative():
    assert shape(((-10, None), (-10, None)), 100, 90) == (10, 10)
    assert shape(((~0, None), (~0, None)), 100, 90) == (1, 1)
    assert shape(((None, ~0), (None, ~0)), 100, 90) == (99, 89)
Beispiel #14
0
def test_shape_negative_stop():
    assert shape(((None, -1), (None, -1)), 100, 90) == (99, 89)
Beispiel #15
0
def test_shape_negative():
    assert shape(((-10, None), (-10, None)), 100, 90) == (10, 10)
    assert shape(((~0, None), (~0, None)), 100, 90) == (1, 1)
    assert shape(((None, ~0), (None, ~0)), 100, 90) == (99, 89)
Beispiel #16
0
def test_shape_negative_start():
    assert shape(((-10, None), (-10, None)), 100, 90) == (10, 10)
    assert shape(((-1, None), (-1, None)), 100, 90) == (1, 1)
Beispiel #17
0
def test_shape_positive():
    assert shape(((0, 4), (1, 102))) == (4, 101)
Beispiel #18
0
def test_shape_None_stop():
    assert shape(((10, None), (10, None)), 100, 90) == (90, 80)
Beispiel #19
0
def test_window_shape_None_start():
    assert shape(((None, 4), (None, 102))) == (4, 102)
Beispiel #20
0
def test_shape_negative_start():
    assert shape(((None, ~0), (None, ~0)), 100, 90) == (99, 89)