Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentinel 1 Stats UDP ported to APEX #36

Merged
merged 11 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions algorithm_catalog/sentinel1_stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"id": "sentinel1_stats",
"type": "Feature",
"conformsTo": [
"http://www.opengis.net/spec/ogcapi-records-1/1.0/req/record-core"
],
"properties": {
"created": "2024-10-03T00:00:00Z",
"updated": "2024-10-03T00:00:00Z",
"type": "apex_algorithm",
"title": "Sentinel-1 statistics",
"description": "A statistics algorithm for Sentinel-1 data, calculating the mean, median, minimum, and maximum values of the data.",
"cost_estimate": 0.1,
"cost_unit": "platform credits per km²",
"keywords": [
"sentinel-1",
"statistics"
],
"language": {
"code": "en-US",
"name": "English (United States)"
},
"languages": [
{
"code": "en-US",
"name": "English (United States)"
}
],
"contacts": [
{
"name": "Pratichhya Sharma",
"position": "Researcher",
"organization": "VITO",
"links": [
{
"href": "https://www.vito.be/",
"rel": "about",
"type": "text/html"
},
{
"href": "https://github.com/pratichhya",
"rel": "about",
"type": "text/html"
}
],
"contactInstructions": "Contact via VITO",
"roles": [
"principal investigator"
]
},
{
"name": "VITO",
"links": [
{
"href": "https://www.vito.be/",
"rel": "about",
"type": "text/html"
}
],
"contactInstructions": "SEE WEBSITE",
"roles": [
"processor"
]
}
],
"themes": [
{
"concepts": [
{
"id": "Active Remote Sensing"
},
{
"id": "Sentinel-1 GRD"
}
],
"scheme": "https://gcmd.earthdata.nasa.gov/kms/concept/c8fe757b-b530-4d67-a553-e4903f4430a5"
}
],
"formats": [
"GeoTiff",
"netCDF"
],
"license": "CC-BY-4.0"
},
"linkTemplates": [],
"links": [
{
"rel": "openeo-process",
"type": "application/json",
"title": "openEO Process Definition",
"href": "https://raw.githubusercontent.com/ESA-APEx/apex_algorithms/openeo_udp/sentinel1_stats/sentinel1_stats.json"
},
{
"rel": "service",
"type": "application/json",
"title": "CDSE openEO federation",
"href": "https://openeofed.dataspace.copernicus.eu"
},
{
"rel": "example",
"type": "application/json",
"title": "Example output",
"href": "https://s3.waw3-1.cloudferro.com/swift/v1/APEx-examples/sentinel_1/s1_stats.nc"
}
]
}
Binary file added algorithm_catalog/sentinel1_stats/sentinel1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions algorithm_catalog/sentinel1_stats/sentinel1_stats_description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Description

This algorithm derives temporal statistics from the Sentinel-1 GRD collection for the selected spatial- and temporal extent of interest. In order to callibrate the SAR backscatter signal, `sigma0-ellipsoid` has been applied within this workflow.


# Performance characteristics
The algorithm was evaluated for a spatial extent of 20x20km, for a temporal period of 3 months. The total cost for the performed evaluation was equal to 4 credits, thereby highlighting the efficiency of the underlying algorithm.



# Examples

Below we show the derived minimum and maximum values for both VV and VH bands, calculated for the 20x20 km2 area of interest.

![s1_stats](sentinel1.png)
27 changes: 27 additions & 0 deletions benchmark_scenarios/sentinel1_stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"id": "sentinel1_stats",
"type": "openeo",
"description": "Sentinel 1 statistics example",
"backend": "openeofed.dataspace.copernicus.eu",
"process_graph": {
"s1stats1": {
"process_id": "sentinel1_stats",
"namespace": "https://raw.githubusercontent.com/ESA-APEx/apex_algorithms/refs/heads/S1_stats/openeo_udp/sentinel1_stats/sentinel1_stats.json",
"arguments": {
"spatial_extent": {
"east": 8.92,
"north": 44.45,
"south": 44.4,
"west": 8.82
},
"temporal_extent": [
"2023-05-01",
"2023-07-30"
]
},
"result": true
}
}
}
]
4 changes: 4 additions & 0 deletions openeo_udp/sentinel1_stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Calculate S1 SAR stats (min, max, mean, sd, q10, q50, q90).

This service can cost an approximate of 3-5 credits per sq km.
This cost is based on resource consumption only and added-value cost has not been included.
73 changes: 73 additions & 0 deletions openeo_udp/sentinel1_stats/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

import json
from pathlib import Path

import openeo
from openeo.api.process import Parameter
from openeo.rest.udp import build_process_dict
from openeo.processes import array_create, array_concat


def generate() -> dict:
# TODO: use/inject dummy connection instead of concrete one? (See cdse_marketplace_services)
connection = openeo.connect("openeofed.dataspace.copernicus.eu")

# define parameters
spatial_extent = Parameter.bounding_box(
name="spatial_extent",
default={"west": 8.82, "south": 44.40, "east": 8.92, "north": 44.45},
)
temporal_extent = Parameter.temporal_interval(
name="temporal_extent", default=["2023-05-01", "2023-07-30"]
)

# load collection
s1_raw = connection.load_collection(
collection_id="SENTINEL1_GRD",
temporal_extent=temporal_extent,
spatial_extent=spatial_extent,
bands=["VH", "VV"],
)

# apply back scatter filtering
s1_raw = s1_raw.sar_backscatter(coefficient="sigma0-ellipsoid")

# calculate stats
s1_stats = s1_raw.apply_dimension(
process=lambda data: array_concat(
array1=array_create([data.min(), data.max(), data.mean(), data.sd()]),
array2=data.quantiles([0.1, 0.5, 0.9]),
),
dimension="t",
target_dimension="bands",
)

# rename the generated bands
s1_stats = s1_stats.rename_labels(
"bands",
[
f"{b}_{s}"
for b in s1_stats.metadata.band_names
for s in ["min", "max", "mean", "sd", "q10", "q50", "q90"]
],
)

return build_process_dict(
process_graph=s1_stats,
process_id="sentinel1_stats",
summary="Calculate Sentinel-1 SAR stats",
description=(Path(__file__).parent / "README.md").read_text(),
parameters=[
spatial_extent,
temporal_extent
],
returns=None, # TODO
categories=None, # TODO
)


if __name__ == "__main__":
# TODO: how to enforce a useful order of top-level keys?
# save the generated process to a file
with open(Path(__file__).parent / "sentinel1_stats.json", "w") as f:
json.dump(generate(), f, indent=2)
Loading