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

Uploaded Python 3

File details

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

File metadata

  • Download URL: geomockimages-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 d9fc9a96bbdc746c58671e89948b0f9cecc711b5e0db9808519ef12c52d708bc
MD5 e42fd52ae670736757b5d8aa6d933d9e
BLAKE2b-256 f0254fd51900c62327402e1b3556baa392890791d299804317a2568b288ec255

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geomockimages-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fbd19709fda9e504dcfa08255eaf27200ed116fb8cc99ac360cdabb2aee3cc9a
MD5 16f943a10e197f0a23e14a35fd858b10
BLAKE2b-256 eaac35a67f1d4987e7d433dde62f1b846cc3abff78c516c82a690c8f24cdd707

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