Skip to content

Commit c5b7e0a

Browse files
committed
Update docs, change version to 1.0.0
1 parent 8e0a481 commit c5b7e0a

File tree

8 files changed

+54
-59
lines changed

8 files changed

+54
-59
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: fldgen
22
Type: Package
33
Title: Generate Temperature Fields with Spatial and Temporal Correlation
4-
Version: 0.5.0
4+
Version: 1.0.0
55
Authors@R: person("Robert", "Link", email = "[email protected]", role = c("aut", "cre"))
66
Description: Provides functions to learn the spatial and temporal correlation of the
77
variability in an ESM and generate random temperature fields with equivalent

R/fldgen.R

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,22 @@
66
#'
77
#' @section Example:
88
#'
9-
#' The data used in this example can be found in \code{tests/testthat/data}
9+
#' The data used in this example can be found in \code{system.file('extdata', package='fldgen')}
1010
#'
1111
#' \verb{
1212
#' library(fldgen)
1313
#'
14-
#' griddata <- read.temperatures('data/tann1.nc')
15-
#' tgav <- readtgav('data/wgttann1.nc')
16-
#' pscl <- pscl_analyze(griddata$tas, tgav)
17-
#' reof <- eof_analyze(pscl$r, griddata$tgop)
18-
#' Fx <- mvfft(reof$x) # Fourier transforms of the coordinates
19-
#' # in the orthogonal basis.
20-
#' Fxmag <- abs(Fx)
21-
#' Fxphase <- atan2(Im(Fx), Re(Fx))
14+
#' emulator <- train('extdata/tann1.nc')
15+
#'
2216
#' tempgrids <- list() # Empty list to hold the temperature
23-
#' # realizations we are about to create.
17+
#' # realizations we are about to create.
2418
#' length(tempgrids) <- 4
2519
#'
2620
#' ## Run with the phases of the actual time series
27-
#' meanfield <- pscl_apply(pscl, tgav)
28-
#' tempgrids[[1]] <- reconst_fields(reof$rotation, mkcorrts(Fxmag, Fxphase) , meanfield)
21+
#' meanfield <- pscl_apply(emulator$pscl, emulator$tgav)
22+
#' tempgrids[[1]] <- reconst_fields(emulator$reof$rotation, mkcorrts(emulator) , meanfield)
2923
#' ## Run the rest with random phases
3024
#' for(i in 2:4)
31-
#' ## If you wanted to use a smaller number of PCs, say 50, you could
32-
#' ## use reof$rotation[,1:50] and Fxmag[,1:50] in the next call.
33-
#' tempgrids[[i]] <- reconst_fields(reof$rotation, mkcorrts(Fxmag), meanfield)
34-
#' }
35-
#'
25+
#' tempgrids[[i]] <- reconst_fields(emulator$reof$rotation, mkcorrts(emulator), meanfield)
26+
#'}
3627
"_PACKAGE"

R/train.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#' returned object. This is for the your information only; none of the code
2222
#' here does anything with the recorded filenames. You have the choice of
2323
#' recording either absolute filenames (useful for determining exactly which
24-
#' dataset was used) or relative filenames (useful if you might distribute a
24+
#' dataset was used, if you have a lot of similarly named files) or relative
25+
#' filenames (useful if you might distribute a
2526
#' saved model to other users who might not have the same directory structure as
2627
#' you).
2728
#'

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,43 @@
55

66

77

8-
This package rovides functions to learn the spatial and temporal
8+
The `fldgen` package rovides functions to learn the spatial and temporal
99
correlation of the variability in an ESM and generate random
1010
temperature fields with equivalent properties.
1111

12+
## Installation
13+
14+
The easiest way to install `fldgen` is using `install_github` from the
15+
`devtools` package.
16+
```R
17+
install_github('JGCRI/fldgen', ref='v1.0.0', build_vignettes=TRUE)
18+
```
19+
1220
## Example
1321

14-
The data used in this example can be found in `tests/testthat/data`.
22+
The data used in this example are installed with the package. They
23+
can be found in `system.file('extdata', package='fldgen')`.
1524

