Skip to content

Commit 2ebfe71

Browse files
committed
Update version, change .resource_* functions for speed, update tests, add contributors
1 parent 6a6bfe4 commit 2ebfe71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+276
-203
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ Package: climateR
22
Type: Package
33
Title: climateR
44
Description: A set of functions to subset climate data.
5-
Version: 0.3.1.2
5+
Version: 0.3.1.3
66
Authors@R: c(person("Mike", "Johnson",
77
role = c("aut", "cre"),
88
email = "[email protected]"),
9+
person("Justin", "Singh", role = "ctb"),
10+
person("Angus", "Watters", role = "ctb"),
911
person("ESIP", role = "fnd"),
1012
person("NOAA OWP", role = "fnd"))
1113
Maintainer: Mike Johnson <[email protected]>

R/utils.R

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,17 @@ try_att <- function(nc, variable, attribute) {
159159
}
160160

161161
#' Extract grid metadata from NC Pointer
162-
#' @param nc "NetCDF" object which points to the NetCDF dataset. Found with RNetCDF::open.nc.
162+
#' @param URL location of data to process
163163
#' @param X_name Name of X diminsion. If NULL it is found
164164
#' @param Y_name Name of Y diminsion. If NULL it is found
165165
#' @param stopIfNotEqualSpaced stop if not equal space grid
166166
#' @return list
167167
#' @family dap
168168

