Skip to content

Commit

Permalink
Update read_ncdf.R
Browse files Browse the repository at this point in the history
  • Loading branch information
mengqi-z committed Jan 9, 2024
1 parent e14f744 commit f5a776c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/read_ncdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ read_ncdf <- function(ncdf = NULL,
ncdf_in <- ncdf4::nc_open(ncdf)
var_names <- attributes(ncdf_in$var)$names

# get unit
var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit

dims <- c(ncdf_in$var[[var]]$dim[[1]]$name,
ncdf_in$var[[var]]$dim[[2]]$name,
ncdf_in$var[[var]]$dim[[3]]$name)
Expand All @@ -39,6 +36,9 @@ read_ncdf <- function(ncdf = NULL,
stop('Climate variable name is not valid. Please provide valid ncdf_var name.')
}

# get unit
var_unit <- ncdf4::ncatt_get(ncdf_in, var)$unit

# get the data time series
ncdf_brick <- raster::brick(ncdf, varname = var, ncdf = TRUE,
dims = dims_order, stopIfNotEqualSpaced = F)
Expand Down Expand Up @@ -120,9 +120,6 @@ read_ncdf <- function(ncdf = NULL,
ncdf_in <- ncdf4::nc_open(ncdf)
var_names <- attributes(ncdf_in$var)$names

# get unit
var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit

dims <- c(ncdf_in$var[[var]]$dim[[1]]$name,
ncdf_in$var[[var]]$dim[[2]]$name,
ncdf_in$var[[var]]$dim[[3]]$name)
Expand All @@ -132,6 +129,9 @@ read_ncdf <- function(ncdf = NULL,
stop('Climate variable name is not valid. Please provide valid ncdf_var name.')
}

# get unit
var_unit <- ncdf4::ncatt_get(ncdf_in, var)$unit

ncdf_brick <- raster::brick(ncdf, varname = var, ncdf = TRUE,
dims = dims_order, stopIfNotEqualSpaced = F)

Expand Down

0 comments on commit f5a776c

Please sign in to comment.