bluegreen-labs / ecmwfr

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

`user` in `wf_request_batch()` #143

Closed Rafnuss closed 1 month ago

Rafnuss commented 1 month ago

Thanks for the update to the new CDS plateform. As I understand it, user is not required anymore, right? I managed to use wf_request() without any problem, but wf_request_batch() doesn't work without user. Is that a desired or required design?

khufkens commented 1 month ago

Strange, this should work as the default is set:

https://github.com/bluegreen-labs/ecmwfr/blob/74be7cd11839505a610314782dadbee431c5a144/R/wf_request_batch.R#L15

I also test the routine here: https://github.com/bluegreen-labs/ecmwfr/blob/74be7cd11839505a610314782dadbee431c5a144/tests/testthat/test_ds.R#L245

So this should pass. Could you remove the package and reinstall, to make sure the right version is loaded (restarting your session might also be key).

khufkens commented 1 month ago

@Rafnuss FYI I like the GeopressureR package very much! I might reach out to you within this context.

Rafnuss commented 1 month ago

Thanks for the help. I've been trying to play a bit more to try to troubleshoot my problem. Do you mind having a look at his tell me what you think I'm doing wrong then?

library(ecmwfr)

years <- c(2017,2018)
requests <- lapply(years, function(y) {
  list(
    dataset_short_name = "reanalysis-era5-pressure-levels",
    product_type = "reanalysis",
    variable = "geopotential",
    year = "2024",
    month = "03",
    day = "01",
    time = "13:00",
    pressure_level = "1000",
    data_format = "grib",
    area = c(51, 1, 50, 2),
    target = paste0(y, "-era5-demo.grib"))
})

keyring::keyring_list()
#>   keyring num_secrets locked
#> 1   login          74  FALSE

wf_set_key( key = Sys.getenv("cds_token"))
#> User ecmwfr for ecmwfr service added successfully in keychain

wf_get_key()
#> [1] "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" # This display my actual key composed of letter and number. Looks correct to me.

wf_request(requests[[1]])
#> Requesting data to the cds service with username ecmwfr
#> - staging data transfer at url endpoint or request id:
#>   2e4f0e8b-c4a5-438c-b0cf-1bfa3012825f
#>   on server: https://cds-beta.climate.copernicus.eu/api
#> - timeout set to 1.0 hours
#> - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ... / polling server ... - polling server ... \ polling server ... | polling server ...    file ready to download...           
#> 
#> Downloading file
#>   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
#> - moved temporary file to -> /var/folders/cm/dh8lmmxn3b5bcb2_gbz16ycm0000gn/T//RtmpS0I4Gd/2017-era5-demo.grib
#> - Delete data from queue for url endpoint or request id:
#>   https://cds-beta.climate.copernicus.eu/api/retrieve/v1/jobs/2e4f0e8b-c4a5-438c-b0cf-1bfa3012825f
#> [1] "/var/folders/cm/dh8lmmxn3b5bcb2_gbz16ycm0000gn/T//RtmpS0I4Gd/2017-era5-demo.grib"

ecmwfr::wf_request_batch(requests)
#> Error in b_macos_list(self, private, service, keyring): keyring error (macOS Keychain), cannot open keychain: The specified keychain could not be found.

sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS Sonoma 14.6.1
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: Europe/Paris
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ecmwfr_2.0.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] assertthat_0.2.1  digest_0.6.37     R6_2.5.1          fastmap_1.2.0    
#>  [5] xfun_0.47         cachem_1.1.0      glue_1.7.0        knitr_1.48       
#>  [9] memoise_2.0.1     htmltools_0.5.8.1 rmarkdown_2.28    lifecycle_1.0.4  
#> [13] cli_3.6.3         reprex_2.1.1      withr_3.0.1       compiler_4.4.1   
#> [17] httr_1.4.7        rstudioapi_0.16.0 tools_4.4.1       curl_5.2.2       
#> [21] evaluate_0.24.0   yaml_2.3.10       jsonlite_1.8.8    rlang_1.1.4      
#> [25] fs_1.6.4          keyring_1.3.2

Created on 2024-09-09 with reprex v2.1.1

If I create the keyring, which I'm not sure I actually need to do, I get another error message:

keyring::keyring_create("ecmwfr", password = Sys.getenv("cds_token"))

wf_request_batch(requests)
#> Requesting data to the cds service with username NA
#> Error: username must be a string (length 1 character) or NULL

Now, if I actually provide user, it works!

> wf_request_batch(requests, user = "ecmwfr")
#>Requesting data to the cds service with username ecmwfr
#>- staging data transfer at url endpoint or request id:
#>  f16e28bf-f664-47de-8f1f-9fef9fba4770
#>
#>  on server: https://cds-beta.climate.copernicus.eu/api
#>
#>- Your request has been submitted as a CDS request.
#>...
Rafnuss commented 1 month ago

Actually, I just looked at the function, and I think that the problem might be coming from: https://github.com/bluegreen-labs/ecmwfr/blob/74be7cd11839505a610314782dadbee431c5a144/R/wf_request_batch.R#L41 If I remove it, wf_request_batch(requests) works like fine!

khufkens commented 1 month ago

That's probably it, thanks. I'm not sure why the unit tests don't catch this though - will check those, too.

khufkens commented 1 month ago

Fixed with #144 - upcoming CRAN release in #146