Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
stineb authored Apr 29, 2024
2 parents ccb1e11 + 571f0fc commit 4949652
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 357 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

name: R-hub
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"

on:
workflow_dispatch:
inputs:
config:
description: 'A comma separated list of R-hub platforms to use.'
type: string
default: 'linux,windows,macos'
name:
description: 'Run name. You can leave this empty now.'
type: string
id:
description: 'Unique ID. You can leave this empty now.'
type: string

jobs:

setup:
runs-on: ubuntu-latest
outputs:
containers: ${{ steps.rhub-setup.outputs.containers }}
platforms: ${{ steps.rhub-setup.outputs.platforms }}

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/actions/setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup

linux-containers:
needs: setup
if: ${{ needs.setup.outputs.containers != '[]' }}
runs-on: ubuntu-latest
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.containers) }}
container:
image: ${{ matrix.config.container }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/run-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/run-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ Suggests:
rmarkdown,
ggplot2,
knitr,
sensitivity,
cowplot
sensitivity
VignetteBuilder: knitr
Encoding: UTF-8
46 changes: 23 additions & 23 deletions R/run_biomee_f_bysite.R
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ run_biomee_f_bysite <- function(
if (continue) {

## C wrapper call
lm3out <- .Call(
biomeeout <- .Call(

'biomee_f_C',

Expand Down Expand Up @@ -569,14 +569,14 @@ run_biomee_f_bysite <- function(
)

# If simulation is very long, output gets massive.
# E.g., In a 3000 years-simulation 'lm3out' is 11.5 GB.
# E.g., In a 3000 years-simulation 'biomeeout' is 11.5 GB.
# In such cases (here, more than 5 GB), ignore hourly and daily outputs at tile and cohort levels
size_of_object_gb <- as.numeric(
gsub(
pattern = " Gb",
replacement = "",
format(
utils::object.size(lm3out),
utils::object.size(biomeeout),
units = "GB"
)
)
Expand All @@ -587,28 +587,28 @@ run_biomee_f_bysite <- function(
sprintf("Warning: Excessive size of output object (%s) for %s.
Hourly and daily outputs at tile and cohort levels are not returned.",
format(
utils::object.size(lm3out),
utils::object.size(biomeeout),
units = "GB"
),
sitename))
}

#---- Single level output, one matrix ----
# hourly
if (size_of_object_gb < 5){
output_hourly_tile <- as.data.frame(lm3out[[1]], stringAsFactor = FALSE)
colnames(output_hourly_tile) <- c("year", "doy", "hour",
"rad", "Tair", "Prcp",
"GPP", "Resp", "Transp",
"Evap", "Runoff", "Soilwater",
"wcl", "FLDCAP", "WILTPT")
} else {
output_hourly_tile <- NA
}
# # hourly
# if (size_of_object_gb < 5){
# output_hourly_tile <- as.data.frame(biomeeout[[1]], stringAsFactor = FALSE)
# colnames(output_hourly_tile) <- c("year", "doy", "hour",
# "rad", "Tair", "Prcp",
# "GPP", "Resp", "Transp",
# "Evap", "Runoff", "Soilwater",
# "wcl", "FLDCAP", "WILTPT")
# } else {
# output_hourly_tile <- NA
# }

# daily_tile
if (size_of_object_gb < 5){
output_daily_tile <- as.data.frame(lm3out[[2]], stringAsFactor = FALSE)
output_daily_tile <- as.data.frame(biomeeout[[1]], stringAsFactor = FALSE)
colnames(output_daily_tile) <- c(
"year", "doy", "Tc",
"Prcp", "totWs", "Trsp",
Expand All @@ -627,7 +627,7 @@ run_biomee_f_bysite <- function(
}

# annual tile
output_annual_tile <- as.data.frame(lm3out[[30]], stringAsFactor = FALSE)
output_annual_tile <- as.data.frame(biomeeout[[29]], stringAsFactor = FALSE)
colnames(output_annual_tile) <- c("year", "CAI", "LAI",
"Density", "DBH", "Density12",
"DBH12", "QMD", "NPP",
Expand Down Expand Up @@ -674,17 +674,17 @@ run_biomee_f_bysite <- function(
"SW_N", "HW_N"
)
output_daily_cohorts <- lapply(1:length(daily_values), function(x){
loc <- 2 + x
loc <- 1 + x
v <- data.frame(
as.vector(lm3out[[loc]]),
as.vector(biomeeout[[loc]]),
stringsAsFactors = FALSE)
names(v) <- daily_values[x]
return(v)
})

output_daily_cohorts <- do.call("cbind", output_daily_cohorts)

cohort <- sort(rep(1:ncol(lm3out[[3]]),nrow(lm3out[[3]])))
cohort <- sort(rep(1:ncol(biomeeout[[3]]),nrow(biomeeout[[3]])))
output_daily_cohorts <- cbind(cohort, output_daily_cohorts)

# drop rows (cohorts) with no values
Expand All @@ -711,9 +711,9 @@ run_biomee_f_bysite <- function(
)

output_annual_cohorts <- lapply(1:length(annual_values), function(x){
loc <- 30 + x
loc <- 29 + x
v <- data.frame(
as.vector(lm3out[[loc]]),
as.vector(biomeeout[[loc]]),
stringsAsFactors = FALSE)
names(v) <- annual_values[x]
return(v)
Expand All @@ -733,7 +733,7 @@ run_biomee_f_bysite <- function(

# format the output in a structured list
out <- list(
output_hourly_tile = output_hourly_tile,
# output_hourly_tile = output_hourly_tile,
output_daily_tile = output_daily_tile,
output_daily_cohorts = output_daily_cohorts,
output_annual_tile = output_annual_tile,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ Weng, E. S., Malyshev, S., Lichstein, J. W., Farrior, C. E., Dybzinski, R., Zhan

## Acknowledgements

The {rsofun} is part of the LEMONTREE project and funded by Schmidt Futures and under the umbrella of the Virtual Earth System Research Institute (VESRI).
The {rsofun} is part of the LEMONTREE project and funded by Schmidt Futures and under the umbrella of the Virtual Earth System Research Institute (VESRI).

7 changes: 7 additions & 0 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# PKG_FFLAGS = -ffree-line-length-0 -fbacktrace -ffpe-trap=invalid,zero,overflow -O1 -Wall -Wextra -pedantic -fbacktrace -fPIC -fmax-errors=1 -ggdb -fcheck=all
# PKG_FFLAGS = -fbounds-check

# Add package flags:
# -frecursive: to avoid "Warning: Array 'out_biosphere' at (1) is larger than limit ..."
# -fbounds-check: https://scicomp.stackexchange.com/questions/36045/ifort-everithing-ok-but-with-gfortran-segmentation-fault
# -Wall -Wextra -Wpedantic: to get more warnings
# -fsanitize=address: Using the Address Sanitizer https://rstudio.github.io/r-manuals/r-exts/Debugging.html#using-the-address-sanitizer
# PKG_FFLAGS = -frecursive -fbounds-check -Wall -Wextra -Wpedantic -g -O0 -fsanitize=address

# C objects
C_OBJS = wrappersc.o

Expand Down
14 changes: 10 additions & 4 deletions src/biosphere_biomee.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ subroutine biosphere_annual(out_biosphere)
! ! local variables
integer :: dm, moy, doy
logical, save :: init = .true. ! is true only on the first day of the simulation
logical, parameter :: verbose = .false. ! change by hand for debugging etc.
! logical, parameter :: verbose = .false. ! change by hand for debugging etc.

!----------------------------------------------------------------
! Biome-E stuff
!----------------------------------------------------------------
integer, parameter :: rand_seed = 86456
integer, parameter :: totalyears = 10
! integer, parameter :: rand_seed = 86456
! integer, parameter :: totalyears = 10
integer, parameter :: nCohorts = 1
real :: tsoil, soil_theta
integer :: year0
Expand Down Expand Up @@ -119,7 +119,7 @@ subroutine biosphere_annual(out_biosphere)
!----------------------------------------------------------------
call vegn_CNW_budget( vegn, myinterface%climate(idata), init )

call hourly_diagnostics( vegn, myinterface%climate(idata), iyears, idoy, i , out_biosphere%hourly_tile(idata))
call hourly_diagnostics( vegn, myinterface%climate(idata) ) !, iyears, idoy, i, out_biosphere%hourly_tile(idata)

init = .false.

Expand Down Expand Up @@ -205,6 +205,12 @@ subroutine biosphere_annual(out_biosphere)

!if (iyears == 700 .or. iyears == 800) &
! call reset_vegn_initial(vegn)

if (myinterface%steering%finalize) then
!----------------------------------------------------------------
! Finazlize run: deallocating memory
!----------------------------------------------------------------
deallocate( vegn )

if(myinterface%params_siml%do_reset_veg) then

Expand Down
27 changes: 12 additions & 15 deletions src/biosphere_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module md_biosphere_pmodel
use md_gpp_pmodel, only: getpar_modl_gpp, gpp
use md_vegdynamics_pmodel, only: vegdynamics
use md_tile_pmodel, only: tile_type, tile_fluxes_type, initglobal_tile, initdaily_tile_fluxes, &
getpar_modl_tile, diag_daily, diag_annual, init_annual
getpar_modl_tile, diag_daily !, init_annual
use md_plant_pmodel, only: getpar_modl_plant
use md_sofunutils, only: calc_patm
use md_soiltemp, only: soiltemp
Expand Down Expand Up @@ -41,7 +41,7 @@ function biosphere_annual() result( out_biosphere )
! local variables
integer :: dm, moy, doy
logical, save :: init_daily ! is true only on the first day of the simulation
logical, parameter :: verbose = .false. ! change by hand for debugging etc.
! logical, parameter :: verbose = .false. ! change by hand for debugging etc.

!----------------------------------------------------------------
! INITIALISATIONS
Expand Down Expand Up @@ -71,10 +71,10 @@ function biosphere_annual() result( out_biosphere )

endif

!----------------------------------------------------------------
! Set annual sums to zero
!----------------------------------------------------------------
call init_annual( tile_fluxes(:) )
! !----------------------------------------------------------------
! ! Set annual sums to zero
! !----------------------------------------------------------------
! call init_annual( tile_fluxes(:) )

!----------------------------------------------------------------
! LOOP THROUGH MONTHS
Expand Down Expand Up @@ -111,8 +111,8 @@ function biosphere_annual() result( out_biosphere )
call solar( tile_fluxes(:), &
myinterface%grid, &
myinterface%climate(doy), &
doy, &
myinterface%params_siml%in_netrad &
doy &
! myinterface%params_siml%in_netrad &
)
! if (verbose) print*,'... done'

Expand All @@ -135,12 +135,10 @@ function biosphere_annual() result( out_biosphere )
tile_fluxes(:), &
myinterface%pco2, &
myinterface%climate(doy), &
myinterface%vegcover(doy), &
myinterface%grid, &
init_daily, &
myinterface%params_siml%in_ppfd &
)

! if (verbose) print*,'... done'

!----------------------------------------------------------------
Expand Down Expand Up @@ -202,12 +200,11 @@ function biosphere_annual() result( out_biosphere )

end do monthloop

!----------------------------------------------------------------
! annual diagnostics
!----------------------------------------------------------------
call diag_annual( tile(:), tile_fluxes(:) )
! !----------------------------------------------------------------
! ! annual diagnostics
! !----------------------------------------------------------------
! call diag_annual( tile(:), tile_fluxes(:) )


! if (verbose) print*,'Done with biosphere for this year. Guete Rutsch!'

end function biosphere_annual
Expand Down
Loading

0 comments on commit 4949652

Please sign in to comment.