CS-SI / eodag

Earth Observation Data Access Gateway
https://eodag.readthedocs.io
Apache License 2.0
327 stars 45 forks source link

Invalid parameter timeIntervals when downloading from meteoblue #1413

Open amarandon opened 1 day ago

amarandon commented 1 day ago

Given this code:

from eodag import EODataAccessGateway, setup_logging
import datetime

setup_logging(3)

dag = EODataAccessGateway()
dag.set_preferred_provider("meteoblue")

tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).isoformat()
after_tomorrow = (datetime.date.today() + datetime.timedelta(days=2)).isoformat()
aoi_bbox = [-5, 40, 10, 45]

products_from_product_type = dag.search(
    start=tomorrow,
    end=after_tomorrow,
    geom=aoi_bbox,
    productType="NEMSGLOBAL_TCDC",
    provider="meteoblue",
)
meteoblue_req_params = {
    "queries":[
        {
            "domain":"NEMSGLOBAL","gapFillDomain":None,"timeResolution":"daily",
            "codes":[{"code":71,"level":"sfc","aggregation":"mean"}],
        }
    ],
    "format": "netCDF",
    "units":{"temperature":"C","velocity":"km/h","length":"metric","energy":"watts"},
    "timeIntervalsAlignment": None,
}

results = dag.search(
    start=tomorrow,
    end=after_tomorrow,
    geom=aoi_bbox,
    **meteoblue_req_params,
)

product = results[0]
product.download()

We get this error:

ValidationError: NEMSGLOBAL_TCDC_20241122_20241123_8b6b1aa3a7cff98e249e49fdf682e2d301107b00 could 
not be ordered {"error_message":"Value was not of type 'Array<JSONValue>' at path 'timeIntervals'. Expected to 
decode Array<JSONValue> but found a string instead.","error":true}

In the output we can see that the parameter timeIntervals is passed as a bare string in the body of the download request:

2024-11-21 15:50:00,709 eodag.download.http              [DEBUG   ] POST https://my.meteoblue.com/dataset/query 
{'User-Agent': 'eodag/3.0.2.dev6+gc8eae412.d20241114'} {'json': {'format': 'netCDF', 'geometry': {"coordinates": [[[-5.0, 40.0], 
[-5.0, 45.0], [10.0, 45.0], [10.0, 40.0], [-5.0, 40.0]]], "type": "Polygon"}, 'runOnJobQueue': True, 'queries': {'codes': [{'aggregation': 
'mean', 'code': 71, 'level': 'sfc'}], 'domain': 'NEMSGLOBAL', 'gapFillDomain': None, 'timeResolution': 'daily'},
'timeIntervals': '2024-11-22/2024-11-22', 'units': {'energy': 'watts', 'length': 'metric', 'temperature': 'C', 'velocity': 'km/h'}}}

Note that in the case of the search request, the timeIntervals parameter is passed wrapped in an array as expected by the API:

2024-11-21 16:00:18,431 eodag.search.qssearch            [DEBUG   ] Query parameters: {"queries": [{"domain": "NEMSGLOBAL", "gapFillDomain": null, "timeResolution": "daily", "codes": [{"code": 71, "level": "sfc"
, "aggregation": "mean"}]}], "format": "netCDF", "units": {"temperature": "C", "velocity": "km/h", "length": "metric", "energy": "watts"},
"timeIntervals": ["2024-11-22/2024-11-22"], "geometry": {"type": "Polygon", "coordinates": [[[-5.0, 40.0], [-5.0, 45.0], [10.0, 45.0], [10.0, 40.0], [-5.0, 40.0]]]}, "checkOnly": true}
amarandon commented 1 day ago

Note that this is blocking resolution of https://github.com/CS-SI/eodag/issues/1385