spexread
A package for reading Princeton Instruments SPE files captured by WinSpec (version 2.x) or LightField(version 3.0).
It relies on xarray to handle the many different possible image shapes, ROIs, etc. that can be stored in an SPE file and reads them into a single xarray.Dataset, or a list of xarray.DataArrays.
Important metadata for both format versions is parsed and validated to a consistent schema using pydantic and stored in the attrs attribute of the dataset.
This has a number of key benefits:
-
Data is described and indexed as a function of dimensions or coordinates.
-
Access per-frame tracking information such as
exposure_timeorgate_widthtrivially (when stored, SPE v3.0 only) as coordinates of your data, alongside the core dimensionx,yandframe. -
The
xarray.Datasetsupports multiple regions of interest (ROI's) that can be accessed like a pythondict.- You can handle files in the same way, regardless of amount of ROI's.
-
Metadata remains closely associated with the data and can be easily accessed.
Installing
spexread can be installed easily with pip, from PyPI:
pip install spexread
To install the latest version from GitHub, you can run the following command:
pip install git+https://github.com/AntoineTUE/spexread
Example usage
The example below demonstrates how to plot a kinetic series.
In LightField it is possible to acquire a kinetic series with varying gate width and gate delay, which can be stored to the file.
You can change the frame coordinate with e.g. gate_width in this example, to plot as a function of this coordinate.
from spexread import read_spe_file
from spexread.data_models import SPEType
from pathlib import Path
import matplotlib.pyplot as plt
# read data as a xarray.Dataset
data = read_spe_file(Path("./my_data.spe"))
print(data.coords._names) # lists available coordinate names
# plot spectra
plt.figure()
for name,roi in data.items():
roi.mean(['frame','y']).plot(x='wavelength', label=name)
# Plot trends over time. You can replace `frame` with e.g. `gate_width` as well.
plt.figure()
for name,roi in data.items():
roi.mean(['y','x']).plot(x='frame',label=name)
# easily convert to numpy arrays if needed, other formats possible as well, see xarray docs.
image = data['ROI 0'].mean('frame').to_numpy()
plt.figure()
plt.imshow(image)
# Convert the SPE metadata to a SPEType pydantic model, allowing attribute access
metadata = SPEType.model_validate(data.attrs)
print(metadata.GeneralInfo)
print(metadata.Calibrations.WavelengthCalib)
print(metadata.Calibrations.WavelengthCalib.wavelength)
License
spexread is licensed under the MIT license.
Metadata
Release files for spexread 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spexread-0.2.2.tar.gz | 20.5 kB | With provenance | Details for spexread-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spexread-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for spexread-0.2.2-py3-none-any.whl |
Total release size: 41.6 kB
Release files / spexread-0.2.2.tar.gz
| Download URL | spexread-0.2.2.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ab325ae56636e00836ab6d4808c7467100ce66f1e372b7934c9de4b78e2543c
|
|
BLAKE2b-256 checksum How to use checksums |
b3fa18ec4930b29f8e9d0589acbd52825b78350c5d355d61b53b26e71cb9dcfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logRelease files / spexread-0.2.2-py3-none-any.whl
| Download URL | spexread-0.2.2-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef4ec60d7b74b50b2639e109672756f0b2d13241f7520a95f1b3c8a582a5f6e8
|
|
BLAKE2b-256 checksum How to use checksums |
fd20eae7cc5ea2f7c1c50d06274e7db97816532cb489c0a292dffb9d089ad5cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logSecurity for spexread 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for spexread-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.