Skip to content

MeasurementManager

Description

Manages saving and loading measurement data collected by the SpectroscopyTool. Handles structured text-based export of both metadata and raw measurement values (wavelength, intensity).

Constructor

python
MeasurementManager(metadata, raw_data)
ParameterTypeDescription
metadatadictMetadata dictionary (e.g., tool info, collection settings).
raw_datadictMeasurement dictionary with "wavelength" and "intensity" keys.

Key Attributes

AttributeTypeDescription
raw_datadictDictionary containing raw measurement data.
wavelengthslist[float]List of measured wavelengths.
intensitieslist[float]List of measured intensities.
metadatadictMetadata associated with the measurement.

Important Methods

MethodReturnsDescription
pretty_print()NoneDisplay the metadata and raw data in a readable format.
generate_file(filename, path)NoneSave the measurement and metadata into a structured .txt file.
read_file(filepath)tupleStatic method to load metadata and measurements from a saved file.

Method Details

Pretty Print

python
pretty_print()

Prints out both metadata and raw data in an easy-to-read format for quick inspection.

Generate File

python
generate_file(filename, path)

Saves the current metadata and measurement data into a text file with the following structure:

plaintext
---- METADATA ----
key1: value1
key2: value2
...

---- RAW DATA ----
wavelength1    intensity1
wavelength2    intensity2
...
  • Automatically adds .txt if the filename does not already have it.
  • Creates both metadata and measurement sections in a human-readable style.

Read File (Static Method)

python
MeasurementManager.read_file(filepath)

Reads a previously saved .txt file and parses:

  • Metadata into a dictionary.
  • Measurements into a dictionary of "Wavelength" and "Intensity" lists.

Returns a tuple: (metadata, measurements)

Usage Example

python
# Initialize a MeasurementManager with collected spectrum
mm = MeasurementManager(metadata, raw_data)

# Save to a file
mm.generate_file(filename="spectrum_20250426", path="./data")

# Read from a file
metadata, measurements = MeasurementManager.read_file("./data/spectrum_20250426.txt")

# Pretty print
mm.pretty_print()

Important Notes

  • Saved text files are easy to inspect manually and compatible with basic parsers (e.g., Python, Excel).
  • The structure is simple but order-sensitive — first METADATA, then RAW DATA.
  • When reading, expects metadata fields separated by ": " and measurement values separated by a tab (\t).

Pre-release documentation · Internal research use only · Not authorized for redistribution.