SindbadTEM Module
SindbadTEM
The SindbadTEM
package provides the core functionality for running the SINDBAD Terrestrial Ecosystem Model (TEM). It includes utilities for preparing model-ready objects, managing spinup processes and running models.
Purpose:
This package integrates various components and utilities required to execute the SINDBAD TEM, including precomputations, spinup, and time loop simulations. It supports parallel execution and efficient handling of large datasets.
Dependencies:
ComponentArrays
: Used for managing complex, hierarchical data structures like land variables and model states.NLsolve
: Used for solving nonlinear equations, particularly in spinup processes (e.g., fixed-point solvers).ProgressMeter
: Displays progress bars for long-running simulations, improving user feedback.Sindbad
: Provides the core SINDBAD models and types.SindbadData
: Provides the SINDBAD data handling functions.SindbadUtils
: Provides utility functions for handling NamedTuple, spatial operations, and other helper tasks for spatial and temporal operations.SindbadSetup
: Provides the SINDBAD setup functions.ThreadPools
: Enables efficient thread-based parallelization for running simulations across multiple locations.
Included Files:
utilsTEM.jl
:
- Contains utility functions for handling extraction of forcing data, managing/filling outputs, and other helper operations required during TEM execution.
deriveSpinupForcing.jl
:
- Provides functionality for deriving spinup forcing data, which is used to force the model during initialization to a steady state.
prepTEMOut.jl
:
- Handles the preparation of output structures, ensuring that results are stored efficiently during simulations.
runModels.jl
:
- Contains functions for executing individual models within the SINDBAD framework.
prepTEM.jl
:
- Prepares the necessary inputs and configurations for running the TEM, including spatial and temporal data preparation.
runTEMLoc.jl
:
- Implements the logic for running the TEM for a single location, including optional spinup and the main simulation loop.
runTEMSpace.jl
:
- Extends the functionality to handle spatial grids, enabling simulations across multiple locations with parallel execution.
runTEMCube.jl
:
- Adds support for running the TEM on 3D data YAXArrayscubes, useful for large-scale simulations with spatial dimensions.
spinupTEM.jl
:
- Manages the spinup process, initializing the model to a steady state using various methods (e.g., ODE solvers, fixed-point solvers).
spinupSequence.jl
:
- Handles sequential spinup loops, allowing for iterative refinement of model states during the spinup process.
Notes:
The package is designed to be modular and extensible, allowing users to customize and extend its functionality for specific use cases.
It integrates tightly with the SINDBAD framework, leveraging shared types and utilities from
SindbadSetup
.
Exported
SindbadTEM.TEMYax Method
TEMYax(map_cubes; loc_land::NamedTuple, tem::NamedTuple, selected_models::Tuple, forcing_vars::AbstractArray)
Arguments:
map_cubes
: collection/tuple of all input and output cubes from mapCubeloc_land
: initial SINDBAD land with all fields and subfieldstem
: a nested NT with necessary information of helpers, models, and spinup needed to run SINDBAD TEM and modelsselected_models
: a tuple of all models selected in the given model structureforcing_vars
: forcing variables
SindbadTEM.computeTEM Method
computeTEM(models, forcing, land, model_helpers)
run the compute function of SINDBAD models
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.computeTEM Method
computeTEM(models, forcing, land, model_helpers, ::DoDebugModel)
debug the compute function of SINDBAD models
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies::DoDebugModel
: a type dispatch to debug the compute functions of model
SindbadTEM.computeTEM Method
computeTEM(models, forcing, land, model_helpers, ::DoNotDebugModel)
run the compute function of SINDBAD models
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies::DoNotDebugModel
: a type dispatch to not debug but run the compute functions of model
SindbadTEM.computeTEM Method
computeTEM(models, forcing, land, model_helpers)
run the compute function of SINDBAD models
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.coreTEM Function
coreTEM(selected_models, loc_forcing, loc_spinup_forcing, loc_forcing_t, loc_land, tem_info, spinup_mode)
Runs the SINDBAD Terrestrial Ecosystem Model (TEM) for a single location, with or without spinup, based on the specified spinup_mode
.
Arguments:
selected_models
: A tuple of all models selected in the given model structure.loc_forcing
: A forcing NamedTuple containing the time series of environmental drivers for a single location.loc_spinup_forcing
: A forcing NamedTuple for spinup, used to initialize the model to a steady state (only used if spinup is enabled).loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.loc_land
: Initial SINDBAD land NamedTuple with all fields and subfields.tem_info
: A helper NamedTuple containing necessary objects for model execution and type consistencies.spinup_mode
: A type that determines whether spinup is included or excluded
Returns:
land_time_series
: A vector of SINDBAD land states for each time step after the model simulation.
SindbadTEM.coreTEM! Method
coreTEM!(selected_models, loc_forcing, loc_spinup_forcing, loc_forcing_t, loc_output, loc_land, tem_info)
Executes the core SINDBAD Terrestrial Ecosystem Model (TEM) for a single location, including precomputations, spinup, and the main time loop.
Arguments:
selected_models
: A tuple of all models selected in the given model structure.loc_forcing
: A forcing NamedTuple containing the time series of environmental drivers for a single location.loc_spinup_forcing
: A forcing NamedTuple for spinup, used to initialize the model to a steady state (only used if spinup is enabled).loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.loc_output
: An output array or view for storing the model outputs for a single location.loc_land
: Initial SINDBAD land NamedTuple with all fields and subfields.tem_info
: A helper NamedTuple containing necessary objects for model execution and type consistencies.
Details
Executes the main TEM simulation logic with the provided parameters and data. Handles both regular simulation and spinup modes based on the spinup_mode flag.
Extended help
- Precomputations:
- The function runs
precomputeTEM
to prepare the land state for the simulation.
- The function runs
SindbadTEM.definePrecomputeTEM Method
definePrecomputeTEM(models::LongTuple, forcing, land, model_helpers)
run the precompute function of SINDBAD models to instantiate all fields of land
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.definePrecomputeTEM Method
definePrecomputeTEM(models, forcing, land, model_helpers)
run the define and precompute functions of SINDBAD models to instantiate all fields of land
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.getAllSpinupForcing Method
getAllSpinupForcing(forcing, spin_seq, tem_helpers)
prepare the spinup forcing all forcing setups in the spinup sequence
Arguments:
forcing
: a forcing NT that contains the forcing time series set for ALL locationsspin_seq
: a sequence of information to carry out spinup at different steps with information on models to use, forcing, stopping critera, etc.tem_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.getDeltaPool Method
getDeltaPool(pool_dat::AbstractArray, spinup_info, t)
helper function to run the spinup models and return the delta in a given pool over the simulation. Used in solvers from DifferentialEquations.jl.
Arguments:
pool_dat
: new values of the storage poolsspinup_info
: NT with all the necessary information to run the spinup models
SindbadTEM.getForcingForTimeStep Method
getForcingForTimeStep(forcing, loc_forcing_t, ts, Val{forc_with_type})
Get forcing values for a specific time step based on the forcing type.
Arguments:
forcing
: a forcing NT that contains the forcing time series set for ALL locationsloc_forcing_t
: a forcing NT for a single timestep to be reused in every time stepts
: time step to get the forcing forforc_with_type
: Value type parameter specifying the forcing type
SindbadTEM.getLocData Method
getLocData(forcing, output_array, loc_ind)
Arguments:
output_array
: an output array/view for ALL locationsloc_ind
: a tuple with the spatial indices of the data for a given location
SindbadTEM.getLocData Method
getLocData(forcing, output_array, loc_ind)
Arguments:
forcing
: a forcing NT that contains the forcing time series set for ALL locationsoutput_array
: an output array/view for ALL locationsloc_ind
: a tuple with the spatial indices of the data for a given location
SindbadTEM.getLocData Method
getLocData(forcing, output_array, loc_ind)
Arguments:
forcing
: a forcing NT that contains the forcing time series set for ALL locationsloc_ind
: a tuple with the spatial indices of the data for a given location
SindbadTEM.getOutDims Function
getOutDims(info, forcing_helpers[, ::OutputArray | ::OutputMArray | ::OutputSizedArray | ::OutputYAXArray])
Retrieves the dimensions for SINDBAD output based on the specified array backend.
Arguments:
info
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.forcing_helpers
: A NamedTuple with information on forcing sizes and dimensions.::OutputArray
: (Optional) A type dispatch for using a base Array as the array backend.::OutputMArray
: (Optional) A type dispatch for using MArray as the array backend.::OutputSizedArray
: (Optional) A type dispatch for using SizedArray as the array backend.::OutputYAXArray
: (Optional) A type dispatch for using YAXArray as the array backend.
Returns:
- A vector of output dimensions, where each dimension is represented as a tuple of
Dim
objects.
Notes:
For
OutputArray
,OutputMArray
, andOutputSizedArray
, all dimensions are included.For
OutputYAXArray
, spatial dimensions are excluded, and metadata is added for each variable.
Examples:
- Using a base Array:
outdims = getOutDims(info, forcing_helpers, OutputArray())
- Using YAXArray:
outdims = getOutDims(info, forcing_helpers, OutputYAXArray())
- Default behavior:
outdims = getOutDims(info, forcing_helpers)
SindbadTEM.getOutDimsArrays Function
getOutDimsArrays(info, forcing_helpers[, ::OutputArray | ::OutputMArray | ::OutputSizedArray | ::OutputYAXArray])
Retrieves the dimensions and corresponding data for SINDBAD output based on the specified array backend.
Arguments:
info
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.forcing_helpers
: A NamedTuple with information on forcing sizes and dimensions.::OutputArray
: (Optional) A type dispatch for using a base Array as the array backend.::OutputMArray
: (Optional) A type dispatch for using MArray as the array backend.::OutputSizedArray
: (Optional) A type dispatch for using SizedArray as the array backend.::OutputYAXArray
: (Optional) A type dispatch for using YAXArray as the array backend.
Returns:
- A tuple
(outdims, outarray)
:outdims
: A vector of output dimensions, where each dimension is represented as a tuple ofDim
objects.outarray
: The corresponding data array, initialized based on the specified array backend.
Notes:
For
OutputArray
,OutputMArray
, andOutputSizedArray
, the data array is initialized with the appropriate backend type.For
OutputYAXArray
, the data array is set tonothing
, as YAXArray handles data differently.
Examples:
- Using a base Array:
outdims, outarray = getOutDimsArrays(info, forcing_helpers, OutputArray())
- Using MArray:
outdims, outarray = getOutDimsArrays(info, forcing_helpers, OutputMArray())
- Using SizedArray:
outdims, outarray = getOutDimsArrays(info, forcing_helpers, OutputSizedArray())
- Using YAXArray:
outdims, outarray = getOutDimsArrays(info, forcing_helpers, OutputYAXArray())
- Default behavior:
outdims, outarray = getOutDimsArrays(info, forcing_helpers)
SindbadTEM.getSequence Method
getSequence(year_disturbance, nrepeat_base=200, year_start = 1979)
Arguments:
year_disturbance
: a year date, as an stringnrepeat_base
=200 [default]year_start
: 1979 [default] start year, as an interger
Outputs
- new spinup sequence object
SindbadTEM.getSpatialInfo Function
getSpatialInfo(forcing_helpers)
getSpatialInfo(forcing, filterNanPixels)
get the information of the indices of the data to run the model for. The second variant additionally filter pixels with all nan data
Arguments:
forcing
: a forcing NT that contains the forcing time series set for ALL locations
SindbadTEM.getSpinupInfo Method
getSpinupInfo(spinup_models, spinup_forcing, loc_forcing_t, land, spinup_pool_name, tem_info, tem_spinup)
helper function to create a NamedTuple with all the variables needed to run the spinup models in getDeltaPool. Used in solvers from DifferentialEquations.jl.
Arguments:
spinup_models
: a tuple of a subset of all models in the given model structure that is selected for spinupspinup_forcing
: a selected/sliced/computed forcing time series for running the spinup sequence for a locationloc_forcing_t
: a forcing NT for a single location and a single time stepland
: SINDBAD NT input to the spinup of TEM during which subfield(s) of pools are overwrittenspinup_pool_name
: name of the land.pool storage component intended for spinuptem_info
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.precomputeTEM Method
precomputeTEM(models, forcing, land, model_helpers)
run the precompute function of SINDBAD models to instantiate all fields of land
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.precomputeTEM Method
precomputeTEM(models, forcing, land, model_helpers, ::DoDebugModel)
debug the precompute function of SINDBAD models
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies::DoDebugModel
: a type dispatch to debug the compute functions of model
SindbadTEM.precomputeTEM Method
precomputeTEM(models, forcing, land, model_helpers, ::DoNotDebugModel)
run the precompute function of SINDBAD models
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies::DoNotDebugModel
: a type dispatch to not debug but run the compute functions of model
SindbadTEM.precomputeTEM Method
precomputeTEM(models, forcing, land, model_helpers)
run the precompute function of SINDBAD models to instantiate all fields of land
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.prepTEM Function
prepTEM(forcing::NamedTuple, info::NamedTuple)
prepTEM(selected_models, forcing::NamedTuple, info::NamedTuple)
prepTEM(selected_models, forcing::NamedTuple, observations::NamedTuple, info::NamedTuple)
Prepares the SINDBAD Terrestrial Ecosystem Model (TEM) for execution by setting up the necessary inputs, outputs, and configurations with different variants for different experimental setups.
Arguments:
selected_models
: A tuple of all models selected in the given model structure.forcing::NamedTuple
: A forcing NamedTuple containing the time series of environmental drivers for all locations.observations::NamedTuple
: A NamedTuple containing observational data for model validation.info::NamedTuple
: A nested NamedTuple containing necessary information, including:Helpers for running the model.
Model configurations.
Spinup settings.
Returns:
run_helpers
: A NamedTuple containing preallocated data and configurations required to run the TEM, including:Spatial forcing data.
Spinup forcing data.
Output arrays.
Land variables.
Temporal and spatial indices.
Model and helper configurations.
Notes:
The function dynamically prepares the required data structures based on the specified
PreAllocputType
ininfo.helpers.run.land_output_type
.It handles spatial and temporal data preparation, including filtering NaN pixels, initializing land variables, and setting up forcing and output arrays.
This function is a key step in preparing the SINDBAD TEM for execution.
Examples:
- Preparing TEM with observations:
selected_models = (model1, model2)
forcing = (data = ..., variables = ...)
observations = (data = ..., variables = ...)
info = (helpers = ..., models = ..., spinup = ...)
run_helpers = prepTEM(selected_models, forcing, observations, info)
- Preparing TEM without observations:
selected_models = (model1, model2)
forcing = (data = ..., variables = ...)
info = (helpers = ..., models = ..., spinup = ...)
run_helpers = prepTEM(selected_models, forcing, info)
SindbadTEM.prepTEMOut Method
prepTEMOut(info::NamedTuple, forcing_helpers::NamedTuple)
Prepares the output NamedTuple required for running the Terrestrial Ecosystem Model (TEM) in SINDBAD.
Arguments:
info
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.forcing_helpers
: A NamedTuple with information on forcing sizes and dimensions.
Returns:
A NamedTuple output_tuple
containing:
land_init
: The initial land state frominfo.land_init
.dims
: A vector of output dimensions, where each dimension is represented as a tuple ofDim
objects.data
: A vector of numeric arrays initialized for output variables.variables
: A list of output variable names.Additional fields for optimization output if optimization is enabled.
Notes:
The function initializes the output dimensions and data arrays based on the specified array backend (
info.helpers.run.output_array_type
).If optimization is enabled (
info.helpers.run.run_optimization
), additional fields for optimized parameters are added to the output.The function uses helper functions like
getOutDimsArrays
andsetupOptiOutput
to prepare the output.
Examples:
- Basic usage:
output_tuple = prepTEMOut(info, forcing_helpers)
- Accessing output fields:
dims = output_tuple.dims
data = output_tuple.data
variables = output_tuple.variables
SindbadTEM.runTEM Function
runTEM(forcing::NamedTuple, info::NamedTuple)
runTEM(selected_models::Tuple, forcing::NamedTuple, loc_spinup_forcing, loc_forcing_t, loc_land::NamedTuple, tem_info::NamedTuple)
runTEM(selected_models::Tuple, loc_forcing::NamedTuple, loc_spinup_forcing, loc_forcing_t, land_time_series, loc_land::NamedTuple, tem_info::NamedTuple)
Runs the SINDBAD Terrestrial Ecosystem Model (TEM) for a single location, with or without spinup, based on the provided configurations. The two main variants are the ones with and without the preallocated land time series. The shorthand version with two input arguments calls the one without preallocated land time series.
Arguments:
selected_models
: A tuple of all models selected in the given model structure.forcing::NamedTuple
: A forcing NamedTuple containing the time series of environmental drivers for all locations.loc_spinup_forcing
: A forcing NamedTuple for spinup, used to initialize the model to a steady state.loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.loc_land::NamedTuple
: Initial SINDBAD land NamedTuple with all fields and subfields.tem_info::NamedTuple
: A nested NamedTuple containing necessary information, including:Model helpers.
Spinup configurations.
Debugging options.
Output configurations.
Returns:
LandWrapper
: A wrapper containing the time series of SINDBAD land states for each time step after the model simulation.
Notes:
The function internally calls
coreTEM
to handle the main simulation logic.If spinup is enabled (
DoSpinupTEM
), the function runs the spinup process before the main simulation.If spinup is disabled (
DoNotSpinupTEM
), the function directly runs the main simulation.The function prepares the necessary inputs and configurations using
prepTEM
before executing the simulation.
Examples:
- Running TEM with spinup:
land_time_series = runTEM(selected_models, forcing, loc_spinup_forcing, loc_forcing_t, loc_land, tem_info)
- Running TEM without spinup:
land_time_series = runTEM(selected_models, forcing, nothing, loc_forcing_t, loc_land, tem_info)
SindbadTEM.runTEM! Function
runTEM!(selected_models, forcing::NamedTuple, info::NamedTuple)
runTEM!(forcing::NamedTuple, info::NamedTuple)
runTEM!(selected_models, space_forcing, space_spinup_forcing, loc_forcing_t, space_output, space_land, tem_info::NamedTuple)
Runs the SINDBAD Terrestrial Ecosystem Model (TEM) for all locations and time steps using preallocated arrays as the model data backend. This function supports multiple configurations for efficient execution.
Arguments:
- For the first variant:
selected_models
: A tuple of all models selected in the given model structure.forcing::NamedTuple
: A forcing NamedTuple containing the time series of environmental drivers for all locations.info::NamedTuple
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.
- For the second variant:
forcing::NamedTuple
: A forcing NamedTuple containing the time series of environmental drivers for all locations.info::NamedTuple
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.
- For the third variant:
selected_models
: A tuple of all models selected in the given model structure.space_forcing
: A collection of forcing NamedTuples for multiple locations, replicated to avoid data races during parallel execution.space_spinup_forcing
: A collection of spinup forcing NamedTuples for multiple locations, replicated to avoid data races during parallel execution.loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.space_output
: A collection of output arrays/views for multiple locations, replicated to avoid data races during parallel execution.space_land
: A collection of initial SINDBAD land NamedTuples for multiple locations, ensuring that the model states for one location do not overwrite those of another.tem_info::NamedTuple
: A helper NamedTuple containing necessary objects for model execution and type consistencies.
Returns:
output_array
: A preallocated array containing the simulation results for all locations and time steps.
Notes:
Precomputations:
- The function uses
prepTEM
to prepare the necessary inputs and configurations for the simulation.
- The function uses
Parallel Execution:
- The function uses
parallelizeTEM!
to distribute the simulation across multiple locations using the specified parallelization backend (Threads.@threads
orqbmap
).
- The function uses
Core Execution:
- For each location, the function calls
coreTEM!
to execute the TEM simulation, including spinup (if enabled) and the main time loop.
- For each location, the function calls
Data Safety:
- The function ensures data safety by replicating forcing, output, and land data for each location, avoiding data races during parallel execution.
Examples:
- Running TEM with preallocated arrays:
output_array = runTEM!(selected_models, forcing, info)
- Running TEM with parallelization:
output_array = runTEM!(forcing, info)
- Running TEM with precomputed helpers:
runTEM!(selected_models, space_forcing, space_spinup_forcing, loc_forcing_t, space_output, space_land, tem_info)
SindbadTEM.runTEMYax Method
runTEMYax(forcing::NamedTuple, output::NamedTuple, tem::NamedTuple, selected_models::Tuple; max_cache = 1.0e9)
Arguments:
forcing
: a forcing NT that contains the forcing time series set for ALL locationsoutput
: an output NT including the data arrays, as well as information of variables and dimensionstem
: a nested NT with necessary information of helpers, models, and spinup needed to run SINDBAD TEM and modelsselected_models
: a tuple of all models selected in the given model structuremax_cache
: cache size to use for mapCube
SindbadTEM.setOutputForTimeStep! Method
setOutputForTimeStep!(outputs, land, ts, Val{output_vars})
Arguments:
outputs
: vector of model output vectorsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepts
: time step::Val{output_vars}
: a dispatch for vals of the output variables to generate the function
SindbadTEM.setSequence Method
setSequence(tem_info, new_sequence)
Arguments:
tem_info
: Tuple with the fieldspinup_sequence
new_sequence
Outputs
- an updated tem_info object with new spinup sequence modes
SindbadTEM.setupOptiOutput Function
setupOptiOutput(info::NamedTuple, output::NamedTuple[, ::DoRunOptimization | ::DoNotRunOptimization])
Creates the output fields needed for the optimization experiment.
Arguments:
info
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.output
: A base output NamedTuple to which optimization-specific fields will be added.::DoRunOptimization
: (Optional) A type dispatch indicating that optimization is enabled. Adds fields for optimized parameters.::DoNotRunOptimization
: (Optional) A type dispatch indicating that optimization is not enabled. Returns the base output unchanged.
Returns:
- A NamedTuple containing the base output fields, with additional fields for optimization if enabled.
Notes:
When optimization is enabled, the function:
Adds a
parameter_dim
field to the output, which includes the parameter dimension and metadata.Creates an
OutDims
object for storing optimized parameters, with the appropriate backend and file path.
When optimization is not enabled, the function simply returns the input
output
NamedTuple unchanged.
Examples:
- With optimization enabled:
output = setupOptiOutput(info, output, DoRunOptimization())
- Without optimization:
output = setupOptiOutput(info, output, DoNotRunOptimization())
SindbadTEM.spinup Function
spinup(spinup_models, spinup_forcing, loc_forcing_t, land, tem_info, n_timesteps, spinup_mode::SpinupMode)
Runs the spinup process for the SINDBAD Terrestrial Ecosystem Model (TEM) to initialize the model to a steady state. The spinup process updates the state variables (e.g., pools) using various spinup methods.
Arguments:
spinup_models
: A tuple of a subset of all models in the given model structure that are selected for spinup.spinup_forcing
: A forcing NamedTuple containing the time series of environmental drivers for the spinup process.loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.land
: A SINDBAD NamedTuple containing all variables for a given time step, which is overwritten at every timestep.tem_info
: A helper NamedTuple containing necessary objects for model execution and type consistencies.n_timesteps
: The number of timesteps for the spinup process.spinup_mode::SpinupMode
: A type dispatch that determines the spinup method to be used.
Returns:
land
: The updated SINDBAD NamedTuple containing the final state of the model after the spinup process.
SpinupMode
Abstract type for model spinup modes in SINDBAD
Available methods/subtypes:
AllForwardModels
: Use all forward models for spinupEtaScaleA0H
: scale carbon pools using diagnostic scalars for ηH and c_remainEtaScaleA0HCWD
: scale carbon pools of CWD (cLitSlow) using ηH and set vegetation pools to c_remainEtaScaleAH
: scale carbon pools using diagnostic scalars for ηH and ηAEtaScaleAHCWD
: scale carbon pools of CWD (cLitSlow) using ηH and scale vegetation pools by ηANlsolveFixedpointTrustregionCEco
: use a fixed-point nonlinear solver with trust region for carbon pools (cEco)NlsolveFixedpointTrustregionCEcoTWS
: use a fixed-point nonlinear solver with trust region for both cEco and TWSNlsolveFixedpointTrustregionTWS
: use a fixed-point nonlinearsolver with trust region for Total Water Storage (TWS)ODEAutoTsit5Rodas5
: use the AutoVern7(Rodas5) method from DifferentialEquations.jl for solving ODEsODEDP5
: use the DP5 method from DifferentialEquations.jl for solving ODEsODETsit5
: use the Tsit5 method from DifferentialEquations.jl for solving ODEsSSPDynamicSSTsit5
: use the SteadyState solver with DynamicSS and Tsit5 methodsSSPSSRootfind
: use the SteadyState solver with SSRootfind methodSelSpinupModels
: run only the models selected for spinup in the model structureSpinup_TWS
: Spinup spinup_mode for Total Water Storage (TWS)Spinup_cEco
: Spinup spinup_mode for cEcoSpinup_cEco_TWS
: Spinup spinup_mode for cEco and TWS
Extended help
Notes:
The spinup process can use different methods depending on the
spinup_mode
, including fixed-point solvers, ODE solvers, and steady-state solvers.The function dynamically selects the appropriate spinup method based on the
spinup_mode
dispatch type.For ODE-based methods, the function uses DifferentialEquations.jl to solve the spinup equations.
For steady-state solvers, the function uses methods like
DynamicSS
orSSRootfind
to find equilibrium states.
Examples:
- Running spinup with selected models:
land = spinup(spinup_models, spinup_forcing, loc_forcing_t, land, tem_info, n_timesteps, SelSpinupModels())
- Running spinup with ODE solver (Tsit5):
land = spinup(spinup_models, spinup_forcing, loc_forcing_t, land, tem_info, n_timesteps, ODETsit5())
- Running spinup with fixed-point solver for cEco and TWS:
land = spinup(spinup_models, spinup_forcing, loc_forcing_t, land, tem_info, n_timesteps, NlsolveFixedpointTrustregionCEcoTWS())
- Running spinup with steady-state solver (SSRootfind):
land = spinup(spinup_models, spinup_forcing, loc_forcing_t, land, tem_info, n_timesteps, SSPSSRootfind())
SindbadTEM.spinupTEM Function
spinupTEM(selected_models, forcing, loc_forcing_t, land, tem_info, spinup_mode)
The main spinup function that handles the spinup method based on inputs from spinup.json. Either the spinup is loaded or/and run using spinup functions for different spinup methods.
Arguments:
selected_models
: a tuple of all models selected in the given model structureforcing
: a forcing NT that contains the forcing time series set for ALL locationsloc_forcing_t
: a forcing NT for a single location and a single time stepland
: SINDBAD NT input to the spinup of TEM during which subfield(s) of pools are overwrittentem_info
: helper NT with necessary objects for model run and type consistenciestem_spinup
: a NT with information/instruction on spinning up the TEMspinup_mode
: A type dispatch that determines whether spinup is included or excluded:::DoSpinupTEM
: Runs the spinup process before the main simulation. Setspinup_TEM
totrue
in the flag section of experiment_json.::DoNotSpinupTEM
: Skips the spinup process and directly runs the main simulation. Setspinup_TEM
tofalse
in the flag section of experiment_json.
Notes:
When
DoSpinupTEM
is used:- The function runs the spinup sequences
When
DoNotSpinupTEM
is used:- The function skips the spinup process returns the land as is`
SindbadTEM.timeLoopTEMSpinup Method
timeLoopTEMSpinup(spinup_models, spinup_forcing, loc_forcing_t, land, tem_info, n_timesteps)
do/run the time loop of the spinup models to update the pool. Note that, in this function, the time series is not stored and the land/land is overwritten with every iteration. Only the state at the end is returned
Arguments:
spinup_models
: a tuple of a subset of all models in the given model structure that is selected for spinupspinup_forcing
: a selected/sliced/computed forcing time series for running the spinup sequence for a locationloc_forcing_t
: a forcing NT for a single location and a single time stepland
: SINDBAD NT input to the spinup of TEM during which subfield(s) of pools are overwrittentem_info
: helper NT with necessary objects for model run and type consistenciesn_timesteps
: number of time steps
Internal
Sindbad.Types.Spinup_TWS Method
(TWS_spin::Spinup_TWS)(pout, p)
Custom callable type function for spinning up TWS pools.
Arguments
pout
: Output poolsp
: Input pools
Note
This method allows a Spinup_TWS
object to be called as a function, implementing the specific spinup logic for the terrestrial water storage components.
Sindbad.Types.Spinup_cEco Method
(cEco_spin::Spinup_cEco)(pout, p)
Custom callable type function for spinning up cEco.
Arguments
pout
: Output poolsp
: Input pools
Note
This method allows a Spinup_cEco
object to be called as a function, implementing the specific spinup logic for ecosystem carbon pools.
Sindbad.Types.Spinup_cEco_TWS Method
(cEco_TWS_spin::Spinup_cEco_TWS)(pout, p)
Custom callable type function for spinning up cEco and TWS pools.
Arguments
pout
: Output poolsp
: Input pools
Note
This method allows a Spinup_cEco_TWS
object to be called as a function, implementing the specific spinup logic for ecosystem carbon pools and the terrestrial water storage components.
SindbadTEM.addErrorCatcher Function
addErrorCatcher(loc_land, debug_mode)
Adds an error catcher to monitor and debug the SINDBAD land variables during model execution.
Arguments:
loc_land
: A core SINDBAD NamedTuple containing all variables for a given time step, which is overwritten at every time step.debug_mode
: A type dispatch to determine whether debugging is enabled:DoDebugModel
: Enables debugging and addsloc_land
to the error catcher. Setdebug_model
to true in flag section of experiment_json.DoNotDebugModel
: Disables debugging and does nothing. Setdebug_model
to false in flag section of experiment_json.
Returns:
nothing
: The function modifies global state or performs debugging actions but does not return a value.
Notes:
When
debug_mode
isDoDebugModel
, the function:Initializes an error catcher if it does not already exist. This error_catcher is a global variable where you can add any variable from within SINDBAD while debugging, and this variable will be available during an experiment run REPL session.
Pushes the current
loc_land
to the error catcher for debugging purposes.Prints the
loc_land
for inspection usingtcPrint
.
When
debug_mode
isDoNotDebugModel
, the function performs no actions.
Examples:
- Enabling debugging:
loc_land = (temperature = 15.0, precipitation = 100.0)
addErrorCatcher(loc_land, DoDebugModel())
- Disabling debugging:
loc_land = (temperature = 15.0, precipitation = 100.0)
addErrorCatcher(loc_land, DoNotDebugModel())
SindbadTEM.addSpinupLog Function
addSpinupLog(loc_land, sequence, ::SpinupLogType)
Adds or skips the preallocated holder for storing the spinup log during model spinup, depending on the specified SpinupLogType
.
Arguments:
loc_land
: A core SINDBAD NamedTuple containing all variables for a given time step, which is overwritten at every time step.sequence
: The spinup sequence, which defines the number of repeats and timesteps for the spinup process.::SpinupLogType
: A type dispatch that determines whether to store the spinup log:DoStoreSpinup
: Enables storing the spinup log for each repeat of the spinup process. Setstore_spinup
to true in flag section of experiment_json.DoNotStoreSpinup
: Skips storing the spinup log. Setstore_spinup
to false in flag section of experiment_json.
Returns:
loc_land
: The updatedloc_land
NamedTuple, potentially with the spinup log added.
Notes:
When
DoStoreSpinup
is used:The function calculates the total number of repeats in the spinup sequence.
Preallocates a vector to store the spinup log for each repeat.
Updates the
loc_land
NamedTuple with the spinup log.
When
DoNotStoreSpinup
is used, the function simply returnsloc_land
without modifications.
Examples:
- Storing the spinup log:
loc_land = (pools = rand(10), states = rand(10))
sequence = [(n_repeat = 3, n_timesteps = 10), (n_repeat = 2, n_timesteps = 5)]
loc_land = addSpinupLog(loc_land, sequence, DoStoreSpinup())
- Skipping the spinup log:
loc_land = (pools = rand(10), states = rand(10))
sequence = [(n_repeat = 3, n_timesteps = 10), (n_repeat = 2, n_timesteps = 5)]
loc_land = addSpinupLog(loc_land, sequence, DoNotStoreSpinup())
SindbadTEM.collectMetadata Method
collectMetadata(info, vname)
Collects metadata for a specific output variable in the SINDBAD experiment.
Arguments:
info
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.vname
: A tuple of symbols representing the variable name, e.g.,(:diagnostics, :water_balance)
.
Returns:
- A dictionary
Dict{String, Any}
containing metadata for the specified variable, including:Metadata from the variable catalog (if available).
Global metadata about the platform from
info.output.file_info.global_metadata
.
Notes:
If the variable is not found in the catalog, a warning is issued, and the metadata dictionary will not include catalog-specific information.
The metadata includes platform information for every output variable. For datasets, this should ideally be added once, not for every variable.
Examples:
- Collecting metadata for a variable:
metadata = collectMetadata(info, (:diagnostics, :water_balance))
- Accessing specific metadata fields:
platform_info = metadata["platform_info"]
variable_units = metadata["units"]
Warnings:
- If the variable is not found in the catalog, a warning is logged.
SindbadTEM.coreTEMYax Method
coreTEMYax(selected_models, loc_forcing, loc_forcing_t, loc_land, tem_info, tem_spinup, ::DoSpinupTEM)
run the SINBAD CORETEM for a given location
Arguments:
selected_models
: a tuple of all models selected in the given model structureloc_forcing
: a forcing NT that contains the forcing time series set for one locationloc_land
: initial SINDBAD land with all fields and subfieldstem_info
: helper NT with necessary objects for model run and type consistenciestem_spinup
: a NT with information/instruction on spinning up the TEM
SindbadTEM.defineTEM Method
defineTEM(models::LongTuple, forcing, land, model_helpers)
run the precompute function of SINDBAD models to instantiate all fields of land
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.defineTEM Method
defineTEM(models, forcing, land, model_helpers)
run the define and precompute functions of SINDBAD models to instantiate all fields of land
Arguments:
models
: a list of SINDBAD models to runforcing
: a forcing NT that contains the forcing time series set for ALL locationsland
: a core SINDBAD NT that contains all variables for a given time step that is overwritten at every timestepmodel_helpers
: helper NT with necessary objects for model run and type consistencies
SindbadTEM.fillLocOutput! Method
fillLocOutput!(ar::T, val::T1, ts::T2) where {T, T1, T2<:Int}
Fill an array ar
with value val
at specific time step ts
. Generic function that works with different array and value types, where the time step must be an integer.
Arguments
ar::T
: Target array to be filledval::T1
: Value to fill into the arrayts::T2<:Int
: Time step indicating position to fill
Notes
Modifies the input array
ar
in-placeTime step
ts
must be an integer type
Returns
Nothing, modifies input array in-place
SindbadTEM.fillOutputYax Method
fillOutputYax(xout, xin)
fills the output array position with the input data/vector
Arguments:
xout
: output array locationxin
: input data/vector
SindbadTEM.filterNanPixels Function
filterNanPixels(forcing, loc_space_maps, filter_nan_pixels_mode)
Filters out spatial pixels where all timesteps contain NaN values, based on the specified filtering mode.
Arguments:
forcing
: A forcing NamedTuple containing the time series of environmental drivers for all locations.loc_space_maps
: A collection of local spatial coordinates for all input points.filter_nan_pixels_mode
: A type dispatch that determines whether to filter NaN-only pixels:DoFilterNanPixels
: Filters out pixels where all timesteps are NaN. Setfilter_nan_pixels
to true in flag section of experiment_json.DoNotFilterNanPixels
: Does not filter any pixels, returning the inputloc_space_maps
unchanged. Setfilter_nan_pixels
to false in flag section of experiment_json.
Returns:
loc_space_maps
: The filtered or unfiltered spatial coordinates, depending on the filtering mode.
Notes:
When
DoFilterNanPixels
is used:The function iterates through all spatial locations and checks if all timesteps for a given location are NaN. NOTE THAT THIS WILL BE SLOW FOR LARGE DATASETS AS ALL LAZILY-LOADED DATA ARE STORED IN MEMORY.
Locations with all NaN values are excluded from the returned
loc_space_maps
.
When
DoNotFilterNanPixels
is used, the function simply returns the inputloc_space_maps
without any modifications.
Examples:
- Filtering NaN-only pixels:
forcing = (data = ..., variables = ...)
loc_space_maps = [(1, 2), (3, 4), (5, 6)]
filtered_maps = filterNanPixels(forcing, loc_space_maps, DoFilterNanPixels())
- Skipping NaN filtering:
forcing = (data = ..., variables = ...)
loc_space_maps = [(1, 2), (3, 4), (5, 6)]
filtered_maps = filterNanPixels(forcing, loc_space_maps, DoNotFilterNanPixels())
SindbadTEM.getForcingV Function
getForcingV(v, ts, <: ForcingTime)
Retrieves forcing values for a specific time step or returns constant forcing values, depending on the forcing type.
Arguments:
v
: The input forcing data. Can be time-dependent or constant.ts
: The time step (integer) for which the forcing value is retrieved. Ignored for constant forcing types.<: ForcingTime
: The type of forcing, which determines how the value is retrieved:ForcingWithTime
: Retrieves the forcing value for the specified time stepts
.ForcingWithoutTime
: Returns the constant forcing value, ignoringts
.
Returns:
- The forcing value for the specified time step (if time-dependent) or the constant forcing value.
Extended help
Examples:
- Time-dependent forcing:
forcing = [1.0, 2.0, 3.0] # Forcing values for time steps
ts = 2 # Time step
value = getForcingV(forcing, ts, ForcingWithTime())
# value = 2.0
- Constant forcing:
forcing = 5.0 # Constant forcing value
ts = 3 # Time step (ignored)
value = getForcingV(forcing, ts, ForcingWithoutTime())
# value = 5.0
SindbadTEM.getLocArrayView Function
getLocArrayView(ar, val, ts)
Creates a view of the input array ar
for a specific time step ts
, based on the type of val
.
Arguments:
ar
: The input array from which a view is created.val
: The value or vector used to determine the size or structure of the view.If
val
is anAbstractVector
, the view spans the time stepts
and the size ofval
.If
val
is aReal
value, the view spans only the time stepts
.
ts
: The time step (integer) for which the view is created.
Returns:
- A view of the array
ar
corresponding to the specified time stepts
.
Notes:
The function dynamically adjusts the view based on whether
val
is a vector or a scalar.This is useful for efficiently accessing or modifying specific slices of the array without copying data.
Examples:
- Creating a view with a vector
val
:
ar = rand(10, 5) # A 10x5 array
val = rand(5) # A vector of size 5
ts = 3 # Time step
view_ar = getLocArrayView(ar, val, ts)
- Creating a view with a scalar
val
:
ar = rand(10) # A 1D array
val = 42.0 # A scalar value
ts = 2 # Time step
view_ar = getLocArrayView(ar, val, ts)
SindbadTEM.getNumericArrays Method
getNumericArrays(info, forcing_sizes)
Defines and instantiates numeric arrays for SINDBAD output variables.
Arguments:
info
: A SINDBAD NamedTuple containing all information needed for setup and execution of an experiment.forcing_sizes
: A NamedTuple with forcing dimensions and their sizes.
Returns:
- A vector of numeric arrays initialized with
NaN
values, where each array corresponds to an output variable.
Notes:
The arrays are created with dimensions based on the forcing sizes and the depth information of the output variables.
The numeric type of the arrays is determined by the model settings (
info.helpers.numbers.num_type
).If forward differentiation is enabled (
info.helpers.run.use_forward_diff
), the array type is adjusted accordingly.
Examples:
- Creating numeric arrays for output variables:
forcing_sizes = (time=10, lat=5, lon=5)
numeric_arrays = getNumericArrays(info, forcing_sizes)
SindbadTEM.getOutArrayType Function
getOutArrayType(num_type, ::DoUseForwardDiff | ::DoNotUseForwardDiff)
Determines the type of elements to be used in the output array based on whether forward differentiation is enabled.
Arguments:
num_type
: The numeric type specified in the model settings (e.g.,Float64
).::DoUseForwardDiff
: A type dispatch indicating that forward differentiation is enabled. Returns a generic type (Real
) to support differentiation.::DoNotUseForwardDiff
: A type dispatch indicating that forward differentiation is not enabled. Returns the specified numeric type (num_type
).
Returns:
- The type of elements to be used in the output array:
Real
if forward differentiation is enabled.num_type
if forward differentiation is not enabled.
Examples:
- Forward differentiation enabled:
num_type = Float64
array_type = getOutArrayType(num_type, DoUseForwardDiff())
# array_type = Real
- Forward differentiation not enabled:
num_type = Float64
array_type = getOutArrayType(num_type, DoNotUseForwardDiff())
# array_type = Float64
SindbadTEM.getOutDimsPairs Method
getOutDimsPairs(tem_output, forcing_helpers; dthres=1)
Creates dimension pairs for each output variable based on forcing dimensions and depth information.
Arguments:
tem_output
: A NamedTuple containing information about output variables and depth dimensions of output arrays.forcing_helpers
: A NamedTuple with information on forcing sizes, dimensions, and optional permutations.dthres
: (Optional) A threshold for the number of depth layers to define depth as a new dimension. Defaults to1
.
Returns:
- A vector of tuples, where each tuple contains dimension pairs for an output variable. Each dimension pair is represented as a
Pair
of a dimension name and its corresponding range or size.
Notes:
If
forcing_helpers.dimensions.permute
is provided, the function reorders dimensions based on the permutation.Depth dimensions are included if their size exceeds the threshold
dthres
. If the depth size is1
, the depth dimension is labeled as"idx"
.The function processes each output variable independently, combining forcing dimensions and depth information.
Examples:
- Basic usage:
tem_output = (variables=[:var1, :var2], depth_info=[(3, "depth"), (1, "depth")])
forcing_helpers = (axes=[(:time, 10), (:lat, 5), (:lon, 5)], dimensions=(permute=nothing))
outdims_pairs = getOutDimsPairs(tem_output, forcing_helpers)
- With dimension permutation:
forcing_helpers = (axes=[(:time, 10), (:lat, 5), (:lon, 5)], dimensions=(permute=["lon", "lat", "time"]))
outdims_pairs = getOutDimsPairs(tem_output, forcing_helpers)
- With depth threshold:
outdims_pairs = getOutDimsPairs(tem_output, forcing_helpers; dthres=2)
SindbadTEM.getRunTEMInfo Method
getRunTEMInfo(info, forcing)
a helper to condense the useful info only for the inner model runs
Arguments:
info
: a nested NT with necessary information of helpers, models, and spinup needed to run SINDBAD TEM and modelsforcing
: a forcing NT that contains the forcing time series set for ALL locations
SindbadTEM.getSpinupForcing Method
getSpinupForcing(forcing, sequence, ::Val{forcing_types})
prepare the spinup forcing set for a given spinup sequence
Arguments:
forcing
: a forcing NT that contains the forcing time series set for a locationsequence
: a with all information needed to run a spinup sequence:Val{forcing_types}
: a type dispatch with the tuple of pairs of forcing name and time/no time types
SindbadTEM.getSpinupForcingVariable Method
getSpinupForcingVariable(v, _, ::ForcingWithoutTime)
get the spinup forcing variable without time axis
Arguments:
v
: a forcing variablesequence
: a with all information needed to run a spinup sequence::ForcingWithoutTime
: a type dispatch to indicate that the variable has NO time axis
SindbadTEM.getSpinupForcingVariable Method
getSpinupForcingVariable(v, sequence, ::ForcingWithTime)
get the aggregated spinup forcing variable
Arguments:
v
: a forcing variablesequence
: a with all information needed to run a spinup sequence::ForcingWithTime
: a type dispatch to indicate that the variable has a time axis
SindbadTEM.getSpinupTemLite Method
getSpinupTemLite(tem_spinup)
a helper to just get the spinup sequence to pass to inner functions
Arguments:
tem_spinup_sequence
: a NT with all spinup information
SindbadTEM.helpPrepTEM Function
helpPrepTEM(selected_models, info, forcing::NamedTuple, output::NamedTuple, ::PreAlloc)
Prepares the necessary information and objects needed to run the SINDBAD Terrestrial Ecosystem Model (TEM).
Arguments:
selected_models
: A tuple of all models selected in the given model structure.info
: A nested NamedTuple containing necessary information, including:Helpers for running the model.
Model configurations.
Spinup settings.
forcing::NamedTuple
: A forcing NamedTuple containing the time series of environmental drivers for all locations.output::NamedTuple
: An output NamedTuple containing data arrays, variable information, and dimensions.::PreAllocputType
: A type dispatch that determines the output preparation strategy.
Returns:
- A NamedTuple (
run_helpers
) containing preallocated data and configurations required to run the TEM, including:Spatial forcing data.
Spinup forcing data.
Output arrays.
Land variables.
Temporal and spatial indices.
Model and helper configurations.
sindbad land output type:
PreAlloc
Abstract type for preallocated land helpers types in prepTEM of SINDBAD
Available methods/subtypes:
PreAllocArray
: use a preallocated array for model outputPreAllocArrayAll
: use a preallocated array to output all land variablesPreAllocArrayFD
: use a preallocated array for finite difference (FD) hybrid experimentsPreAllocArrayMT
: use arrays of nThreads size for land model output for replicates of multiple threadsPreAllocStacked
: save output as a stacked vector of land using map over temporal dimensionPreAllocTimeseries
: save land output as a preallocated vector for time series of landPreAllocYAXArray
: use YAX arrays for model output
Extended help
Notes:
The function dynamically prepares the required data structures based on the specified
PreAllocputType
.It handles spatial and temporal data preparation, including filtering NaN pixels, initializing land variables, and setting up forcing and output arrays.
This function is a key step in preparing the SINDBAD TEM for execution.
Examples:
- Preparing TEM with
PreAllocArray
:
run_helpers = helpPrepTEM(selected_models, info, forcing, output, PreAllocArray())
- Preparing TEM with
PreAllocTimeseries
:
run_helpers = helpPrepTEM(selected_models, info, forcing, output, PreAllocTimeseries())
- Preparing TEM with
PreAllocArrayFD
for FD experiments:
run_helpers = helpPrepTEM(selected_models, info, forcing, observations, output, PreAllocArrayFD())
SindbadTEM.nrepeatYearsAge Method
nrepeatYearsAge(year_disturbance; year_start = 1979)
Arguments:
year_disturbance
: a year date, as an stringyear_start
: 1979 [default] start year, as an integer
Outputs
- year difference
SindbadTEM.nrepeat_age Method
nrepeat_age(year_disturbance; year_start = 1979)
Arguments:
year_disturbance
: a year date, as an stringyear_start
: 1979 [default] start year, as an integer
SindbadTEM.parallelizeTEM! Function
parallelizeTEM!(space_selected_models, space_forcing, space_spinup_forcing, loc_forcing_t, space_output, space_land, tem_info, parallelization_mode::SindbadParallelizationMethod)
Parallelizes the SINDBAD Terrestrial Ecosystem Model (TEM) across multiple locations using the specified parallelization backend.
Arguments:
space_selected_models
: A vector of tuple of all models selected in the given model structure that vary per location.space_forcing
: A collection of forcing NamedTuples for multiple locations, replicated to avoid data races during parallel execution.space_spinup_forcing
: A collection of spinup forcing NamedTuples for multiple locations, replicated to avoid data races during parallel execution.loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.space_output
: A collection of output arrays/views for multiple locations, replicated to avoid data races during parallel execution.space_land
: A collection of initial SINDBAD land NamedTuples for multiple locations, ensuring that the model states for one location do not overwrite those of another.tem_info
: A helper NamedTuple containing necessary objects for model execution and type consistencies.parallelization_mode
: A type dispatch that determines the parallelization backend to use:ThreadsParallelization
: Uses Julia'sThreads.@threads
for parallel execution.QbmapParallelization
: Usesqbmap
for parallel execution.
Returns:
nothing
: The function modifiesspace_output
andspace_land
in place to store the results for each location.
Notes:
Thread-based Parallelization:
- When
ThreadsParallelization
is used, the function distributes the locations across threads usingThreads.@threads
.
- When
Qbmap-based Parallelization:
- When
QbmapParallelization
is used, the function distributes the locations using theqbmap
backend.
- When
Core Execution:
- For each location, the function calls
coreTEM!
to execute the TEM simulation, including spinup (if enabled) and the main time loop.
- For each location, the function calls
Data Safety:
- The function ensures data safety by replicating forcing, output, and land data for each location, avoiding data races during parallel execution.
Examples:
- Parallelizing TEM using threads:
parallelizeTEM!(selected_models, space_forcing, space_spinup_forcing, loc_forcing_t, space_output, space_land, tem_info, ThreadsParallelization())
- Parallelizing TEM using qbmap:
parallelizeTEM!(selected_models, space_forcing, space_spinup_forcing, loc_forcing_t, space_output, space_land, tem_info, QbmapParallelization())
SindbadTEM.runTEMOne Method
runTEMOne(selected_models, forcing, output_array::AbstractArray, land_init, loc_ind, tem)
run the SINDBAD TEM for one time step
Arguments:
selected_models
: a tuple of all models selected in the given model structureloc_forcing
: a forcing NT for a single locationland_init
: initial SINDBAD land with all fields and subfieldstem
: a nested NT with necessary information of helpers, models, and spinup needed to run SINDBAD TEM and models
Returns:
loc_forcing_t
: the forcing NT for the current time steploc_land
: the SINDBAD land NT after a run of model for one time step. This contains all the variables from the selected models and their structure and type will remain the same across the experiment.
SindbadTEM.sequenceForcing Method
sequenceForcing(spinup_forcings::NamedTuple, forc_name::Symbol)
Processes and sequences forcing data for spinup simulations.
Arguments
spinup_forcings::NamedTuple
: A named tuple containing the forcing data for different spinup sequenceforc_name::Symbol
: Symbol indicating the name of the forcing data set to be extracted from the NT for the given sequence
SindbadTEM.setSpinupLog Function
setSpinupLog(land, log_index, spinup_log_mode)
Stores or skips the spinup log during the spinup process, depending on the specified spinup_log_mode
.
Arguments:
land
: A SINDBAD NamedTuple containing all variables for a given time step, which is overwritten at every timestep.log_index
: The index in the spinup log where the current state ofland.pools
will be stored.spinup_log_mode
: A type dispatch that determines whether to store the spinup log:DoStoreSpinup
: Enables storing the spinup log at the specifiedlog_index
. Set thestore_spinup
flag totrue
in flag section of experiment_json.DoNotStoreSpinup
: Skips storing the spinup log. Set thestore_spinup
flag tofalse
in flag section of experiment_json.
Returns:
land
: The updated SINDBAD NamedTuple, potentially with the spinup log stored.
Notes:
When
DoStoreSpinup
is used:- The function stores the current state of
land.pools
inland.states.spinuplog
at the specifiedlog_index
.
- The function stores the current state of
When
DoNotStoreSpinup
is used:- The function does nothing and simply returns the input
land
.
- The function does nothing and simply returns the input
Examples:
- Storing the spinup log:
land = (pools = ..., states = (spinuplog = Vector{Any}(undef, 10)))
log_index = 1
land = setSpinupLog(land, log_index, DoStoreSpinup())
- Skipping the spinup log:
land = (pools = ..., states = (spinuplog = Vector{Any}(undef, 10)))
log_index = 1
land = setSpinupLog(land, log_index, DoNotStoreSpinup())
SindbadTEM.spinupSequence Method
spinupSequence(spinup_models, sel_forcing, loc_forcing_t, land, tem_info, n_timesteps, log_index, n_repeat, spinup_mode)
Executes a sequence of model spinup iterations for the Terrestrial Ecosystem Model (TEM).
Arguments
spinup_models
: Collection of model configurations for spinupsel_forcing
: Selected forcing dataloc_forcing_t
: Localized forcing data with temporal componentland
: Land surface parameterstem_info
: TEM model information and parametersn_timesteps
: Number of timesteps for the spinuplog_index
: Index for logging purposesn_repeat
: Number of times to repeat the spinup sequencespinup_mode
: Mode of spinup operation (e.g., "normal", "accelerated")
Description
Performs model spinup by running multiple iterations of the TEM model to achieve steady state conditions. The function handles different spinup modes and manages the sequence of model runs according to specified parameters.
Returns
land with the updated pools after the spinup sequence.
SindbadTEM.spinupSequenceLoop Method
spinupSequenceLoop(spinup_models, sel_forcing, loc_forcing_t, land, tem_info, n_timesteps, log_loop, n_repeat, spinup_mode)
Runs sequential loops for model spin-up simulations for each repeat of a spinup sequence.
Arguments
spinup_models
: Collection of spin-up model instancessel_forcing
: Selected forcing dataloc_forcing_t
: Localized forcing data in temporal dimensionland
: Land surface parameters/conditionstem_info
: Model configuration and parameters for TEMn_timesteps
: Number of timesteps to simulatelog_loop
: Boolean flag for logging loop informationn_repeat
: Number of times to repeat the spin-up loopspinup_mode
: Mode of spin-up simulation (e.g., "normal", "accelerated")
SindbadTEM.timeAggregateForcingV Method
getSpinupForcing(forcing, loc_forcing_t, time_aggregator, tem_helpers, ::TimeIndexed)
aggregate the forcing variable with time where an aggregation/collection is needed in time
Arguments:
v
: a forcing variableaggregator
: a time aggregator object/index needed to slice data::TimeIndexed
: a type dispatch to just slice the variable time series using index
SindbadTEM.timeAggregateForcingV Method
getSpinupForcing(forcing, loc_forcing_t, time_aggregator, tem_helpers, ::TimeIndexed)
aggregate the forcing variable with time where an aggregation/collection is needed in time
Arguments:
v
: a forcing variableaggregator
: a time aggregator object needed to time aggregate the dataag_type::TimeNoDiff
: a type dispatch to indicate that the variable has to be aggregated in time
SindbadTEM.timeLoopTEM Function
timeLoopTEM(selected_models, loc_forcing, loc_forcing_t, land_time_series, land, tem_info, debug_mode)
timeLoopTEM(selected_models, loc_forcing, loc_forcing_t, land, tem_info, debug_mode)
Executes the time loop for the SINDBAD Terrestrial Ecosystem Model (TEM), running the model for each time step using the provided forcing data and updating the land. There are two major variants with and without the preallocated land time series. In the debug mode only 1 time step is executed for debugging the allocations in each model.
Arguments:
selected_models
: A tuple of all models selected in the given model structure.loc_forcing
: A forcing NamedTuple containing the time series of environmental drivers for all locations.loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.land_time_series
: A preallocated vector (length = number of time steps) to store SINDBAD land states for each time step.land
: A SINDBAD NamedTuple containing all variables for a given time step, which is overwritten at every time step.tem_info
: A helper NamedTuple containing necessary objects for model execution and type consistencies.debug_mode
: A type dispatch that determines whether debugging is enabled or disabled:DoDebugModel
: Runs the model for a single time step and displays debugging information (e.g., allocations, execution time). Setdebug_model
totrue
in flag section of experiment_json.DoNotDebugModel
: Runs the model for all time steps without debugging. Setdebug_model
tofalse
in flag section of experiment_json.
Returns:
nothing
: The function modifiesland_time_series
in place to store the results for each time step.
Notes:
For each time step:
The function retrieves the forcing data for the current time step using
getForcingForTimeStep
.The model is executed using
computeTEM
, which updates the land state.The updated land state is stored in
land_time_series
.
When
DoDebugModel
is used:- The function runs the model for a single time step and logs debugging information, such as execution time and memory allocations.
When
DoNotDebugModel
is used:- The function runs the model for all time steps in a loop.
Examples:
- Running the time loop without debugging:
timeLoopTEM(selected_models, loc_forcing, loc_forcing_t, land_time_series, land, tem_info, DoNotDebugModel())
- Running the time loop with debugging:
timeLoopTEM(selected_models, loc_forcing, loc_forcing_t, land_time_series, land, tem_info, DoDebugModel())
SindbadTEM.timeLoopTEM! Function
timeLoopTEM!(selected_models, loc_forcing, loc_forcing_t, loc_output, land, forcing_types, model_helpers, output_vars, n_timesteps, debug_mode)
Executes the time loop for the SINDBAD Terrestrial Ecosystem Model (TEM), running the model for each time step and storing the outputs in preallocated arrays.
Arguments:
selected_models
: A tuple of all models selected in the given model structure.loc_forcing
: A forcing NamedTuple containing the time series of environmental drivers for a single location.loc_forcing_t
: A forcing NamedTuple for a single location and a single time step.loc_output
: A preallocated output array or view for storing the model outputs for a single location.land
: A SINDBAD NamedTuple containing all variables for a given time step, which is overwritten at every time step.forcing_types
: A NamedTuple specifying the types of forcing variables (e.g., time-dependent or constant).model_helpers
: A NamedTuple containing helper functions and configurations for model execution.output_vars
: A list of output variables to be stored for each time step.n_timesteps
: The total number of time steps to run the simulation.debug_mode
: A type dispatch that determines whether debugging is enabled or disabled:DoDebugModel
: Runs the model for a single time step and logs debugging information (e.g., allocations, execution time). Setdebug_model
totrue
in flag section of experiment_json.DoNotDebugModel
: Runs the model for all time steps without debugging. Setdebug_model
tofalse
in flag section of experiment_json.
Returns:
nothing
: The function modifiesloc_output
in place to store the results for each time step.
Notes:
Forcing Retrieval:
- For each time step, the function retrieves the forcing data using
getForcingForTimeStep
.
- For each time step, the function retrieves the forcing data using
Model Execution:
- The model is executed using
computeTEM
, which updates the land state.
- The model is executed using
Output Storage:
- The updated land state is stored in the preallocated
loc_output
array usingsetOutputForTimeStep!
.
- The updated land state is stored in the preallocated
Debugging:
- When
DoDebugModel
is used, the function logs detailed debugging information for a single time step, including execution time and memory allocations.
- When
Examples:
- Running the time loop without debugging:
timeLoopTEM!(selected_models, loc_forcing, loc_forcing_t, loc_output, land, forcing_types, model_helpers, output_vars, n_timesteps, DoNotDebugModel())
- Running the time loop with debugging:
timeLoopTEM!(selected_models, loc_forcing, loc_forcing_t, loc_output, land, forcing_types, model_helpers, output_vars, n_timesteps, DoDebugModel())
SindbadTEM.unpackYaxForward Method
unpackYaxForward(args; tem::NamedTuple, forcing_vars::AbstractArray)
unpack the input and output cubes from all cubes thrown by mapCube
Arguments:
all_cubes
: collection/tuple of all input and output cubesforcing_vars
: forcing variablesoutput_vars
: output variables