Workflows, Interoperability & Provenance API#
Auto-Detection (pymorgan.detect)#
Universal format auto-detection and dispatching for PyMORGAN.
- class pymorgan.detect.FormatMatch(dimension, data_type, confidence, reason, resolved_path)[source]#
Bases:
objectResult of probing a file or directory for its PyMORGAN dataset format.
- Parameters:
- pymorgan.detect.detect_format(path, *, return_all=False)[source]#
Detect the PyMORGAN dataset/project/recipe format for
path.- Parameters:
return_all (bool) – When
True, return a list of all matchingFormatMatchentries ordered by descending confidence. WhenFalse(default), return the single highest-confidence match orNone.
- Return type:
FormatMatch | list[FormatMatch] | None
Glotaran / pyglotaran Interoperability (pymorgan.oneD.interop)#
Interoperability readers and writers for Glotaran / pyglotaran formats.
- pymorgan.oneD.interop.read_glotaran_ascii(path)[source]#
Read a Glotaran / TIMP
.asciifile (Time explicitorWavelength explicit).
- pymorgan.oneD.interop.write_glotaran_ascii(dataset, path, *, orientation='time', signal_unit='mOD', use_corrected=True, detector=0)[source]#
Export a
Dataset1Dto Glotaran / TIMP.asciiformat.
- pymorgan.oneD.interop.read_glotaran_nc(path)[source]#
Read a Glotaran / pyglotaran NetCDF4 (CF-1.8 / HDF5) dataset (
.nc).
FAIR HDF5 Metadata Helpers (pymorgan.hdf5_meta)#
FAIR / NeXus HDF5 metadata and compressed dataset helpers for PyMORGAN.
- pymorgan.hdf5_meta.json_safe_value(val)[source]#
Recursively convert
valto a JSON-serializable structure.Returns
(ok, converted)whereokisFalsefor raw multi-element arrays or unsupported objects so caller mappings can drop them safely.
- pymorgan.hdf5_meta.json_safe_units(mapping, *, drop_keys=frozenset({}))[source]#
Return a JSON-safe copy of
mapping, dropping ndarray/excluded entries.
- pymorgan.hdf5_meta.compute_source_sha256(source, *, max_bytes=52428800)[source]#
Return the hex SHA-256 of
sourceif it is a regular file undermax_bytes.
- pymorgan.hdf5_meta.extract_sample_info_metadata(units)[source]#
Collect sample-info strings and instrument metadata dictionaries from
units.
- pymorgan.hdf5_meta.write_fair_root_attrs(f, *, pymorgan_format, source=None, original_data_type=None, units=None, dataset=None, format_version='2.0')[source]#
Populate FAIR / NeXus root HDF5 attributes on
f.
- pymorgan.hdf5_meta.restore_dataset_history(f, ds)[source]#
Restore processing history from
history_jsonattr if supported byds.- Parameters:
ds (Any)
- Return type:
None
- pymorgan.hdf5_meta.create_compressed_dataset(group, name, data, *, units=None, long_name=None, dtype=None)[source]#
Create a gzip+shuffle compressed HDF5 dataset with optional CF metadata attrs.
- pymorgan.hdf5_meta.deserialize_chirp_fit(raw_json)[source]#
Deserialize JSON created by
serialize_chirp_fit()back intoChirpFit.
Processing Provenance & Script Export (pymorgan.provenance)#
Processing provenance, undo/redo history, and Python script export for PyMORGAN.
- pymorgan.provenance.sanitize_params(params)[source]#
Return a JSON/TOML-safe parameter dictionary with
Noneentries omitted.
- pymorgan.provenance.format_step_label(op, params=None)[source]#
Build a concise human-readable label for a processing step.
- class pymorgan.provenance.ProcessingStep(op, params=<factory>, timestamp_utc=<factory>, label='')[source]#
Bases:
objectRecord of a single semantic processing operation applied to a dataset.
- classmethod from_dict(data)[source]#
Reconstruct a
ProcessingStepfrom a serialized dictionary.- Parameters:
- Return type:
- class pymorgan.provenance.HistoryManager(*, max_snapshots=12)[source]#
Bases:
objectBounded undo/redo stack and semantic processing history for a dataset.
- Parameters:
max_snapshots (int)
- property steps: list[ProcessingStep]#
Ordered list of recorded processing steps.
- guard()[source]#
Re-entrancy guard preventing inner helper calls from recording extra steps.
- Return type:
Iterator[None]
- suppress()[source]#
Temporarily disable history recording (e.g. during internal GUI init).
- Return type:
Iterator[None]
- ensure_baseline(ds)[source]#
Capture the initial raw state once before the first recorded mutation.
- Parameters:
ds (Any)
- Return type:
None
- record_call(ds, op, fn, *, params_fn=None, params=None, label='', coalesce=False, should_record=None)[source]#
Execute
fn()inside the re-entrancy guard and record a step on success.If
fn()raises, no snapshot is pushed and history remains untouched.
- commit_coalesced_external(ds, op, params, pre_snap=None, *, coalesce=True, label='')[source]#
Record or coalesce a step computed on a worker copy onto
ds.
- update_last_step_param(op, key, value)[source]#
Update a parameter on the latest step if it matches
op(e.g. post-save chirp path).
- pymorgan.provenance.generate_python_script(ds, *, include_plot=True, include_settings=True, plot_kwargs=None)[source]#
Generate a clean, standalone, Ruff-valid Python script reproducing
ds.- Parameters:
ds (Dataset1D or Dataset2D) – Processed dataset whose recorded history will be emitted.
include_plot (bool, default True) – Whether to append
pm.apply_style(), a contour/map plot, andpm.show_plots().include_settings (bool, default True) – Whether to emit
pm.update_settings(...)for non-default settings.plot_kwargs (mapping, optional) – Extra keyword arguments passed to
ds.plot_contour(...)(1D) ords.plot_map(...)(2D).
- Return type:
Processing Recipes (pymorgan.recipe)#
Portable TOML processing recipes (.pmrecipe.toml) for PyMORGAN.
- pymorgan.recipe.resolve_aux_path(raw_path, *, base_dir=None, dataset_source=None, fallback_abs=None)[source]#
Resolve an auxiliary file path against
base_dir,dataset_source, orfallback_abs.
- class pymorgan.recipe.Recipe(schema_version='1.0', name='Untitled Recipe', dimension='1D', data_type='auto', calibration_file=None, steps=<factory>, export_formats=<factory>, export_suffix='_PROCESSED', write_noise=True, description='')[source]#
Bases:
objectSerializable, dataset-agnostic processing recipe (
.pmrecipe.toml).- Parameters:
- classmethod from_dataset(ds, *, name=None, data_type=None, calibration_file=None, export_formats=None, export_suffix='_PROCESSED', write_noise=True, description='', base_dir=None)[source]#
Build a
Recipefrom a processed dataset’s recorded history.
Batch Processing Engine (pymorgan.batch)#
Headless and GUI-callable batch processing engine for PyMORGAN.
- class pymorgan.batch.BatchItemResult(input_path, data_type, status, elapsed_s=0.0, output_files=<factory>, error=None)[source]#
Bases:
objectResult record for a single dataset in a batch run.
- Parameters:
- class pymorgan.batch.BatchReport(recipe_name, output_dir, total, succeeded, failed, skipped, cancelled=False, dry_run=False, elapsed_s=0.0, items=<factory>, report_csv=None, report_json=None)[source]#
Bases:
objectAggregated summary of a batch processing execution.
- Parameters:
- items: list[BatchItemResult]#
- pymorgan.batch.discover_batch_inputs(paths_or_dir, *, data_type='auto', dimension=None, glob_pattern=None, recursive=False)[source]#
Discover dataset files/folders suitable for batch processing.
- Parameters:
paths_or_dir (path-like or iterable of path-like) – File path(s) or directory path(s) to scan.
data_type (str, default "auto") – Explicit PyMORGAN loader key (e.g.
"PDAT","P2DAT","PyMESS_PP") or"auto"to sniff formats automatically.dimension ({"1D", "2D"}, optional) – Filter auto-discovered inputs to a specific dimensionality.
glob_pattern (str, optional) – Optional filename wildcard pattern (e.g.
"sample_*.pdat").recursive (bool, default False) – Recurse into subdirectories when scanning folders.
- Returns:
Sorted deduplicated list of
(resolved_path, data_type)pairs.- Return type:
- pymorgan.batch.run_batch(inputs, recipe, output_dir, *, workers=1, on_error='skip', dry_run=False, base_dir=None, progress_callback=None, cancel_event=None)[source]#
Apply
recipeacross a sequence of dataset inputs and write reports.- Parameters:
inputs (sequence of path-like or
(path, data_type)tuples) – Input datasets to process.recipe (Recipe or path to
.pmrecipe.toml) – LoadedRecipeinstance or path to load one from.output_dir (str or PathLike) – Directory where processed exports and
batch_report.{csv,json}are saved.workers (int, default 1) – Number of worker processes (
workers > 1usesProcessPoolExecutor).on_error ({"skip", "stop"}, default "skip") – Whether to continue past item errors (
"skip") or abort remaining work.dry_run (bool, default False) – If True, discover and report planned outputs without processing or writing files.
base_dir (str or PathLike, optional) – Base directory for resolving relative auxiliary files inside the recipe.
progress_callback (callable, optional) – Called as
progress_callback(completed_count, total_count, item_result).cancel_event (threading.Event-like, optional) – Object with
is_set() -> boolchecked between items for cooperative cancellation.
- Return type:
Project Sessions (pymorgan.project)#
Portable TOML session/project files (.pmproj) for PyMORGAN.
- pymorgan.project.resolve_session_path(entry, abs_fallback=None, *, base_dir=None, role='file', relocate_callback=None, warnings_out=None)[source]#
Resolve a project file/dir reference using relative first, then abs fallback, then callback.
- class pymorgan.project.ProjectSession(schema_version='1.0', root_dir=None, root_dir_abs=None, active_tab=0, oneD=<factory>, twoD=<factory>, settings_overrides=<factory>, saved_utc='', project_path=None)[source]#
Bases:
objectSerializable full workspace session (
.pmproj) for PyMORGAN.- Parameters:
- classmethod from_dict(data)[source]#
Construct a
ProjectSessionfrom a parsed TOML dictionary.- Parameters:
- Return type:
- classmethod load(path)[source]#
Load a
ProjectSessionfrom a.pmprojfile.- Parameters:
- Return type: