Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Franssen, Wietse
WFRTools
Commits
05df0569
Commit
05df0569
authored
Mar 25, 2015
by
Franssen, Wietse
Browse files
added the function convertUnit
parent
f1e436f7
Changes
5
Hide whitespace changes
Inline
Side-by-side
DESCRIPTION
View file @
05df0569
...
...
@@ -5,6 +5,6 @@ Version: 1.0
Date: 2015-02-16
Author: Wietse Franssen
Maintainer: Wietse Franssen <wietse.franssen@wur.nl>
Depends: R (>= 3.0.0), ncdf4, fields, RColorBrewer, ggplot2
Depends: R (>= 3.0.0), ncdf4, fields, RColorBrewer, ggplot2
, udunits2
Description: Some usefull R-Functions
License: GPL
R/WFRTools.R
View file @
05df0569
...
...
@@ -32,11 +32,32 @@ plotje <-function(data, title = NULL) {
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
#' @export
ncPlot
<-
function
(
file
,
varName
=
NULL
,
lonlatbox
=
NULL
,
timesteps
=
NULL
,
z
=
NULL
)
{
data
<-
ncLoad
(
file
,
varName
,
lonlatbox
,
timesteps
,
z
)
ncPlot
<-
function
(
file
,
varName
=
NULL
,
lonlatbox
=
NULL
,
timesteps
=
NULL
,
z
=
NULL
,
convertUnit
=
NULL
)
{
data
<-
ncLoad
(
file
,
varName
,
lonlatbox
,
timesteps
,
z
,
convertUnit
)
plotje
(
data
)
}
#' Make a image of the NetCDF data
#' @details BLAAT.
#' @return Nothing
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
convertUnit
<-
function
(
data
)
{
data
$
Variable
$
units
<-
gsub
(
"kg m-2"
,
"mm"
,
data
$
Variable
$
units
)
data
$
Variable
$
units
<-
gsub
(
"kg/m2"
,
"mm"
,
data
$
Variable
$
units
)
if
(
ud.are.convertible
(
data
$
Variable
$
units
,
"mm day-1"
))
{
data
$
Data
[]
<-
ud.convert
(
data
$
Data
[],
data
$
Variable
$
units
,
"mm day-1"
)
data
$
Variable
$
units
<-
"mm day-1"
}
if
(
ud.are.convertible
(
data
$
Variable
$
units
,
"Celsius"
))
{
data
$
Data
[]
<-
ud.convert
(
data
$
Data
[],
data
$
Variable
$
units
,
"Celsius"
)
data
$
Variable
$
units
<-
"Celsius"
}
return
(
data
)
}
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
rDataStructure
<-
function
()
{
...
...
@@ -107,6 +128,7 @@ ggplotje <-function(rdata,lon = NULL, lat = NULL) {
data
<-
r2ggplotDataStructure
(
rdata
)
myPalette
<-
colorRampPalette
(
rev
(
brewer.pal
(
11
,
"Spectral"
)),
space
=
"Lab"
)
# myPalette <- colorRampPalette(rev(rainbow(100)), space="Lab")
zp1
<-
ggplot
(
data
,
aes
(
x
=
lon
,
y
=
lat
,
fill
=
data
))
+
...
...
@@ -184,7 +206,7 @@ ncCheck <-function(ncFile, variable) {
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
#' @export
ncLoad
<-
function
(
file
,
varName
=
NULL
,
lonlatbox
=
NULL
,
timesteps
=
NULL
,
z
=
NULL
)
{
ncLoad
<-
function
(
file
,
varName
=
NULL
,
lonlatbox
=
NULL
,
timesteps
=
NULL
,
z
=
NULL
,
convertUnit
=
NULL
)
{
## first build an empty data structure
data
<-
rDataStructure
()
...
...
@@ -314,6 +336,10 @@ ncLoad <-function(file, varName = NULL, lonlatbox = NULL, timesteps = NULL, z =
data
$
Variable
$
units
<-
"missing"
}
if
(
!
is.null
(
convertUnit
))
{
data
<-
convertUnit
(
data
)
}
## Close the file
nc_close
(
ncFile
)
...
...
man/convertUnit.Rd
0 → 100644
View file @
05df0569
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/WFRTools.R
\name{convertUnit}
\alias{convertUnit}
\title{Make a image of the NetCDF data}
\usage{
convertUnit(data)
}
\value{
Nothing
}
\description{
Make a image of the NetCDF data
}
\details{
BLAAT.
}
\author{
Wietse Franssen \email{wietse.franssen@wur.nl}
}
\keyword{internal}
man/ncLoad.Rd
View file @
05df0569
...
...
@@ -5,7 +5,7 @@
\title{ncLoad}
\usage{
ncLoad(file, varName = NULL, lonlatbox = NULL, timesteps = NULL,
z = NULL)
z =
NULL, convertUnit =
NULL)
}
\arguments{
\item{file}{Name of the NetCDF file}
...
...
man/ncPlot.Rd
View file @
05df0569
...
...
@@ -5,7 +5,7 @@
\title{Make a image of the NetCDF data}
\usage{
ncPlot(file, varName = NULL, lonlatbox = NULL, timesteps = NULL,
z = NULL)
z =
NULL, convertUnit =
NULL)
}
\value{
Nothing
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment