bluegreen-labs / ecmwfr

Interface to the public ECMWF API Web Services
https://bluegreen-labs.github.io/ecmwfr/
Other
102 stars 30 forks source link

How to manage 'dataset' property within a dataset #60

Closed AndreaDuane closed 4 years ago

AndreaDuane commented 4 years ago

Dear Koen,

Thanks for your nice contribution with this package.

I have a problem and I don't know how to solve it. In some datasets of the CDS (e.g Fire Danger https://cds.climate.copernicus.eu/cdsapp#!/dataset/cems-fire-historical?tab=form or River discharge https://cds.climate.copernicus.eu/cdsapp#!/dataset/cems-glofas-historical?tab=form ) there is a manadatory property of the dataset called "dataset". When I include both datasets descriptors in my request it gives an error.

How can I call this property from the ecmwfr package?

Thanks in advance

khufkens commented 4 years ago

This seems to be a bug, due to double use of variables (which generally doesn't cause issues).

The demo below shows the fix by splitting up the dataset and the dataset_short_name variable. Will post a fix to master later on. Will take a while as this traces through a lot of code and validation subroutines.

request <- list(
  format = "zip",
  product_type = "reanalysis",
  variable = "fire_weather_index",
  version = "3.1",
  dataset_short_name = "cems-fire-historical",
  dataset = "Consolidated dataset",
  year = "1979",
  day = "01",
  month = "05",
  target = "download.zip"
)

url <- "https://cds.climate.copernicus.eu/api/v2"
user <- "XXX"
key <- "XXX"

response <- httr::POST(
  sprintf(
    "%s/resources/%s",
    url,
    request$dataset_short_name
  ),
  httr::authenticate(user, key),
  httr::add_headers("Accept" = "application/json",
                    "Content-Type" = "application/json"),
  body = request,
  encode = "json"
)
khufkens commented 4 years ago

Fix is in master, tentative on unit checks with CI. YMMV

https://github.com/khufkens/ecmwfr/commit/3384b4b61d34cb771ea1eca63b6ea74d020c1f88

AndreaDuane commented 4 years ago

OK, thanks!!

It is thus already fixed in all the package??

khufkens commented 4 years ago

If you install from github yes.

khufkens commented 4 years ago
if(!require(devtools)){install.packages("devtools")}
devtools::install_github("khufkens/ecmwfr")
library("ecmwfr")