Add reformat_phenology function
Add function to format properly phenology data.frame from MuSICA format to a proper and usable format. Code basis :
phenology1 <- calc_phenology(list.year = c(2022),
nleafage = 3,
budburst_date = 110,
leaf_age_max_in = 2.8,
relative_age_firstmax = 0.05,
relative_age_lastmax = 0.83,
LAI_max_per_cohort = plant_area_index1/3)
phenology2 <- calc_phenology(list.year = c(2022),
nleafage = 3,
budburst_date = 120,
leaf_age_max_in = 2.8,
relative_age_firstmax = 0.12,
relative_age_lastmax = 0.90,
LAI_max_per_cohort = plant_area_index2/3)
phenology <-
rbind(tmp1, tmp2) %>%
pivot_longer(c(Leaf_area_1yr, Leaf_area_2yr, Leaf_area_3yr,
Leaf_age_1yr, Leaf_age_2yr, Leaf_age_3yr)) %>%
mutate(leaf_age = case_when(
grepl("1yr", name) ~ 1,
grepl("2yr", name) ~ 2,
grepl("3yr", name) ~ 3),
variable = case_when(
grepl("area", name) ~ "LAI",
grepl("age", name) ~ "relative_age")
) %>%
select(-name) %>%
pivot_wider(id_cols = c(year, Julian_day, run, leaf_age),
names_from = variable, values_from = value)