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

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 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
        )

    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.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fake_geo_images-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fake-geo-images-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for fake-geo-images-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5898909478840c7d47df186882f075ae4b474710303869ef29fda3b1220d499c
MD5 1b2febdcf543d6b475967138edf4db9c
BLAKE2b-256 8a42861d8be971911c2c61565f6573c6d7da31ac1dc90595de1cdeee5b5bca51

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fake_geo_images-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for fake_geo_images-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b892dce321513fbf4f0ac2fbf4df6229a9791c738419484064d76e251180fbe
MD5 4bef0b8ce03829d177676d98dd12e40a
BLAKE2b-256 2bd6dc395960312d1244264a5ea98f341a27c2f94a4fb18af78335acd288078e

See more details on using hashes here.

Supported by

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