A module for reading Princeton Instruments SPE files (version 2.x and 3.0) captured by WinSpec or LightField
Project description
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.
[!IMPORTANT]
spexreadis functional, but some features and metadata that you use may be missing. Please file an issue and provide a sample file to add support for them. Found a bug? Please raise an issue as well!
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spexread-0.2.0.tar.gz.
File metadata
- Download URL: spexread-0.2.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d65f1f42e41ef2100265d276b26b44f6e0b777f2ca0132d26796a4ff4f9e9332
|
|
| MD5 |
ba865b73cafad8c607b70f7c56a1670c
|
|
| BLAKE2b-256 |
a5b11d321ea4b40a8fa34fdfc86dd532e4ae8d50b9c72429654e6baa7ac06a72
|
Provenance
The following attestation bundles were made for spexread-0.2.0.tar.gz:
Publisher:
build.yml on AntoineTUE/spexread
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spexread-0.2.0.tar.gz -
Subject digest:
d65f1f42e41ef2100265d276b26b44f6e0b777f2ca0132d26796a4ff4f9e9332 - Sigstore transparency entry: 734862934
- Sigstore integration time:
-
Permalink:
AntoineTUE/spexread@ac53370ddbc3380951ba7055ad97199c5dd257d7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/AntoineTUE
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@ac53370ddbc3380951ba7055ad97199c5dd257d7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spexread-0.2.0-py3-none-any.whl.
File metadata
- Download URL: spexread-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e23fb421635877073f4df550b7cf7953927d9130acc0b1f56370b05fa8d0f00b
|
|
| MD5 |
0d5bcc63dbfafd04cfccc945bded1d47
|
|
| BLAKE2b-256 |
c73aa13f7cca9a5162d922a87d01dd11b23cc6811625571d2bfd0362faa78364
|
Provenance
The following attestation bundles were made for spexread-0.2.0-py3-none-any.whl:
Publisher:
build.yml on AntoineTUE/spexread
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spexread-0.2.0-py3-none-any.whl -
Subject digest:
e23fb421635877073f4df550b7cf7953927d9130acc0b1f56370b05fa8d0f00b - Sigstore transparency entry: 734862975
- Sigstore integration time:
-
Permalink:
AntoineTUE/spexread@ac53370ddbc3380951ba7055ad97199c5dd257d7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/AntoineTUE
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@ac53370ddbc3380951ba7055ad97199c5dd257d7 -
Trigger Event:
push
-
Statement type: