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.3.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.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geomockimages-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 1b3ad4d02e0076e02341f1e0935d8cce10cf31ad8ff91e6d708fe0719183c6a0
MD5 16eb39518d099f26ff38a3e205d0c055
BLAKE2b-256 a9af622dad4e36f808c350f4c50b310f98c85854ddef2dc3f72b269be9e36d46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geomockimages-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c5eafccc62e09830d8e62d2b8d9907c3cc7e508c7a23418858c02e7ab857a502
MD5 2983b59559e50a7e58872fcf19b19108
BLAKE2b-256 482d86557c4580f0e201db4ef7bff0b4bfee162c0d7621229ff70191222900b2

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