Open-EO / openeo-processes-dask

Python implementations of many OpenEO processes, dask-friendly by default.
Apache License 2.0
19 stars 14 forks source link

load_stac 'crs' error #226

Closed automataIA closed 7 months ago

automataIA commented 7 months ago

Utilizzando in questo codice:

import openeo_processes_dask
from openeo_processes_dask.process_implementations import *
import numpy as np

url = "https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a"
range_time = ["2022-01-01", "2022-02-01"]
bbox =  {"east": 11.40, "north": 46.52, "south": 46.46, "west": 11.25}
properties = {"eo:cloud_cover": dict(lt=100)}

cube = load_stac(url=url, 
    spatial_extent = bbox,
    temporal_extent = range_time,
    bands=["red", "nir"],
    properties=properties,
    )

It gives me this error:

{
    "name": "Exception",
    "message": "Unable to parse the provided spatial extent: 'dict' object has no attribute 'crs'",
    "stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.pyenv/versions/3.9.18/envs/backend/lib/python3.9/site-packages/openeo_processes_dask/process_implementations/cubes/load.py:108, in load_stac(url, spatial_extent, temporal_extent, bands, properties)
    107 spatial_extent_4326 = spatial_extent
--> 108 if spatial_extent.crs is not None:
    109     if not pyproj.crs.CRS(spatial_extent.crs).equals(\"EPSG:4326\"):

AttributeError: 'dict' object has no attribute 'crs'

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
Cell In[72], line 41
     38 # range_time= [\"2022-06-01\", \"2022-06-30\"]
     39 properties = {\"eo:cloud_cover\": dict(lt=100)}
---> 41 cube = load_stac(url=url, 
     42     spatial_extent = bbox,
     43     temporal_extent = range_time,
     44     bands=[\"red\", \"nir\"],
     45     properties=properties,
     46     )

File ~/.pyenv/versions/3.9.18/envs/backend/lib/python3.9/site-packages/openeo_processes_dask/process_implementations/cubes/load.py:121, in load_stac(url, spatial_extent, temporal_extent, bands, properties)
    119         query_params[\"bbox\"] = bbox
    120     except Exception as e:
--> 121         raise Exception(f\"Unable to parse the provided spatial extent: {e}\")
    123 if temporal_extent is not None:
    124     start_date = None

Exception: Unable to parse the provided spatial extent: 'dict' object has no attribute 'crs'"
}

If I use load_stac with openeo client local version, everything works fine.

clausmichele commented 7 months ago

That's because the load_stac implementation requires the parameters to be parsed first, look at the object type required for spatial_extent and temporal_extent here: https://github.com/Open-EO/openeo-processes-dask/blob/50786cc3fe7e2dbcf3882b8e6b8a0dcf6b0e3c56/openeo_processes_dask/process_implementations/cubes/load.py#L83-L89

You can find examples on how to do that in the tests, like: https://github.com/Open-EO/openeo-processes-dask/blob/50786cc3fe7e2dbcf3882b8e6b8a0dcf6b0e3c56/tests/conftest.py#L46

and https://github.com/Open-EO/openeo-processes-dask/blob/50786cc3fe7e2dbcf3882b8e6b8a0dcf6b0e3c56/tests/conftest.py#L97