Skip to content
This repository was archived by the owner on Mar 6, 2023. It is now read-only.
This repository was archived by the owner on Mar 6, 2023. It is now read-only.

Update And process to cope with array and a number  #179

@danielFlemstrom

Description

@danielFlemstrom

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions