Commit 05df0569 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

added the function convertUnit

parent f1e436f7
......@@ -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
......@@ -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)
......
% 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}
......@@ -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}
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment