Skip to content

Commit 7be9135

Browse files
committed
variability map: avoid float output, fix band name
1 parent 200c5bc commit 7be9135

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

algorithm_catalog/vito/variabilitymap/openeo_udp/generate.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def get_variabilitymap(
3838

3939
biopar_type = "FAPAR"
4040

41-
mask = mask = scl.process("to_scl_dilation_mask", data=scl)
41+
mask = scl.process("to_scl_dilation_mask", data=scl)
4242
S2_bands_mask = s2_cube.mask(mask)
4343

4444
# fetch udf to reduce bands
4545
reduce_bands_udf = openeo.UDF.from_file("shub_fapar_udf.py")
4646
S2_bands_mask_reduced = S2_bands_mask.reduce_bands(reduce_bands_udf)
4747

48-
input_data = S2_bands_mask_reduced.add_dimension(label=biopar_type, name=biopar_type, type='bands')
48+
input_data = S2_bands_mask_reduced.add_dimension(label=biopar_type, name='bands', type='bands')
4949

5050
################ get and apply variability map udf #################
5151

@@ -57,7 +57,9 @@ def get_variabilitymap(
5757
runtime='Python', context={
5858
'mask_value': mask_value, 'raw': {"from_parameter": "raw"}, 'band': biopar_type
5959
})
60-
variabilitymap = input_data.apply_polygon(geometries=spatial_extent, process=udf_process, mask_value=mask_value)
60+
variabilitymap = (input_data.apply_polygon(geometries=spatial_extent, process=udf_process, mask_value=mask_value)
61+
.linear_scale_range(0,100,0,100).rename_labels(dimension= 'bands', target=['variability']))
62+
6163
return variabilitymap
6264

6365

algorithm_catalog/vito/variabilitymap/openeo_udp/variabilitymap.json

Lines changed: 39 additions & 2 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
}
@@ -86,7 +86,7 @@
8686
"from_node": "reducedimension1"
8787
},
8888
"label": "FAPAR",
89-
"name": "FAPAR",
89+
"name": "bands",
9090
"type": "bands"
9191
}
9292
},
@@ -122,6 +122,43 @@
122122
}
123123
}
124124
}
125+
}
126+
},
127+
"apply1": {
128+
"process_id": "apply",
129+
"arguments": {
130+
"data": {
131+
"from_node": "applypolygon1"
132+
},
133+
"process": {
134+
"process_graph": {
135+
"linearscalerange1": {
136+
"process_id": "linear_scale_range",
137+
"arguments": {
138+
"inputMax": 100,
139+
"inputMin": 0,
140+
"outputMax": 100,
141+
"outputMin": 0,
142+
"x": {
143+
"from_parameter": "x"
144+
}
145+
},
146+
"result": true
147+
}
148+
}
149+
}
150+
}
151+
},
152+
"renamelabels1": {
153+
"process_id": "rename_labels",
154+
"arguments": {
155+
"data": {
156+
"from_node": "apply1"
157+
},
158+
"dimension": "bands",
159+
"target": [
160+
"variability"
161+
]
125162
},
126163
"result": true
127164
}

0 commit comments

Comments
 (0)