autoemx.config.ledger_io module

Convenience I/O helpers for sample ledgers.

autoemx.config.ledger_io.create_sample_ledger(sample_dir: str | Path, sample_id: str, configs: LedgerConfigs) → SampleLedger[source]

New ledger of a sample, with its configurations and no spectra, particles or quantification runs (not saved).

autoemx.config.ledger_io.ingest_spectra(ledger: SampleLedger) → tuple[int, int][source]

Synchronize ledger spectra entries with files in <ledger.sample_path>/spectra.

Appends pointer files whose spectrum id is not already present in ledger.spectra and removes ledger entries whose spectrum id no longer exists on disk, so that wrong spectra can be deleted before quantification. Entries that already have quantification results are kept even when their file is missing, since deleting a quantified spectrum is assumed to be a mistake.

Returns:

Number of newly ingested spectra and number of removed spectra.

Return type:

tuple[int, int]

autoemx.config.ledger_io.load_sample_ledger(file_path: str | Path) → SampleLedger[source]

Load a sample ledger, with full legacy bootstrap when ledger.json is missing.

If the ledger file does not exist, this uses legacy Data.csv + config JSON files to bootstrap a populated ledger (configs, spectra, and quantification payloads).

autoemx.config.ledger_io.get_active_quantification_config(ledger: SampleLedger | None) → QuantificationConfig | None[source]

Return the active quantification run of the ledger (the last one if none is active), or None if none.

class autoemx.config.ledger_io.LedgerRuntimeConfigs(microscope_cfg: MicroscopeConfig, sample_cfg: SampleConfig, measurement_cfg: MeasurementConfig, sample_substrate_cfg: SampleSubstrateConfig, plot_cfg: PlotConfig, powder_meas_cfg: PowderMeasurementConfig | None, bulk_meas_cfg: BulkMeasurementConfig | None, quant_cfg: QuantificationOptionsConfig, clustering_cfg: ClusteringConfig, active_quant_config: QuantificationConfig | None)[source]

Bases: object

Configurations of a sample ledger, as used by the runners.

The acquisition configurations are the ledger’s own objects (not copies). The quantification options and the clustering configuration are those of the active quantification run, or defaults if the sample was never quantified or analysed.

microscope_cfg: MicroscopeConfig
sample_cfg: SampleConfig
measurement_cfg: MeasurementConfig
sample_substrate_cfg: SampleSubstrateConfig
plot_cfg: PlotConfig
powder_meas_cfg: PowderMeasurementConfig | None
bulk_meas_cfg: BulkMeasurementConfig | None
quant_cfg: QuantificationOptionsConfig
clustering_cfg: ClusteringConfig
active_quant_config: QuantificationConfig | None
autoemx.config.ledger_io.ledger_runtime_configs(ledger: SampleLedger) → LedgerRuntimeConfigs[source]

Collect the configurations of a sample ledger needed to quantify or analyse it again.

autoemx.config.ledger_io.save_sample_ledger(ledger: SampleLedger, file_path: str | Path, *, indent: int = 2) → None[source]

Save a sample ledger JSON in one call.