From 747371b100f88430cf6f6f8d9be779d8dc0f4049 Mon Sep 17 00:00:00 2001 From: Barbara Robson Date: Mon, 22 May 2023 15:37:27 +1000 Subject: [PATCH 1/2] Fixed bug in get_ereefs_ts() in mmp check. --- DESCRIPTION | 4 ++-- R/data_extraction_functions.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8dc7aa6..b83cdd1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ereefs Title: Useful Functions to Handle eReefs and EMS model Output -Version: 3.2.4 +Version: 3.2.5 Encoding: UTF-8 Authors@R: c(person("Barbara", "Robson", email="B.Robson@aims.gov.au", role = c("aut", "cre")), @@ -43,7 +43,7 @@ URL: https://ereefs.info Date: 2021-08-18 License: MIT + file LICENSE LazyData: true -Imports: ncdf4 (>= 1.16), +Imports: ncdf4 (== 1.19), plyr (>= 1.8.4), dplyr (>= 0.7.6), magrittr, diff --git a/R/data_extraction_functions.R b/R/data_extraction_functions.R index f10052f..c5a380a 100644 --- a/R/data_extraction_functions.R +++ b/R/data_extraction_functions.R @@ -526,7 +526,7 @@ get_ereefs_ts <- function(var_names=c('Chl_a_sum', 'TN'), if (layer=='integrated') return(get_ereefs_depth_integrated_ts(var_names, location_latlon, start_date, end_date, input_file, input_grid, eta_stem, override_positive)) if ((layer=='bottom')&&(length(location_latlon[,1])>1)) stop('Only one location can be given if layer==bottom') # if (layer=='bottom') return(get_ereefs_bottom_ts(var_names, location_latlon, start_date, end_date, input_file, input_grid, eta_stem, override_positive)) - if (location_latlon[[1]]=="mmp") { + if (location_latlon[[1]][1]=="mmp") { location_latlon <- data.frame(latitude=mmp_sites$latitude, longitude=mmp_sites$longitude) mmp <- TRUE } else { From 72ffc12cb1966d4bde8169c6a1c9ed747a66cfb0 Mon Sep 17 00:00:00 2001 From: Barbara Robson Date: Tue, 23 May 2023 14:05:45 +1000 Subject: [PATCH 2/2] Fixed warn() error (changed to warning()) --- R/data_extraction_functions.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/R/data_extraction_functions.R b/R/data_extraction_functions.R index c5a380a..e6a059f 100644 --- a/R/data_extraction_functions.R +++ b/R/data_extraction_functions.R @@ -554,7 +554,7 @@ get_ereefs_ts <- function(var_names=c('Chl_a_sum', 'TN'), if (length(ilat)) { location_latlon <- data.frame(latitude = location_latlon[, ilat], longitude = location_latlon[, ilon]) } else { - warn("Assuming that the first column of location_latlon is latitude and the second column is longitude") + warning("Assuming that the first column of location_latlon is latitude and the second column is longitude") } names(location_latlon)[1:2] <- c("latitude", "longitude") grid_index <- apply(location_latlon,1, function(ll) which.min((latitude - ll[1])^2 + (longitude - ll[2])^2)) @@ -651,6 +651,9 @@ get_ereefs_ts <- function(var_names=c('Chl_a_sum', 'TN'), } #input_file <- paste0(input_file, '?', var_list, ',time') nc <- safe_nc_open(input_file) + ## tindyc: + ## nc <- tindync::tidync(input_file) + # if ((ereefs_case[2] == "1km")||(ereefs_case[2] == "4km")) { # if (!is.null(nc$var[['t']])) { # d <- as.Date(safe_ncvar_get(nc, "t"), origin = as.Date("1990-01-01"))[from_day:(from_day+day_count-1)] @@ -670,14 +673,22 @@ get_ereefs_ts <- function(var_names=c('Chl_a_sum', 'TN'), dims <- nc$var[[var_names[j]]][['size']] if (is.null(dims)) stop(paste(var_names[j], ' not found in netcdf file.')) ndims[j] <- length(dims) + ## tidync: + ## ndims[j] <- dim(nc %>% tidync::activate(var_names[j]) %>% hyper_dims())[1] } if (layer == 'surface') { dims <- nc$var[[var_names[j]]][['size']] layer_actual <- dims[3] + ## tidync: + ## layer_actual <- nc %>% tidync::hyper_dims() %>% dplyr::filter(name=="k") %>% dplyr::select("length") } else if (layer == 'bottom') { # find the bottom layer -- assume it is the first layer that is not NA if (ndims[j] == 4) { dum1 <- safe_ncvar_get(nc, var_names[j], start=c(startv,1,from_day), count=c(countv,-1,1)) + ## tidync: [need to check whether dims of startv and countv are the right way around + ## dum1 <- nc %>% tidync::activate(var_names[j]) %>% + ## tidync::hyper_filter(i = dplyr::between(i, startv[1], startv[1]+countv[1]), j = dply::between(j, startv[2], startv[2]+countv[2]), time = time == from_day) %>% + ## tidync::hyper_array() if (length(which(!is.na(dum1)))==0) stop('Location given is a dry cell at start time. It is probably on land.') layer <- min(which(!is.na(dum1))) layer_actual <- layer