ropensci / rnoaa

R interface to many NOAA data APIs
https://docs.ropensci.org/rnoaa
Other
330 stars 84 forks source link

Make ens and time dimensions specific to variable being called. #321

Closed potterzot closed 5 years ago

potterzot commented 5 years ago

Change ensemble and time indices to be set according to the variable being queried rather than be fixed.

Description

ens_idx and time_idx were previously fixed by default to

ens_idx = 1:21
time_idx = 1:65

but some variables have different lengths of time dimension. Now both indices are set based on the value range of the specific variable. In addition, ens_idx and time_idx were depreciated in favor of ens and time, which allow the user to specify the values rather than the indices. This conforms to how the other dimension values (latitude and longitude) are set.

Tests are also included to check that the new values are correctly set, that indices out of bounds return an informative error, and that indices override values if both are set (i.e. if time = c(6,12) and time_idx = 1:3, the query will return times c(6,12,18) that correspond to time indices 1:3).

Related Issue

Fixes #320

sckott commented 5 years ago

thanks ! a few thigns:

gefs(var, lat, lon, date = date, forecast_time = "1800", ens_idx=2:4,
      time_idx=1:8)
#> 'ens_idx' is depreciated and will be removed in future versions, please specify values (not indices) in 'ens' instead.
#> 'time_idx' is depreciated and will be removed in future versions, please specify values (not indices) in 'time' instead.

so instead change the example to use what whatever the new thing is


the last example, that is commented out, seems like it could be removed, especially since it fails, or should it stay?:

gefs(var, ens=1, time=1:12)
#> Error in round(lat, 0) : non-numeric argument to mathematical function
sckott commented 5 years ago

thanks, looks good