Type: | Package |
Title: | Stable Isotope Box Modelling in R |
Version: | 2.0.0 |
Description: | A set of functions to run simple and composite box-models to describe the dynamic or static distribution of stable isotopes in open or closed systems. The package also allows the sweeping of many parameters in both static and dynamic conditions. The mathematical models used in this package are derived from Albarede, 1995, Introduction to Geochemical Modelling, Cambridge University Press, Cambridge <doi:10.1017/CBO9780511622960>. |
Depends: | R (≥ 3.5.0) |
License: | GPL-3 |
URL: | https://github.com/ttacail/isobxr, https://ttacail.github.io/isobxr_web/, https://ttacail.github.io/isobxr/ |
BugReports: | https://github.com/ttacail/isobxr/issues |
Encoding: | UTF-8 |
Imports: | stringr, readxl, dplyr, data.table, deSolve, rlang (≥ 0.4.11), grid, ggplot2, ggrepel, qgraph, writexl, R.utils, fs, magrittr, tidyr, gridExtra, purrr, reshape2, tictoc |
RoxygenNote: | 7.2.1 |
Suggests: | knitr, rmarkdown, devtools, MASS, roxygen2, tidyselect, grDevices |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2023-08-23 10:21:54 UTC; sz18642 |
Author: | Theo Tacail [aut, cre] |
Maintainer: | Theo Tacail <theo.tacail@protonmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-08-23 14:50:03 UTC |
isobxr: Stable Isotope Box Modelling in R
Description
A set of functions to run simple and composite box-models to describe the dynamic or static distribution of stable isotopes in open or closed systems. The package also allows the sweeping of many parameters in both static and dynamic conditions. The mathematical models used in this package are derived from Albarede, 1995, Introduction to Geochemical Modelling, Cambridge University Press, Cambridge doi:10.1017/CBO9780511622960.
Author(s)
Maintainer: Theo Tacail theo.tacail@protonmail.com
See Also
Useful links:
Report bugs at https://github.com/ttacail/isobxr/issues
Calculate delta values at t time with ODE solutions from ana_slvr
Description
Calculate the delta values at t time using the ODE analytical solutions of the isotopic box model.
Usage
ANA_delta_t_Calculator(
t,
ODE_Constants,
ODE_Eigenvalues,
ODE_Eigenvectors,
BOXES_IDs,
ratio_standard
)
Arguments
t |
Time at which the delta values are to be calculated (numeric) |
ODE_Constants |
Constants as determined by the analytical solver for the system of |
ODE_Eigenvalues |
Eigenvalues as determined by the analytical solver for the system of |
ODE_Eigenvectors |
Eigenvectors as determined by the analytical solver for the system of |
BOXES_IDs |
Vector of character strings with the names of the boxes |
ratio_standard |
Isotope ratio of the reference material used to calculate the delta values. |
Value
Dataframe of the delta values in all boxes at t time.
Verticalizes a dataframe
Description
Takes a dataframe with a set of different columns containing numerical values to be verticalized, returns a vertical dataframe with all variables in a single column called "VAR" together with a "VAR_TYPE" column defining the type of variable for the given row, named after the column name found in horizontal dataframe.
Usage
DF_verticalizer(df_hor, vert_col)
Arguments
df_hor |
Horizontal dataframe |
vert_col |
Vector of the names of the columns of numerical variables to be verticalized. |
Value
A vertical dataframe containing the variables to be verticalized (column "VAR", numeric) and the name of the variable (column "VAR_TYPE", character strings).
Gauge of calculation
Description
Prints a gauge of the calculation progress
Usage
calculation_gauge(i, len)
Arguments
i |
Calculating step number |
len |
Total calculation steps |
Value
A print summarizing the progress of calculation
check_FORCINGS
Description
A function to check the formatting data frames used as forcing inputs
in several functions (e.g., sim.single_run)
Usage
check_FORCINGS(type, FORCING, isobxr_master)
Arguments
type |
Type of forcing. As character. |
FORCING |
Forcing data frame. |
isobxr_master |
Isobxr master as a list as returned from read_isobxr_master |
Value
aborts run if a mistake is found
Clear a subset
Description
Takes a previously subsetted dataframe, clears its deleted levels and resets its row indexes.
Usage
clear_subset(dataset)
Arguments
dataset |
Previously subsetted dataframe. |
Value
Cleared dataframe.
corr_stats
Description
edits dataframe report of linear regression and correlation tests (Pearson and Spearman)
Usage
corr_stats(data_lm, X, Y, as_character = F, n = 3, m = 4)
Arguments
data_lm |
a data frame with X and Y data |
X |
name of X variable column (character) |
Y |
name of Y variable column (character) |
as_character |
reports statistics formatted as characters. Default is FALSE. |
n |
number of digits to display in correlation coefficient/rho. Default is 3. Only used if as_character = T. |
m |
number of digits to display in regression equation parameters (slope, y-intercept). Default is 4. Only used if as_character = T. |
Value
report of regression and correlation tests
Print a number with 0 decimal figures
Description
Takes a numerical value and returns a string of the rounded value, with 0 decimal figures.
Usage
dec_0(x)
Arguments
x |
Numerical value |
Value
A character string with 0 decimal figures.
Print a number with 1 decimal figures
Description
Takes a numerical value and returns a print with 1 decimal figures.
Usage
dec_1(x)
Arguments
x |
Numerical value |
Value
A character string with 1 decimal figure.
Print a number with 2 decimal figures
Description
Takes a numerical value and returns a print with 2 decimal figures.
Usage
dec_2(x)
Arguments
x |
Numerical value |
Value
A character string with 2 decimal figures.
Print a number with 3 decimal figures
Description
Takes a numerical value and returns a print with 3 decimal figures.
Usage
dec_3(x)
Arguments
x |
Numerical value |
Value
A character string with 3 decimal figures.
Print a number with 4 decimal figures
Description
Takes a numerical value and returns a print with 4 decimal figures.
Usage
dec_4(x)
Arguments
x |
Numerical value |
Value
A character string with 4 decimal figures.
Print a number with n decimal figures
Description
Takes a numerical value and returns a print with n decimal figures.
Usage
dec_n(x, n)
Arguments
x |
Numerical value |
n |
number of decimals |
Value
A character string with 4 decimal figures.
Delete rows of a dataframe containing NaN values in a given column
Description
Delete rows of a dataframe containing NaN values in a given column
Usage
del_NaN_rows(dataframe, by_col, resetrows)
Arguments
dataframe |
dataframe |
by_col |
Name of column from which NaN values should be removed. Character string. |
resetrows |
Logical value to reset the row numbering or not. |
Value
Subset of dataframe without the rows containing NaN values in column by_col
Fit n parameters to observations
Description
A function to find the combinations of values of n parameters producing final state delta values fitting within confidence intervals of observations.
Usage
fit.final_space(
workdir,
obs_file_name,
sweep_space_digest_folders,
fit_name = NULL,
output_dir = NULL,
delta_reference_box = NaN,
excluded_boxes = NULL,
print_correlogram = FALSE,
print_lda = FALSE,
print_LS_surfaces = FALSE,
parameter_subsets = NULL,
custom_expressions = NULL,
save_outputs = FALSE,
export_fit_data = FALSE
)
Arguments
workdir |
Working directory of 0_ISOBXR_MASTER.xlsx master file, |
obs_file_name |
Name of csv file containing observations with csv extension.
|
sweep_space_digest_folders |
Name of sweep.final_nD digest directory. |
fit_name |
Name given to specific fit. If NULL, output are named after date and time of fit. |
output_dir |
Destination directory for fit outputs. If NULL, outputs are stored in sweep_space_digest_folders directory. Default is NULL. |
delta_reference_box |
BOX ID of reference box, used to calculate difference
between any box delta and reference box delta. Default is NaN. |
excluded_boxes |
list of boxes to exclude from fit. Default is NULL. |
print_correlogram |
If TRUE, includes correlograms to final report when applicable. |
print_lda |
If TRUE, includes linear discriminant analysis to final report
when applicable. |
print_LS_surfaces |
If TRUE, includes surfaces of least squarred residuals
to final report when applicable. |
parameter_subsets |
List of limits vectors for parameters to subset before fit. |
custom_expressions |
Vector of expressions to add to the list of fitted parameters. |
save_outputs |
If TRUE, saves all run outputs to local working directory (workdir). |
export_fit_data |
If TRUE, exports fitted data as csv and rds files. |
Value
A observation fit graphical report, in R session or exported as pdf, and a data report as R list or xlsx if required.
Merge results from all chunks of a given sweep.final_nD run
Description
Merge results from all chunks of a given sweep.final_nD run
Usage
merge_FINnD_chunks(workdir, FINnD_digest_dir.to_merge, save_outputs = FALSE)
Arguments
workdir |
Working directory of 0_ISOBXR_MASTER.xlsx master file, |
FINnD_digest_dir.to_merge |
Name of sweep.final_nD digest directory
to which current chunks should be merged. |
save_outputs |
If TRUE, saves merged chunks outputs to sweep.final_nD digest directory. |
Value
Merged chunks sweep.final_nD outputs, including results, chunk logs, chunked parameter spaces.
Collate multiple ggplot object into a grid format
Description
Takes a list of ggplot objects and returns a single object with a grid of the ggplot objects.
ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
- cols: Number of columns in layout
- layout: A matrix specifying the layout. If present, 'cols' is ignored.
If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
multiplot(a, b, c, layout = matrix(c(1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3), nrow=1, byrow=TRUE))
then plot 1 will go in the upper left, 2 will go in the upper right, and
3 will go all the way across the bottom.
Usage
multiplot(..., plotlist = NULL, file, cols = 1, layout = NULL)
Arguments
... |
initiation of plot list (ggplot objects) |
plotlist |
the list of plots |
file |
file |
cols |
number of columns for the facetting |
layout |
user defined matrix layout (numeric matrix). default is NULL. |
Value
A plot composed of multiple subplots.
plot_LS_surfaces_ADSR
Description
Plot surfaces of summed squared residuals.
Usage
plot_LS_surfaces_ADSR(DF, names.swp.ADSR)
Arguments
DF |
fit.final_space data frame |
names.swp.ADSR |
names of swept ADSR parameters (alpha, delta, size, rayleigh, custom expressions), as vector |
Value
A plot of surfaces of summed squared residuals for each ADSR parameter.
plot_LS_surfaces_lists
Description
Plot surfaces of summed squared residuals.
Usage
plot_LS_surfaces_lists(DF, names.swp.lists)
Arguments
DF |
fit.final_space data frame |
names.swp.lists |
names of swept list parameters (flux and coeff lists), as vector |
Value
A plot of surfaces of summed squared residuals for flux lists and coeff lists.
plot_correlogram_all_CIfit
Description
Plot correlogram of CI fitted ADSR parameter values
Usage
plot_correlogram_all_CIfit(DF, names.swp.ADSR)
Arguments
DF |
fit.final_space data frame |
names.swp.ADSR |
names of swept ADSR parameters (alpha, delta, size, rayleigh, custom expressions), as vector |
Value
A correlogram of CI fitted ADSR parameter values
plot_diagram
Description
plot diagrams for fluxes and coefficients using the qgraph network function
Usage
plot_diagram(input, title, matrix_layout, BOXES_master_loc, COEFF_FLUX)
Arguments
input |
matrix of fluxes or coefficients |
title |
title of diagram |
matrix_layout |
matrix of X,Y layout |
BOXES_master_loc |
BOXES_master_loc |
COEFF_FLUX |
"COEFF" or "FLUX" |
Value
diagrams for console or pdf edition (not used in shinobxr)
plot sweep.dyn_2D outputs
Description
A function to plot delta vs time from the sweep.dyn_2D runs
Usage
plot_dyn_2D(
workdir,
sweep_dir_name,
time_unit = NULL,
time_range = NULL,
hidden_boxes = NULL,
return_as_print = TRUE,
free_y_scale = TRUE,
swap_sweep_params = FALSE,
show.delta_drift = FALSE,
time_as_log10 = TRUE
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
sweep_dir_name |
Full name of sweep.dyn_2D SERIES directory (character string) |
time_unit |
Time unit to use on plot if different from native time unit. |
time_range |
Time range to zoom on as vector of two values, such as: c(0,100) |
List of boxes to hide from plots, as a vector of character strings. | |
return_as_print |
If TRUE, prints delta and size vs. time plots in a single page figure on R. |
free_y_scale |
If TRUE, frees Y axis scale. |
swap_sweep_params |
If TRUE, swaps the sweep parameter 1 and 2 representations
from color to facet scales. |
show.delta_drift |
If TRUE, displays drift of delta values from t0. |
time_as_log10 |
If TRUE, uses logarithmic time scale in plot. |
Value
A set of plots showing the evolution of delta and sizes with time.
plot_freq_ADSR
Description
Plot frequency profiles by fitted parameter of ADSR types
Usage
plot_freq_ADSR(DF, names.swp.ADSR, parameter_subsets)
Arguments
DF |
fit.final_space data frame |
names.swp.ADSR |
names of swept ADSR parameters (alpha, delta, size, rayleigh, custom expressions), as vector |
parameter_subsets |
parameter subsets passed from fit.final_space |
Value
A frequency plot of fitted parameter values.
plot_freq_coeff
Description
Plot frequency profiles by fitted coeff lists
Usage
plot_freq_coeff(DF, parameter_subsets)
Arguments
DF |
fit.final_space data frame |
parameter_subsets |
fitted coeff lists subsets passed from fit.final_space |
Value
A frequency plot of fitted parameter values.
plot_freq_flux
Description
Plot frequency profiles by fitted flux lists
Usage
plot_freq_flux(DF, parameter_subsets)
Arguments
DF |
fit.final_space data frame |
parameter_subsets |
fitted flux lists subsets passed from fit.final_space |
Value
A frequency plot of fitted parameter values.
plot_lda
Description
Plot linear discriminant analysis by quartiles of summed squared residuals for all ADSR parameters
Usage
plot_lda(DF, names.swp.ADSR)
Arguments
DF |
fit.final_space data frame |
names.swp.ADSR |
names of swept ADSR parameters (alpha, delta, size, rayleigh, custom expressions), as vector |
Value
A linear discriminant analysis by quartiles of summed squared residuals for all ADSR parameters
plot relaxation
Description
A function to plot the relaxation of isotope ratios in a system, including characteristic times
Usage
plot_relaxation(
workdir,
flux_list,
coeff_list,
spiked_boxes,
spike.max_delta = 100,
n_steps = 10000,
hidden_boxes = NULL,
show.residence_time = TRUE,
show.facets = FALSE,
time_landmarks = NULL,
time_as_log10 = TRUE,
isobxr_master_file = "0_ISOBXR_MASTER",
time.resolution_cut = NULL
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
flux_list |
Name of the list of fluxes and initial box sizes to be used for the run, |
coeff_list |
Name of the list of fractionation coefficients to be used for the run, |
spiked_boxes |
Vector of box names ("BOX_ID") to be spiked. |
spike.max_delta |
Value of the maximum spike isotope composition |
n_steps |
Number of calculation steps. Determines the resolution of the run. |
Vector of boxes to hide from plots. | |
show.residence_time |
If TRUE, displays box-specific residence times on plot. |
show.facets |
If TRUE, displays results in box-specific facets. |
time_landmarks |
Vector of time landmarks to display on x-axis (numerical values). |
time_as_log10 |
If TRUE, uses logarithmic time scale in plot. |
isobxr_master_file |
Name of isobxr excel master file. |
time.resolution_cut |
Time below which resolution is increased. Default is NULL. |
Value
A plots showing the evolution of the isotopic ratios in the system until full relaxation,
defined as the maximum relaxation time multiplied by 10.
Examples
## Not run:
plot_relaxation(workdir = "/Users/username/Documents/1_ABC_tutorial",
flux_list = "Fx6_ABC_open_bal",
coeff_list = "a0",
n_steps = 1000,
spiked_boxes = c("SOURCE"))
## End(Not run)
plot sim.scenario outputs
Description
A function to plot delta and size vs time from the sim.scenario runs and to include observations along simulations.
Usage
plot_scenario(
workdir,
scenario_dir_name,
shown_runs = NULL,
time_unit = NULL,
hidden_boxes = NULL,
return_as_print = TRUE,
show.facets = FALSE,
show.run_separations = TRUE,
observations_file = NULL,
observations_groups = NULL
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
scenario_dir_name |
name of sim.scenario SERIES directory (starts with 3_SCEN) |
shown_runs |
Vector of successive run numbers (RUN_n) to be displayed (e.g., 1:5). |
time_unit |
Time unit to use on plot if different from native time unit. |
List of boxes to hide from plots, as a vector of character strings. | |
return_as_print |
If TRUE, prints delta and size vs. time plots in a single page figure on R. |
show.facets |
If TRUE, shows delta vs. time as faceted by BOX. |
show.run_separations |
If TRUE, shows limits between subruns. |
observations_file |
Name of the csv file containing observations (without csv extension).
Default is NULL. |
observations_groups |
vector of observations groups to include in plot, |
Value
A set of plots showing the evolution of delta and sizes with time.
plot_sim_distrib
Description
Plot distributions of all and fitted simulations
Usage
plot_sim_distrib(DF, fit.counts, observations, bx.fit)
Arguments
DF |
fit.final_space data frame |
fit.counts |
counts of simulations by groups passed from fit.final_space |
observations |
data frame of observations |
bx.fit |
list of boxes fitted and unfitted groups and subgroups passed from fit.final_space |
Value
A plot of distributions of all and fitted simulations
plot_sim_obs
Description
Plot simulations against observations
Usage
plot_sim_obs(DF, bx.fit, fit.counts)
Arguments
DF |
fit.final_space data frame |
bx.fit |
list of boxes fitted and unfitted groups and subgroups passed from fit.final_space |
fit.counts |
counts of simulations by groups passed from fit.final_space |
Value
A plot of fitted simulated delta values against observations
plot sim.single_run outputs
Description
A function to plot delta and size vs time from the sim.single_run outputs
Usage
plot_single_run(
workdir,
RUN_ID,
time_as_log10 = TRUE,
time_unit = NULL,
hidden_boxes = NULL,
return_as_print = TRUE
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
RUN_ID |
ID of the run (formerly SERIES_RUN_ID). Corresponds to the name of the .rds file storing the results of the run. |
time_as_log10 |
If TRUE, uses logarithmic time scale in plot. |
time_unit |
Time unit to use on plot if different from native time unit. |
List of boxes to hide from plots, as a vector of character strings. | |
return_as_print |
If TRUE, prints delta and size vs. time plots in a single page figure on R. |
Value
A set of plots showing the evolution of delta and sizes with time.
Preventing any console prints (for sweepers only)
Description
Preventing any console prints (for sweepers only)
Usage
quiet(x)
Arguments
x |
function to quiet |
Value
No return value, called for side effects
Read and inspect sweep.dyn_2D master files
Description
A function to read and inspect the sweep.dyn_2D master files and obtain a master formatted list.
Usage
read.dyn_2D_master(workdir, dyn_2D_master_file, isobxr_master_file)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
dyn_2D_master_file |
Name of sweep.dyn_2D excel master file. (without file "xlsx" extension). |
isobxr_master_file |
Name of isobxr excel master file. (without file "xlsx" extension). Default is "0_ISOBXR_MASTER". |
Value
List of formatted dyn_2D_master_file master inputs.
Examples
read.dyn_2D_master(workdir = "/Users/username/Documents/1_ABC_tutorial",
dyn_2D_master_file = "0_SWEEP_DYN_demo",
isobxr_master_file = "0_ISOBXR_MASTER")
Read and inspect sweep.final_nD master files
Description
A function to read and inspect the sweep.final_nD master files and obtain a master formatted list.
Usage
read.final_nD_master(workdir, final_nD_master_file, isobxr_master_file)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
final_nD_master_file |
Name of sweep.final_nD excel master file. (without file "xlsx" extension). |
isobxr_master_file |
Name of isobxr excel master file. (without file "xlsx" extension). Default is "0_ISOBXR_MASTER". |
Details
List contains:
-
param_space data frame of shuffled all combinations of all parameters values.
-
sweep.DEFAULT data frame of default run conditions
(flux and coeff lists, t_max, chunk size) -
sweep_lists_ids list of names of swept parameters
Value
List of formatted sweep.final_nD master inputs
Examples
read.final_nD_master(workdir = "/Users/username/Documents/1_ABC_tutorial",
final_nD_master_file = "0_SWEEP_FINnD_demo",
isobxr_master_file = "0_ISOBXR_MASTER")
Read and inspect isobxr master files
Description
A function to read and inspect the isobxr master files and obtain a master formatted list.
Usage
read.isobxr_master(
workdir,
isobxr_master_file = "0_ISOBXR_MASTER",
inspect = TRUE,
export_rds = FALSE
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
isobxr_master_file |
Name of isobxr excel master file. (without file "xlsx" extension). Default is "0_ISOBXR_MASTER". |
inspect |
If TRUE, checks all inputs from isobxr master file for format
and structure errors. |
export_rds |
If TRUE, exports rds version of isobxr master file
to working directory. |
Value
A formatted list of data frames containing constants, box, fluxes and fractionation coefficients descriptions.
Examples
read.isobxr_master(workdir = "/Users/username/Documents/1_ABC_tutorial",
isobxr_master_file = "0_ISOBXR_MASTER",
export_rds = FALSE,
inspect = TRUE)
Read and inspect scenario master files
Description
A function to read and inspect the scenario master files and obtain a master formatted list.
Usage
read.scenario_master(
workdir,
scenario_master_file,
isobxr_master_file = "0_ISOBXR_MASTER"
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
scenario_master_file |
Name of scenario excel master file. (without file "xlsx" extension). |
isobxr_master_file |
Name of isobxr excel master file. (without file "xlsx" extension). Default is "0_ISOBXR_MASTER". |
Value
List of formatted scenario master inputs.
Examples
read.scenario_master(workdir = "/Users/username/Documents/1_ABC_tutorial",
scenario_master_file = "0_SCENARIO_source_change",
isobxr_master_file = "0_ISOBXR_MASTER")
edits a full dataframe of significance symbols from a dataframe of p-values
Description
edits a full dataframe of significance symbols from a dataframe of p-values
Symbols as asterisks denote p-values lower than .0001, .001, .01, .05. ns refers to non significant (higher than .5).
Usage
significance_pval_df(x)
Arguments
x |
a data frame column of p-values or a pvalues as double (alone or in vector). |
Value
p-values symbols as dataframe or as string.
Simulate a scenario
Description
A function to compose an isotope box model scenario,
defined by a series of successive runs,
each run inheriting from the final state conditions of the previous run.
It is possible to force parameters at each run, namely:
-
fluxes
(overwriting all or a subset of fluxes defined in 0_ISOBXR_MASTER.xlsx master file) -
isotope fractionation coefficients
(overwriting all or a subset of coefficients defined in 0_ISOBXR_MASTER.xlsx master file) -
box sizes
(overwriting all or a subset of box sizes defined in 0_ISOBXR_MASTER.xlsx master file) -
rayleigh isotope distillation
-
isotope composition of a source box at initial state
Usage
sim.scenario(
workdir,
SERIES_ID,
scenario_master_file,
isobxr_master_file = "0_ISOBXR_MASTER",
plot.hidden_boxes = NULL,
plot.time_unit = NULL,
export.single_run_digests = FALSE,
export.data_as_csv_xlsx = FALSE,
show.delta_plot = TRUE,
save_outputs = FALSE,
inspect_inputs = TRUE
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. |
SERIES_ID |
Name of the series the scenario run belongs to. It determines the folder in which the output files will be stored inside workdir. |
scenario_master_file |
Name of scenario excel master file. |
isobxr_master_file |
Name of isobxr excel master file. |
list of box names (BOX_ID) to hide in scenario plot. | |
plot.time_unit |
Time unit to use on plot if different from native time unit. |
export.single_run_digests |
If TRUE, exports full digest of each single run of the scenario. Default is FALSE. |
export.data_as_csv_xlsx |
If TRUE, exports full scenario result data as csv and xlsx fo full
to scenario digest directory. |
show.delta_plot |
If TRUE, prints delta and size time evolution plots in R. |
save_outputs |
If TRUE, saves all run outputs to local working directory (workdir). |
inspect_inputs |
If TRUE, inspects and proof checks format of input taken from
isobxr excel master file. |
Value
Delta values and box sizes as a function of time.
sim.scenario outputs are saved to workdir if save_outputs = TRUE.
sim.scenario outputs consist of
-
single run results in SERIES directory: all single runs results as rds files
-
scenario digest in scenario DIGEST directory (SERIES/DIGEST):
-
isobxr master file archive as xlsx
-
scenario master file archive as xlsx
-
plot of delta and size vs. time as pdf
-
scenario results data set as rds, containing:
-
delta_vs_t data frame of delta as a function of time
-
size_vs_t data frame of box sizes as a function of time
-
scenario_master list containing all inputs from scenario master file
-
scenario_log data frame of scenario specific LOG excerpt
-
isobxr_master list containing all inputs from isobxr master file
-
paths list of scenario specific paths
-
-
Examples
## Not run:
sim.scenario(workdir = "/Users/username/Documents/1_ABC_tutorial",
SERIES_ID = "1_source_change",
scenario_master_file = "0_SCENARIO_source_change",
isobxr_master_file = "0_ISOBXR_MASTER")
## End(Not run)
Run a single isotope box-model simulation
Description
A function to run the isobxr stable isotope box model,
assessing the design of the model and automatically running solve_numerically
or solve_analytically
depending on system design.
Usage
sim.single_run(
workdir,
SERIES_ID,
flux_list,
coeff_list,
t_max,
n_steps,
isobxr_master_file = "0_ISOBXR_MASTER",
suppress_messages = FALSE,
export.diagrams = FALSE,
export.delta_plot = FALSE,
export.data_as_csv_xlsx = FALSE,
plot.time_as_log10 = TRUE,
plot.time_unit = NULL,
show.delta_plot = TRUE,
inspect_inputs = TRUE,
save_outputs = FALSE,
return_data = FALSE,
solver = "auto",
n_zeros_RUN_IDs = 4,
FORCING_RAYLEIGH = NULL,
FORCING_SIZE = NULL,
FORCING_DELTA = NULL,
FORCING_ALPHA = NULL,
COMPOSITE = FALSE,
COMPO_SERIES_n = NaN,
COMPO_SERIES_FAMILY = NaN,
EXPLORER = FALSE,
EXPLO_SERIES_n = NaN,
EXPLO_SERIES_FAMILY = NaN,
isobxr_master = NULL,
diagram_pdf.widh_height = NULL
)
Arguments
workdir |
Working directory of isobxr excel master file and where output files will be stored if exported by user. (character string) |
SERIES_ID |
Name of the series the run belongs to. |
flux_list |
Name of the list of fluxes and initial box sizes to be used for the run, |
coeff_list |
Name of the list of fractionation coefficients to be used for the run, |
t_max |
Run duration, given in the same time units as unit declared in CONSTANTS |
n_steps |
Number of calculation steps. |
isobxr_master_file |
Name of isobxr excel master file. |
suppress_messages |
If TRUE, hides all information and warning messages regarding run. |
export.diagrams |
If TRUE, exports box-model flux and fractionation diagrams as pdf. |
export.delta_plot |
If TRUE, exports delta and size time evolution plots of the evolution
of the system, as pdf. |
export.data_as_csv_xlsx |
If TRUE, exports all results and run conditions as csv and xlsx files, |
plot.time_as_log10 |
If TRUE, uses logarithmic time scale in plot. |
plot.time_unit |
Time unit to use on plot if different from native time unit. |
show.delta_plot |
If TRUE, prints delta and size time evolution plots in R. Default is TRUE. |
inspect_inputs |
If TRUE, inspects and proof checks format of input taken from
isobxr excel master file. |
save_outputs |
If TRUE, saves all run outputs to local working directory (workdir). |
return_data |
If TRUE, returns all data (inputs and outputs) as a list. |
solver |
Determines what solver to used: "analytical" or "numerical". |
n_zeros_RUN_IDs |
Number of figures used in iteration of RUNs of a given series (SERIES_ID). |
FORCING_RAYLEIGH |
OPTIONAL |
FORCING_SIZE |
OPTIONAL |
FORCING_DELTA |
OPTIONAL |
FORCING_ALPHA |
OPTIONAL |
COMPOSITE |
NOT TO BE USED IN SINGLE RUN |
COMPO_SERIES_n |
NOT TO BE USED IN SINGLE RUN |
COMPO_SERIES_FAMILY |
NOT TO BE USED IN SINGLE RUN |
EXPLORER |
NOT TO BE USED IN SINGLE RUN |
EXPLO_SERIES_n |
NOT TO BE USED IN SINGLE RUN |
EXPLO_SERIES_FAMILY |
NOT TO BE USED IN SINGLE RUN |
isobxr_master |
isobxr_master list of input dataframes formatted by
|
diagram_pdf.widh_height |
Vector of width and height in inches of the pdf diagrams. |
Value
A results data set as a list containing the following components:
-
inputs input data:
-
CONSTS data frame of all run specific constants.
-
INITIAL data frame of delta and sizes at t = 0 in all boxes.
-
FLUXES data frame of all fluxes intensities (row ID: FROM / col ID: TO)
-
COEFFS data frame of all fractionation coefficient values (row ID: FROM / col ID: TO)
-
BOX_META data frame of box specific metadata (e.g., flux balance, residence times, layout position )
-
bx.groups list of box names grouped by relevant categories (e.g., disconnected boxes, infinite boxes)
-
LOG data frame of run specific LOG excerpt.
-
-
outputs output data:
-
solver
-
final_state
-
delta_vs_t
-
size_vs_t
-
for analytical solutions
-
diffeq_solutions solutions of differential equations,
including relaxation times, eigenvalues, constants, eigenvectors
-
-
-
paths list of run specific paths
Examples
## Not run:
sim.single_run(workdir = "/Users/username/Documents/1_ABC_tutorial",
SERIES_ID = "1_ABC_balanced_closed",
flux_list = "Fx1_ABC_bal",
coeff_list = "a1",
t_max = 2500,
n_steps = 2500)
## End(Not run)
Analytically solve stable isotope box models
Description
An analytical solver of the system of ordinary differential
equations (ODES) of stable isotope ratios of element X in all boxes.
Not intended for manual use.
The analytical solver finds the eigenvalues and eigenvectors of the ODES.
It determines the set of analytical solutions that describes
the evolution of isotope ratios in each box over time.
Usage
solve_analytically(IN, paths, to_DIGEST_csv = FALSE, return_results = FALSE)
Arguments
IN |
input data, edited by |
paths |
paths object edited by |
to_DIGEST_csv |
if TRUE, edits csv outputs to DIGEST directory |
return_results |
if TRUE, results returned as a list of R objects. |
Value
Analytically determined evolution of stable isotope compositions
in all boxes over the run duration as specified in INPUT file.
Run outputs are stored in a temporary directory and not exported by solve_numerically
.
The outputs of the run are stored in the rds output file in the SERIES directory
with the following file name structure:
SERIES_ID + RUN_n.rds
Optional csv outputs to the DIGEST folder are as follows
OUT data file with initial and final size and delta values in all boxes.
(file name structure: out_1_A_OUT + SERIES_ID + RUN_n + .csv)ODE_SOLNs data file summarizing outputs of the analytical solutions of the ODES
(eigenvalues, eigenvectors, relaxation times, constants according to initial conditions).
(file name structure: out_2_A_ODE_SOLNs + SERIES_ID + RUN_n + .csv)evD data file of the evolution with time of the delta values in all boxes.
(file name structure: out_3_A_evD + SERIES_ID + RUN_n + .csv)
Numerically solve stable isotope box models
Description
A numerical solver of the system of ordinary differential equations (ODES),
describing the evolution of stable isotope ratios in all boxes of a system.
Not intended for manual use.
The numerical solver uses the deSolve::ode function
to integrate the stable isotopes ratios over time in each box. It allows the
calculation of the evolution of stable isotope ratio in the case of
unbalanced outward and inward fluxes of element X in a given box
resulting in the accumulation or loss of element X.
Usage
solve_numerically(IN, paths, to_DIGEST_csv = FALSE, return_results = FALSE)
Arguments
IN |
input data, edited by |
paths |
paths object edited by |
to_DIGEST_csv |
if TRUE, edits csv outputs to DIGEST directory |
return_results |
if TRUE, results returned as a list of R objects. |
Value
Numerically determined evolution of stable isotope compositions
and masses of element X in all boxes over the run duration as specified in INPUT file.
Run outputs are stored in a temporary directory and not exported by solve_numerically
.
The outputs of the run are stored in the rds output file in the SERIES directory
with the following file name structure:
SERIES_ID + RUN_n.rds
Optional csv outputs to DIGEST directory are as follows
OUT data file storing initial and final size and delta values in all boxes.
(file name structure: out_1_N_OUT + RUN name + .csv)evS data file storing the evolution with time of the sizes (masses of element X) of all boxes.
(file name structure: out_2_N_evS + RUN name + .csv)evD data file storing the evolution with time of the delta values in all boxes.
(file name structure: out_3_N_evD + RUN name + .csv)
Sweep the space of two parameters during the response to a perturbation
Description
A function to assess the influence of two parameters (varying over a range of values) on dynamic evolution of a system in response to a given perturbation.
Usage
sweep.dyn_2D(
workdir,
SERIES_ID,
plot.time_unit = NULL,
isobxr_master_file = "0_ISOBXR_MASTER",
sweep_master_file,
swept_param_1,
swept_param_2,
export.data_as_csv_xlsx = TRUE,
show.delta_plot = TRUE,
save_outputs = FALSE,
ask_confirmation = TRUE,
keep_single_run_rds = FALSE
)
Arguments
workdir |
Working directory of 0_ISOBXR_MASTER.xlsx master file, |
SERIES_ID |
Name of the sweep series belongs to. |
plot.time_unit |
Time unit to use on plot if different from native time unit. |
isobxr_master_file |
Name of isobxr excel master file. |
sweep_master_file |
Name of sweep.dyn_2D excel master file. (without file "xlsx" extension). |
swept_param_1 |
Set of values of sweeping parameter 1. |
swept_param_2 |
Set of values of sweeping parameter 2. |
export.data_as_csv_xlsx |
If TRUE, exports full sweep result data as csv and xlsx fo full
to sweep digest directory. |
show.delta_plot |
If TRUE, prints delta and size time evolution plots in R. |
save_outputs |
If TRUE, saves all run outputs to local working directory (workdir). |
ask_confirmation |
If TRUE, asks confirmation to run in interactive sessions. |
keep_single_run_rds |
If TRUE, keeps single runs outputs (rds files in SERIES directory). |
Value
Delta values and box sizes as a function of time in response to a perturbation, in a 2D space of parameters sweep.dyn_2D outputs are saved to workdir if save_outputs = TRUE.
sweep.dyn_2D outputs consist of
-
single run results in SERIES directory: all single runs results as rds files
(keep_single_run_rds = TRUE) -
sweep digest in sweep DIGEST directory (SERIES/DIGEST):
-
isobxr master file archive as xlsx (export.data_as_csv_xlsx = TRUE)
-
sweep.dyn_2D master file archive as xlsx (export.data_as_csv_xlsx = TRUE)
-
sweep.dyn_2D LOG excerpt as csv (export.data_as_csv_xlsx = TRUE)
-
delta_size_vs_t csv of delta and size vs time in 2D space (export.data_as_csv_xlsx = TRUE)
-
plot of delta and size vs. time in 2D space as pdf
-
sweep.dyn_2D results data set as rds, containing:
-
delta_size_vs_t data frame of delta and size as a function of time
-
sweeep_master list containing all inputs from sweep master file
-
sweep_log data frame of sweep specific LOG excerpt
-
isobxr_master list containing all inputs from isobxr master file
-
paths list of sweep specific paths
-
-
Examples
## Not run:
sweep.dyn_2D(workdir = "/Users/username/Documents/1_ABC_tutorial",
SERIES_ID = "sweep_dyn_test",
isobxr_master_file = "0_ISOBXR_MASTER",
sweep_master_file = "0_SWEEP_DYN_demo",
swept_param_1 = data.frame(FROM = c("A"),
TO = c("C"),
ALPHA_MIN = 0.999,
ALPHA_MAX = 1,
ALPHA_STEPS = 0.0005,
EXPLO_TYPES = "EXPLO_1_ALPHA"),
swept_param_2 = data.frame(BOX_ID = c("B"),
SIZE_MIN = 2100,
SIZE_MAX = 3000,
SIZE_STEPS = 300,
EXPLO_TYPES = "EXPLO_1_SIZE"),
ask_confirmation = FALSE)
## End(Not run)
Sweep the space of n parameters at the final state of a system
Description
A function to assess the influence of n parameters (varying over a range of values) on the final state of a system.
Usage
sweep.final_nD(
workdir,
sweep_master_file,
sweep_dir_to_complete = NULL,
export.data_as_csv_xlsx = FALSE,
isobxr_master_file = "0_ISOBXR_MASTER",
save_outputs = FALSE
)
Arguments
workdir |
Working directory of 0_ISOBXR_MASTER.xlsx master file, |
sweep_master_file |
Name of sweep.final_nD excel master file. (without file "xlsx" extension). |
sweep_dir_to_complete |
Name of directory of previously halted sweep.final_nD
run that the user wishes to continue. Starts with "4_FINnD". |
export.data_as_csv_xlsx |
If TRUE, exports chunk sweep result data as csv and xlsx fo full
to chunk digest directory. |
isobxr_master_file |
Name of isobxr excel master file. |
save_outputs |
If TRUE, saves all run outputs to local working directory (workdir). |
Value
Delta values and box sizes at final state of the system, in the n-dimensions space of parameters. sweep.final_nD outputs are saved to workdir if save_outputs = TRUE.
sweep.final_nD outputs
-
digest sweep.final_nD outputs full sweep.final_nD outputs are stored in a digest directory directly in workdir:
-
isobxr master file archive as xlsx
-
global chunk_log as csv
-
global chunk_log as rds
-
sweep.final_nD master file archive as xlsx
-
sweep.final_nD merged chunks LOG excerpt as csv
-
sweep.final_nD merged param_space, current progress, as rds (space of swept parameters)
-
sweep.final_nD merged results, current progress, as rds
data frame containing delta and size at final state across whole n-dimensions space of parameters
-
sweep.final_nD param_space as planned, as rds
-
sweep.final_nD sweep_default data frame of default run conditions, as rds
-
sweep.final_nD sweep progress plot as pdf, follows merging of chunks
-
-
chunks sweep.final_nD outputs chunk directories are edited in case total number. of runs exceeds chunk size defined in sweep.final_nD master file. They are removed after full sweep.
tempdir_tree
Description
display tree of the temporary isobxr directory
Usage
tempdir_tree()
Value
a print of the directory tree
Convert time units in a dataframe column
Description
Convert the time units in plots
Usage
time_converter(
dataframe,
time_colname,
conv_timecolname,
former_unit,
new_unit
)
Arguments
dataframe |
dataframe for which a column with numerical time values should be converted. |
time_colname |
name of column with time (numerical) values to be converted to a different time unit. |
conv_timecolname |
name of the column after time units conversion. |
former_unit |
former time unit. Character string among the following: |
new_unit |
new time unit. Character string among the following: |
Value
a dataframe with values converted to new time unit.
address_to_tmpdir
Description
makes path to a isobxr_temp_data directory located in temporary directory
Usage
to_tmpdir(dir_or_file)
Arguments
dir_or_file |
directory or file to address in temporary directory |
Value
name of subdirectory or file
using_extdata_tutorial V1
Description
identifies workdir value referring to use of extdata tutorial files, returns correct workdir value,
prevents saving outputs locally (save_run_outputs = FALSE)
forces display of default graphical output to R session (plot_results = TRUE)
Usage
using_extdata_tutorial(workdir, save_run_outputs, plot_results)
Arguments
workdir |
working directory value referring to extdata tutorial files, several options among the following: |
Value
a vector with a boolean stating whether this is a tutorial mode, a workdir value allowing reading of extdata tutorial files, save_run_outputs = FALSE, plot_results = TRUE
using_extdata_tutorial_2
Description
identifies workdir value referring to use of extdata tutorial files, returns correct workdir value,
prevents saving outputs locally (save_run_outputs = FALSE)
forces display of default graphical output to R session (plot_results = TRUE)
Usage
using_extdata_tutorial_2(workdir, save_outputs, plot_results)
Arguments
workdir |
working directory value referring to extdata tutorial files, several options among the following: |
Value
a list with a boolean stating whether this is a tutorial mode, a workdir value allowing reading of extdata tutorial files, save_run_outputs = FALSE, plot_results = TRUE