ropensci / weathercan

R package for downloading weather data from Environment and Climate Change Canada
https://docs.ropensci.org/weathercan
GNU General Public License v3.0
102 stars 29 forks source link

Error when attempting to download normals #106

Closed AnneDaySRK closed 3 years ago

AnneDaySRK commented 3 years ago

I'm having problems trying to download climate normals using weathercan::normals_dl(). I've noticed that when I go to the climate normals index to download directly (i.e. https://dd.meteo.gc.ca/climate/observations/normals/csv/1981-2010/) that the stations available are not the same stations that are listed under weathercan::stations_search().

Error message:

`Error: Problem with `mutate()` input `normals`.
x Not all variables for climate station 2100517 were identified.
Please report this here: https://github.com/ropensci/weathercan/issues
i Input `normals` is `purrr::map2(...)`.
Run `rlang::last_error()` to see where the error occurred.`

Example setup:

EC.normal.stations <- weathercan::stations_search(coords = c(Latitude, Longitude), dist = 200,
                            normals_only = TRUE)

normals.climateIDS <- as.character(EC.normal.stations$climate_id)

#download normals data for all stations within 200 km of FMC
normals <- weathercan::normals_dl(climate_ids = normals.climateIDS,
                                  normals_years = "1981-2010")
steffilazerte commented 3 years ago

Hi @AnneDaySRK, Thanks for letting me know!

So the first problem you mentioned is related to a change in ECCC's list of stations that is out of date in weathercan's stations data.frame. I've updated the stations data frame in the version below, but in the future, you could use the stations_dl() function to update it yourself to use manually.

The second problem you found is that weathercan matches normals column names to an internally stored list. I have it set up to send the user an error asking them to alert me if there is a column name that doesn't match. And there was (well actually there were several changes)! In your case, ECCC added units to the Extreme Wind Chill variable so they no longer matched 🤦🏼

I've updated the variables list in addition to the stations data frame. You can test these out by installing the development branch:

install.packages("remotes")
remotes::install_github("ropensci/weathercan" ref = "fix_normals")

Then test with:

library(weathercan)
normals <- weathercan::normals_dl(climate_ids = 2100517)

Let me know how it goes!

AnneDaySRK commented 3 years ago

Thanks Steffi, I really appreciate your super speedy reply and help!

steffilazerte commented 3 years ago

So just to be clear this definitely fixed the problem? If so I'll push to master and we'll see about CRAN sometime in the New Year

AnneDaySRK commented 3 years ago

Yes, this did fix the problem, thanks 👍