Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
03665ed
implemented new vcmax and jmax calculation using tchome
Mar 17, 2025
7cabc8c
removed tcref mentiones
Mar 18, 2025
9c4daf3
deleted test file
Mar 18, 2025
cba0d66
declared type for tchome
Mar 18, 2025
e66e3b5
added missing comma
Mar 18, 2025
d72d3f1
removed a comma
Mar 18, 2025
8747af2
updated temp_home calculation
Mar 18, 2025
547063c
updated temp_home calculation
Mar 18, 2025
533013e
updated t_home calculation
Mar 19, 2025
60c439d
converted double to int
Mar 19, 2025
d645339
converted int
Mar 19, 2025
7089ade
converted to int
Mar 19, 2025
170c993
renamed tchome to temp_home
Mar 19, 2025
f4749e1
numeric to integer
Mar 19, 2025
c6a6b5c
Updated integer
Mar 20, 2025
7ad9de7
corrected order of variables
Mar 20, 2025
0b03682
debugging
Mar 20, 2025
40572a1
debugging
Mar 20, 2025
39b54a9
debugging
Mar 20, 2025
fb5c17b
debugging
Mar 20, 2025
014584d
debugging
Mar 20, 2025
5c87dac
debugging
Mar 20, 2025
edd10cc
debugging
Mar 20, 2025
987c8f8
debugging
Mar 20, 2025
2b53749
debugging
Mar 20, 2025
e63f7f5
debugging
Mar 20, 2025
a99c984
debugging
Mar 20, 2025
8b6a474
debugging
Mar 20, 2025
626a4c7
debugging
Mar 20, 2025
56fd7be
debugging
Mar 20, 2025
d6de988
debugging
Mar 20, 2025
04c8221
debugging
Mar 20, 2025
40ceaef
debugging
Mar 20, 2025
6888623
debugging
Mar 20, 2025
7d130b9
debugging
Mar 20, 2025
665b093
improved code documentation
Mar 24, 2025
141d4a3
debugging
Mar 24, 2025
5cb50fd
debugging
Mar 24, 2025
cb62ad4
debugging
Mar 24, 2025
0dd5570
debugging
Mar 24, 2025
04775f6
debugging
Mar 24, 2025
950695a
debugging
Mar 24, 2025
5e3f180
debugging
Mar 24, 2025
79acb1a
debugging
Mar 24, 2025
45ab712
debugging
Mar 24, 2025
3bfb1e8
included library
Mar 24, 2025
26b46fd
change in library use
Mar 24, 2025
631140c
debugging
Mar 24, 2025
7c7d36c
debugging
Mar 24, 2025
376d87f
debugging
Mar 24, 2025
4acb3bc
debugging
Mar 24, 2025
a4a45a6
debugging
Mar 24, 2025
7799cc9
removed tchome from biomee
Mar 24, 2025
a8ba0b4
debugging
Mar 24, 2025
d7e3519
debugging
Mar 24, 2025
6b3eaab
int error
Mar 24, 2025
580c960
Update .gitignore with VS Code and act configuration
Mar 26, 2025
f0860a7
Update binary data files for p-model and biomee simulations
Mar 26, 2025
3b5d095
Solving `no visible binding for global variable`error and remove unn…
Mar 26, 2025
770907d
Refactor tchome calculation and remove non-ASCII character
Mar 26, 2025
8dd20b8
Revert driver changes
Mar 26, 2025
2905e9f
Variable name change and minor ganges
Mar 26, 2025
93e70f1
Add EOL
Mar 26, 2025
6c2ef02
Add EOL
Mar 26, 2025
95b0c8e
Fix compilation with additional renames of tchome to tc_home
fabern Mar 27, 2025
5bff793
Replace all occurences of tchome with tc_home
fabern Mar 27, 2025
e5f107d
Add tc_home to site_info
fabern Mar 27, 2025
fdb591b
Refactor definition of tc_home in run_pmodel_f_bysite()
fabern Mar 27, 2025
7a6a7ee
Add tc_home to biomee part
Apr 7, 2025
c045fbb
Merge branch 'master' of github.com:maloan/rsofun_fork
Apr 7, 2025
1ab5c90
Resolve "no visible binding"-Error
Apr 7, 2025
7ef5bac
Correct no visible binding error
Apr 7, 2025
710f71a
Remove non-ASCII character
Apr 7, 2025
149f2cb
Upgrade version number in DESCRIPTION
maloan Apr 7, 2025
7e43832
Keep whitespace
fabern Apr 7, 2025
2cf295a
Update tc_home calculation by calculating tmax first.
Apr 8, 2025
fbfcc66
Implement consistent tc_home calculation.
Apr 10, 2025
d5da7c8
Formatting and visible binding
Apr 10, 2025
8b247b3
Merge branch 'master' into maloan-master
fabern Jul 29, 2025
4fb2105
Cherry pick again old PR #293
fabern Jul 29, 2025
345cf7a
Use tc_home as inputs%site_info in BiomeE
fabern Jul 29, 2025
d51f09a
Use tc_home as inputs%site_info in BiomeE II
fabern Jul 29, 2025
7d4ddf8
Add lubridate to Imports
fabern Jul 29, 2025
93082a9
Add lubridate to Imports II
fabern Jul 30, 2025
e22d7e9
Refactor to reduce differences with previous implementation
fabern Jul 29, 2025
e5a916e
Refactor to reduce differences with previous implementation II
fabern Jul 29, 2025
2f291cc
Refactor to reduce differences with previous implementation III
fabern Jul 30, 2025
1b924e6
Use tc_home as inputs%site_info in BiomeE III
fabern Jul 30, 2025
3c86f92
Fix R CMD check
fabern Jul 30, 2025
45ce572
Merge remote-tracking branch 'origin/master' into 'maloan/master'
fabern Aug 5, 2025
3a0925c
Update reference data sets
fabern Aug 5, 2025
1d590f8
Update numeric values of regression tests
fabern Aug 5, 2025
4e026ba
Refrain from comparing vcmax25 and jmax25 with rpmodel
fabern Aug 5, 2025
2f5fcb9
Update NEWS.md
fabern Aug 5, 2025
bb60a35
Reduce tolerance of PLULUC regression test
fabern Aug 5, 2025
4dcc1ae
Style unit comments
fabern Aug 5, 2025
08427db
Add again 'tc_ref' as argument to calc_ftemp for vcmax and jmax
fabern Aug 5, 2025
219f0b9
Update NEWS.md
fabern Aug 5, 2025
467ff25
Update comments
fabern Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
.DS_Store
.idea

