ropensci / nasapower

API Client for NASA POWER Global Meteorology, Surface Solar Energy and Climatology in R
https://docs.ropensci.org/nasapower
Other
98 stars 22 forks source link

site_elevation and wind_elevation needs fixing #69

Closed daniel-althoff closed 2 years ago

daniel-althoff commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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!

https://github.com/ropensci/nasapower/commit/5858247a9f21e529268e511a70415b862707a8dc

adamhsparks commented 2 years ago

closed with https://github.com/ropensci/nasapower/commit/5858247a9f21e529268e511a70415b862707a8dc

daniel-althoff commented 2 years ago

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 commented 2 years ago

Hmm. I did test it and it seems to work but I guess I don’t know what it should look like otherwise?

Can you please provide me with a correct example to match against?

On 25 Feb 2022, at 22:09, Daniel Althoff @.***> wrote:

 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). So maybe there is something else going on.

Thanks again!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.

daniel-althoff commented 2 years ago

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 commented 2 years ago

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