def test_png_thumbnail_has_expected_properties(): raster = GeoRaster2.open("tests/data/raster/rgb.tif") expected_thumbnail = raster.resize(dest_width=512, resampling=Resampling.nearest) result_thumbnail = GeoRaster2.from_bytes( raster.to_png(transparent=True, thumbnail_size=512, resampling=Resampling.nearest, in_range='image'), affine=expected_thumbnail.affine, crs=expected_thumbnail.crs, band_names=expected_thumbnail.band_names ) assert result_thumbnail == expected_thumbnail
def test_png_thumbnail_has_expected_properties(): raster = GeoRaster2.open("tests/data/raster/rgb.tif") expected_thumbnail = raster.resize(dest_width=512, resampling=Resampling.nearest) result_thumbnail = GeoRaster2.from_bytes( raster._repr_png_(), affine=expected_thumbnail.affine, crs=expected_thumbnail.crs, band_names=expected_thumbnail.band_names) assert result_thumbnail == expected_thumbnail
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)
def test_to_png_from_bytes(): arr = np.array( [np.full((3, 5), 1), np.full((3, 5), 5), np.full((3, 5), 10)], dtype=np.uint8) raster = GeoRaster2(image=arr, affine=Affine.identity(), crs=WEB_MERCATOR_CRS, band_names=['r', 'g', 'b']) png_bytes = raster.to_png() assert raster == GeoRaster2.from_bytes(png_bytes, affine=raster.affine, crs=raster.crs, band_names=raster.band_names)