Skip to content

Commit 4313a82

Browse files
committed
fix: updated varmap parameter as bbox is not supported in UDF implementation
1 parent 0a110b2 commit 4313a82

File tree

2 files changed

+13
-93
lines changed

2 files changed

+13
-93
lines changed

algorithm_catalog/vito/variabilitymap/openeo_udp/generate.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ def get_variabilitymap(
5050
################ get and apply variability map udf #################
5151

5252
mask_value = 999.0
53-
54-
variabilitymap_udf = Path("variabilitymap_udf.py").read_text()
55-
56-
udf_process = lambda data: data.run_udf(udf=variabilitymap_udf,
57-
runtime='Python', context={
58-
'mask_value': mask_value, 'raw': {"from_parameter": "raw"}, 'band': biopar_type
53+
udf_process = openeo.UDF.from_file(
54+
"variabilitymap_udf.py",
55+
runtime='Python',
56+
context={
57+
'mask_value': mask_value, 'raw': raw, 'band': biopar_type
5958
})
6059
variabilitymap = input_data.apply_polygon(geometries=spatial_extent, process=udf_process, mask_value=mask_value)
6160
return variabilitymap
@@ -68,9 +67,9 @@ def generate() -> dict:
6867
name="temporal_extent",
6968
description="Temporal extent specified as two-element array with start and end date/date-time. \nThis is date range for which to apply the data fusion"
7069
)
71-
spatial_extent = Parameter.spatial_extent(
70+
spatial_extent = Parameter.geojson(
7271
name="spatial_extent",
73-
description="Limits the data to process to the specified bounding box or polygons.\nFor raster data, the process loads the pixel into the data cube if the point at the pixel center intersects with the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC).\nFor vector data, the process loads the geometry into the data cube if the geometry is fully within the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC). Empty geometries may only be in the data cube if no spatial extent has been provided.\nEmpty geometries are ignored.\nSet this parameter to null to set no limit for the spatial extent."
72+
description="Limits the data to process to the specified polygons.\nFor raster data, the process loads the pixel into the data cube if the point at the pixel center intersects with any of the polygons (as defined in the Simple Features standard by the OGC).\nFor vector data, the process loads the geometry into the data cube if the geometry is fully within the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC). Empty geometries may only be in the data cube if no spatial extent has been provided.\nEmpty geometries are ignored.\nSet this parameter to null to set no limit for the spatial extent."
7473
)
7574

7675
raw = Parameter.boolean(

algorithm_catalog/vito/variabilitymap/openeo_udp/variabilitymap.json

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"from_parameter": "data"
7272
},
7373
"runtime": "Python",
74-
"udf": "\"\"\"\nImport the biopar library and the BioParNp class to calculate the FAPAR index.\nIt is the Python implementation of biophyscial parameter computation, \nas described here: http://step.esa.int/docs/extra/ATBD_S2ToolBox_L2B_V1.1.pdf\n\"\"\"\nfrom functools import lru_cache\nimport numpy as np\nfrom typing import Dict\nfrom numpy import cos, radians\n\nfrom openeo.udf.xarraydatacube import XarrayDataCube\nfrom biopar.bioparnp import BioParNp\n\n\n@lru_cache(maxsize=6)\ndef get_bioparrun(biopar) -> BioParNp:\n return BioParNp(version='3band', parameter=biopar, singleConfig = True)\n \n\ndef apply_datacube(cube: XarrayDataCube, context: Dict) -> XarrayDataCube:\n ds_date = cube.get_array()\n\n ### LOAD THE DIFFERENT REQUIRED BANDS FOR THE 8-BAND FAPAR\n scaling_bands = 0.0001\n\n saa = ds_date.sel(bands='sunAzimuthAngles')\n sza = ds_date.sel(bands=\"sunZenithAngles\")\n vaa = ds_date.sel(bands=\"viewAzimuthMean\")\n vza = ds_date.sel(bands=\"viewZenithMean\")\n\n B03 = ds_date.sel(bands='B03') * scaling_bands\n B04 = ds_date.sel(bands='B04') * scaling_bands\n B8 = ds_date.sel(bands='B08') * scaling_bands\n\n g1 = cos(radians(vza))\n g2 = cos(radians(sza))\n g3 = cos(radians(saa - vaa))\n\n #### FLATTEN THE ARRAY ####\n flat = list(map(lambda arr: arr.flatten(),\n [B03.values, B04.values, B8.values, g1.values, g2.values, g3.values]))\n bands = np.array(flat)\n\n #### CALCULATE THE BIOPAR BASED ON THE BANDS #####\n \n image = get_bioparrun('FAPAR').run(bands,\n output_scale=1,\n output_dtype=np.float32,\n minmax_flagging=False) # netcdf algorithm\n as_image = image.reshape((g1.shape))\n\n ## SET NOTDATA TO NAN\n as_image[np.where(np.isnan(B03))] = np.nan\n xr_biopar = vza.copy()\n xr_biopar.values = as_image\n return XarrayDataCube(xr_biopar)"
74+
"udf": "\"\"\"\nImport the biopar library and the BioParNp class to calculate the FAPAR index.\nIt is the Python implementation of biophysical parameter computation, \nas described here: http://step.esa.int/docs/extra/ATBD_S2ToolBox_L2B_V1.1.pdf\n\"\"\"\nfrom functools import lru_cache\nimport numpy as np\nfrom typing import Dict\nfrom numpy import cos, radians\n\nfrom openeo.udf.xarraydatacube import XarrayDataCube\nfrom biopar.bioparnp import BioParNp\n\n\n@lru_cache(maxsize=6)\ndef get_bioparrun(biopar) -> BioParNp:\n return BioParNp(version='3band', parameter=biopar, singleConfig = True)\n \n\ndef apply_datacube(cube: XarrayDataCube, context: Dict) -> XarrayDataCube:\n ds_date = cube.get_array()\n\n ### LOAD THE DIFFERENT REQUIRED BANDS FOR THE 8-BAND FAPAR\n scaling_bands = 0.0001\n\n saa = ds_date.sel(bands='sunAzimuthAngles')\n sza = ds_date.sel(bands=\"sunZenithAngles\")\n vaa = ds_date.sel(bands=\"viewAzimuthMean\")\n vza = ds_date.sel(bands=\"viewZenithMean\")\n\n B03 = ds_date.sel(bands='B03') * scaling_bands\n B04 = ds_date.sel(bands='B04') * scaling_bands\n B8 = ds_date.sel(bands='B08') * scaling_bands\n\n g1 = cos(radians(vza))\n g2 = cos(radians(sza))\n g3 = cos(radians(saa - vaa))\n\n #### FLATTEN THE ARRAY ####\n flat = list(map(lambda arr: arr.flatten(),\n [B03.values, B04.values, B8.values, g1.values, g2.values, g3.values]))\n bands = np.array(flat)\n\n #### CALCULATE THE BIOPAR BASED ON THE BANDS #####\n \n image = get_bioparrun('FAPAR').run(bands,\n output_scale=1,\n output_dtype=np.float32,\n minmax_flagging=False) # netcdf algorithm\n as_image = image.reshape((g1.shape))\n\n ## SET NOTDATA TO NAN\n as_image[np.where(np.isnan(B03))] = np.nan\n xr_biopar = vza.copy()\n xr_biopar.values = as_image\n return XarrayDataCube(xr_biopar)"
7575
},
7676
"result": true
7777
}
@@ -160,90 +160,11 @@
160160
},
161161
{
162162
"name": "spatial_extent",
163-
"description": "Limits the data to process to the specified bounding box or polygons.\nFor raster data, the process loads the pixel into the data cube if the point at the pixel center intersects with the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC).\nFor vector data, the process loads the geometry into the data cube if the geometry is fully within the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC). Empty geometries may only be in the data cube if no spatial extent has been provided.\nEmpty geometries are ignored.\nSet this parameter to null to set no limit for the spatial extent.",
164-
"schema": [
165-
{
166-
"title": "Bounding Box",
167-
"type": "object",
168-
"subtype": "bounding-box",
169-
"required": [
170-
"west",
171-
"south",
172-
"east",
173-
"north"
174-
],
175-
"properties": {
176-
"west": {
177-
"description": "West (lower left corner, coordinate axis 1).",
178-
"type": "number"
179-
},
180-
"south": {
181-
"description": "South (lower left corner, coordinate axis 2).",
182-
"type": "number"
183-
},
184-
"east": {
185-
"description": "East (upper right corner, coordinate axis 1).",
186-
"type": "number"
187-
},
188-
"north": {
189-
"description": "North (upper right corner, coordinate axis 2).",
190-
"type": "number"
191-
},
192-
"base": {
193-
"description": "Base (optional, lower left corner, coordinate axis 3).",
194-
"type": [
195-
"number",
196-
"null"
197-
],
198-
"default": null
199-
},
200-
"height": {
201-
"description": "Height (optional, upper right corner, coordinate axis 3).",
202-
"type": [
203-
"number",
204-
"null"
205-
],
206-
"default": null
207-
},
208-
"crs": {
209-
"description": "Coordinate reference system of the extent, specified as as [EPSG code](http://www.epsg-registry.org/) or [WKT2 CRS string](http://docs.opengeospatial.org/is/18-010r7/18-010r7.html). Defaults to `4326` (EPSG code 4326) unless the client explicitly requests a different coordinate reference system.",
210-
"anyOf": [
211-
{
212-
"title": "EPSG Code",
213-
"type": "integer",
214-
"subtype": "epsg-code",
215-
"minimum": 1000,
216-
"examples": [
217-
3857
218-
]
219-
},
220-
{
221-
"title": "WKT2",
222-
"type": "string",
223-
"subtype": "wkt2-definition"
224-
}
225-
],
226-
"default": 4326
227-
}
228-
}
229-
},
230-
{
231-
"title": "Vector data cube",
232-
"description": "Limits the data cube to the bounding box of the given geometries in the vector data cube. For raster data, all pixels inside the bounding box that do not intersect with any of the polygons will be set to no data (`null`). Empty geometries are ignored.",
233-
"type": "object",
234-
"subtype": "datacube",
235-
"dimensions": [
236-
{
237-
"type": "geometry"
238-
}
239-
]
240-
},
241-
{
242-
"title": "No filter",
243-
"description": "Don't filter spatially. All data is included in the data cube.",
244-
"type": "null"
245-
}
246-
]
163+
"description": "Limits the data to process to the specified polygons.\nFor raster data, the process loads the pixel into the data cube if the point at the pixel center intersects with any of the polygons (as defined in the Simple Features standard by the OGC).\nFor vector data, the process loads the geometry into the data cube if the geometry is fully within the bounding box or any of the polygons (as defined in the Simple Features standard by the OGC). Empty geometries may only be in the data cube if no spatial extent has been provided.\nEmpty geometries are ignored.\nSet this parameter to null to set no limit for the spatial extent.",
164+
"schema": {
165+
"type": "object",
166+
"subtype": "geojson"
167+
}
247168
},
248169
{
249170
"name": "raw",

0 commit comments

Comments
 (0)