169-
.resource_grid <- function(nc, X_name = NULL, Y_name = NULL, stopIfNotEqualSpaced = TRUE) {
169+
.resource_grid <- function(URL, X_name = NULL, Y_name = NULL, stopIfNotEqualSpaced = TRUE) {
170170

171+
nc = open.nc(URL)
172+
171173
if (is.null(X_name) | is.null(Y_name)) {
172174
atts <- dap_xyzv(nc)
173175
X_name <- omit.na(unique(atts$X_name))
@@ -202,7 +204,18 @@ try_att <- function(nc, variable, attribute) {
202204
ncols <- dim.inq.nc(nc, X_name)$len
203205
nrows <- dim.inq.nc(nc, Y_name)$len
204206

205-
xx <- try(var.get.nc(nc, X_name))
207+
close.nc(nc)
208+
209+
if(file.exists(URL)){
210+
xnc = open.nc(URL)
211+
xx <- try(var.get.nc(xnc, X_name))
212+
213+
} else {
214+
xurl = gsub("#fillmismatch", "", URL)
215+
xurl = glue("{xurl}?{X_name}")
216+
xnc = open.nc(xurl)
217+
xx <- try(var.get.nc(xnc, X_name))
218+
}
206219

207220
if (inherits(xx, "try-error")) { xx <- seq_len(ncols) }
208221

@@ -223,7 +236,21 @@ try_att <- function(nc, variable, attribute) {
223236
X1 <- xx[1]
224237
Xn <- xx[length(xx)]
225238

226-
yy <- try(var.get.nc(nc, Y_name))
239+
close.nc(xnc)
240+
241+
242+
if(file.exists(URL)){
243+
ync = open.nc(URL)
244+
yy <- try(var.get.nc(ync, Y_name))
245+
246+
} else {
247+
yurl = gsub("#fillmismatch", "", URL)
248+
yurl = glue("{yurl}?{Y_name}")
249+
ync = open.nc(yurl)
250+
yy <- try(var.get.nc(ync, Y_name))
251+
}
252+
253+
227254

228255
if (inherits(yy, "try-error")) { yy <- seq_len(nrows) }
229256

@@ -265,25 +292,40 @@ try_att <- function(nc, variable, attribute) {
265292
}
266293

267294
#' Extract time metadata from NC Pointer
268-
#' @param nc "NetCDF" object which points to the NetCDF dataset.
269-
#' @param T_name Name of T diminsion. If NULL it is found
295+
#' @param URL location of data to process
296+
#' @param T_name Name of T dimension. If NULL it is found
270297
#' @return list
271298
#' @family dap
272299

273-
.resource_time <- function(nc, T_name = NULL) {
300+
.resource_time <- function(URL, T_name = NULL) {
274301

275302
if (is.null(T_name)) {
303+
nc = open.nc(URL)
276304
atts <- dap_xyzv(nc)
277305
T_name <- omit.na(unique(atts$T_name))
306+
close.nc(nc)
278307
}
279308

280-
T_var_info <- var.inq.nc(nc, T_name)
281-
282-
time_steps <- utcal.nc(
283-
unitstring = att.get.nc(nc, T_var_info$name, "units"),
284-
value = var.get.nc(nc, T_var_info$name, unpack = TRUE),
285-
type = "c"
286-
)
309+
310+
if(file.exists(URL)){
311+
nc = open.nc(URL)
312+
313+
time_steps <- utcal.nc(
314+
unitstring = att.get.nc(nc, T_name, "units"),
315+
value = var.get.nc(nc, T_name, unpack = TRUE),
316+
type = "c"
317+
)
318+
319+
} else {
320+
url = gsub("#fillmismatch", "", URL)
321+
nc = open.nc(glue("{url}?{T_name}"))
322+
323+
time_steps <- utcal.nc(
324+
unitstring = att.get.nc(nc, T_name, "units"),
325+
value = var.get.nc(nc, T_name, unpack = TRUE),
326+
type = "c"
327+
)
328+
}
287329

288330
dT <- diff(time_steps)
289331

@@ -339,9 +381,9 @@ read_dap_file <- function(URL, varname = NULL, id, varmeta = TRUE) {
339381
raw$URL <- URL
340382
raw$id <- id
341383

342-
raw <- merge(raw, data.frame(.resource_time(nc, T_name = raw$T_name[1]), id = id), by = "id")
384+
raw <- merge(raw, data.frame(.resource_time(URL, T_name = raw$T_name[1]), id = id), by = "id")
343385

344-
raw <- merge(raw, .resource_grid(nc, X_name = raw$X_name[1], Y_name = raw$Y_name[1]))
386+
raw <- merge(raw, .resource_grid(URL, X_name = raw$X_name[1], Y_name = raw$Y_name[1]))
345387

346388
raw
347389
}

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ animation(county, feild_pattern = "pr_", outfile = "man/figures/vect_gif.gif")
117117
```{r, echo = FALSE}
118118
knitr::include_graphics("man/figures/vect_gif.gif")
119119
```
120-
```
120+

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ system.time({
8080
endDate = "1991-11-06")
8181
})
8282
#> user system elapsed
83-
#> 0.222 0.079 1.954
83+
#> 0.245 0.054 0.982
8484
```
8585

8686
<img src="man/figures/README-unnamed-chunk-7-1.png" width="100%" />
@@ -102,7 +102,7 @@ system.time({
102102
county = execute_zonal(d, geom = AOI, ID = "fip_code")
103103
})
104104
#> user system elapsed
105-
#> 0.312 0.012 0.326
105+
#> 0.328 0.018 0.366
106106
```
107107

108108
<img src="man/figures/README-unnamed-chunk-11-1.png" width="100%" />
@@ -111,4 +111,4 @@ system.time({
111111
animation(county, feild_pattern = "pr_", outfile = "man/figures/vect_gif.gif")
112112
```
113113

114-
<img src="man/figures/vect_gif.gif" width="100%" /> \`\`\`
114+
<img src="man/figures/vect_gif.gif" width="100%" />

_pkgdown.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ template:
44
bootswatch: litera
55
authors:
66
ESIP:
7-
html: "<img src='man/figures/esip-logo.png' height='36' alt='ESIP'/>"
7+
html: "<img src='man/figures/esip-logo.png' width=72' alt='ESIP'/>"
88
href: "https://www.esipfed.org"
99
NOAA OWP:
10-
html: "<img src='man/figures/noaa-logo.png' height='36' alt='ESIP'/>"
10+
html: "<img src='man/figures/noaa-logo.png' width=72 alt='ESIP'/>"
1111
href: "https://www.esipfed.org"
1212
footer:
13-
roles: [cre]
13+
roles: [cre,ctb]
1414
citation:
1515
roles: [cre]
16+
sidebar:
17+
roles: [cre,ctb, fnd]
1618
articles:
1719
- title: climateR
1820
desc: Data access in R

docs/404.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/01-intro.html

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
121 Bytes
Loading
15.9 KB
Loading

0 commit comments

Comments
 (0)