Skip to content

Commit

Permalink
should fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Nov 12, 2024
1 parent b260f29 commit 65f625d
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 58 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: raadfiles
Title: File Database Management for 'raadtools'
Version: 0.1.4.9011
Version: 0.1.4.9012
Authors@R: c(person("Michael D.","Sumner", role = c("aut", "cre"), email = "michael.sumner@aad.gov.au"),
person("Ben", "Raymond", role = "ctb"),
person("Kimberlee", "Baldry", role = c("ctb"), comment = c(ORCID = "0000-0003-3286-8624")))
Expand All @@ -9,7 +9,7 @@ Depends:
R (>= 3.3.0)
Imports:
digest,
fs (>= 1.6.4.9000),
fs (>= 1.6.5),
rlang,
stringr,
dplyr,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# raadfiles dev

* Fix problematic old UTC flush (thanks Dale Maschette #33).

* Avoid oldformat in Copernicus altimetry files.


Expand Down
3 changes: 1 addition & 2 deletions R/altimetry-antarctica.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ pattern <- c("ftp-access.aviso.altimetry.fr",
files <- dplyr::mutate(files, date = as.POSIXct(as.Date(stringr::str_extract(basename(.data$fullname), "[0-9]{8}"),
"%Y%m%d"),tz = "UTC"))
dplyr::arrange(dplyr::distinct(files, date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)

}
6 changes: 2 additions & 4 deletions R/amps-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ amps_model_files <- function(time.resolution = "4hourly", grid = "d1", ...) {
sprintf("_%s_", grid)))
dplyr::transmute(files, hour = substr(basename(.data$fullname), 20, 22),
model = substr(basename(.data$fullname), 9, 10),
date = as.POSIXct(strptime(basename(files$fullname), "%Y%m%d%H"), tz = "GMT") +
as.integer(.data$hour) * 3600, .data$fullname, .data$root) %>%
set_dt_utc()

date = as.POSIXct(strptime(basename(files$fullname), "%Y%m%d%H"), tz = "UTC") +
as.integer(.data$hour) * 3600, .data$fullname, .data$root)

}

Expand Down
3 changes: 1 addition & 2 deletions R/cafe-modis.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ cafe_monthly_files <- function() {
files <- dplyr::mutate(files, date = as.POSIXct(as.Date(stringr::str_extract(basename(.data$fullname), "[0-9]{7}"),
"%Y%j"),tz = "UTC"))
dplyr::arrange(dplyr::distinct(files, date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)

}
3 changes: 1 addition & 2 deletions R/ccmpwind-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ ccmp_6hourly_files <- function() {
## put all NRT last before distinct by date
files <- files[nrow(files):1, ]
files <- dplyr::arrange(dplyr::distinct(files, .data$date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
raadfiles:::set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)

files
}
5 changes: 2 additions & 3 deletions R/fsle-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ fsle_files <- function() {
stop("no files found")
## datadir <- get_raad_datadir()
files <- dplyr::mutate(files, date = as.POSIXct(as.Date(stringr::str_extract(basename(.data$fullname), "[0-9]{8}"),
"%Y%m%d"),tz = "GMT"))
"%Y%m%d"),tz = "UTC"))
dplyr::arrange(dplyr::distinct(files, date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)
}

