Either I have misunderstood the openeo cookbook, or we need to do some work on and_.
I would expect mask =( band & 2) = 2 to work.
In the generated code, the operator ´=´becomes EQ which can handle array:int, but the operator ´&´ becomes logic and_ which assumes that both are arrays as I can see. Although & and and in python seems to give the same result, i suspect things get worse when handling arrays.
WATER_FLAG_MASK=2
res=connection.load_collection(s3.s3_olci_l2wfr,
spatial_extent=s3.bbox.karlstad_large,
bands=['oa04','oa06','oa09','wqsf_lsb'],
temporal_extent=["2022-05-01", "2022-05-02"])
wqsf_band = res.band('wqsf_lsb')
mask = (wqsf_band & WATER_FLAG_MASK ) == WATER_FLAG_MASK
res = res.mask(mask)
display(res.flat_graph())
-->
{'loadcollection1': {...},
'reducedimension1': {'process_id': 'reduce_dimension',
'arguments': {'data': {'from_node': 'loadcollection1'},
'dimension': 'bands',
'reducer': {'process_graph': {'arrayelement1': {'process_id': 'array_element',
'arguments': {'data': {'from_parameter': 'data'}, 'index': 3}},
'and1': {'process_id': 'and',
'arguments': {'x': {'from_node': 'arrayelement1'}, 'y': 2}},
'eq1': {'process_id': 'eq',
'arguments': {'x': {'from_node': 'and1'}, 'y': 2},
'result': True}}}}},
'mask1': {'process_id': 'mask',
'arguments': {'data': {'from_node': 'loadcollection1'},
'mask': {'from_node': 'reducedimension1'}},
'result': True}}
Which generates the following script:
...
_arrayelement1_2 = oeop.array_element(
**{"data": _loadcollection1_0, "index": 3, "dimension": "bands"}
)
_and1_3 = oeop.and_(**{"x": _arrayelement1_2, "y": 2})
_eq1_4 = oeop.eq(**{"x": _and1_3, "y": 2})
_reducedimension1_1 = oeop.reduce_dimension(
**{"data": _eq1_4, "dimension": "bands", "reducer": {}}
)
_mask1_5 = oeop.mask(**{"data": _loadcollection1_0, "mask": _reducedimension1_1})
...
... which results in some error text:
Traceback (most recent call last):
File "code.py", line 69, in <module>
_and1_3 = oeop.and_(**{"x": _arrayelement1_2, "y": 2})
File "/user/ubuntu/.venv/lib/python3.8/site-packages/openeo_processes/utils.py", line 116, in fun_wrapper
return cls_fun(*args, **kwargs)
File "/user/ubuntu/.venv/lib/python3.8/site-packages/openeo_processes/logic.py", line 96, in exec_xar
y_nan = y.where(y == True, False)
AttributeError: 'int' object has no attribute 'where'
/All the best
The DigitalEarthSweden team!
Either I have misunderstood the openeo cookbook, or we need to do some work on
and_.I would expect
mask =( band & 2) = 2to work.In the generated code, the operator ´=´becomes EQ which can handle array:int, but the operator ´&´ becomes logic
and_which assumes that both are arrays as I can see. Although & andandin python seems to give the same result, i suspect things get worse when handling arrays.-->
Which generates the following script:
... which results in some error text:
/All the best
The DigitalEarthSweden team!