Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in get_ereefs_ts() in mmp check. #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
role = c("aut", "cre")),
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions R/data_extraction_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)]
Expand All @@ -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
Expand Down