spectrochempy.ScpObjectList

class ScpObjectList(iterable=(), /)[source]

A list subclass for groups of SpectroChemPy objects returned by public APIs.

ScpObjectList behaves like a regular Python list while exposing a few helpers that are especially useful when a reader returns several datasets instead of a single merged NDDataset.

Available helpers include:

Examples

>>> datasets = scp.read_matlab("data.mat", merge=False)
>>> datasets.names
>>> X = datasets.select_largest(ndim=2)
>>> C = datasets.select_by_name("conc")

Attributes Summary

names

Return a list of dataset names.

Methods Summary

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

filter_by_ndim(ndim)

Return a new ScpObjectList containing only datasets with ndim dimensions.

filter_by_shape(shape)

Return a new ScpObjectList containing only datasets with a given shape.

index(value[, start, stop])

Return first index of value.

insert(index, object, /)

Insert object before index.

pop([index])

Remove and return item at index (default last).

remove(value, /)

Remove first occurrence of value.

reverse()

Reverse IN PLACE.

select_by_name(name)

Select the first dataset whose name contains name (case-insensitive).

select_largest([ndim])

Select the dataset with the largest number of elements.

sort(*[, key, reverse])

Sort the list in ascending order and return None.

Attributes Documentation

names

Return a list of dataset names.

Methods Documentation

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

filter_by_ndim(ndim)[source]

Return a new ScpObjectList containing only datasets with ndim dimensions.

Filters the list to include only datasets that have the specified number of dimensions.

Parameters:

ndim (int) – Number of dimensions to filter by.

Returns:

ScpObjectList – A new list with matching datasets.

filter_by_shape(shape)[source]

Return a new ScpObjectList containing only datasets with a given shape.

Filters the list to include only datasets whose shape exactly matches the provided tuple.

Parameters:

shape (tuple) – Shape to match exactly.

Returns:

ScpObjectList – A new list with matching datasets.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

insert(index, object, /)

Insert object before index.

pop(index=-1, /)

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value, /)

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()

Reverse IN PLACE.

select_by_name(name)[source]

Select the first dataset whose name contains name (case-insensitive).

Parameters:

name (str) – Substring to match against dataset names.

Returns:

object – The first matching dataset.

Raises:

ValueError – If no matching dataset is found.

Examples

>>> datasets = scp.read_matlab("data.mat", merge=False)
>>> C = datasets.select_by_name("conc")  # concentration profile
select_largest(ndim=None)[source]

Select the dataset with the largest number of elements.

Parameters:

ndim (int, optional) – If given, restrict selection to datasets with this number of dimensions.

Returns:

object – The largest matching dataset.

Raises:

ValueError – If the list is empty or no matching dataset is found.

Examples

>>> datasets = scp.read_matlab("data.mat", merge=False)
>>> X = datasets.select_largest(ndim=2)  # biggest 2D dataset
sort(*, key=None, reverse=False)

Sort the list in ascending order and return None.

The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).

If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.

The reverse flag can be set to sort in descending order.

Examples using spectrochempy.ScpObjectList

MCR-ALS example (adapted from Jaumot et al. 2005)

MCR-ALS example (adapted from Jaumot et al. 2005)

MCR-ALS with kinetic constraints

MCR-ALS with kinetic constraints

SIMPLISMA example

SIMPLISMA example

PLS regression example

PLS regression example

Reading datasets

Reading datasets

Reading SPC format files

Reading SPC format files