An R6 class that provides an interface to a folder-based data storage system for the evoland package. This class uses DuckDB for in-memory SQL operations while persisting data to a DuckLake catalog on disk.
Inherits from ducklake_db for generic database operations.
See also
Additional methods and active bindings are added to this class in separate files:
evoland_db_views - View active bindings (lulc_meta_long_v, etc.) and methods
Super class
ducklake_db -> evoland_db
Active bindings
coords_tGet or upsert coords_t
periods_tGet or upsert periods_t
lulc_meta_tGet or upsert lulc_meta_t
lulc_data_tGet or upsert lulc_data_t
pred_data_tGet or upsert pred_data_t
pred_meta_tGet or upsert pred_meta_t
trans_meta_tGet or upsert trans_meta_t
trans_preds_tGet or upsert trans_preds_t
trans_rates_tGet or upsert trans_rates_t
intrv_meta_tGet or upsert intrv_meta_t
intrv_masks_tGet or upsert intrv_masks_t
trans_models_tGet or upsert trans_models_t
alloc_params_tGet or upsert alloc_params_t
trans_pot_tGet or upsert raw transition potentials trans_pot_t. These are per-transition model probabilities stored by
predict_trans_pot(). Useadjusted_trans_pot_v()for allocation-ready values.neighbors_tGet or upsert neighbors_t
reporting_tGet or upsert reporting_t
runs_tGet or upsert runs_t
id_runGet or set active id_run, see runs_t
run_lineageGet id_run, see runs_t
Methods
evoland_db$new()
Initialize a new evoland_db object
Usage
evoland_db$new(
path = NULL,
id_run = 0L,
read_only = FALSE,
catalog = NULL,
data_path = NULL,
sqlite_journal_mode = "wal",
expire_older_than = NULL,
delete_older_than = NULL,
...
)Arguments
pathCharacter. Path to the data folder; may be omitted when both
cataloganddata_pathare given, see ducklake_db.id_runAtomic integer run ID, defaults to 0. Can be set to NULL
read_onlyLogical. Whether to update the reporting table upon initialization; if TRUE, the catalog is attached read-only.
catalogCharacter. DuckLake catalog connection, see ducklake_db.
data_pathCharacter. DuckLake data files location, see ducklake_db.
sqlite_journal_modeCharacter. Journal mode for a SQLite catalog, see ducklake_db.
expire_older_than, delete_older_thanRetention for
$checkpoint(), see ducklake_db....passed on to
set_report
evoland_db$get_read_expr()
Get SQL expression to read a table, respecting active run hierarchy. For each data slice, returns data from the closest ancestor run that has it.
evoland_db$set_report()
Set reporting metadata, see db_set_report()
evoland_db$set_neighbors()
Set the neighbors table, see set_neighbors()
evoland_db$generate_neighbor_predictors()
Generate neighbor prediction table, i.e. "how many neighbors within
distance X are of type Y", see generate_neighbor_predictors()
evoland_db$upsert_new_neighbors()
Append new neighbors to predictor for a given period; depends on generate_neighbor_predictors() having been run.
evoland_db$add_predictor()
Add a predictor using the currently active id_run, see add_predictor()
Usage
evoland_db$add_predictor(
pred_data_raw,
name,
fill_value,
pretty_name = name,
description = NA_character_,
orig_format = NA_character_,
sources = data.frame(url = character(0), md5sum = character(0)),
unit = NA_character_
)Arguments
pred_data_rawData frame with columns
id_coord,id_period, andvaluenameUnique short name
fill_valueValue to substitute if a coordinate point in coords_t does not have an explicit associated value
pretty_namechar, Friendly name for use in reporting
descriptionchar, For use in reporting.
orig_formatchar, Format description of the underlying data (raster, vector…)
sourcesdata.frame with url/md5sum columns, used for keeping track of underlying raw data, see
download_and_verify()unitchar, SI unit for physical predictors, or descriptions like "bed nights/year" as a proxy for touristic activity
evoland_db$pred_wide_train_v()
Get transitions along with their predictor data in a wide
data.table, see pred_wide_train_v()
Arguments
id_transInteger transition ID, see trans_meta_t
id_predOptional integer vector of predictor IDs to include
evoland_db$pred_wide_predict_v()
Retrieve a wide view of the predictor data, see pred_wide_predict_v()
Arguments
id_transInteger transition ID, see trans_meta_t
id_period_anteriorInteger ID of period to retrieve data for
evoland_db$figure_of_merit_v()
Pontius' figure of merit of simulated against observed change, see
figure_of_merit_v()
Usage
evoland_db$figure_of_merit_v(
id_period_anterior,
id_period_post,
id_run_reference,
id_run_simulated = self$id_run,
by_transition = FALSE,
exclude_id_lulc = integer(0)
)Arguments
id_period_anteriorInteger, period of the initial map
id_period_postInteger, period of the observed and simulated maps
id_run_referenceInteger, run holding the initial and observed maps
id_run_simulatedInteger vector, runs holding the simulated maps; defaults to the active run
by_transitionLogical; if
TRUE, report per transition instead of overall.exclude_id_lulcInteger vector of classes; cells whose class in the reference run, at
id_period_anteriororid_period_post, is one of them are ignored. Default none.
evoland_db$lulc_crosstab_v()
Cross-tabulation of land use between two periods, see lulc_crosstab_v()
evoland_db$alloc_dinamica()
Runs a path-dependent Monte Carlo simulation using Dinamica
EGO, see alloc_dinamica()
Usage
evoland_db$alloc_dinamica(
id_periods,
select_score,
select_maximize,
work_dir = NULL,
keep_intermediate = FALSE,
use_parent_trans_pot = FALSE,
force_predict_trans_pot = FALSE,
update_neighbors = TRUE
)Arguments
id_periodsInteger vector of period IDs to include in the simulation.
select_scoreCharacter string; mlr3 measure ID (e.g.
"classif.auc") used to select model for extrapolationselect_maximizeLogical; maximize (
TRUE) or minimize (FALSE) the score.work_dirCharacter path for Dinamica working directory;
NULL(default) uses a temporary directory.keep_intermediateLogical, keep intermediate Dinamica files? Default FALSE.
use_parent_trans_potLogical; use the direct parent run's transition potentials
force_predict_trans_potLogical; re-run prediction for trans_pot_t even if those values already exist
update_neighborsLogical; recompute neighbour predictors after the last requested period. Intermediate periods are always updated.
evoland_db$alloc_clumpy()
Runs CLUMPY-style LULC allocation, see alloc_clumpy().
The method (uSAM vs uPAM) is selected automatically from the patch
parameters: mono-pixel patches (area_mean == 1, area_var == 0) use
uSAM, otherwise uPAM.
Usage
evoland_db$alloc_clumpy(
id_periods,
select_score,
select_maximize,
area_dist = "lognormal",
avoid_aggregation = TRUE,
batch_size = 0L,
use_parent_trans_pot = FALSE,
force_predict_trans_pot = FALSE,
update_neighbors = TRUE
)Arguments
id_periodsInteger vector of period IDs to include in the simulation.
select_scoreCharacter string; mlr3 measure ID (e.g.
"classif.auc") used to select model for extrapolation.select_maximizeLogical; maximize (
TRUE) or minimize (FALSE) the score.area_distCharacter; patch-area distribution,
"lognormal"(default) or"normal". Seealloc_clumpy().avoid_aggregationLogical; if
TRUE(default) uPAM patches that would merge fail and allocate nothing. Ignored for uSAM.batch_sizeInteger; uPAM pivots attempted per MuST re-draw.
0(default) auto-scales with the source pool;> 0is an explicit cap (1= strict uPAM);< 0= all candidates in one pass. Ignored for uSAM.use_parent_trans_potLogical; use the direct parent run's transition potentials (useful for repeated allocation)
force_predict_trans_potLogical; re-run prediction for trans_pot_t even if those values already exist
update_neighborsLogical; recompute neighbour predictors after the last requested period. Intermediate periods are always updated.
evoland_db$alloc_greedy()
Runs deterministic greedy (rank-and-fill) allocation, see
alloc_greedy(): each transition's demand goes to the cells of highest adjusted
potential, every cell changes at most once.
Usage
evoland_db$alloc_greedy(
id_periods,
select_score,
select_maximize,
arbitration = c("joint", "ordered"),
order = NULL,
use_parent_trans_pot = FALSE,
force_predict_trans_pot = FALSE,
update_neighbors = TRUE
)Arguments
id_periodsInteger vector of period IDs to include in the simulation.
select_scoreCharacter string; mlr3 measure ID (e.g.
"classif.auc") used to select model for extrapolation.select_maximizeLogical; maximize (
TRUE) or minimize (FALSE) the score.arbitrationCharacter;
"joint"(default) ranks all transitions together,"ordered"lets transitions claim cells in the priority given byorder.orderInteger vector of
id_trans, the priority for"ordered".use_parent_trans_potLogical; use the direct parent run's transition potentials
force_predict_trans_potLogical; re-run prediction for trans_pot_t even if those values already exist
update_neighborsLogical; recompute neighbour predictors after the last requested period. Intermediate periods are always updated.
evoland_db$eval_alloc_params_t()
Evaluates allocation parameters in dinamica, see eval_alloc_params_t()
Usage
evoland_db$eval_alloc_params_t(
select_score,
select_maximize,
work_dir = NULL,
keep_intermediate = FALSE
)Arguments
select_scoreCharacter string; mlr3 measure ID (e.g.
"classif.auc") used to select model for extrapolationselect_maximizeLogical; maximize (
TRUE) or minimize (FALSE) the score.work_dirCharacter path for Dinamica working directory;
NULL(default) uses a temporary directory.keep_intermediateLogical, keep intermediate Dinamica files? Default FALSE.
evoland_db$create_alloc_params_t()
Estimates allocation parameters for all viable transitions under the active id_run,
see create_alloc_params_t()
evoland_db$lulc_data_as_rast()
Retrieve LULC data as a SpatRaster object for a given
period. See lulc_data_as_rast()
evoland_db$fit_full_models()
Fit full models (trained on the complete dataset) for each viable transition,
see fit_full_models(). Two mutually exclusive modes: pass learner to train
directly, or pass select_score to pick the best partial model by score.
Usage
evoland_db$fit_full_models(
learner = NULL,
select_score = NULL,
select_maximize = TRUE,
cluster = NULL,
trans_preds = NULL,
trans_meta = NULL
)Arguments
learnerAn mlr3
LearnerorAutoTunerfor direct-learner mode (NULLwhenselect_scoreis used).select_scoreMeasure ID string for score-select mode, e.g.
"classif.auc"(NULLwhenlearneris used).select_maximizeLogical; maximize (
TRUE) or minimize (FALSE) the score.clusterOptional cluster object for parallel processing
trans_predsOptional trans_preds_t; bypasses the database read in direct-learner mode. Ignored in score-select mode.
trans_metaOptional trans_meta_t; bypasses the database read in direct-learner mode. Ignored in score-select mode.
evoland_db$fit_partial_models()
Fit partial models for each viable transition using stratified
sampling. Models are trained on a subsample and evaluated on held-out data, see
fit_partial_models() for details.
Usage
evoland_db$fit_partial_models(
learner,
measures,
sample_frac = 0.7,
seed = NULL,
cluster = NULL,
trans_preds = NULL,
trans_meta = NULL
)Arguments
learnerAn mlr3
LearnerorAutoTunerR6 object.measuresA vector of
Measurenames passed to mlr3::msr or a list ofMeasureobjects for scoring the held-out split.sample_fracFraction in \(0, 1\) for stratified sampling.
seedRandom seed for reproducible sampling
clusterOptional cluster object for parallel processing
trans_predsOptional trans_preds_t; bypasses the
trans_preds_tdatabase read.trans_metaOptional trans_meta_t; bypasses the
trans_meta_tdatabase read.
evoland_db$get_crossval_plots()
Get cross-validation plots for stored predictions, see get_crossval_plots()
Arguments
id_runOptional integer; filter by run ID.
id_transOptional integer; filter by transition ID.
...Passed to
mlr3viz::autoplot.PredictionClassif()
evoland_db$set_full_trans_preds()
Set an initial full set of transition / predictor relations, see set_full_trans_preds()
evoland_db$get_pred_filter_score()
Add filter scores to predictors for each id_run, id_trans.
See get_pred_filter_score().
Usage
evoland_db$get_pred_filter_score(
filter = "correlation",
trans_preds = NULL,
cluster = NULL,
...
)Arguments
filterCharacter passed to mlr3filters::flt or mlr3filters::Filter object specifying the filter method to use for feature selection.
trans_predsOptional trans_preds_t; when supplied, it is used directly instead of reading from the database.
clusterOptional cluster object for parallel processing
...Additional arguments passed to
flt.
evoland_db$predict_trans_pot()
Predict the raw transition potential for a given period and store in
trans_pot_t, see predict_trans_pot(). Raw potentials are per-transition
model probabilities (not yet allocation-ready); use adjusted_trans_pot_v()
to obtain column-scaled, row-closed values.
evoland_db$get_obs_trans_rates()
Get the transition rates that were observed, see trans_rates_t