8 changes: 3 additions & 5 deletions R/ncep2-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ ncep2_uwnd_6hr_files <- function() {
stop("no files found")
files <- dplyr::transmute(files, date = ISOdate(as.integer(stringr::str_extract(basename(fullname), "[0-9]{4}")), 1, 1, 0, 0, 0, tz = "UTC"),
fullname = .data$fullname, root = .data$root)
dplyr::arrange(dplyr::distinct(files, .data$date, .keep_all = TRUE), .data$date) %>%
set_dt_utc()
dplyr::arrange(dplyr::distinct(files, .data$date, .keep_all = TRUE), .data$date)

}
#' @name ncep2_files
Expand All @@ -36,10 +35,9 @@ ncep2_vwnd_6hr_files <- function() {

if (nrow(files) < 1)
stop("no files found")
files <- dplyr::transmute(files, date = ISOdate(as.integer(stringr::str_extract(basename(fullname), "[0-9]{4}")), 1, 1),
files <- dplyr::transmute(files, date = ISOdate(as.integer(stringr::str_extract(basename(fullname), "[0-9]{4}")), 1, 1, tz = "UTC"),
fullname = .data$fullname, root = .data$root)
dplyr::arrange(dplyr::distinct(files, .data$date, .keep_all = TRUE), .data$date) %>%
set_dt_utc()
dplyr::arrange(dplyr::distinct(files, .data$date, .keep_all = TRUE), .data$date)


}
Expand Down
2 changes: 1 addition & 1 deletion R/par-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (nrow(files) < 1)
files <- files[nrow(files):1, ]
files <- dplyr::arrange(dplyr::distinct(files, .data$date,
.keep_all = TRUE), date) %>% dplyr::select(.data$date,
.data$fullname, .data$root) %>% raadfiles:::set_dt_utc()
.data$fullname, .data$root)

files
}
5 changes: 2 additions & 3 deletions R/seapodym-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ seapodym_weekly_files <- function() {

## datadir <- get_raad_datadir()
files <- dplyr::mutate(files, date = as.POSIXct(as.Date(stringr::str_extract(basename(.data$fullname), "[0-9]{8}"),
"%Y%m%d"),tz = "GMT"))
"%Y%m%d"),tz = "UTC"))
dplyr::arrange(dplyr::distinct(files, date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)

}
3 changes: 1 addition & 2 deletions R/smap-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ smap_8day_files <- function() {

files$date <- as.POSIXct(strptime(sprintf("%s-%s", Y, jday), "%Y-%j"), tz = "UTC") #as.POSIXct(strptime(basename(.data$fullname), "RSS_smap_SSS_L3_8day_running_40km"), tz = "UTC"))
files <- dplyr::arrange(dplyr::distinct(files, date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
raadfiles:::set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)
files
}
6 changes: 3 additions & 3 deletions R/sst-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ oisst_daily_files <- function() {
stop("no files found")
}
files <- dplyr::mutate(files, date = as.POSIXct(as.Date(stringr::str_extract(basename(.data$fullname), "[0-9]{8}"),
"%Y%m%d"),tz = "GMT"))
"%Y%m%d"),tz = "UTC"))
dplyr::arrange(dplyr::distinct(files, date, .keep_all = TRUE), date) %>%
dplyr::select(.data$date, .data$fullname, .data$root) %>%
set_dt_utc()
dplyr::select(.data$date, .data$fullname, .data$root)

}
#' @name oisst
#' @export
Expand Down
29 changes: 0 additions & 29 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ globalVariables("desc") ## for dplyr in arrange()
}



set_utc_md <- function(x) {
attr(x, "tzone") <- "UTC"
x
}
## apply UTC metadata for print (raadtools#72)
set_dt_utc <- function(x) {
x[["date"]] <- set_utc_md(x[["date"]])

## and do sanity checks on last 20 files
files <- x[["fullname"]]
if (is.null(files)) {
files <- x[["ufullname"]]
if (is.null(files)) files <- x[["vfullname"]]
}

if (!is.null(files)) {
sizes <- fs::file_size(tail(files, 20L))
bad <- !sizes > 0
if (any(bad)) {
message(sprintf("\n(please inform maintainers)\n\n problem with zero-size files near\n %s\n", files[which(bad)[1L]]))
idx <- c(rep(TRUE, dim(x)[1L] - 20), !bad)
x <- x[idx, ]
}
}
x
}


## file cache utilities

remove_leading_slash <- function(x) {
Expand Down

0 comments on commit 65f625d

Please sign in to comment.