generated from geco-bern/R_proj_template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from cwd_byLON() and cwd_annmax_byLON() to generic fct().
- Loading branch information
Showing
6 changed files
with
100 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
apply_fct_to_each_file <- function( | ||
fct_to_apply_per_location, | ||
filnam, | ||
outdir, | ||
overwrite, | ||
outfilename_template #"resultfile_[LONSTRING].rds" | ||
){ | ||
|
||
# prepare output | ||
stopifnot(grepl(pattern = "\\[LONSTRING\\]", outfilename_template)) | ||
|
||
curr_LON_string <- gsub("^.*?(LON_[0-9.+-]*).rds$", "\\1", basename(filnam)) | ||
outpath <- file.path(outdir, gsub("\\[LONSTRING\\]", curr_LON_string, outfilename_template)) | ||
|
||
if (file.exists(outpath) && !overwrite){ | ||
|
||
return(paste0("File exists already: ", outpath)) # don't do anything | ||
|
||
} else { | ||
# read from file that contains tidy data for a single longitudinal band | ||
|
||
# read evapotranspiration file tidy | ||
df_evap <- readr::read_rds(filnam) | ||
|
||
# apply the custom function on the time series data frame separately for each gridcell. | ||
out <- df_evap |> | ||
dplyr::mutate(data = purrr::map(data, ~fct_to_apply_per_location(.))) | ||
|
||
# write result to file | ||
message(paste0("Writing file ", outpath, " ...")) | ||
readr::write_rds(out, outpath) | ||
|
||
# don't return data - it's written to file | ||
return(paste0("Written results to: ", outpath)) | ||
|
||
|
||
# UNUSED: stems originally from the function cwd_byLON() | ||
# read other required files (precipitation, temperature, ... | ||
# # merge all such that monthly data is repeated for each day within month | ||
# df <- df_prec |> # one of the daily data frames | ||
# tidyr::unnest(data) |> # must unnest to join by date | ||
# left_join( | ||
# df_evap |> # one of the monthly data frames | ||
# tidyr::unnest(data), | ||
# by = join_by(year, month) | ||
# ) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Testing whether CMIP6 data is correctly read from files and handled. | ||
# For Patricia Gribi | ||
|
||
library(FluxDataKit) | ||
library(FluxDataKit) # remotes::install_github("geco-bern/[email protected]") | ||
library(tidyverse) | ||
library(terra) | ||
library(lubridate) | ||
|