Skip to content

Commit

Permalink
Merge pull request #30 from jread-usgs/master
Browse files Browse the repository at this point in the history
v0.2.1 example data w/ pkg and check fixes according to as-cran
  • Loading branch information
Jordan S Read committed Jul 28, 2014
2 parents 49f2b94 + c0364e2 commit 4626c97
Show file tree
Hide file tree
Showing 47 changed files with 308 additions and 225 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rGLM
Type: Package
Title: rGLM
Version: 0.2.0
Version: 0.2.1
Date: 2013-07-23
Author: Jordan S Read, Luke A Winslow
Maintainer: Jordan S Read <jread@usgs.gov>, Luke A Winslow <lawinslow@wisc.edu>
Expand Down
16 changes: 0 additions & 16 deletions Examples/GLMncExample.R

This file was deleted.

31 changes: 0 additions & 31 deletions Examples/nml_readwrite.R

This file was deleted.

33 changes: 0 additions & 33 deletions Examples/writeAll_LA.R

This file was deleted.

19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
U.S.Geological Survey Software User Rights Notice

Copied from http://water.usgs.gov/software/help/notice/ on September 7, 2012. Please check webpage for updates.

Software and related material (data and (or) documentation), contained in or furnished in connection with a software distribution, are made available by the U.S. Geological Survey (USGS) to be used in the public interest and in the advancement of science. You may, without any fee or cost, use, copy, modify, or distribute this software, and any derivative works thereof, and its supporting documentation, subject to the following restrictions and understandings.

If you distribute copies or modifications of the software and related material, make sure the recipients receive a copy of this notice and receive or can get a copy of the original distribution. If the software and (or) related material are modified and distributed, it must be made clear that the recipients do not have the original and they must be informed of the extent of the modifications. For example, modified files must include a prominent notice stating the modifications made, the author of the modifications, and the date the modifications were made. This restriction is necessary to guard against problems introduced in the software by others, reflecting negatively on the reputation of the USGS.

The software is public property and you therefore have the right to the source code, if desired.

You may charge fees for distribution, warranties, and services provided in connection with the software or derivative works thereof. The name USGS can be used in any advertising or publicity to endorse or promote any products or commercial entity using this software if specific written permission is obtained from the USGS.

The user agrees to appropriately acknowledge the authors and the USGS in publications that result from the use of this software or in products that include this software in whole or in part.

Because the software and related material are free (other than nominal materials and handling fees) and provided "as is," the authors, the USGS, and the United States Government have made no warranty, express or implied, as to accuracy or completeness and are not obligated to provide the user with any support, consulting, training or assistance of any kind with regard to the use, operation, and performance of this software nor to provide the user with any updates, revisions, new versions or "bug fixes".

The user assumes all risk for any damages whatsoever resulting from loss of use, data, or profits arising in connection with the access, use, quality, or performance of this software.

R and other package dependencies have more restrictive licenses.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2 (4.0.1): do not edit by hand

