darsia.presets.workflows.rig.Rig#

class Rig[source]#

Bases: object

Rig object for CO2 analysis.

Methods

import_from_csv(path, *[, delimiter, date, ...])

Import scalar result data from CSV.

load(folder[, corrections_config])

Load rig object from file.

load_corrections(folder[, corrections_config])

Load persisted corrections from disk.

load_experiment(experiment)

Load experiment and associated protocols.

mass_analysis(img)

Mass analysis of the image.

read_image(path)

Read image from file and apply corrections.

save(folder)

Save rig object to file.

setup(experiment, baseline_path, ...[, ...])

Fast setup.

setup_boolean_image_porosity([threshold, ...])

Setup boolean porosity based on the defined threshold.

setup_color_corrections([...])

Setup label-dependent color corrections after labels/porosity are available.

setup_depth(path[, log])

Setup depth map for the rig object.

setup_facies(path[, apply_corrections, log, ...])

Setup facies.

setup_facies_props([props_path, porosity, ...])

Define facies properties like porosity.

setup_geometry()

Setup geometry for volumetric integration of images.

setup_illumination_correction(config[, log, ...])

Setup and return illumination correction.

setup_image_porosity([path, log, config, ...])

Setup image porosity based on the baseline image.

setup_inner_labels([log])

Define boolean mask which excludes the label boundaries.

setup_labels(path[, apply_corrections, log])

Setup labels for the rig object.

setup_mass_analysis(atmospheric_pressure, ...)

setup_patchwise_illumination_correction(config)

Setup and return patchwise illumination correction.

setup_reading(baseline_path, experiment[, ...])

setup_shape_corrections(pre_baseline[, ...])

Setup shape corrections that do not depend on labels/porosity.

threshold_analysis(mass_analysis_result)

Threshold analysis of the mass analysis result.

update(path)

Update the state of the rig based on the image path.

Attributes

corrections

Combined correction workflow in execution order.

classmethod load(folder, corrections_config=None)[source]#

Load rig object from file.

Mimick the save method.

Parameters:
folderPath

Path to the folder where the rig object is saved.

import_from_csv(path, *, delimiter=',', date=None, reference_date=None, time=None, name=None, is_extensive=False)[source]#

Import scalar result data from CSV.

load_corrections(folder, corrections_config=None)[source]#

Load persisted corrections from disk.

Supports both split-format files (shape_correction_*, color_correction_*) and legacy mixed-format files (correction_*).

load_experiment(experiment)[source]#

Load experiment and associated protocols.

This is required to read images and compute the injected mass correctly.

Parameters:
experimentdarsia.ProtocolledExperiment

Experiment object containing imaging, injection, and pressure/temperature protocols.

mass_analysis(img)[source]#

Mass analysis of the image.

read_image(path)[source]#

Read image from file and apply corrections.

The respective date is extracted from the path using the imaging protocol.

Parameters:
pathPath

Path to the image file.

Returns:
darsia.Image

Image object with applied corrections.

save(folder)[source]#

Save rig object to file.

setup(experiment, baseline_path, depth_map_path, labels_path, facies_path=None, facies_props_path=None, corrections_config=None, image_porosity_config=None, log=None, show_plot=False)[source]#

Fast setup.

setup_boolean_image_porosity(threshold=None, log=None, config=None, show_plot=False)[source]#

Setup boolean porosity based on the defined threshold.

In mode="full" the boolean mask is always all-True (full image domain), regardless of threshold / tol. In mode="from_image" the mask is derived by thresholding self.image_porosity with the effective tolerance.

The effective tolerance is resolved in order of precedence:

  1. threshold argument (when explicitly passed).

  2. config.tol (when config is given).

  3. self._image_porosity_config.tol (stored by setup_image_porosity()).

  4. 0.9 (hard-coded default).

Parameters:
thresholdfloat | None

Override tolerance value. Deprecated in favour of config.tol; kept for backward compatibility.

logPath | None

Folder for diagnostic output. When given, a JPG illustration is stored to log/image_porosity/boolean_porosity.jpg.

configImagePorosityConfig | None

Porosity configuration. Falls back to the config stored by the last call to setup_image_porosity(), and finally to ImagePorosityConfig() (mode="full").

show_plotbool

