darsia.presets.workflows.rig.Rig#

class Rig[source]#

Bases: object

Rig object for CO2 analysis.

Methods

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(source, *[, date, native])

Read an image, given as a file or as the bytes of a file, and apply the corrections of the rig.

read_field(path, *[, on_photo])

Read a field of the rig (labels, facies, depth, porosity, ...) onto the grid of the baseline.

regions(name)

Regions to group pixels by, on the grid of the labels.

save(folder)

Save rig object to file.

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

Fast setup.

setup_color_corrections([...])

Setup label-dependent color corrections after labels 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_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.

corrections_configCorrectionsConfig | None

Corrections of the config ([corrections]).

Returns:
Rig

The loaded rig.

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 gives images read from files their date (read) and is required to 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(source, *, date=None, native=False)[source]#

Read an image, given as a file or as the bytes of a file, and apply the corrections of the rig.

The date of the image is, in this order: the given date; for a file, the date of the imaging protocol if an experiment is loaded (see load_experiment; a file missing from the protocol raises); otherwise none. The time of the image counts from the start of the loaded experiment (the first injection); without an experiment, from the date of the baseline. Without a date or such a reference, the image has no time. Analyses which need the date or the time check for it themselves.

Parameters:
sourcePath or bytes

Image file, or the bytes of an image file (e.g. received over a network).

datedatetime, optional

Date of the image, instead of the one of the imaging protocol.

nativebool

Keep the data type resulting from the corrections (the integers of the file without a type correction) instead of converting to float in the end, see darsia.imread_from_optical. Saves memory when many images are held; the user of the image has to support the type (Image.as_float).

Returns:
darsia.Image

Image with the corrections of the rig applied.

read_field(path, *, on_photo=False)[source]#

Read a field of the rig (labels, facies, depth, porosity, …) onto the grid of the baseline.

Parameters:
pathPath

File of the field.

on_photobool

Whether the field was drawn on the uncorrected baseline photo (e.g. labels from the labeling step). Then the shape corrections for fields follow: nearest neighbor resize, curvature correction, final nearest neighbor resize. Drift and type corrections do not apply to fields drawn on the baseline photo itself. Otherwise (default, e.g. saved rigs) the field lies on the corrected baseline and is transferred to its grid (darsia.transfer): center sampling for integer fields, area averaging for float fields; the identity on the grid of the baseline.

Returns:
darsia.Image

The field on the grid of the baseline.

Raises:
ValueError

If a field on the corrected baseline covers another domain than the baseline.

regions(name)[source]#

Regions to group pixels by, on the grid of the labels.

Parameters:
nameRegionName

“labels” (segments), “facies” (groups of labels; the labels without a facies file) or “global” (one region 0, the whole image).

Returns:
darsia.Image

The labels or facies (not copies; not to be modified), or a new zero image.

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, roi_registry=None, image_porosity_config=None, log=None, show_plot=False, dimensions=None)[source]#

Fast setup.

dimensions is the physical size (height, width) of the rig ([rig]); without it, and without a crop correction setting the size, images get the size 1 x 1.

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

Setup label-dependent color corrections after labels 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).

With [corrections.illumination] mask = “boolean_porosity”, the illumination correction is fitted on the boolean image porosity of the current baseline ([image_porosity] method > tol), computed here and not kept; the stored image porosity is a setup step of its own, after the rig.

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, image_porosity_config=None)[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).

image_porosity_configImagePorosityConfig | None

[image_porosity]: with config.mask = “boolean_porosity”, the correction is fitted on the boolean image porosity of the current baseline (method > tol, before cutoff and boundary band), computed here and not kept. None means the defaults.

Notes

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

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, roi_registry=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.