OSChromatogram#

class pyopenms.OSChromatogram#

Bases: object

Cython implementation of _OSChromatogram

Original C++ documentation is available here

__init__()#

Overload:

__init__(self) None

Overload:

__init__(self, in_0: OSChromatogram) None

Methods

__init__

get_data_arrays

Get all data arrays associated with the chromatogram.

get_intensity_array

Get the intensity array of the chromatogram as a numpy array (copy).

get_intensity_array_mv

Get the intensity array of the chromatogram as a memory view (no copy).

get_time_array

Get the time array of the chromatogram as a numpy array (copy).

get_time_array_mv

Get the time array of the chromatogram as a memory view (no copy).

set_data_arrays

Set all data arrays for the chromatogram.

set_intensity_array

Set the intensity array for the chromatogram.

set_time_array

Set the time array (retention times) for the chromatogram.

get_data_arrays()#

Get all data arrays associated with the chromatogram.

This includes the time array, intensity array, and any additional meta data arrays that may be present in the chromatogram.

Returns:
list: A list of OSBinaryDataArray objects containing all data arrays

associated with this chromatogram.

Example:
>>> chromatogram = OSChromatogram()
>>> data_arrays = chromatogram.get_data_arrays()
>>> print(f"Number of data arrays: {len(data_arrays)}")
>>> for i, array in enumerate(data_arrays):
...     print(f"Array {i}: {len(array.get_data())} data points")
get_intensity_array()#

Get the intensity array of the chromatogram as a numpy array (copy).

Returns:
np.ndarray: A 1D numpy array (float64) containing the intensity values

for each data point in the chromatogram.

Example:
>>> chromatogram = OSChromatogram()
>>> intensities = chromatogram.get_intensity_array()
>>> print(f"Max intensity: {max(intensities)}")
>>> # Safe to modify the returned array
>>> intensities *= 2.0  # This won't affect the original data
get_intensity_array_mv()#

Get the intensity array of the chromatogram as a memory view (no copy).

This method provides direct access to the underlying data without copying, which is more memory efficient for large datasets.

Returns:
memoryview: A memory view of the intensity values

for each data point in the chromatogram, or None if empty.

Warning:

DO NOT store the returned memory view for later use after the chromatogram object goes out of scope, as this will lead to undefined behavior and potential crashes.

Example:
>>> chromatogram = OSChromatogram()
>>> intensities_mv = chromatogram.get_intensity_array_mv()
>>> # CORRECT: Use immediately for calculations
>>> total_intensity = sum(intensities_mv)
>>>
>>> # WRONG: Don't do this!
>>> # stored_mv = chromatogram.get_intensity_array_mv()
>>> # del chromatogram  # Memory view now points to invalid memory!
>>> # print(sum(stored_mv))  # Undefined behavior/crash
get_time_array()#

Get the time array of the chromatogram as a numpy array (copy).

Returns:
np.ndarray: A 1D numpy array (float64) containing the time values (retention times)

for each data point in the chromatogram.

Example:
>>> chromatogram = OSChromatogram()
>>> times = chromatogram.get_time_array()
>>> print(f"Retention times: {times}")
>>> # Safe to modify the returned array
>>> times[0] = 0.0  # This won't affect the original data
get_time_array_mv()#

Get the time array of the chromatogram as a memory view (no copy).

This method provides direct access to the underlying data without copying, which is more memory efficient for large datasets.

Returns:
memoryview: A memory view of the time values (retention times)

for each data point in the chromatogram, or None if empty.

Warning:

DO NOT store the returned memory view for later use after the chromatogram object goes out of scope, as this will lead to undefined behavior and potential crashes.

Example:
>>> chromatogram = OSChromatogram()
>>> times_mv = chromatogram.get_time_array_mv()
>>> # CORRECT: Use immediately
>>> max_time = max(times_mv)
>>>
>>> # WRONG: Don't do this!
>>> # stored_mv = chromatogram.get_time_array_mv()
>>> # del chromatogram  # Memory view now points to invalid memory!
>>> # print(stored_mv[0])  # Undefined behavior/crash
set_data_arrays()#

Set all data arrays for the chromatogram.

This method replaces all existing data arrays with the provided ones. The input should include time array, intensity array, and any additional meta data arrays.

Args:
inp (list): A list of OSBinaryDataArray objects to set as the

chromatogram’s data arrays.

Raises:
AssertionError: If inp is not a list or contains elements that are

not OSBinaryDataArray instances.

Example:
>>> chromatogram = OSChromatogram()
>>> time_array = OSBinaryDataArray()
>>> intensity_array = OSBinaryDataArray()
>>> # ... populate arrays with data ...
>>> chromatogram.set_data_arrays([time_array, intensity_array])
set_intensity_array()#

Set the intensity array for the chromatogram.

Args:
data (list): A list of numeric values representing the intensity values

for each data point in the chromatogram. The length should match the time array length.

Raises:

AssertionError: If data is not a list.

Example:
>>> chromatogram = OSChromatogram()
>>> intensities = [1000.0, 1500.0, 2000.0, 1200.0, 800.0]
>>> chromatogram.set_intensity_array(intensities)
>>> # Make sure length matches time array
>>> assert len(intensities) == len(chromatogram.get_time_array())
set_time_array()#

Set the time array (retention times) for the chromatogram.

Args:
data (list): A list of numeric values representing the retention times

for each data point in the chromatogram. Values should be in ascending order.

Raises:

AssertionError: If data is not a list.

Example:
>>> chromatogram = OSChromatogram()
>>> retention_times = [0.5, 1.0, 1.5, 2.0, 2.5]  # in minutes
>>> chromatogram.set_time_array(retention_times)