Skip to content

Commit

Permalink
Closes #85 (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks authored May 18, 2024
1 parent fc4e3ea commit 50b5918
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nasapower
Title: NASA POWER API Client
Version: 4.2.0
Version: 4.2.1
Authors@R: c(
person("Adam H.", "Sparks", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-0061-8359")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# nasapower 4.2.1

* Fixes [Issue](https://github.com/ropensci/nasapower/issues/85) where querying all parameters failed.

# nasapower 4.2.0

## Minor Changes
Expand Down
29 changes: 12 additions & 17 deletions R/query_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @param community An optional character vector providing community name:
#' \dQuote{ag}, \dQuote{sb} or \dQuote{re}.
#' @param pars A required character string of a single solar, meteorological or
#' @param pars An optional character string of a single solar, meteorological or
#' climatology parameter to query.
#' @param temporal_api An optional character vector indicating the temporal
#' \acronym{API} end-point for data being queried, supported values are
Expand Down Expand Up @@ -51,14 +51,11 @@
#' @export

query_parameters <- function(community = NULL,
pars,
pars = NULL,
temporal_api = NULL,
metadata = FALSE) {
community_vals <- c("AG", "RE", "SB")
temporal_api_vals <- c("DAILY",
"MONTHLY",
"HOURLY",
"CLIMATOLOGY")
temporal_api_vals <- c("DAILY", "MONTHLY", "HOURLY", "CLIMATOLOGY")

# if the args for `community` and `temporal_api` are not empty, check and
# then reset `community_vals` and `temporal_api_vals` for use later
Expand All @@ -82,12 +79,13 @@ query_parameters <- function(community = NULL,
temporal_api_vals <- temporal_api
}

pars <- toupper(pars)
pars <-
.check_pars(pars = pars,
community = community_vals,
temporal_api = temporal_api_vals)

if (!is.null(pars)) {
pars <- toupper(pars)
pars <-
.check_pars(pars = pars,
community = community_vals,
temporal_api = temporal_api_vals)
}
power_url <-
"https://power.larc.nasa.gov/api/system/manager/parameters"

Expand All @@ -96,11 +94,9 @@ query_parameters <- function(community = NULL,
"%s/%s?user=nasapower4r", power_url, pars
)))
} else {

if (!.is_boolean(metadata)) {
cli::cli_abort(
c(x = "{.arg metadata} should be a Boolean value.",
i = "{Please provide either {.var TRUE} or {.var FALSE}.")
c(x = "{.arg metadata} should be a Boolean value.", i = "{Please provide either {.var TRUE} or {.var FALSE}.")
)
}

Expand All @@ -114,8 +110,7 @@ query_parameters <- function(community = NULL,
)

query_list <- query_list[lengths(query_list) != 0]
response <- .send_query(.query_list = query_list,
.url = power_url)
response <- .send_query(.query_list = query_list, .url = power_url)

return(jsonlite::fromJSON(response$parse(encoding = "UTF8")))
}
Expand Down
8 changes: 4 additions & 4 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ropensci/nasapower",
"issueTracker": "https://github.com/ropensci/nasapower/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "4.2.0",
"version": "4.2.1",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -251,7 +251,7 @@
"applicationCategory": "Tools",
"isPartOf": "https://ropensci.org",
"keywords": ["NASA", "meteorological-data", "weather", "global", "weather-data", "meteorology", "NASA-POWER", "agroclimatology", "earth-science", "data-access", "climate-data", "r", "nasa-power", "nasa", "agroclimatology-data", "weather-variables", "rstats", "r-package"],
"fileSize": "496.327KB",
"fileSize": "496.399KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand All @@ -265,7 +265,7 @@
"name": "{nasapower}: NASA-POWER Data from R",
"identifier": "10.5281/zenodo.1040727",
"url": "https://CRAN.R-project.org/package=nasapower",
"description": "R package version 4.2.0",
"description": "R package version 4.2.1",
"@id": "https://doi.org/10.5281/zenodo.1040727",
"sameAs": "https://doi.org/10.5281/zenodo.1040727"
},
Expand Down Expand Up @@ -299,7 +299,7 @@
"relatedLink": ["https://docs.ropensci.org/nasapower/", "https://CRAN.R-project.org/package=nasapower"],
"releaseNotes": "https://github.com/ropensci/nasapower/blob/master/NEWS.md",
"readme": "https://github.com/ropensci/nasapower/blob/main/README.md",
"contIntegration": ["https://github.com/ropensci/nasapower/actions", "https://app.codecov.io/gh/ropensci/nasapower"],
"contIntegration": ["https://github.com/ropensci/nasapower/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/ropensci/nasapower"],
"developmentStatus": "https://www.repostatus.org/#active",
"review": {
"@type": "Review",
Expand Down
9 changes: 7 additions & 2 deletions man/query_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
37 changes: 19 additions & 18 deletions vignettes/nasapower.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The `get_power()` function has eight possible arguments and returns a data frame
Fetch daily "AG" community temperature, relative humidity and precipitation for January 1985 for Kingsthorpe, Queensland, Australia.


```r
``` r
library("nasapower")
daily_single_ag <- get_power(
community = "ag",
Expand Down Expand Up @@ -70,7 +70,7 @@ daily_single_ag
Fetch daily "ag" community relative humidity and temperature for south east Queensland region.


```r
``` r
daily_region_ag <- get_power(
community = "ag",
lonlat = c(150.5, -28.5 , 153.5, -25.5),
Expand Down Expand Up @@ -112,7 +112,7 @@ daily_region_ag
Fetch interannual solar cooking parameters for south east Queensland region.


```r
``` r
interannual_re <- get_power(
community = "re",
lonlat = c(150.5, -28.5 , 153.5, -25.5),
Expand All @@ -135,19 +135,20 @@ interannual_re
#> CLRSKY_SFC_SW_DWN CERES SYN1deg Clear Sky Surface Shortwave Downward Irradiance (kW-hr/m^2/day)
#>
#> # A tibble: 144 × 17
#> PARAMETER YEAR LAT LON JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANN
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 ALLSKY_SFC_SW_DWN 1984 -25.8 151. 6.01 6.49 5.79 4.67 4.12 3.77 2.46 4.87 6.11 5.5 7.97 7.03 5.39
#> 2 ALLSKY_SFC_SW_DWN 1984 -25.8 151. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6 6.76 5.19
#> 3 ALLSKY_SFC_SW_DWN 1984 -25.8 152. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6 6.76 5.19
#> 4 ALLSKY_SFC_SW_DWN 1984 -25.8 152. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23 6.68 5.06
#> 5 ALLSKY_SFC_SW_DWN 1984 -25.8 153. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23 6.68 5.06
#> 6 ALLSKY_SFC_SW_DWN 1984 -25.8 153. 6.23 6.05 5.88 4.26 3.81 3.3 2.96 4.73 5.66 5.25 7.6 7.06 5.23
#> 7 ALLSKY_SFC_SW_DWN 1984 -26.2 151. 5.97 6.65 6 4.66 4.02 3.72 2.28 4.86 6.08 5.74 7.74 6.97 5.38
#> 8 ALLSKY_SFC_SW_DWN 1984 -26.2 151. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46 6.89 5.24
#> 9 ALLSKY_SFC_SW_DWN 1984 -26.2 152. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46 6.89 5.24
#> 10 ALLSKY_SFC_SW_DWN 1984 -26.2 152. 5.75 5.96 5.37 4.13 3.8 3.44 2.38 4.81 5.75 4.99 6.94 6.56 4.98
#> PARAMETER YEAR LAT LON JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 ALLSKY_SFC_SW… 1984 -25.8 151. 6.01 6.49 5.79 4.67 4.12 3.77 2.46 4.87 6.11 5.5 7.97
#> 2 ALLSKY_SFC_SW… 1984 -25.8 151. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6
#> 3 ALLSKY_SFC_SW… 1984 -25.8 152. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6
#> 4 ALLSKY_SFC_SW… 1984 -25.8 152. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23
#> 5 ALLSKY_SFC_SW… 1984 -25.8 153. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23
#> 6 ALLSKY_SFC_SW… 1984 -25.8 153. 6.23 6.05 5.88 4.26 3.81 3.3 2.96 4.73 5.66 5.25 7.6
#> 7 ALLSKY_SFC_SW… 1984 -26.2 151. 5.97 6.65 6 4.66 4.02 3.72 2.28 4.86 6.08 5.74 7.74
#> 8 ALLSKY_SFC_SW… 1984 -26.2 151. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46
#> 9 ALLSKY_SFC_SW… 1984 -26.2 152. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46
#> 10 ALLSKY_SFC_SW… 1984 -26.2 152. 5.75 5.96 5.37 4.13 3.8 3.44 2.38 4.81 5.75 4.99 6.94
#> # ℹ 134 more rows
#> # ℹ 2 more variables: DEC <dbl>, ANN <dbl>
```

### Example fetching climatology data
Expand All @@ -158,7 +159,7 @@ Change the `temporal_api` value to "climatology" to get these data.
Fetch "ag" climatology for temperature and relative humidity for Kingsthorpe, Queensland, Australia.


```r
``` r
climatology_ag <- get_power(
community = "ag",
pars = c("T2M", "RH2M"),
Expand Down Expand Up @@ -195,7 +196,7 @@ This can be used to find available parameter names and definitions for each comm
Fetch the complete available information for the temperature at 2 metres above the Earth's surface, T2M.


```r
``` r
query_parameters(pars = "T2M")
#> $T2M
#> $T2M$temporal
Expand Down Expand Up @@ -263,7 +264,7 @@ query_parameters(pars = "T2M")
Fetch complete temporal and community specific attribute information for "T2M" in the "ag" community for the "hourly" temporal API.


```r
``` r
query_parameters(pars = "T2M",
community = "ag",
temporal_api = "hourly")
Expand Down

0 comments on commit 50b5918

Please sign in to comment.