When True the boolean porosity is displayed interactively. Pass True when calling from a GUI or user-interface workflow.

setup_color_corrections(corrections_config=None, log=None, show_plot=False)[source]#

Setup label-dependent color corrections after labels/porosity are available.

Execution order is fixed: 1) illumination, 2) relative color, 3) color correction. Relative color can either be loaded from a precomputed correction file or calibrated from configured images (interactive mode only).

setup_depth(path, log=None)[source]#

Setup depth map for the rig object.

Parameters:
pathPath | None

Path to the precomputed depth map file. If provided, it will be loaded and used as the depth map.

logPath | None

Path to the log folder where geometry images will be saved.

setup_facies(path, apply_corrections=False, log=None, show_plot=False)[source]#

Setup facies.

This method loads facies from a specified path and applies corrections if needed.

Parameters:
pathPath

Path to the facies file. If the file exists, it will be loaded.

apply_correctionsbool

If True, applies corrections to the facies based on the baseline image.

logPath | None

Path to the log folder where facies images will be saved.

setup_facies_props(props_path=None, porosity=None, permeability=None)[source]#

Define facies properties like porosity.

Parameters:
props_pathPath | None

Path to the facies properties CSV file. If provided, it will load the facies properties from this path.

porosityPath | None

Path to the porosity image file. If provided, it will load the porosity image from this path.

setup_geometry()[source]#

Setup geometry for volumetric integration of images.

setup_illumination_correction(config, log=None, show_plot=False)[source]#

Setup and return illumination correction.

Parameters:
configIlluminationCorrectionConfig | None

Configuration for the illumination correction. If provided, it will set up the illumination correction based on this configuration.

logPath | None

Path to the log folder where diagnostic plots will be saved.

show_plotbool

Whether to show diagnostic plots during setup (default: False).

Notes

Illumination calibration in Rig intentionally uses the shape-corrected baseline as setup input.

setup_image_porosity(path=None, log=None, config=None, show_plot=False)[source]#

Setup image porosity based on the baseline image.

Behaviour is controlled by config:

  • mode="full" (default): constant porosity of 1 over the full domain.

  • mode="from_image": porosity derived from the baseline image via patched_porosity_analysis() using the parameters stored in config (patches, num_clusters, sample_width, tol_color_distance, tol_color_gradient).

When path is provided the image is always loaded from disk regardless of config, which is useful for restoring a previously saved rig.

Parameters:
pathPath | None

Path to a previously saved porosity .npz file. When given, the file is loaded and config is not used.

logPath | None

Folder for diagnostic output. When given, a JPG illustration is stored to log/image_porosity/image_porosity.jpg.

configImagePorosityConfig | None

Porosity configuration. Defaults to ImagePorosityConfig() (i.e. mode="full") when not provided.

show_plotbool

When True the image porosity is displayed interactively. Pass True when calling from a GUI or user-interface workflow.

setup_inner_labels(log=None)[source]#

Define boolean mask which excludes the label boundaries.

setup_labels(path, apply_corrections=False, log=None)[source]#

Setup labels for the rig object.

This method loads labels from a specified path and applies corrections if needed.

Parameters:
pathPath

Path to the labels file. If the file exists, it will be loaded.

apply_correctionsbool

If True, applies corrections to the labels based on the baseline image.

logPath | None

Path to the log folder where label images will be saved.

setup_patchwise_illumination_correction(config, show_plot=False)[source]#

Setup and return patchwise illumination correction.

Parameters:
configPatchwiseIlluminationCorrectionConfig | None

Configuration for the patchwise illumination correction. If provided, it will set up the correction based on this configuration.

Notes

Patchwise illumination calibration uses the labels image to enable per-label reference color computation within each patch, ensuring heterogeneous regions contribute equally by material.

setup_shape_corrections(pre_baseline, corrections_config=None)[source]#

Setup shape corrections that do not depend on labels/porosity.

threshold_analysis(mass_analysis_result)[source]#

Threshold analysis of the mass analysis result.

update(path)[source]#

Update the state of the rig based on the image path.

This method updates the current date, time, pressure, and temperature of the rig object based on the provided image path.

Parameters:
pathPath

Path to the image file.

property corrections#

Combined correction workflow in execution order.