Skip to main content

Python client library for WCPS (OGC Web Coverage Processing Service) backends.

Project description

Overview

The OGC Web Coverage Processing Service (WCPS) standard defines a protocol-independent declarative query language for the extraction, processing, and analysis of multi-dimensional coverages (datacubes) representing sensor, image, or statistics data.

This Python library allows to dynamically build WCPS queries and execute on a WCPS server.

Installation

pip install wcps

Examples

Derive an NDVI map from red and near-infrared bands of a Sentinel-2 datacube, threshold the very green areas (values greater than 0.5) as true values (white in a PNG), and save the result as a PNG image.

from wcps.service import Service
from wcps.model import Datacube

# Let S2_L2A be a 3D coverage with nir and red bands;
# slice it at "2025-01-15" on the time axis, getting a 2D map
cov = Datacube("S2_L2A")["time", "2025-01-15"]
# NDVI formula
ndvi = (cov.nir - cov.red) / (cov.nir + cov.red)
# threshold NDVI values to highlight areas with high vegetation
vegetation = ndvi > 0.5
# encode final result to PNG
query = vegetation.encode("PNG")

service = Service("https://ows.rasdaman.org/rasdaman/ows")

# execute the query on the server and get back the response
result = service.execute(query)

# similar to above, but automatically convert the PNG result 
# to a numpy array
result = service.execute(query, convert_to_numpy=True)

# alternatively, save the content of the response into a file
service.download(query, output_file='vegetation.png')

We can calculate the average NDVI as follows:

cov = ...
# NDVI formula
ndvi = (cov.nir - cov.red) / (cov.nir + cov.red)
# get average NDVI value
query = ndvi.avg()

service = ...
result = service.execute(query)

print(f'The average NDVI is {result.value}')

A more advanced expression is the general condenser (aggregation) operation. The example calculates the maximum values across all time slices from a 3D datacube between "2015-01-01" and "2015-07-01" for which the average is greater than 20:

from wcps.model import Datacube, AxisIter, Condense, CondenseOp
from wcps.service import Service

cov = Datacube("AvgTemperatureColorScaled")
ansi_iter = (AxisIter("ansi_iter", "ansi")
             .of_geo_axis(cov["ansi" : "2015-01-01" : "2015-07-01"]))
max_map = (Condense(CondenseOp.MAX)
           .over(ansi_iter)
           .where(cov["ansi": ansi_iter.ref()].avg() > 20)
           .using(cov["ansi": ansi_iter.ref()]))
query = max_map.encode("PNG")

service = Service("https://ows.rasdaman.org/rasdaman/ows")
service.download(query, 'max_map.png')

Contributing

The directory structure is as follows:

  • wcps - the main library code
  • tests - testing code
  • docs - documentation in reStructuredText format

Tests

To run the tests:

# install dependencies
pip install wcps[tests]

pytest

Documentation

To build the documentation:

# install dependencies
pip install wcps[docs]

cd docs
make html

The built documentation can be found in the docs/_build/html/ subdir.

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

wcps-0.2.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wcps-0.2.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file wcps-0.2.0.tar.gz.

File metadata

  • Download URL: wcps-0.2.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for wcps-0.2.0.tar.gz
Algorithm Hash digest
SHA256 51c318b15c32203340188bca4c2bf87125c8c6ad8b385d23c715b5a8abdd0de4
MD5 bd9c36493244eff44894e66e75f7da4f
BLAKE2b-256 230c247d1fead9514656daa526692d1b949cd4869e8056b220ff846190fb4559

See more details on using hashes here.

Provenance

The following attestation bundles were made for wcps-0.2.0.tar.gz:

Publisher: release.yml on rasdaman/wcps-python-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wcps-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: wcps-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for wcps-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ddd3639570d258656c0c130ca1b6208d29a3cd4ce7ec4f794a23592c0937c4c
MD5 32b386c28577bbdc4d810bbb2524cdad
BLAKE2b-256 9cf9cdf19b3e551abb15c34afcb979fb7b3f4fc6527e72baf896502a3ea3e062

See more details on using hashes here.

Provenance

The following attestation bundles were made for wcps-0.2.0-py3-none-any.whl:

Publisher: release.yml on rasdaman/wcps-python-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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