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.

geomockimages is able to create both electro-optical as well as SAR images. More specificially, 4-band optical images and SAR images with one or two polarizations are supported explicitely. It is also possible to create images with more or less images, but the results will be less realistic.

Besides singe image tests, geomockimages can also create image pairs with small differences. This allows to do basic testing of change detection algorithms.

Install package

pip install geomockimages

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

Documentation

geomockimages was written for python engineers. The best way to learn about the option it offers do:

from geomockimages.imagecreator import GeoMockImage
help(GeoMockImage)

More examples

...can be found within two jupyter notebooks:

Basic 4-band optical example

SAR images and change detection

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.4.tar.gz (10.5 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.4-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geomockimages-0.2.4.tar.gz
  • Upload date:
  • Size: 10.5 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.4.tar.gz
Algorithm Hash digest
SHA256 0c075bdadf0db11242cbf73abc783e3b326b765deb6eca64fa1852a78cceb104
MD5 77a9f32c915557476d79487612bb8593
BLAKE2b-256 8a21115a9d4567e7cdc66200a99c491ee88053f04b5f7f5a057704f3cd49f738

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geomockimages-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 10.5 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a14bb56bc9953f21e241c25e7e79694b24a6f8d2f60e12856b464759442ba3b5
MD5 b86942e412800159194e0740e7dbb6b4
BLAKE2b-256 84eb22100e2a75a68699319c3fa451e874249673c54723d86179e72c0679c5fb

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