Skip to main content

Fake geospatial images for unit tests

Project description

fake-geo-images

A module to programmatically create geotiff images which can be used for unit tests.

The underlying idea is that in order to write unit tests for geospatial image processsing algorithms, it is necessary to have an actual input image file or array. Organising these test images becomes a chore over time, they should not be stored in git as they are large binary data and when stored outside, there always is the danger that they are not updated according to changes in the code repo.

fake-geo-images provides a solution to the problem by providing simple code that allows to create geospatial images (so far geotiffs) in a parameterised way.

Install package

pip install fake-geo-images

Run tests

pytest

Usage

In the following an example unit test for a hypothetical NDVI function.

import numpy as np
import rasterio as rio
from pathlib import Path

from rasterio.transform import from_origin
from my_image_processing import ndvi
from fake_geo_images.fakegeoimages import FakeGeoImage

def test_ndvi():
    """
    A unit test if an NDVI method works in general
    """
    # Create 4-band image simulating RGBN as needed for NDVI
    test_image, _ = FakeGeoImage(
        300,
        150,
        4,
        "uint16",
        out_dir=Path("/tmp"),
        crs=4326,
        nodata=0,
        nodata_fill=3,
        cog=False,
    ).create(seed=42, transform=from_origin(13.428596, 52.494384, 0.000006, 0.000006))

    ndvi_image = ndvi(test_image)

    with rio.open(str(ndvi_image)) as src:
        ndvi_array = src.read()
        # NDVI only has one band of same size as input bands
        assert ndvi_array.shape == (1, 300, 150)
        # NDVI has float values between -1 and 1
        assert ndvi_array.dtype == np.float
        assert ndvi_array.min >= -1
        assert ndvi_array.max <= 1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fake-geo-images-0.1.4.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

fake_geo_images-0.1.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file fake-geo-images-0.1.4.tar.gz.

File metadata

  • Download URL: fake-geo-images-0.1.4.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.12

File hashes

Hashes for fake-geo-images-0.1.4.tar.gz
Algorithm Hash digest
SHA256 07910b50d2f58359f19a72df2ab8aaccd39ec7d71ffbb6e75d2527f12507dda5
MD5 8f03235e7f59f05e954e18369e0eed11
BLAKE2b-256 7bd5bd8a8c7469c1fef4dcf0495eb3f6e8afb68a04b60f9da904b7a44c110e26

See more details on using hashes here.

File details

Details for the file fake_geo_images-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fake_geo_images-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f04458d8dce4e3b2c58413778caf5cc7e5517e9afcf28c95e7f458a29a7349d1
MD5 aee5f536eb3519b732f034e8fb224307
BLAKE2b-256 ca715f59e012ac3c1f08f94ce5c09e931f8c6321712aba9043e7cd78afaac131

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page