Skip to content

Commit

Permalink
fixing some typos/bugs in the RNetCDF conversion for NetCDF writing p…
Browse files Browse the repository at this point in the history
…rocess
  • Loading branch information
aestears committed Jun 14, 2024
1 parent 4891211 commit 8462234
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
19 changes: 10 additions & 9 deletions functions/netcdf_functions_HPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ NULL
#' unlink(unlist(tmp_nc))
#'
#' @export
create_netCDF <- function(
create_netCDF_use <- function(
filename,
xyspace,
data = NULL,
Expand Down Expand Up @@ -1145,7 +1145,7 @@ var_defs <- var_names
)


nc_dimvars <- c(nc_dimvars, "vertical_bnds")
#nc_dimvars <- c(nc_dimvars, "vertical_bnds")
}

if (has_T_timeAxis != "none") {
Expand All @@ -1160,7 +1160,7 @@ var_defs <- var_names
)


nc_dimvars <- c(nc_dimvars, varid_timebnds)
# nc_dimvars <- c(nc_dimvars, varid_timebnds)
}
}

Expand Down Expand Up @@ -1208,10 +1208,10 @@ var_defs <- var_names
shuffle = nc_shuffle,
chunksizes = c(2L, n_yvals)
)
nc_dimvars <- c(bnds_name)
#nc_dimvars <- c(bnds_name)

} else {
nc_dimvars <- c()
#nc_dimvars <- c()
}

if (has_Z_verticalAxis != "none") {
Expand All @@ -1227,7 +1227,7 @@ var_defs <- var_names
)


nc_dimvars <- c(nc_dimvars, "vertical_bnds")
#nc_dimvars <- c(nc_dimvars, "vertical_bnds")
}

if (has_T_timeAxis != "none") {
Expand All @@ -1242,7 +1242,7 @@ var_defs <- var_names
)


nc_dimvars <- c(nc_dimvars, varid_timebnds)
#nc_dimvars <- c(nc_dimvars, varid_timebnds)
}

#------ Write dimensional variable values ------
Expand Down Expand Up @@ -1287,7 +1287,8 @@ var_defs <- var_names
RNetCDF::var.put.nc(
nc,
variable = "vertical_bnds",
data = t(vertical_bounds),
data = #t(vertical_bounds),
matrix(data = 1, nrow = nrow(t(vertical_bounds)), ncol = ncol(t(vertical_bounds))),
start = c(1,1),
count = c(2L, n_vertical)
)
Expand Down Expand Up @@ -1369,7 +1370,7 @@ var_defs <- var_names
for (natt in ns_att_vert) {
RNetCDF::att.put.nc(
nc,
variable = "variable",
variable = "vertical",
name = natt,
value = vertical_attributes[[natt]],
type = "NC_CHAR"
Expand Down
23 changes: 12 additions & 11 deletions main/implementation/01.1_create-netcdfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@


# rm(list = ls(all = TRUE))
#library(RNetCDF) # this package has parallel capabilities now, so replace pdbNCDF4??
library(RNetCDF) # this package has parallel capabilities now, so replace pdbNCDF4??
library(ncdf4)
#library(pbdNCDF4)
#source('functions/netcdf_functions2.R')
#source('functions/netcdf_functions_HPC.R')
# source functions
# Begin ------------------------------------------------------------------------
#file_list <- list.files(path = "./functions/", full.names = TRUE)
# Iterate over the file list and source each file. TO DO: package all these functions
# for (file in file_list) {
# print(file)
# source(file)
# }

#Iterate over the file list and source each file. TO DO: package all these functions
for (file in file_list) {
print(file)
source(file)
}

#devtools::install_github("r4ecology/rcdo", dependencies = TRUE, force = TRUE)
#library(rcdo)
# source('projects/03-Make-Climatologies-netCDF/nc_clip_edit.R')
Expand Down Expand Up @@ -296,7 +296,7 @@ for(nc in 1:106){
names(data_dims_nc) <- c("ns", "nx", "ny", "nz", "nt", "nv")
# create netCDF
# create netCDF
assign(names[nc], create_netCDF(
assign(names[nc], create_netCDF_use(
filename = file.path(Output_folder,
paste0(attributes$Name[nc], '_', format(currDate, "%m%Y"), '.nc')),
overwrite = TRUE,
Expand All @@ -318,14 +318,15 @@ for(nc in 1:106){
nc_shuffle = FALSE,
nc_deflate = 5,
global_attributes = nc_att_global,
isParallel = isParallel # set in main runner file
isParallel = isParallel, # set in main runner file
data_type = "float"
))
} else {
## data_dims ---------------------------------
data_dims_nc <- c(0, 739, 585, 0, nrow(time_bounds), 0)
names(data_dims_nc) <- c("ns", "nx", "ny", "nz", "nt", "nv")
# create netCDF
assign(names[nc], create_netCDF(
assign(names[nc], create_netCDF_use(
filename = file.path(Output_folder,
paste0(attributes$Name[nc], '_', format(currDate, "%m%Y"), '.nc')),
overwrite = TRUE,
Expand Down

0 comments on commit 8462234

Please sign in to comment.