Skip to content

Commit

Permalink
Merge pull request #10 from stineb/main
Browse files Browse the repository at this point in the history
Chapter 6 continuation
  • Loading branch information
stineb authored Apr 25, 2024
2 parents 615e961 + fcc7e3f commit db65461
Show file tree
Hide file tree
Showing 40 changed files with 1,380 additions and 831 deletions.
4 changes: 2 additions & 2 deletions R/read_fdk.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
read_fdk <- function(site, path){
read_fdk <- function(site, path, pattern = "DD"){
print(site)
filn <- list.files(path = path)
filn <- filn[which(stringr::str_detect(filn, pattern = site))]
filn <- filn[which(stringr::str_detect(filn, pattern = "DD"))]
filn <- filn[which(stringr::str_detect(filn, pattern = pattern))]
readr::read_csv(paste0(path, "/", filn))
}
70 changes: 51 additions & 19 deletions analysis/plot_anet_vs_temp.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,70 @@
library(tidyverse)
library(readr)
library(dplyr)
library(ggplot2)
library(cowplot)

# load Kumarathunge et al. data
df <- read_csv("~/data/aci-tglob_v1.0/ACi-TGlob_V1.0.csv")

df |>
filter(Dataset == "Tundra USA-AK") |>
group_by(Species) |>
summarise(n = n())
df <- read_rds("~/Downloads/all_sites_simulation_and_original-data.rds")

# spatial - adaptation
df |>
filter(
Dataset == "Tundra USA-AK" &
Ci > 270 & Ci < 280
) |>
# good: 5
gg1 <- df$data_org[[9]] |>
ggplot(
aes(
x = Tleaf,
y = Photo
y = Photo,
color = Ci,
shape = as.factor(Curve_Id)
)
) +
geom_point()

# seasonal - acclimation
df |>
filter(
Dataset == "Maritime Pine, France" &
Ci > 250 & Ci < 300
) |>
gg2 <- df$data_org[[9]] |>
filter(Curve_Id == 1) |>
ggplot(
aes(
x = Tleaf,
x = Ci,
y = Photo
)
) +
geom_point()

plot_grid(gg1, gg2, nrow = 2)

ggsave(here::here("fig/example.pdf"), width = 8, height = 6)

#
# df |>
# filter(Dataset == "Tundra USA-AK") |>
# group_by(Species) |>
# summarise(n = n())
#
# # spatial - adaptation
# df |>
# filter(
# Dataset == "Tundra USA-AK" &
# Ci > 270 & Ci < 280
# ) |>
# ggplot(
# aes(
# x = Tleaf,
# y = Photo
# )
# ) +
# geom_point()
#
# # seasonal - acclimation
# df |>
# filter(
# Dataset == "Maritime Pine, France" &
# Ci > 250 & Ci < 300
# ) |>
# ggplot(
# aes(
# x = Tleaf,
# y = Photo
# )
# ) +
# geom_point()
#
19 changes: 12 additions & 7 deletions analysis/plot_climate_diagrams_biomes.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ source(here::here("R/read_fdk.R"))

# Reading from file prepared above -----------
# read from file
df_sites <- read_rds(here::here("data/df_sites.rds"))
# df_sites <- read_rds(here::here("data/df_sites.rds"))
df_sites <- read_csv(here::here("data/fdk_site_info.csv"))

# chose representative sites
use_sites <- c(
Expand All @@ -45,12 +46,15 @@ use_sites <- c(
"FR-Pue", # Mediterranean Forests, Woodlands & Scrub
"DE-Hai", # Temperate Broadleaf & Mixed Forests
"US-Tw1", # Temperate Grasslands, Savannas & Shrublands
"AU-How", # Tropical & Subtropical Grasslands, Savannas & Shrublan
"MY-PSO", # Tropical moist broadleaved (evergreen) forest
"AU-How", # Tropical & Subtropical Grasslands, Savannas & Shrubland
# "MY-PSO", # Tropical moist broadleaved (evergreen) forest
"BR-Sa3", # Tropical
"ZM-Mon", # Tropical deciduous forest (xeric woodland)
"GL-ZaH" # Tundra
"US-ICh" # Tundra
# "GL-ZaH" # Tundra
)


# subset sites
df_sites_sub <- df_sites |>
filter(sitename %in% use_sites)
Expand All @@ -59,8 +63,9 @@ saveRDS(df_sites_sub, file = here::here("data/df_sites_sub.rds"))

# read daily flux data for each site
df <- df_sites_sub |>
select(sitename, lon, lat, elv, BIOME_NAME) |>
mutate(data = purrr::map(sitename, ~read_fdk(., path = "~/data/FluxDataKit/FLUXDATAKIT_FLUXNET"))) |>
select(sitename, lon, lat, elv) |>
# mutate(data = purrr::map(sitename, ~read_fdk(., path = "~/data/FluxDataKit/FLUXDATAKIT_FLUXNET"))) |>
mutate(data = purrr::map(sitename, ~read_fdk(., path = "~/data/FluxDataKit/v3.1/zenodo_upload/fluxnet/"))) |>
unnest(data) |>
group_by(sitename) |>
nest()
Expand All @@ -71,7 +76,7 @@ create_diagram_per_site <- function(site, df){
mutate(year = lubridate::year(TIMESTAMP),
month = lubridate::month(TIMESTAMP),
day = lubridate::mday(TIMESTAMP)) |>
select(year, month, day, P_F, TMAX_F_MDS, TMIN_F_MDS, lat, lon, elv, BIOME_NAME) |>
select(year, month, day, P_F, TMAX_F_MDS, TMIN_F_MDS, lat, lon, elv) |>
as.data.frame()

filn <- paste0(here::here("book/images/diagram_"),
Expand Down
Loading

0 comments on commit db65461

Please sign in to comment.