Exemplo n.º 1
0
def test_to_png_uses_the_first_three_bands_for_a_more_than_three_bands_raster(recwarn):
    raster = make_test_raster(257 * 42, band_names=[1, 2, 3, 4], dtype=np.int32)

    png_bytes = raster.to_png(transparent=True, thumbnail_size=512)

    w = recwarn.pop(GeoRaster2Warning)
    assert str(w.message) == "Limiting %d bands raster to first three bands to generate png" % raster.num_bands

    w = recwarn.pop(GeoRaster2Warning)
    assert str(w.message) == "downscaling dtype to 'uint8' to convert to png"

    img = Image.frombytes('RGBA', (raster.width, raster.height), png_bytes)
    expected_image_size = raster.limit_to_bands([1, 2]).astype(np.uint8).to_pillow_image().size
    assert img.size == expected_image_size
Exemplo n.º 2
0
def test_to_png_int32(recwarn):
    raster = make_test_raster(257 * 42, band_names=[1, 2, 3], dtype=np.int32)

    png_bytes = raster.to_png(transparent=True)
    w = recwarn.pop(GeoRaster2Warning)
    assert str(w.message) == "downscaling dtype to 'uint8' to convert to png"

    img = Image.frombytes('RGBA', (raster.width, raster.height), png_bytes)
    expected_image_size = raster.astype(np.uint8).to_pillow_image().size
    assert img.size == expected_image_size
    assert raster.astype(np.uint8) == GeoRaster2.from_bytes(
        png_bytes,
        affine=raster.affine,
        crs=raster.crs,
        band_names=raster.band_names)
Exemplo n.º 3
0
def test_to_png_uses_the_first_band_for_a_two_bands_raster(recwarn):
    raster = make_test_raster(257 * 42, band_names=[1, 2], dtype=np.int32)

    png_bytes = raster.to_png(transparent=True, thumbnail_size=512)
    w = recwarn.pop(GeoRaster2Warning)
    assert str(w.message) == "Deprecation: to_png of less then three bands raster will be not be supported in next \
release, please use: .colorize('gray').to_png()"
    w = recwarn.pop(GeoRaster2Warning)
    assert str(w.message) == "Limiting two bands raster to use the first band to generate png"

    w = recwarn.pop(GeoRaster2Warning)
    assert str(w.message) == "downscaling dtype to 'uint8' to convert to png"

    img = Image.frombytes('RGBA', (raster.width, raster.height), png_bytes)
    expected_image_size = raster.limit_to_bands([1]).astype(np.uint8).to_pillow_image().size
    assert img.size == expected_image_size
Exemplo n.º 4
0
def test_merge_all_different_crs():
    roi = GeoVector(
        Polygon.from_bounds(-6321833, -3092272, -6319273, -3089712),
        WEB_MERCATOR_CRS)
    affine = Affine.translation(-57, -26) * Affine.scale(0.00083, -0.00083)
    expected_resolution = 10
    expected_crs = WEB_MERCATOR_CRS

    # from memory
    raster_0 = make_test_raster(1, [1],
                                height=1200,
                                width=1200,
                                affine=affine,
                                crs=WGS84_CRS)
    result_0 = merge_all([raster_0],
                         roi=roi,
                         dest_resolution=expected_resolution,
                         crs=expected_crs)
    assert (result_0.resolution() == expected_resolution)
    assert (result_0.crs == expected_crs)
    assert (result_0.footprint().envelope.almost_equals(roi.envelope,
                                                        decimal=3))

    # from file
    path = "/vsimem/raster_for_test.tif"
    result_0.save(path)
    raster_1 = GeoRaster2.open(path)
    result_1 = merge_all([raster_1],
                         roi=roi,
                         dest_resolution=expected_resolution,
                         crs=expected_crs)

    assert (result_1.resolution() == expected_resolution)
    assert (result_1.crs == expected_crs)
    assert (result_1.footprint().envelope.almost_equals(roi.envelope,
                                                        decimal=3))
    assert (result_0 == result_1)
Exemplo n.º 5
0
import pytest
from unittest import mock

pytest.importorskip("tornado")  # noqa: E402

