Skip to main content

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

Project description

geomockimages

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 geomockimages.imagecreator import GeoMockImage

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, _ = GeoMockImage(
        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, 150, 300)
        # NDVI has float values between -1 and 1
        assert ndvi_array.dtype == np.dtype('float32')
        assert np.nanmin(ndvi_array) >= -1
        assert np.nanmax(ndvi_array) <= 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.1.tar.gz (9.7 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.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geomockimages-0.2.1.tar.gz
  • Upload date:
  • Size: 9.7 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.1.tar.gz
Algorithm Hash digest
SHA256 c121e6b80f61c9707d0fd574a13fe6338d4f2e1e05b94b27995a9abca56c396a
MD5 b4c356dad852939024e5ad13b2e60b25
BLAKE2b-256 c5ec58aa502812c7ae0aff736b6897798618b000d182dc4367a5b91a7c08c50e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geomockimages-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7df4e578c4871da972f7eda40c59d31187997b71582240395a912d1998ecd2e2
MD5 a51ae658f0cc92726f4ce7f67d4a8ab8
BLAKE2b-256 151b694567e5d3cdc1894964dfacc04eb03b6f68de20d8bb5448d3bb2c9bb1a0

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