export(get_evaporation)
export(get_hypsography)
export(get_ice)
export(get_nml_value)
Expand Down
26 changes: 26 additions & 0 deletions R/get_evaporation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#'@title get evaporation from GLM simulation
#'@description
#'Creates a data.frame with DateTime and E (mm/day). \cr
#'
#'@param file a string with the path to the netcdf output from GLM
#'@return a data.frame with DateTime and evaporation (in mm/day)
#'@keywords methods
#'@author
#'Jordan S. Read
#'@examples
#'file <- system.file('extdata', 'output.nc', package = 'rGLM')
#'evap <- get_evaporation(file)
#'plot(evap)
#'@import ncdf4
#'@export
get_evaporation <- function(file){
day_secs <- 86400
m_to_mm <- 1000
glm_nc <- get_glm_nc(file)
evaporation <- ncvar_get(glm_nc, "evap")*day_secs*m_to_mm
time <- get_time(glm_nc)

glm_evaporation <- data.frame('DateTime'=time, 'evaporation(mm/d)'=evaporation)
close_glm_nc(glm_nc)
return(glm_evaporation)
}
17 changes: 9 additions & 8 deletions R/get_hypsography.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#'@title retrieve hypsography information from glm_nml object or file
#'@title retrieve hypsography information
#'@description
#'Retrieves hypsography information from glm_nml object or file \cr
#'
#'Retrieves hypsography information from glm_nml object or file. \cr
#'Hypsography is the relationship between depth and area of a lake.
#''Depth' is referenced from the lake surface and downward values are positive in meters. Areas are in square meters.
#'
#'@param glm_nml a nml (a list) for GLM config
#'@param file a string with the path to the GLM glm.nml file
Expand All @@ -11,16 +12,16 @@
#'Jordan S. Read
#'@seealso \link{write_lvl}, \link{read_nml}, \link{get_nml_value}
#'@examples
#'nml_file <- '../resources/glm.nml'
#'nml_file <- system.file('extdata', 'glm.nml', package = 'rGLM')
#'glm_nml <- read_nml(nml_file)
#'get_hypsography(glm_nml)
#'get_hypsography(file=nml_file)
#'get_hypsography(file = nml_file)
#'@export
get_hypsography <- function(glm_nml=NULL, file=NULL){
get_hypsography <- function(glm_nml, file){
# if both are passed, glm_nml is used and 'file' is ignored
if (is.null(file) & is.null(glm_nml)){stop('glm.nml file path OR glm_nml must be specified')}
if (missing(file) & missing(glm_nml)){stop('glm.nml file path OR glm_nml must be specified')}

if (is.null(glm_nml)){
if (missing(glm_nml)){
glm_nml <- read_nml(file)
}

Expand Down
20 changes: 14 additions & 6 deletions R/get_ice.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#'@title get ice depth from GLM simulation
#'@description
#'Creates a data.frame with DateTime and ice. \cr
#'
#'This function sums the thickness of the clear ice, white ice,
#'and optionally, the thickness of snow for each timestep in the GLM model.
#'
#'@param file a string with the path to the netcdf output from GLM
#'@return a data.frame with DateTime and ice
#'@param snow.rm a boolean for ignoring snow depth in the calculation of ice thickness
#'@return a data.frame with DateTime and ice (in meters)
#'@keywords methods
#'@author
#'Luke A. Winslow, Jordan S. Read
#'@examples
#'file = '../test/output.nc'
#'file <- system.file('extdata', 'output.nc', package = 'rGLM')
#'ice <- get_ice(file)
#'ice_and_snow <- get_ice(file, snow.rm = FALSE)
#'plot(ice)
#'points(ice_and_snow, col = "red")
#'@import ncdf4
#'@export
get_ice <- function(file){
get_ice <- function(file, snow.rm = TRUE){
glm_nc <- get_glm_nc(file)
ice <- ncvar_get(glm_nc, "hice")+ncvar_get(glm_nc, "hwice")+ncvar_get(glm_nc, "hsnow")
ice <- ncvar_get(glm_nc, "hice") + ncvar_get(glm_nc, "hwice")
if (!snow.rm){
ice <- ice + ncvar_get(glm_nc, "hsnow")
}
time <- get_time(glm_nc)

glm_ice <- data.frame('DateTime'=time, 'ice'=ice)
glm_ice <- data.frame('DateTime'=time, 'ice(m)'=ice)
close_glm_nc(glm_nc)
return(glm_ice)
}
8 changes: 4 additions & 4 deletions R/get_nml_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#'@author
#'Jordan S. Read
#'@examples
#'file = '../resources/glm.nml'
#'glm_nml <- read_nml(file)
#'get_nml_value(glm_nml,arg_name='Kw')
#'nml_file <- system.file('extdata', 'glm.nml', package = 'rGLM')
#'glm_nml <- read_nml(nml_file)
#'get_nml_value(glm_nml,arg_name = 'Kw')
#'@export
get_nml_value <- function(glm_nml,arg_name){
get_nml_value <- function(glm_nml, arg_name){

blckI <- findBlck(glm_nml,arg_name)

Expand Down
13 changes: 9 additions & 4 deletions R/get_surface_height.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
#'
#'@param file a string with the path to the netcdf output from GLM
#'@param ice.rm a boolean for including ice thickness in surface height
#'@param snow.rm a boolean for including snow depth thickness in surface height
#'@return a data.frame with DateTime and surface_height (in meters)
#'@keywords methods
#'@author
#'Jordan S. Read, Luke A. Winslow
#'@examples
#'file = '../test/output.nc'
#'file <- system.file('extdata', 'output.nc', package = 'rGLM')
#'surface <- get_surface_height(file)
#'surface_w_ice <- get_surface_height(file, ice.rm = FALSE)
#'surface_w_ice <- get_surface_height(file, ice.rm = FALSE, snow.rm = FALSE)
#'@import ncdf4
#'@export
get_surface_height <- function(file, ice.rm = TRUE){
get_surface_height <- function(file, ice.rm = TRUE, snow.rm = TRUE){
glm_nc <- get_glm_nc(file)
NS <- ncvar_get(glm_nc, "NS")
elev <- ncvar_get(glm_nc, "z")
Expand All @@ -27,7 +28,11 @@ get_surface_height <- function(file, ice.rm = TRUE){
surface_height[j] <- elev[NS[j],j]
}
if (!ice.rm){
surface_height <- surface_height + get_ice(file)[, 2]
surface_height <- surface_height + get_ice(file, snow.rm = TRUE)[, 2]
}
if (!snow.rm){
snow <- get_ice(file, snow.rm = TRUE)[, 2] - get_ice(file, snow.rm = TRUE)[, 2]
surface_height <- surface_height + snow
}

glm_surface <- data.frame('DateTime'=time, 'surface_height'=surface_height)
Expand Down
12 changes: 7 additions & 5 deletions R/get_temp.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#'@title get water temperatures from a GLM simulation
#'@description
#'Creates a data.frame with DateTime and temperatures (in deg C). \cr
#'
#'Temperatures that are sampled out of the GLM output are taken relative
#'to the surface (\code{reference = 'surface'}) or the bottom of the lake
#'(\code{reference = 'bottom'}).
#'
#'@param file a string with the path to the netcdf output from GLM
#'@param reference a string which specifies the vertical reference ('surface' or 'bottom')
Expand All @@ -11,12 +13,12 @@
#'@author
#'Jordan S. Read, Luke A. Winslow
#'@examples
#'file = '../test/output.nc'
#'temp_surf <- get_temp(file,reference='surface',z_out=c(0,1,2))
#'temp_bot <- get_temp(file,reference='bot',z_out=c(0,1,2))
#'file <- system.file('extdata', 'output.nc', package = 'rGLM')
#'temp_surf <- get_temp(file, reference = 'surface', z_out = c(0,1,2))
#'temp_bot <- get_temp(file, reference = 'bottom', z_out = c(0,1,2))
#'@import ncdf4
#'@export
get_temp <- function(file, reference='bottom', z_out){
get_temp <- function(file, reference = 'bottom', z_out){
if (reference!='bottom' & reference!='surface'){
stop('reference input must be either "surface" or "bottom"')
}
Expand Down
4 changes: 2 additions & 2 deletions R/get_wind.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#'@author
#'Luke A. Winslow, Jordan S. Read
#'@examples
#'file = '../test/output.nc'
#'ice <- get_wind(file)
#'file <- system.file('extdata', 'output.nc', package = 'rGLM')
#'wind <- get_wind(file)
#'@import ncdf4
#'@export
get_wind <- function(file){
Expand Down
3 changes: 0 additions & 3 deletions R/nc_helpers.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

get_glm_nc <- function(file){
require(ncdf4)
glm_nc <- nc_open(file)
return(glm_nc)
}
Expand All @@ -12,7 +11,6 @@ close_glm_nc <- function(glm_nc){

# Summary: Returns the converted time vector in R format
get_time <- function(glm_nc){
require(ncdf4)
hours_since <- ncvar_get(glm_nc, "time")
time_info <- get_time_info(glm_nc)

Expand All @@ -23,7 +21,6 @@ get_time <- function(glm_nc){
}

get_time_info <- function(glm_nc){
require(ncdf4)
day_secs = 86400
time_unit <- 3600/day_secs

Expand Down
12 changes: 6 additions & 6 deletions R/nml_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ findBlck <- function(nml,argName){
}

# private function
setnmlList <- function(nml,argList){
if (!is.list(argList)){stop("argList must be a list")}
setnmlList <- function(glm_nml,arg_list){
if (!is.list(arg_list)){stop("argList must be a list")}

argNames <- names(argList)
for (i in 1:length(argNames)){
nml <- set_nml(nml,argName=argNames[i],argVal=argList[[i]])
arg_names <- names(arg_list)
for (i in 1:length(arg_names)){
glm_nml <- set_nml(glm_nml,arg_name=arg_names[i],arg_val=arg_list[[i]])
}
return(nml)
return(glm_nml)
}


Expand Down
4 changes: 2 additions & 2 deletions R/pretty_nml.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#'@author
#'Jordan S. Read
#'@examples
#'file = '../resources/glm.nml'
#'glm_nml <- read_nml(file)
#'nml_file <- system.file('extdata', 'glm.nml', package = 'rGLM')
#'glm_nml <- read_nml(nml_file)
#'pretty_nml(glm_nml)
#'@export
pretty_nml <- function(glm_nml){
Expand Down
6 changes: 3 additions & 3 deletions R/read_nml.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#'Jordan S. Read
#'@seealso \link{get_nml_value}
#'@examples
#'file = '../resources/glm.nml'
#'glm_nml <- read_nml(file)
#'nml_file <- system.file('extdata', 'glm.nml', package = 'rGLM')
#'glm_nml <- read_nml(nml_file)
#'pretty_nml(glm_nml)
#'@export
read_nml <- function(file = '../resources/glm.nml'){
read_nml <- function(file){
# skip all commented lines, return all variables and associated values
# requires NO return line variables (all variables must be completely defined on a single line)
c <- file(file,"r")
Expand Down
Loading

0 comments on commit 4626c97

Please sign in to comment.