1625
```R
1726
library(fldgen)
1827

19-
griddata <- read.ncdf('data/tann1.nc')
20-
tgav <- readtgav('data/wgttann1.nc')
21-
pscl <- pscl_analyze(griddata$tas, tgav)
22-
reof <- eof_analyze(pscl$r, griddata$tgop)
23-
Fx <- mvfft(reof$x) # Fourier transforms of the coordinates
24-
# in the orthogonal basis.
25-
Fxmag <- abs(Fx)
26-
Fxphase <- atan2(Im(Fx), Re(Fx))
28+
emulator <- train('extdata/tann1.nc')
29+
2730
tempgrids <- list() # Empty list to hold the temperature
2831
# realizations we are about to create.
2932
length(tempgrids) <- 4
3033

3134
## Run with the phases of the actual time series
32-
meanfield <- pscl_apply(pscl, tgav)
33-
tempgrids[[1]] <- reconst_fields(reof$rotation, mkcorrts(Fxmag, Fxphase) , meanfield)
35+
meanfield <- pscl_apply(emulator$pscl, emulator$tgav)
36+
tempgrids[[1]] <- reconst_fields(emulator$reof$rotation, mkcorrts(emulator) , meanfield)
3437
## Run the rest with random phases
3538
for(i in 2:4)
36-
## If you wanted to use a smaller number of PCs, say 50, you could
37-
## use reof$rotation[,1:50] and Fxmag[,1:50] in the next call.
38-
tempgrids[[i]] <- reconst_fields(reof$rotation, mkcorrts(Fxmag), meanfield)
39+
tempgrids[[i]] <- reconst_fields(emulator$reof$rotation, mkcorrts(emulator), meanfield)
40+
41+
```
3942

43+
A more detailed example can be found in the tutorial vignette included
44+
with the package.
45+
```R
46+
vignette('tutorial','fldgen')
4047
```

fldgen.Rproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ StripTrailingWhitespace: Yes
1818
BuildType: Package
1919
PackageUseDevtools: Yes
2020
PackageInstallArgs: --no-multiarch --with-keep.source
21-
PackageRoxygenize: rd,collate,namespace
21+
PackageRoxygenize: rd,collate,namespace,vignette

man/fldgen-package.Rd

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

man/train.Rd

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

vignettes/tutorial.Rmd

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: "Robert Link"
44
date: "`r Sys.Date()`"
55
output: rmarkdown::html_vignette
66
vignette: >
7-
%\VignetteIndexEntry{Vignette Title}
7+
%\VignetteIndexEntry{Fldgen Tutorial}
88
%\VignetteEngine{knitr::rmarkdown}
99
%\VignetteEncoding{UTF-8}
1010
---
@@ -55,10 +55,15 @@ datadir <- system.file('extdata', package='fldgen')
5555

5656
### One-step emulator training
5757

58-
You can do the read and analyze steps below in a single command by running
58+
You can do the read and analyze steps below in a single command by running:
5959
```
60-
emulator <- train(file.path(datadir, 'tann1.nc'))
60+
infile <- file.path(datadir, 'tann1.nc')
61+
emulator <- train(infile)
6162
```
63+
If you want to use multiple ESM runs for the training, you can either pass
64+
`train` a list of filenames, or you can give it the name of a directory, in
65+
which case it will use all of the netCDF files it finds there.
66+
6267
If you use this (recommended) method, then you can skip directly to [Generating
6368
fields]. For users that wish to customize the training process, the next two
6469
sections describe what is happening inside the `train` function and show how to
@@ -130,7 +135,7 @@ emulator <- fldgen_object(griddata, tgav, pscl, reof, Fx, phasecoef, filename)
130135

131136
Now we're ready to generate fields. We'll do `r ngen` fields in this example.
132137
The first one will be a reconstruction of the original input. The other three
133-
will new fields.
138+
will be new fields.
134139

135140
```{r genfields}
136141
tempgrids <- list()
@@ -140,13 +145,11 @@ length(tempgrids) <- ngen
140145
meanfield <- pscl_apply(pscl, tgav)
141146
142147
## First field will have the same phases as the input ESM data
143-
tempgrids[[1]] <- suppressMessages( # mkcorrts emits a bunch of status messages that we don't want here.
144-
reconst_fields(reof$rotation, mkcorrts(emulator, Fxphase), meanfield))
148+
tempgrids[[1]] <- reconst_fields(reof$rotation, mkcorrts(emulator, Fxphase), meanfield)
145149
146150
## Other fields will have random phases
147151
for(i in 2:ngen) {
148-
tempgrids[[i]] <- suppressMessages( # don't want the status messages
149-
reconst_fields(reof$rotation, mkcorrts(emulator), meanfield))
152+
tempgrids[[i]] <- reconst_fields(reof$rotation, mkcorrts(emulator), meanfield)
150153
}
151154
152155
## Subtract off the mean field. Save these because we will want to use them later

0 commit comments

Comments
 (0)