Scipp
Scipp is a Python library for multi-dimensional data arrays with labeled dimensions, designed for scientific data analysis, especially in neutron and muon scattering. It provides unit-aware data structures and operations, enabling robust handling of physical quantities. The current version is 26.3.1, and it maintains a rapid release cadence with monthly major updates.
Common errors
-
ModuleNotFoundError: No module named 'scipp'
cause The scipp package is not installed in the current Python environment.fixRun `pip install scipp` to install the library. -
scipp.core.UnitError: Units do not match
cause Attempting an operation (e.g., addition, subtraction) on Scipp variables or data arrays that have incompatible physical units.fixEnsure all operands have compatible units. Use `my_var.to(target_unit)` to convert units or `my_var.without_units()` to remove units before the operation. -
TypeError: 'Variable' object is not subscriptable
cause Trying to access elements of a `scipp.Variable` object using array indexing (e.g., `my_variable[0]`) instead of its underlying NumPy array.fixAccess the underlying NumPy array first using `.values` attribute: `my_variable.values[0]`. -
scipp.core.DimensionError: Cannot perform operation ... dimensions ... do not align
cause Operations between data arrays with non-matching dimensions, dimension labels, or dimension order without explicit alignment.fixEnsure dimensions align or explicitly broadcast/reorder them. For element-wise operations, dimensions and their order must match. Use `my_da.transpose()` or ensure common dimensions are present.
Warnings
- breaking Scipp dropped support for Python 3.10. Users must upgrade to Python 3.11 or newer.
- breaking The custom HTML representation for Scipp objects in Jupyter notebooks (`sc` notebook HTML repr) was removed. Objects now rely on their standard `__repr__` method.
- gotcha Scipp is strictly unit-aware. Operations on `Variable` or `DataArray` objects with incompatible units will raise a `UnitError`.
- gotcha Accessing the underlying NumPy array data requires using the `.values` attribute. Directly indexing a `Variable` object will result in a `TypeError`.
Install
-
pip install scipp
Imports
- scipp
import scipp as sc
- Variable
from scipp import Variable
- DataArray
from scipp import DataArray
- Dataset
from scipp import Dataset
Quickstart
import scipp as sc
import numpy as np
# Create a variable with units
x = sc.linspace(dim='x', start=0.1, stop=0.9, num=10, unit='m')
y = sc.sin(x)
# Create a DataArray, including coordinates and data
data_array = sc.DataArray(data=y, coords={'x': x})
print("Original DataArray:\n", data_array)
# Perform a unit-aware operation (e.g., sum over 'x' dimension)
sum_result = data_array.sum('x')
print("\nSum along 'x' dimension:\n", sum_result)