Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

site_elevation and wind_elevation needs fixing #69

Closed
daniel-althoff opened this issue Feb 25, 2022 · 8 comments
Closed

site_elevation and wind_elevation needs fixing #69

daniel-althoff opened this issue Feb 25, 2022 · 8 comments

Comments

@daniel-althoff
Copy link

daniel-althoff commented Feb 25, 2022

Describe the bug
The script has a problem that requires fixing for site_elevation and wind_elevation.
On lines 243 and 250 (https://github.com/ropensci/nasapower/blob/main/R/get_power.R) it says
length(latlon !=2 ) instead of length(latlon) != 2

Code to Reproduce

library(nasapower)
daily_single_ag <- get_power(
  community = "ag",
  lonlat = c(151.5, -27.5),
  pars =c('RH2M', 'PS', 'ALLSKY_SFC_LW_DWN', 'ALLSKY_SFC_SW_DWN') ,
  dates = c(data_ini, data_fin),
  temporal_api = "daily",
  site_elevation = 410,
)
> You have provided `site_elevation` for a region request.
> The `site_elevation` value will be ignored.

Expected behaviour
Return atmospheric pressure corrected by elevation

OS and R versions (please complete the following information):
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

I tried a workaround to get the atmospheric pressure corrected by elevation, but it doesn't seem to work., even when including the variable "PSC" in pars.

@adamhsparks
Copy link
Member

Hi there. Elevation only works with single point requests. Please refer to the docs for more and see the error message that the API returns.

@daniel-althoff
Copy link
Author

Hi there. Elevation only works with single point requests. Please refer to the docs for more and see the error message that the API returns.

This is a single point request
lonlat = c(151.1, -27.5)

I tried this fixes myself (changing length(latlon !=2 ) instead of length(latlon) != 2) but it returned another error:

get_power_custom(
  community = "ag",
  lonlat = c(151.5, -27.5),
  pars = c('RH2M', 'PSC') ,
  dates = c(data_ini, data_fin),
  temporal_api = "daily",
  site_elevation = 410,
)
>Error: HTTP (422) - The request was well-formed but was unable to be followed due to semantic errors (WebDAV; RFC 4918)
> Please provide a site elevation with the 'PSC' parameter abbreviation. 

Could you provide me with an example where the site_elevation is used to retrieve corrected atmospheric pressure?

Thank you

@adamhsparks adamhsparks reopened this Feb 25, 2022
@adamhsparks
Copy link
Member

Right! Really sorry, I looked on my phone and didn't inspect closely. You've found a bug. I've patched it in the devel branch and will get a new release on CRAN as soon as I can!

5858247

@adamhsparks
Copy link
Member

closed with 5858247

@daniel-althoff
Copy link
Author

daniel-althoff commented Feb 25, 2022

closed with 5858247

Hi Adam!

I recommend you to test the corrected code before pushing the new release.
I tried a custom fix for that, but the function still did not return PSC (PS corrected) for a point request. So maybe there is something else going on.

Thanks again!

@adamhsparks
Copy link
Member

adamhsparks commented Feb 26, 2022 via email

@adamhsparks adamhsparks reopened this Feb 26, 2022
@daniel-althoff
Copy link
Author

daniel-althoff commented Feb 26, 2022

I think you can only check if it is working properly by passing the "PSC" to "pars" argument.
Example:

library(nasapower)

get_power_custom(
          community = "ag",
          lonlat = c(151.5, -27.5),
          pars = c("RH2M", "PSC"),
          dates = "1985-01-01",
          temporal_api = "daily",
          site_elevation = 400
)

Even after the fix, I get the following now:

 Erro: HTTP (422) - The request was well-formed but was unable to be followed due to semantic errors (WebDAV; RFC 4918)
  Please provide a site elevation with the 'PSC' parameter abbreviation. 

I have tried digging into internal functions but could not figure it out. Could be something related to the query?
Instead of sending siteElev, maybe it should be site-elevation?
I think a while back it used to be siteElev, but now is site-elevation.

API example:
/api/temporal/daily/point?parameters=T2M&community=SB&longitude=0&latitude=0&start=20170101&end=20170201&format=JSON&site-elevation=50

@daniel-althoff
Copy link
Author

I installed the latest version and it seems to be working properly!
I'm now closing this. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants