Skip to content

Commit

Permalink
renaming files + processing
Browse files Browse the repository at this point in the history
  • Loading branch information
khufkens committed Oct 3, 2023
1 parent 87dce80 commit 1a994a5
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ options(dplyr.summarise.inform = FALSE)
library(dplyr)
library(tidyr)
library(ggplot2)
library(ingestr)
library(rsofun)
lapply(list.files("R/","*.R", full.names = TRUE), source)

input_path <- "/data/scratch/beta-v4/fluxnet/"

# read in sites to process
sites <- FluxDataKit::fdk_site_info
#site <- c("FR-Pue", "CH-Lae", "CH-Dav")

#site <- c("FR-Pue", "CH-Lae")

# subset sites
# sites <- sites |>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ data_fix_years <- df |>
nest() |>
rename(
forcing = data
)
) |>
ungroup()

df1 <- df |>
filter(tolower(sitename) %in% tolower(screen$sitename)) |>
Expand All @@ -76,3 +77,47 @@ data <- bind_rows(df1, df2)

# save data
saveRDS(data, "data/rsofun_driver_data_clean.rds", compress = "xz")

data |>
group_by(sitename) |>
do({

tmp <- .$forcing[[1]] |>
tidyr::pivot_longer(
col = !contains("date"),
names_to = "measurement",
values_to = "value"
)

sitename <- .$sitename[1]

l <- seq(as.Date("1990/1/1"), as.Date("2023/1/1"), "years")

p <- ggplot(data = tmp) +
geom_line(
aes(
date,
value
),
colour = "red"
) +
geom_vline(xintercept = l) +
labs(
title = sitename
) +
theme_bw() +
theme(panel.grid.minor = element_line()
) +
facet_grid(
measurement ~ .,
scales = "free"
)

ggsave(
paste0("manuscript/rsofun_input/",sitename,".png"),
width = 12,
height = 14,
dpi = 175
)

})
100 changes: 100 additions & 0 deletions analysis/04_create_zenodo_upload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# This script does the final renaming of all the files
# to a consistent format, as well as zipping them up
# for uploading to Zenodo
#
# This script uses bash system calls
# as well as the "rename" function which
# is not installed by default. Run on linux
# or a bash compatible system.
#
# Compressed data should be uploaded to
# the Zenodo repository:
# https://zenodo.org/record/7258291

input_path <- "/data/scratch/beta-v4/"
tmp_path <- "/data/scratch/upload"z

#---- purge old data -----

# remove temporary path
system(sprintf("rm -rf %s", tmp_path))

# recreate temporary path
dir.create(tmp_path)

#---- copy new data over ----
system(
sprintf(
"cp -R %s/lsm %s/lsm",
input_path,
tmp_path
)
)

system(
sprintf(
"cp -R %s/fluxnet %s/fluxnet",
input_path,
tmp_path
)
)

#---- rename all files in place ----

# rename LSM data

system(
sprintf(
"rename 's/FLUXNET2015/FLUXDATAKIT/g' %s/lsm/*.nc",
tmp_path
)
)

system(
sprintf(
"rename 's/OxFlux/FLUXDATAKIT/g' %s/lsm/*.nc",
tmp_path
)
)

system(
sprintf(
"rename 's/LaThuile/FLUXDATAKIT/g' %s/lsm/*.nc",
tmp_path
)
)

# rename FLUXNET data

system(
sprintf(
"rename 's/PLUMBER/FLUXDATAKIT/g' %s/fluxnet/*.csv",
tmp_path
)
)

#---- zip up all data -----

# compress LSM data
system(
sprintf(
"
cd %s/lsm;
tar -czvf %s/FLUXDATAKIT_LSM.tar.gz *.nc
",
tmp_path,
tmp_path
)
)

# compress FLUXNET data
system(
sprintf(
"
cd %s/fluxnet;
tar -czvf %s/FLUXDATAKIT_FLUXNET.tar.gz *.csv
",
tmp_path,
tmp_path
)
)
4 changes: 2 additions & 2 deletions analysis/06_p-model_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for(i in driver_data$sitename){
output <- try(rsofun::runread_pmodel_f(
df,
par = params_modl,
makecheck = TRUE
makecheck = FALSE
))

print(output)
Expand Down Expand Up @@ -68,7 +68,7 @@ for(i in driver_data$sitename){

ggsave(
file.path(
"./manuscript/figures/",
"./manuscript/rsofun_output/",
paste0(df$sitename,".png")
),
width = 12,
Expand Down
141 changes: 0 additions & 141 deletions analysis/scraps/process_pmodel_data.R

This file was deleted.

Loading

0 comments on commit 1a994a5

Please sign in to comment.