Skip to main content

A module to programmatically create geotiff images which can be used 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.

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

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

geomockimages-0.2.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

geomockimages-0.2.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file geomockimages-0.2.0.tar.gz.

File metadata

  • Download URL: geomockimages-0.2.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Darwin/23.5.0

File hashes

Hashes for geomockimages-0.2.0.tar.gz
Algorithm Hash digest
SHA256 08512722bfb8622497d285839030e8d29f8f350753abc8fbc63d79bb7a366d81
MD5 43fc30cd76bce34812ef242fecdb25db
BLAKE2b-256 4082ff5c22b7b1eacec510ae797218309285580a1fb51ff689265ee8a137fee4

See more details on using hashes here.

File details

Details for the file geomockimages-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: geomockimages-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Darwin/23.5.0

File hashes

Hashes for geomockimages-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cca4af87891bc7d8263f62141cf6716bbc658edcb737251f229aeb0ab15c80b
MD5 40e7a3aaaf0a978dd5955b42046acff5
BLAKE2b-256 3f91b60bbceb1b781e2e8a3c793dac5cd2b62b3c683e72cb2a75fb2ecbe535d4

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