Fake geospatial images 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.
fake-geo-images 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 fake-geo-images
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 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)
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
Built Distribution
File details
Details for the file fake-geo-images-0.1.3.tar.gz
.
File metadata
- Download URL: fake-geo-images-0.1.3.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eb06406cf2f8b2df81a5c3d9f49356d6ebdea61e9537340558be7fc33438bb6 |
|
MD5 | ebe5e71986e63059b462850380c8e99e |
|
BLAKE2b-256 | a99f40a11184f61480f88254f5e62dcaf8ac25ac72b0455bdb36adddb2552e66 |
File details
Details for the file fake_geo_images-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: fake_geo_images-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89cda70888dcaacd3c289c942858f07fe79f93a6d88be3dd430c96352de200ad |
|
MD5 | 554f01b6ec0089d9cd6460ea1335e319 |
|
BLAKE2b-256 | 38c837ddbbc289e3582112245ca2c763fdd0311cb999d1c5c33d78fead21830c |