Variograms
Part 3 of 6 in IAEG 2026 notebooks.
A variogram per simulation domain describes how fast a CPT parameter loses its correlation with
distance: vertically along a CPT, and horizontally between CPTs at one level. 04 uses them to
simulate the parameter in each domain’s voxels.
Reads the simulation domains that 02_simulation_domains.py saves, in
notebooks/simulation_domains.json and data/voxel_domains.parquet, and the CPT readings in
data/cpts.parquet. The readings are resampled at the sample height chosen below. Samples and variograms are
saved per height, and 04 can simulate at each saved height: it conditions on that height’s samples with that
height’s variograms, since both only hold at their own height. The variograms are of normal scores: per domain, the parameter
(log₁₀ of qc and fs), optionally without its linear trend with depth, ranked and mapped onto a
standard normal distribution. Their sill is therefore 1.
Hidden cell
import jsonfrom datetime import datetimefrom pathlib import Pathfrom statistics import NormalDist
import altair as altimport gstools as gsimport marimo as moimport numpy as npimport polars as pl
# The charts take thousands of CPT sample pairsalt.data_transformers.disable_max_rows()Hidden cell: inputs
DATA_DIR = Path(mo.notebook_dir()).parent / "data"# The simulation domains 02_simulation_domains.py saves, and the variograms this notebook saves for 04.# The cells that read them run again when they are saved.DOMAINS_JSON = Path(mo.notebook_dir()) / "simulation_domains.json"VARIOGRAMS_JSON = Path(mo.notebook_dir()) / "variograms.json"domains_json = mo.watch.file(DOMAINS_JSON)voxels_parquet = mo.watch.file(DATA_DIR / "voxel_domains.parquet")cpts_parquet = mo.watch.file(DATA_DIR / "cpts.parquet")def samples_path(height): """The CPT samples saved with the variograms of a sample height, for 04""" return DATA_DIR / f"simulation_samples_{height * 100:g}cm.parquet"
variograms_json = mo.watch.file(VARIOGRAMS_JSON)Hidden cell: read_inputs
mo.stop( not all(Path(_f).exists() for _f in (domains_json, voxels_parquet, cpts_parquet)), mo.md("Save the simulation domains in `02_simulation_domains.py` first."),)domain_definition = json.loads(Path(domains_json).read_text(encoding="utf-8"))# The domains from the top down, in the colors 02 gave themDOMAIN_COLORS = domain_definition["colors"]# The voxels in a simulation domain, and the CPT readingsvoxels = pl.read_parquet(Path(voxels_parquet)).filter(pl.col("domain").is_not_null())cpts = pl.read_parquet(Path(cpts_parquet))1 · The data per domain
Section titled “1 · The data per domain”Choose the parameters and the sample height. Below the sample height nothing is measured for the
simulation, and a finer height means more samples to condition on in 04, so a slower simulation. With the
trend removed, each domain’s linear trend with depth comes off before
the normal-score transform, so the variograms describe what varies around it; 04 adds the trend back.
Hidden cell: parameter
# The CPT parameters, each with how it is transformed before its normal scores. Rf is not simulated, so# it has no variograms: it follows from each realization's qc and fs.PARAMETERS = { "qc (cone resistance)": "qc", "fs (sleeve friction)": "fs",}LOG_PARAMETERS = {"qc", "fs"}UNITS = {"qc": "log₁₀ MPa", "fs": "log₁₀ MPa"}# GSTools' covariance models a domain's variogram can follow; a model's len_scale is what 04 passes onMODELS = { "Exponential": gs.Exponential, "Spherical": gs.Spherical, "Gaussian": gs.Gaussian,}# The least nugget of a model's fits and sliders. A Gaussian model without a nugget is so smooth that the# simulation's kriging becomes unstable where CPTs close together differ at one depth: its scores then# run far beyond the CPTs' values.MIN_NUGGET = {"Gaussian": 0.05}parameters = mo.ui.multiselect( PARAMETERS, value=["qc (cone resistance)", "fs (sleeve friction)"], label="Parameters")detrend = mo.ui.switch( value=True, label="Remove each domain's linear trend with depth")# Heights that divide a voxel_heights = {"10 cm": 0.1, "25 cm": 0.25, "50 cm: the GeoTOP voxels": 0.5}sample_height = mo.ui.dropdown( _heights, value="10 cm", label="Sample height",)mo.hstack([parameters, sample_height, detrend], justify="start", gap=2)Hidden cell: samples
_height = sample_height.value# The CPT readings per sample of this height in the voxels they pass through: their medians, with z the# center of the sample and voxel_z the level of its voxel, whose x and y are its south-west corner. A# voxel's z is its center.samples = ( cpts.with_columns( column_x=pl.col("x") // 100 * 100, column_y=pl.col("y") // 100 * 100, voxel_z=(pl.col("z") * 2).round() / 2, ) .with_columns(level=((pl.col("z") - pl.col("voxel_z") + 0.25) / _height).floor().clip(0, round(0.5 / _height) - 1)) .with_columns(sample_z=(pl.col("voxel_z") - 0.25 + (pl.col("level") + 0.5) * _height).round(3)) .group_by("bro_id", "column_x", "column_y", "voxel_z", "sample_z") .agg(pl.first("x", "y"), pl.median("qc", "fs", "rf"), pl.len().alias("readings")) .join( voxels.select( column_x="x", column_y="y", voxel_z="z", stratigraphic_unit="stratigraphic_unit", lithoklasse="lithoklasse", grondsoort="grondsoort", domain="domain" ), on=["column_x", "column_y", "voxel_z"], ) .rename({"sample_z": "z"}) .with_columns(sample_height=pl.lit(_height)) # In one order, so that the trends come out the same each time .sort("bro_id", "z"))mo.md( f"**{samples.height} CPT samples** of {_height * 100:g} cm from {samples['bro_id'].n_unique()} CPTs in " f"**{len(DOMAIN_COLORS)} simulation domains**, saved in `02` on {domain_definition['saved']}.")Hidden cell: scores
mo.stop(not parameters.value, mo.md("Choose at least one parameter."))
def _transformed(name): """The samples of one parameter, with its transformed value: log10 of qc and fs""" _value = pl.col(name).log10() if name in LOG_PARAMETERS else pl.col(name) return samples.filter(pl.col(name) > 0).select( "domain", "bro_id", "x", "y", "z", value=_value, parameter=pl.lit(name) )
# Per parameter and domain: the transformed parameter, its linear trend with depth (none with detrend# off), and the normal scores of what is left around it: ranked and mapped onto a standard normal# distribution_data = pl.concat([_transformed(_name) for _name in parameters.value])trends = ( _data.group_by("parameter", "domain") .agg( samples=pl.len(), cpts=pl.n_unique("bro_id"), mean=pl.mean("value"), std=pl.col("value").std(), slope=(pl.cov("z", "value") / pl.col("z").var()).fill_nan(0.0) if detrend.value else pl.lit(0.0), mean_z=pl.mean("z"), ) .with_columns(intercept=pl.col("mean") - pl.col("slope") * pl.col("mean_z")) .drop("mean_z"))_inverse_normal = NormalDist().inv_cdf_group = ["parameter", "domain"]scores = ( _data.join(trends.select(*_group, "slope", "intercept"), on=_group) .with_columns(residual=pl.col("value") - (pl.col("intercept") + pl.col("slope") * pl.col("z"))) .with_columns( score=((pl.col("residual").rank("average").over(_group) - 0.5) / pl.len().over(_group)).map_elements( _inverse_normal, return_dtype=pl.Float64 ) ) .select(*_group, "bro_id", "x", "y", "z", "value", "residual", "score"))Hidden cell: data_table
# The parameters in the order they were chosen, each with its domains from the top down, in their colors_order = { "parameter": {_name: _i for _i, _name in enumerate(parameters.value)}, "domain": {_domain: _i for _i, _domain in enumerate(DOMAIN_COLORS)},}mo.ui.table( trends.sort(*(pl.col(_column).replace_strict(_rank) for _column, _rank in _order.items())).select( "parameter", "domain", "samples", pl.col("cpts").alias("CPTs"), pl.col("parameter").replace_strict(UNITS).alias("unit"), pl.col("mean").round(3), pl.col("std").round(3), (-pl.col("slope")).round(4).alias("change with depth (unit per m)"), ), selection=None, style_cell=lambda _row, column, value: {"backgroundColor": DOMAIN_COLORS[value]} if column == "domain" else {},)Hidden cell: lags
# The experimental variograms: vertically up to MAX_LAG["vertical"] along each CPT, in steps of the# samples' height; horizontally up to MAX_LAG["horizontal"] between CPTs at one level, in bins of# HORIZONTAL_BIN. A lag needs MIN_PAIRS pairs of samples to count in the fit.MAX_LAG = {"vertical": 10.0, "horizontal": 300.0}HORIZONTAL_BIN = 20.0MIN_PAIRS = 30# The length scales a fit and the sliders can take, in mLEN_SCALE_BOUNDS = {"vertical": [0.1, 10.0], "horizontal": [5.0, 1000.0]}Hidden cell: experimental
# Half the mean squared difference between the normal scores of pairs of samples of one parameter in one# domain, per lag_s = scores.select("parameter", "domain", "bro_id", "x", "y", "z", "score")_semivariance = 0.5 * ((pl.col("score") - pl.col("score_2")) ** 2).mean()# Vertically: pairs of samples of one CPT, the upper one first_vertical = ( _s.join(_s, on=["parameter", "domain", "bro_id"], suffix="_2") .with_columns(lag=(pl.col("z") - pl.col("z_2")).round(3)) .filter((pl.col("lag") > 0) & (pl.col("lag") <= MAX_LAG["vertical"])) .group_by("parameter", "domain", "lag") .agg(gamma=_semivariance, pairs=pl.len()) .with_columns(direction=pl.lit("vertical")))# Horizontally: pairs of samples of two CPTs at one level, each pair once, at their mean distance per bin_horizontal = ( _s.join(_s, on=["parameter", "domain", "z"], suffix="_2") .filter(pl.col("bro_id") < pl.col("bro_id_2")) .with_columns(distance=((pl.col("x") - pl.col("x_2")) ** 2 + (pl.col("y") - pl.col("y_2")) ** 2).sqrt()) .filter(pl.col("distance") <= MAX_LAG["horizontal"]) .group_by("parameter", "domain", (pl.col("distance") // HORIZONTAL_BIN).alias("bin")) .agg(lag=pl.mean("distance"), gamma=_semivariance, pairs=pl.len()) .drop("bin") .with_columns(direction=pl.lit("horizontal")))experimental = pl.concat([_vertical, _horizontal], how="diagonal").sort("parameter", "domain", "direction", "lag")Hidden cell: fit
def _fit(model_name, points, nugget, len_scale_bounds): """A model fitted by least squares to the points of one direction, with a sill of 1 and the lags weighted by their pairs: its nugget (fitted when nugget is True), its len_scale within len_scale_bounds and its misfit, the weighted root mean square of its residuals; or None with too few lags""" points = points.filter(pl.col("pairs") >= MIN_PAIRS) if points.height < 3: return None _lags, _gamma, _pairs = (points[_column].to_numpy() for _column in ("lag", "gamma", "pairs")) _model = MODELS[model_name](dim=1) _model.len_scale_bounds = len_scale_bounds try: _model.fit_variogram(_lags, _gamma, sill=1.0, nugget=nugget, weights=_pairs, loss="linear") # A fitted nugget below the model's least nugget: fitted again with that nugget if nugget is True and _model.nugget < MIN_NUGGET.get(model_name, 0.0): _model.fit_variogram(_lags, _gamma, sill=1.0, nugget=MIN_NUGGET[model_name], weights=_pairs, loss="linear") except (RuntimeError, ValueError): return None _misfit = float(np.sqrt(np.average((_model.variogram(_lags) - _gamma) ** 2, weights=_pairs))) return _model.nugget, _model.len_scale, _misfit
def _fit_both(model_name, points): """A model fitted to a domain's experimental variograms: the nugget from the vertical one, which has the short lags, and the horizontal one fitted with that nugget. Its misfit is the mean of the two directions' misfits.""" _vertical = _fit( model_name, points.filter(pl.col("direction") == "vertical"), nugget=True, len_scale_bounds=LEN_SCALE_BOUNDS["vertical"] ) _nugget = _vertical[0] if _vertical else MIN_NUGGET.get(model_name, 0.0) _horizontal = _fit( model_name, points.filter(pl.col("direction") == "horizontal"), nugget=_nugget, len_scale_bounds=LEN_SCALE_BOUNDS["horizontal"] ) _misfits = [_direction[2] for _direction in (_vertical, _horizontal) if _direction] return { "nugget": _nugget, "vertical": _vertical[1] if _vertical else None, "horizontal": _horizontal[1] if _horizontal else None, "misfit": float(np.mean(_misfits)) if _misfits else None, }
# Per parameter, domain and model, the fitted model; and per parameter and domain, the model that misfits# leastfitted = { _name: { _domain: { _model: _fit_both(_model, experimental.filter((pl.col("parameter") == _name) & (pl.col("domain") == _domain))) for _model in MODELS } for _domain in DOMAIN_COLORS } for _name in parameters.value}best_models = { _name: { _domain: min( (_model for _model, _fit in _fits.items() if _fit["misfit"] is not None), key=lambda _model: _fits[_model]["misfit"], default="Exponential", ) for _domain, _fits in _domains.items() } for _name, _domains in fitted.items()}best_modelsHidden cell: saved_variograms
# The variograms saved before, per sample height and parameter; empty until they are saved. Each parameter's# carry when they were saved and the date of the simulation domains they were fitted on: SAVE_DATES.SAVE_DATES = ("saved", "simulation_domains_saved")saved_variograms = json.loads(Path(variograms_json).read_text(encoding="utf-8")) if Path(variograms_json).exists() else {}# Those of the chosen sample heightsaved_at_height = saved_variograms.get(f"{sample_height.value:g}", {})Hidden cell: variograms_intro
reset_to_fit = mo.ui.run_button(label="Start again from the best fits")# Which parameter's variograms the rows show, when several are chosen_chosen = {_label: _name for _label, _name in PARAMETERS.items() if _name in parameters.value}shown_parameter = mo.ui.radio(_chosen, value=next(iter(_chosen)), inline=True, label="Show the variograms of")mo.vstack( [ mo.md(r"""## 2 · The variograms per domain
Each row is one domain: its model and sliders, its vertical variogram along the CPTs and its horizontalone between CPTs at one level. The dots are the experimental variogram, as large as their number ofpairs of samples, and faint below the number a lag needs to count in the fit. The line is the model ofthe sliders. Exponential, spherical and Gaussian models are each fitted by weighted least squares with asill of 1, and a domain starts with the one that misfits least, unless the saved variograms are of thisparameter and trend. Choosing another model for a domain starts its sliders from that model's fit. Bothdirections share the nugget. Each chosen parameter has its own models and sliders."""), mo.hstack([shown_parameter, reset_to_fit], justify="space-between") if len(_chosen) > 1 else reset_to_fit, ])Hidden cell: model_choice
def _start_model(name, domain): """A domain's model for one parameter: the saved one at this sample height, when the saved variograms of the parameter have this trend; otherwise the best-fitting one""" _saved = saved_at_height.get(name, {}) _use_saved = not reset_to_fit.value and _saved.get("detrend") == detrend.value _variogram = _saved.get("domains", {}).get(domain) if _use_saved else None return _variogram.get("model", _saved.get("model")) if _variogram else best_models[name][domain]
model_choice = mo.ui.dictionary( { _name: mo.ui.dictionary( {_domain: mo.ui.dropdown(list(MODELS), value=_start_model(_name, _domain), label="Model") for _domain in DOMAIN_COLORS} ) for _name in parameters.value })Hidden cell: moved_sliders
# The sliders as they were last moved, per parameter with each domain's model, so that choosing another# model for one domain leaves the other domains' sliders where they areget_moved_sliders, set_moved_sliders = mo.state({})Hidden cell: variogram_controls
# Where a domain's sliders start for one parameter: where they were last moved with its model; otherwise# its saved variogram at this sample height, when the saved variograms of the parameter have this trend and it has the same# model; otherwise that model's fit, or DEFAULTS where there is noneDEFAULTS = {"nugget": 0.0, "vertical": 1.0, "horizontal": 100.0}_moved = {} if reset_to_fit.value else get_moved_sliders()if reset_to_fit.value: set_moved_sliders({})
def _start(name, domain): _model = model_choice.value[name][domain] _last = _moved.get(name, {}) _last = _last["domains"].get(domain, {}) if _last.get("detrend") == detrend.value and _last.get("sample_height") == sample_height.value else {} if _last.get("model") == _model: return _last _saved = saved_at_height.get(name, {}) _use_saved = not reset_to_fit.value and _saved.get("detrend") == detrend.value _variogram = _saved.get("domains", {}).get(domain) if _use_saved else None if _variogram and _variogram.get("model", _saved.get("model")) == _model: return {"nugget": _variogram["nugget"], **_variogram["len_scale"]} _fit = fitted[name][domain][_model] return {_key: DEFAULTS[_key] if _fit[_key] is None else float(_fit[_key]) for _key in DEFAULTS}
def _slider(bounds, step, value, label): _value = round(round(min(max(value, bounds[0]), bounds[1]) / step) * step, 2) return mo.ui.slider(start=bounds[0], stop=bounds[1], step=step, value=_value, show_value=True, label=label)
def _sliders(start, model): return mo.ui.dictionary( { "nugget": _slider([MIN_NUGGET.get(model, 0.0), 1.0], 0.01, start["nugget"], "Nugget"), "vertical": _slider(LEN_SCALE_BOUNDS["vertical"], 0.05, start["vertical"], "Vertical length scale (m)"), "horizontal": _slider(LEN_SCALE_BOUNDS["horizontal"], 5.0, start["horizontal"], "Horizontal length scale (m)"), } )
def _remember(value): set_moved_sliders( { _name: { "detrend": detrend.value, "sample_height": sample_height.value, "domains": { _domain: {"model": model_choice.value[_name][_domain], **_values} for _domain, _values in _domains.items() }, } for _name, _domains in value.items() } )
variogram_controls = mo.ui.dictionary( { _name: mo.ui.dictionary( {_domain: _sliders(_start(_name, _domain), model_choice.value[_name][_domain]) for _domain in DOMAIN_COLORS} ) for _name in parameters.value }, on_change=_remember,)Hidden cell: variogram_rows
def model_of(name, domain, direction): """The GSTools model of a domain's model and sliders for one parameter, in one direction""" _sliders = variogram_controls.value[name][domain] return MODELS[model_choice.value[name][domain]]( dim=1, var=1.0 - _sliders["nugget"], len_scale=_sliders[direction], nugget=_sliders["nugget"] )
def _chart(name, domain, direction): _lags = np.linspace(0, MAX_LAG[direction], 200)[1:] _curve = pl.DataFrame({"lag": _lags, "gamma": model_of(name, domain, direction).variogram(_lags)}) _x = alt.X("lag:Q", title="Lag (m)", scale=alt.Scale(domain=[0, MAX_LAG[direction]])) _y = alt.Y("gamma:Q", title="Semivariance", scale=alt.Scale(domain=[0, 2], clamp=True)) _points = ( alt.Chart( experimental.filter( (pl.col("parameter") == name) & (pl.col("domain") == domain) & (pl.col("direction") == direction) ) ) .mark_circle(color=DOMAIN_COLORS[domain], stroke="#333", strokeWidth=0.6) .encode( x=_x, y=_y, size=alt.Size("pairs:Q", legend=None, scale=alt.Scale(range=[10, 220])), opacity=alt.condition(f"datum.pairs >= {MIN_PAIRS}", alt.value(1.0), alt.value(0.3)), tooltip=[alt.Tooltip("lag:Q", format=".1f"), alt.Tooltip("gamma:Q", format=".3f"), "pairs:Q"], ) ) _line = alt.Chart(_curve).mark_line(color="#333").encode(x=_x, y=_y) _sill = alt.Chart(pl.DataFrame({"gamma": [1.0]})).mark_rule(strokeDash=[4, 3], color="#999").encode(y="gamma:Q") _title = "Vertical, along the CPTs" if direction == "vertical" else "Horizontal, between CPTs at one level" return (_sill + _points + _line).properties(width=300, height=180, title=_title)
def _row(name, domain): _sliders = variogram_controls[name][domain] _trend = trends.filter((pl.col("parameter") == name) & (pl.col("domain") == domain)).row(0, named=True) _ranges = {_d: model_of(name, domain, _d).percentile_scale(0.95) for _d in ("vertical", "horizontal")} _misfits = " · ".join( f"{_model} {_fit['misfit']:.3f}" for _model, _fit in fitted[name][domain].items() if _fit["misfit"] is not None ) _about = mo.md( f'<span style="display:inline-block;width:12px;height:12px;background:{DOMAIN_COLORS[domain]};' f'border:1px solid #999;margin-right:6px"></span>**{domain}**<br>' f"{_trend['cpts']} CPTs, {_trend['samples']} samples. 95 % of the sill at " f"{_ranges['vertical']:.1f} m vertically and {_ranges['horizontal']:.0f} m horizontally.<br>" f"Misfit of the fits: {_misfits}; {best_models[name][domain]} fits best." ) return mo.vstack( [ _about, mo.hstack( [model_choice[name][domain], _sliders["nugget"], _sliders["vertical"], _sliders["horizontal"]], justify="start", gap=2, ), mo.hstack([_chart(name, domain, "vertical"), _chart(name, domain, "horizontal")], justify="start", gap=2), ] )
mo.vstack([_row(shown_parameter.value, _domain) for _domain in DOMAIN_COLORS], gap=2)Hidden cell: variograms
# The variograms of the models and sliders, per parameter and domain, in GSTools' terms: the nugget and# the variance (the partial sill) add up to 1; a len_scale per directionvariograms = pl.DataFrame( [ { "parameter": _name, "domain": _domain, "model": model_choice.value[_name][_domain], "nugget": _sliders["nugget"], "variance": round(1.0 - _sliders["nugget"], 2), "len_scale vertical (m)": _sliders["vertical"], "len_scale horizontal (m)": _sliders["horizontal"], "anisotropy (vertical / horizontal)": round(_sliders["vertical"] / _sliders["horizontal"], 4), "95 % range vertical (m)": round(model_of(_name, _domain, "vertical").percentile_scale(0.95), 2), "95 % range horizontal (m)": round(model_of(_name, _domain, "horizontal").percentile_scale(0.95), 1), } for _name, _domains in variogram_controls.value.items() for _domain, _sliders in _domains.items() ])mo.vstack( [ mo.md("## 3 · The variograms"), mo.ui.table( variograms, selection=None, style_cell=lambda _row, column, value: {"backgroundColor": DOMAIN_COLORS[value]} if column == "domain" else {}, ), ])4 · Save the variograms
Section titled “4 · Save the variograms”Saving pins the variograms of the chosen parameters at the chosen sample height for 04. It writes them to
notebooks/variograms.json, which is committed with the notebooks, and the CPT samples of that height to
data/simulation_samples_<height>cm.parquet. It leaves the other heights and the other parameters as they
are; saving again at one height replaces that height’s variograms of the chosen parameters. Each parameter has
its transform, its sample height and, per domain, its model, nugget, length scales and trend, with the date it
was saved and the date of the simulation domains it was fitted on.
Hidden cell: variogram_definition
# The variograms of the chosen parameters as variograms.json holds them_trends = {(_row["parameter"], _row["domain"]): _row for _row in trends.iter_rows(named=True)}variogram_definitions = { _name: { "transform": "log10" if _name in LOG_PARAMETERS else "none", "detrend": detrend.value, "sample_height": sample_height.value, "domains": { _domain: { "model": model_choice.value[_name][_domain], "nugget": _sliders["nugget"], "len_scale": {"horizontal": _sliders["horizontal"], "vertical": _sliders["vertical"]}, # The trend of the transformed parameter: intercept + slope * z, z in m NAP "trend": {"intercept": _trends[_name, _domain]["intercept"], "slope": _trends[_name, _domain]["slope"]}, } for _domain, _sliders in _domains.items() }, } for _name, _domains in variogram_controls.value.items()}save_variograms = mo.ui.run_button(label="Save these variograms")save_variogramsHidden cell: saved_status
def _status(name): """Whether the saved variograms of one parameter are the ones above, and fitted on the saved simulation domains""" _saved = saved_at_height.get(name) if _saved is None: return mo.callout(mo.md(f"No variograms of {name} are saved at this sample height yet."), kind="warn") _when = _saved.get("saved", "an unknown date") if {_k: _v for _k, _v in _saved.items() if _k not in SAVE_DATES} != json.loads(json.dumps(variogram_definitions[name])): return mo.callout(mo.md(f"The variograms of {name} above differ from the ones saved on {_when}."), kind="warn") if _saved.get("simulation_domains_saved") != domain_definition["saved"]: return mo.callout( mo.md( f"The variograms of {name} above are the ones saved on {_when}, but those were fitted on other " "simulation domains. Save them again." ), kind="warn", ) return mo.callout(mo.md(f"The variograms of {name} above are the ones saved on {_when}."), kind="success")
mo.vstack([_status(_name) for _name in parameters.value])Hidden cell: save
mo.stop(not save_variograms.value)samples.write_parquet(samples_path(sample_height.value))# The chosen parameters' variograms at this sample height, each with this save's date and the simulation# domains' date; the other parameters and heights as they were saved before, from the finest height up_dates = {"saved": datetime.now().isoformat(timespec="seconds"), "simulation_domains_saved": domain_definition["saved"]}_saved = { **saved_variograms, f"{sample_height.value:g}": { **saved_at_height, **{_name: {**_definition, **_dates} for _name, _definition in variogram_definitions.items()}, },}VARIOGRAMS_JSON.write_text( json.dumps(dict(sorted(_saved.items(), key=lambda _item: float(_item[0]))), indent=2, ensure_ascii=False) + "\n", encoding="utf-8",)Hidden cell: saved_table
# The variograms in variograms.json, per sample height, parameter and domain_saved = pl.DataFrame( [ { "sample height (cm)": round(float(_height) * 100, 1), "parameter": _name, "domain": _domain, "model": _variogram["model"], "nugget": _variogram["nugget"], "len_scale vertical (m)": _variogram["len_scale"]["vertical"], "len_scale horizontal (m)": _variogram["len_scale"]["horizontal"], "saved": _definition["saved"], } for _height, _parameters in saved_variograms.items() for _name, _definition in _parameters.items() for _domain, _variogram in _definition["domains"].items() ])mo.vstack( [ mo.md("## 5 · The saved variograms"), mo.ui.table( _saved, selection=None, page_size=36, style_cell=lambda _row, column, value: {"backgroundColor": DOMAIN_COLORS.get(value, "#ffffff")} if column == "domain" else {}, ), ])