from common_for_tests import make_test_raster
from tornado.testing import AsyncHTTPTestCase
from tornado.concurrent import Future

import telluric as tl
from telluric.util.local_tile_server import TileServer, make_app, TileServerHandler

tiles = [(131072, 131072, 18), (65536, 65536, 17), (32768, 32768, 16), (16384, 16384, 15)]

rasters = [
    make_test_raster(i, band_names=["band%i" % i], height=300, width=400)
    for i in range(3)
]


class TestFCLocalTileServer(AsyncHTTPTestCase):

    def get_app(self):

        self.fc = tl.FeatureCollection([tl.GeoFeature.from_raster(r, {}) for r in rasters])
        TileServer.add_object(self.fc, self.fc.envelope)
        return make_app(TileServer.objects)

    def test_server_is_alive(self):
        response = self.fetch('/ok')
        self.assertEqual(response.code, 200)
Exemplo n.º 6
0
def test_astype_uint8_to_uint8_roundtrip():
    raster_uint8 = make_test_raster(value=20,
                                    band_names=[1, 2],
                                    dtype=np.uint8)
    assert raster_uint8 == raster_uint8.astype(np.uint16).astype(np.uint8)
Exemplo n.º 7
0
def test_astype_uint8_to_uint8_conversion():
    raster_uint8 = make_test_raster(value=42,
                                    band_names=[1, 2],
                                    dtype=np.uint8)
    raster_uint8_copy = raster_uint8.astype(np.uint8)
    assert raster_uint8 == raster_uint8_copy
Exemplo n.º 8
0
def test_astype_uint8_to_float32_conversion_without_stretching():
    raster_uint8 = make_test_raster(value=20, band_names=[1, 2], dtype=np.uint8)
    raster_float32 = raster_uint8.astype(np.float32, in_range=None, out_range=None)
    expected_raster_float32 = make_test_raster(value=20, band_names=[1, 2], dtype=np.float32)
    assert raster_float32 == expected_raster_float32
Exemplo n.º 9
0
def test_astype_float32_to_uint8_conversion_without_stretching():
    raster_float32 = make_test_raster(10.0, band_names=[1, 2], dtype=np.float32)
    raster_uint8 = raster_float32.astype(np.uint8, in_range=None, out_range=None)
    expected_raster_uint8 = make_test_raster(10, band_names=[1, 2], dtype=np.uint8)
    assert raster_uint8 == expected_raster_uint8
Exemplo n.º 10
0
def test_astype_raises_error_for_dtype_out_range_for_non_integer():
    raster = make_test_raster(value=20, band_names=[1, 2], dtype=np.uint8)
    with pytest.raises(GeoRaster2Error) as excinfo:
        raster.astype(np.float32, out_range='dtype')

    assert "Value 'dtype' of out_range parameter is supported only for integer type." in excinfo.exconly()
Exemplo n.º 11
0
def test_astype_uint8_to_int32_conversion():
    raster_uint8 = make_test_raster(42, band_names=[1, 2], dtype=np.uint8)
    raster_int32 = raster_uint8.astype(np.int32)
    expected_value = (2**32 - 1) / (2**8 - 1) * (42 - 127.5) - 1
    expected_raster_int32 = make_test_raster(expected_value, band_names=[1, 2], dtype=np.int32)
    assert raster_int32 == expected_raster_int32
Exemplo n.º 12
0
def test_astype_uint16_to_uint8_conversion():
    expected_raster_uint8 = make_test_raster(value=20, band_names=[1, 2], dtype=np.uint8)
    raster_uint16 = make_test_raster(128 * 42, band_names=[1, 2], dtype=np.uint16)
    raster_uint8 = raster_uint16.astype(np.uint8)
    assert raster_uint8 == expected_raster_uint8
Exemplo n.º 13
0
def test_astype_uint8_to_uint16_conversion():
    raster_uint8 = make_test_raster(value=42, band_names=[1, 2], dtype=np.uint8)
    raster_uint16 = raster_uint8.astype(np.uint16)
    expected_raster_uint16 = make_test_raster(257 * 42, band_names=[1, 2], dtype=np.uint16)
    assert raster_uint16 == expected_raster_uint16