# VS Code local settings
.vscode/

# act local config & secrets
.actrc
.secrets

# source files
src/*.o
src/*.so
Expand All @@ -18,4 +25,5 @@ vignettes/*.html
# documentation dir
docs/

# CRAN submission archives
CRAN-SUBMISSION
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Imports:
magrittr,
GenSA,
BayesianTools,
lubridate,
multidplyr,
stats,
utils
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(runread_pmodel_f)
import(BayesianTools)
import(GenSA)
import(dplyr)
import(lubridate)
importFrom(magrittr,"%>%")
importFrom(stats,setNames)
useDynLib(rsofun)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
easier processing within cost-functions. Default cost-functions were updated,
but currently ignore the names. This is fully backward compatible, but allows
to use the names in user-created cost functions.
* Internally, P-model now computes temperature dependencies of jmax and vcmax
with Kumarathunge et al. (2019) instead of Kattge & Knorr (2007), effectively
using a dampened signal for tc_growth and long-term averages for tc_home. This
alters the simulation results. Formattting of inputs remains unchanged.

# rsofun 5.1.0

Expand Down
47 changes: 46 additions & 1 deletion R/run_biomee_f_bysite.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' @param luc_forcing An array of land use change (LUC) used during transient phase.
#'
#' For further specifications of above inputs and examples see \code{\link{biomee_gs_leuning_drivers}}, \code{\link{biomee_p_model_drivers}}, or \code{\link{biomee_p_model_luluc_drivers}}.

#' @import lubridate
#'
#' @returns A data.frame with columns containing model output for each land unit (LU).
#' See examples \code{\link{biomee_gs_leuning_output}}, \code{\link{biomee_p_model_output}}, or \code{\link{biomee_p_model_luluc_output}}.
Expand Down Expand Up @@ -231,6 +233,48 @@ run_biomee_f_bysite <- function(
makecheck = TRUE
){
ndayyear <- 365

# Default value for tc_home
if ("tc_home" %in% names(site_info)) {
stop("Unexpectedly received site_info$tc_home; it should be calculated internally.")
}

conditionally_add_tmax <- function(df){
need_to_add_tmax <- !("tmax" %in% colnames(df))
if (need_to_add_tmax) {
df %>% dplyr::group_by(.data$date) %>%
dplyr::summarise(daily_tmax = max(.data$temp, na.rm = TRUE)) %>%
dplyr::ungroup()
} else {
df %>% dplyr::rename(daily_tmax = "tmax")
}
}
tc_home <- forcing %>%
# conditionally add daily max temp (if needed, e.g. when running "gs_leuning" with hourly forcing)
conditionally_add_tmax() %>%
# add grouping variables:
mutate(month = lubridate::month(.data$date), year = lubridate::year(.data$date)) %>%
# monthly means of daily maximum:
group_by(.data$year, .data$month) %>%
summarise(monthly_avg_daily_tmax = mean(.data$daily_tmax, na.rm = TRUE), .groups = "drop") %>%
# warmest month of each year:
group_by(year) %>%
summarise(t_warmest_month = max(.data$monthly_avg_daily_tmax)) %>%
# mean of yearly warmest months:
ungroup() %>%
summarise(tc_home = mean(.data$t_warmest_month, na.rm = TRUE)) %>%
# extract scalar value
dplyr::pull(.data$tc_home)

site_info$tc_home <- tc_home # TODO: rather in site_info or in params_tile?
# params_tile$tc_home <- tc_home # TODO: rather in site_info or in params_tile?

# Validate calculation
if (is.na(site_info$tc_home) || length(site_info$tc_home) == 0) {
warning("Calculated tc_home is NA or missing; defaulting to 25C.")
site_info$tc_home <- 25
}

# record number of years in forcing data
# frame to use as default values (unless provided othrwise as params_siml$nyeartrend)
forcing_years <- nrow(forcing)/(ndayyear * params_siml$steps_per_day)
Expand Down Expand Up @@ -548,7 +592,8 @@ prepare_site_info <- function(site_info){
site_info <- site_info %>% select(
"lon",
"lat",
"elv"
"elv",
"tc_home"
)
return(site_info)
}
Expand Down
43 changes: 42 additions & 1 deletion R/run_pmodel_f_bysite.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#' For further specifications of above inputs and examples see \code{\link{p_model_drivers}} or \code{\link{p_model_drivers_vcmax25}}

#' @import dplyr
#' @import lubridate
#'
#' @returns Model output is provided as a tidy dataframe, with columns:
#' \describe{
Expand Down Expand Up @@ -159,7 +160,46 @@ run_pmodel_f_bysite <- function(
secs_per_tstep <- difftime(times[1], times[2], units = "secs") %>%
as.integer() %>%
abs()


# Default value for tc_home
if ("tc_home" %in% names(site_info)) {
stop("Unexpectedly received site_info$tc_home; it should be calculated internally.")
}

conditionally_add_tmax <- function(df){
need_to_add_tmax <- !("tmax" %in% colnames(df))
if (need_to_add_tmax) {
df %>% dplyr::group_by(.data$date) %>%
dplyr::summarise(daily_tmax = max(.data$temp, na.rm = TRUE)) %>%
dplyr::ungroup()
} else {
df %>% dplyr::rename(daily_tmax = "tmax")
}
}
tc_home <- forcing %>%
# conditionally add daily max temp (if needed, e.g. when running "gs_leuning" with hourly forcing)
conditionally_add_tmax() %>%
# add grouping variables:
mutate(month = lubridate::month(.data$date), year = lubridate::year(.data$date)) %>%
# monthly means of daily maximum:
group_by(.data$year, .data$month) %>%
summarise(monthly_avg_daily_tmax = mean(.data$daily_tmax, na.rm = TRUE), .groups = "drop") %>%
# warmest month of each year:
group_by(year) %>%
summarise(t_warmest_month = max(.data$monthly_avg_daily_tmax)) %>%
# mean of yearly warmest months:
ungroup() %>%
summarise(tc_home = mean(.data$t_warmest_month, na.rm = TRUE)) %>%
# extract scalar value
dplyr::pull(.data$tc_home)

site_info$tc_home <- tc_home
# Validate calculation
if (is.na(site_info$tc_home) || length(site_info$tc_home) == 0) {
warning("Calculated tc_home is NA or missing; defaulting to 25C.")
site_info$tc_home <- 25
}

# re-define units and naming of forcing dataframe
# keep the order of columns - it's critical for Fortran (reading by column number)
forcing_features <- c(
Expand Down Expand Up @@ -307,6 +347,7 @@ run_pmodel_f_bysite <- function(
latitude = as.numeric(site_info$lat),
altitude = as.numeric(site_info$elv),
whc = as.numeric(site_info$whc),
tc_home = as.numeric(site_info$tc_home),
n = as.integer(nrow(forcing)), # number of rows in matrix (pre-allocation of memory)
par = c(as.numeric(params_modl$kphio), # model parameters as vector in order
as.numeric(params_modl$kphio_par_a),
Expand Down
Binary file modified data/biomee_gs_leuning_output.rda
Binary file not shown.
Binary file modified data/biomee_p_model_luluc_output.rda
Binary file not shown.
Binary file modified data/biomee_p_model_output.rda
Binary file not shown.
Binary file modified data/p_model_output.rda
Binary file not shown.
Binary file modified data/p_model_output_vcmax25.rda
Binary file not shown.
3 changes: 2 additions & 1 deletion src/biosphere_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ function biosphere_annual() result( out_biosphere )
myinterface%climate(doy), &
myinterface%grid, &
init_daily, &
myinterface%params_siml%in_ppfd &
myinterface%params_siml%in_ppfd, &
myinterface%tc_home &
)
! if (verbose) print*,'... done'

Expand Down
13 changes: 7 additions & 6 deletions src/gpp_biomee.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ subroutine gpp( forcing, vegn )
integer :: i
real :: rad_top ! downward radiation at the top of the canopy, W/m2
real :: rad_net ! net radiation absorbed by the canopy, W/m2
real :: TairC, TairK ! air temperature, degC and degK
real :: TairC, TairK ! air temperature, deg C and deg K
real :: cana_q ! specific humidity in canopy air space, kg/kg
real :: cana_co2 ! co2 concentration in canopy air space, mol CO2/mol dry air
real :: p_surf ! surface pressure, Pa
Expand Down Expand Up @@ -149,7 +149,7 @@ subroutine gpp( forcing, vegn )
rad_net = f_light(cc%layer) * forcing%radiation * 0.9 ! net radiation absorbed by the canopy, W/m2
p_surf = forcing%P_air ! Pa
TairK = forcing%TairK ! K
TairC = forcing%TairC ! degC
TairC = forcing%TairC ! deg C
cana_q = (calc_esat(TairC) * forcing%RH * h2o_molmass) / (p_surf * kMa) ! air specific humidity, kg/kg
cana_co2 = forcing%CO2 ! co2 concentration in canopy air space, mol CO2/mol dry air

Expand Down Expand Up @@ -240,6 +240,7 @@ subroutine gpp( forcing, vegn )
tc = vegn%dampended_forcing%temp, &
vpd = vegn%dampended_forcing%vpd, &
patm = vegn%dampended_forcing%patm, &
tc_home = inputs%site_info%tc_home, &
c4 = .false., &
method_optci = "prentice14", &
method_jmaxlim = "wang17" &
Expand Down Expand Up @@ -270,7 +271,7 @@ subroutine gs_leuning( rad_top, rad_net, tl, ea, lai, &

real, intent(in) :: rad_top ! PAR dn on top of the canopy, w/m2
real, intent(in) :: rad_net ! PAR net on top of the canopy, w/m2
real, intent(in) :: tl ! leaf temperature, degK
real, intent(in) :: tl ! leaf temperature, K
real, intent(in) :: ea ! specific humidity in the canopy air, kg/kg
real, intent(in) :: lai ! leaf area index
!real, intent(in) :: leaf_age ! age of leaf since budburst (deciduos), days
Expand Down Expand Up @@ -519,14 +520,14 @@ function qscomp(T, p) result(qsat)
!--------Output
real :: qsat ! Output type: saturated specific humidity, kg/kg
!--------Inputs
real :: T ! temperature, degK
real :: T ! temperature, K
real :: p ! pressure, Pa
!--------local var
real :: myesat ! sat. water vapor pressure
real :: Temp ! degC
real :: Temp ! deg C

! calculate saturated specific humidity
Temp = T - 273.16 ! degC
Temp = T - 273.16 ! deg C
myesat=MIN(610.78*exp(17.27*Temp/(Temp+237.3)), p) ! Pa
qsat = 0.622*myesat /(p - 0.378*myesat )

Expand Down
18 changes: 14 additions & 4 deletions src/gpp_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module md_gpp_pmodel

contains

subroutine gpp( tile, tile_fluxes, co2, climate, grid, init, in_ppfd)
subroutine gpp( tile, tile_fluxes, co2, climate, grid, init, in_ppfd, tc_home)
!//////////////////////////////////////////////////////////////////
! Wrapper function to call to P-model.
! Calculates meteorological conditions with memory based on daily
Expand All @@ -63,7 +63,7 @@ subroutine gpp( tile, tile_fluxes, co2, climate, grid, init, in_ppfd)
type(gridtype) :: grid
logical, intent(in) :: init ! is true on the very first simulation day (first subroutine call of each gridcell)
logical, intent(in) :: in_ppfd ! whether to use PPFD from forcing or from SPLASH output

real, intent(in) :: tc_home ! long-term mean max temp of the warmest month (deg C)
! local variables
type(outtype_pmodel) :: out_pmodel ! list of P-model output variables
type(climate_type) :: climate_acclimation ! list of climate variables to which P-model calculates acclimated traits
Expand Down Expand Up @@ -151,6 +151,7 @@ subroutine gpp( tile, tile_fluxes, co2, climate, grid, init, in_ppfd)
tc = temp_memory, &
vpd = vpd_memory, &
patm = patm_memory, &
tc_home = tc_home, &
c4 = params_pft_plant(pft)%c4, &
method_optci = "prentice14", &
method_jmaxlim = "wang17" &
Expand Down Expand Up @@ -209,8 +210,17 @@ subroutine gpp( tile, tile_fluxes, co2, climate, grid, init, in_ppfd)
tile_fluxes(lu)%plant(pft)%iwue = out_pmodel%iwue

! quantities with instantaneous temperature response
tile_fluxes(lu)%plant(pft)%vcmax = calc_ftemp_inst_vcmax( climate%dtemp, climate%dtemp, tcref = 25.0 ) * out_pmodel%vcmax25
tile_fluxes(lu)%plant(pft)%jmax = calc_ftemp_inst_jmax( climate%dtemp, climate%dtemp, tcref = 25.0 ) * out_pmodel%jmax25
tile_fluxes(lu)%plant(pft)%vcmax = calc_ftemp_inst_vcmax( &
tc_leaf = climate%dtemp, &
tc_growth = temp_memory, &
! no tc_home needed for calc_ftemp_inst_vcmax
tc_ref = 25.0 ) * out_pmodel%vcmax25

tile_fluxes(lu)%plant(pft)%jmax = calc_ftemp_inst_jmax( &
tc_leaf = climate%dtemp, &
tc_growth = temp_memory, &
tc_home = tc_home, &
tc_ref = 25.0 ) * out_pmodel%jmax25

!----------------------------------------------------------------
! Stomatal conductance
Expand Down
1 change: 1 addition & 0 deletions src/interface_biosphere_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module md_interface_pmodel
real :: pco2
type(gridtype) :: grid
real :: whc_prescr
real :: tc_home
type(climate_type), dimension(ndayyear) :: climate
type(vegcover_type), dimension(ndayyear):: vegcover
type(outtype_steering) :: steering_state
Expand Down
10 changes: 6 additions & 4 deletions src/interface_in_biosphere_biomee.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module md_interface_in_biomee

!===== Number of parameters
integer, public, parameter :: nvars_params_siml = 11
integer, public, parameter :: nvars_site_info = 3
integer, public, parameter :: nvars_site_info = 4
integer, public, parameter :: nvars_params_tile = 19
integer, public, parameter :: nvars_init_soil = 4
integer, public, parameter :: nvars_init_cohorts = 9
Expand Down Expand Up @@ -203,6 +203,7 @@ module md_interface_in_biomee
real :: lon
real :: lat
real :: elv ! elevation
real :: tc_home

contains

Expand Down Expand Up @@ -407,9 +408,10 @@ subroutine populate_site_info(self, site_info)
real(kind=c_double), dimension(nvars_site_info), intent(in) :: site_info

! Site info
self%lon = real( site_info(1) )
self%lat = real( site_info(2) )
self%elv = real( site_info(3) )
self%lon = real( site_info(1) )
self%lat = real( site_info(2) )
self%elv = real( site_info(3) )
self%tc_home = real( site_info(4) )
end subroutine populate_site_info

subroutine populate_spec_data(self, params_species)
Expand Down
Loading
Loading