Skip to content

Commit

Permalink
Merge pull request #189 from jread-usgs/master
Browse files Browse the repository at this point in the history
updating to ncdf4 instead of ncdf
  • Loading branch information
Luke Winslow committed Jan 18, 2016
2 parents b92a8c3 + 982e09f commit 1267f54
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ before_install:
- ./travis-tool.sh bootstrap
install:
- ./travis-tool.sh install_deps
- ./travis-tool.sh github_package jimhester/covr
- ./travis-tool.sh r_install covr
- ./travis-tool.sh install_github GLEON/GLMr
script: ./travis-tool.sh run_tests

Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: glmtools
Type: Package
Title: glmtools
Version: 0.10.3
Date: 2013-09-18
Version: 0.11.0
Date: 2016-01-15
Authors@R: c( person("Jordan", "Read", role = c("aut","cre"),
email = "jread@usgs.gov"),
person("Luke", "Winslow", role = "aut",
Expand All @@ -19,7 +19,7 @@ Depends:
GLMr,
rLakeAnalyzer
Imports:
ncdf,
ncdf4,
tools,
akima
Suggests:
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export(validate_sim)
export(water.temperature)
export(write_nml)
import(GLMr)
import(ncdf)
import(rLakeAnalyzer)
import(tools)
importFrom(akima,interp)
importFrom(ncdf4,nc_close)
importFrom(ncdf4,nc_open)
importFrom(ncdf4,ncatt_get)
importFrom(ncdf4,ncvar_get)
4 changes: 2 additions & 2 deletions R/get_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
#'sim_folder <- run_example_sim(verbose = FALSE)
#'nc_file <- file.path(sim_folder, 'output.nc')
#'wind <- get_raw(nc_file, 'wind') #raw wind data
#'@import ncdf
#'@importFrom ncdf4 ncvar_get
#'@seealso \code{\link{sim_vars}}
#'@export
get_raw <- function(file='output.nc', param_name){
glm_nc <- get_glm_nc(file)
raw_data <- get.var.ncdf(glm_nc, param_name)
raw_data <- ncvar_get(glm_nc, param_name)

close_glm_nc(glm_nc)
return(raw_data)
Expand Down
6 changes: 3 additions & 3 deletions R/get_surface_height.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#'nc_file <- file.path(sim_folder, 'output.nc')
#'surface <- get_surface_height(file = nc_file)
#'surface_w_ice <- get_surface_height(file = nc_file, ice.rm = FALSE, snow.rm = FALSE)
#'@import ncdf
#'@importFrom ncdf4 ncvar_get
#'@export
get_surface_height <- function(file='output.nc', ice.rm = TRUE, snow.rm = TRUE, ...){
glm_nc <- get_glm_nc(file)
NS <- get.var.ncdf(glm_nc, "NS")
elev <- get.var.ncdf(glm_nc, "z")
NS <- ncvar_get(glm_nc, "NS")
elev <- ncvar_get(glm_nc, "z")
time <- get_time(glm_nc)
close_glm_nc(glm_nc)

Expand Down
8 changes: 4 additions & 4 deletions R/get_var.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
#'print(sim_vars(nc_file))
#'evaporation <- get_var(nc_file, var_name = "evap")
#'plot(evaporation)
#'@import ncdf
#'@importFrom ncdf4 ncvar_get
#'@export
get_var <- function(file='output.nc', var_name, reference = 'bottom', z_out = NULL, t_out = NULL, ...){



glm_nc <- get_glm_nc(file)

tallest_layer <- get.var.ncdf(glm_nc, "NS") #The last useful index
elev <- get.var.ncdf(glm_nc, "z" )
temp <- get.var.ncdf(glm_nc, var_name)
tallest_layer <- ncvar_get(glm_nc, "NS") #The last useful index
elev <- ncvar_get(glm_nc, "z" )
temp <- ncvar_get(glm_nc, var_name)
time <- get_time(glm_nc)

close_glm_nc(glm_nc)
Expand Down
15 changes: 9 additions & 6 deletions R/nc_helpers.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@

#' @importFrom ncdf4 nc_open
get_glm_nc <- function(file){
if(length(file) < 1 || is.na(file)){
stop('glm_nc file must be supplied string or proper file handle')
}
glm_nc <- open.ncdf(file, readunlim=TRUE)
glm_nc <- nc_open(file, readunlim=TRUE)
return(glm_nc)
}

#' @importFrom ncdf4 nc_close
close_glm_nc <- function(glm_nc){
close.ncdf(glm_nc)
nc_close(glm_nc)
}


# Summary: Returns the converted time vector in R format
#' @importFrom ncdf4 ncvar_get
get_time <- function(glm_nc){
hours_since <- get.var.ncdf(glm_nc, "time")
hours_since <- ncvar_get(glm_nc, "time")
time_info <- get_time_info(glm_nc)

time <- time_info$startDate + time_info$time_unit * hours_since * 60*60*24
Expand All @@ -23,6 +25,7 @@ get_time <- function(glm_nc){

}

#' @importFrom ncdf4 ncatt_get ncvar_get
get_time_info <- function(glm_nc, file = NULL){

day_secs = 86400
Expand All @@ -34,7 +37,7 @@ get_time_info <- function(glm_nc, file = NULL){
glm_nc <- get_glm_nc(file)
close_nc <- TRUE
}
time_units <- att.get.ncdf(glm_nc,'time','units')$value
time_units <- ncatt_get(glm_nc,'time','units')$value


#It is written in prose instead of machine-readable format. Check to makes sure
Expand All @@ -59,7 +62,7 @@ get_time_info <- function(glm_nc, file = NULL){
time_info <- cbind(time_info,"startDate"=start_date)

#End date/time
endT <- time_info$startDate + get.var.ncdf(glm_nc, 'time', start=tLen, count=1) * time_unit * day_secs
endT <- time_info$startDate + ncvar_get(glm_nc, 'time', start=tLen, count=1) * time_unit * day_secs

time_info <- cbind(time_info,"stopDate"=endT[1])
if (close_nc){
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ How do I install `glmtools`? It isn't on CRAN!

What libraries does `glmtools` need?
===
This version requires the NetCDF version R library (called `ncdf`), and `rLakeAnalyzer`, and `tools` if you would like to run all examples.
This version requires the NetCDF version R library (called `ncdf4`), and `rLakeAnalyzer`, and `tools` if you would like to run all examples.

How do I contribute new code back to the glmtools project?
===
Expand Down

0 comments on commit 1267f54

Please sign in to comment.