Registry / data / specutils

specutils

JSON →
library2.4.0pypypi✓ verified 83d ago

A Python package for spectroscopic astronomical data analysis, part of the Astropy ecosystem. Version 2.3.0 supports Python >=3.11. It provides classes for representing spectra (Spectrum1D, SpectrumList), spectral regions, and operations like resampling, fitting, and combining spectra. Release cadence is irregular with major version bumps about every 2 years.

pip install specutils
INSTALL
IMPORT
SIG · SPECUTILS
S
specutils
datapythonv2.4.0
Install
12.2s avg
Import
4059ms
Disk
327MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 4.184s · 318.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 12.2s · import 3.934s · 315MB
327MB installed
● package 327MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Spectrum1D
from specutils import Spectrum1D
from specutils import Spectrum1D as Spectrum1D
No common mistake; classic import is correct.
SpectralRegion
from specutils import SpectralRegion
import SpectralRegion
SpectralRegion is a class in specutils, not a top-level module.

Basic usage: create a Spectrum1D and extract a spectral region.

import numpy as np from specutils import Spectrum1D, SpectralRegion from specutils.manipulation import extract_region from astropy import units as u # Create a simple spectrum flux = np.array([1.0, 2.0, 3.0]) * u.Jy spectral_axis = np.array([5000, 5010, 5020]) * u.Angstrom spec = Spectrum1D(spectral_axis=spectral_axis, flux=flux) # Extract a region region = SpectralRegion(5005 * u.Angstrom, 5015 * u.Angstrom) extracted = extract_region(spec, region) print(extracted)
Debug
Known issues
breakingIn specutils 2.x, the class previously known as Spectrum1D is now Spectrum and Spectrum1D is an alias. Code relying on Spectrum1D subclassing may break if using isinstance checks against old class hierarchy.
fix
Use 'from specutils import Spectrum' for new code, or continue using Spectrum1D as an alias.
affects: 2.0.0 and later
breakingSupport for Python 3.10 dropped in specutils 2.2.0. Python 3.11 or later is required.
fix
Upgrade to Python >=3.11.
affects: 2.2.0 and later
deprecatedThe 'spectral_axis_index' keyword argument introduced in 2.0 is deprecated in favor of automatic detection. Using it may emit deprecation warnings.
fix
Remove spectral_axis_index and rely on automatic axis ordering.
affects: 2.0.0 through current
gotchaWhen passing a SpectralRegion to extract_region, if the units of the region do not match the spectrum's spectral axis units, an error may not be raised immediately but results can be incorrect. Always ensure consistent units.
fix
Use equivalencies if needed, e.g., via astropy.units.equivalencies.spectral().
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'specutils' has no attribute 'Spectrum1D'
Outdated specutils version (<1.20) where Spectrum1D was not yet exposed at top level.
fix
Upgrade specutils to >=1.20: pip install --upgrade specutils
ValueError: The spectral axis must be monotonically increasing.
Spectral axis values are not sorted in ascending order.
fix
Ensure spectral_axis is sorted: spec = Spectrum1D(spectral_axis=np.sort(spectral_axis), flux=flux)
ImportError: No module named 'gwcs'
Missing optional dependency for GWCS support.
fix
Install gwcs: pip install gwcs
Upgrade
Version history
2.4.0latest on PyPI · released Jun 1, 2026
Audit
Dependencies
astropyrequiredCore dependency for units, quantities, and WCS
gwcsoptionalFor generalized WCS support in Spectrum2D
scipyrequiredFor interpolation and fitting backends
ndcubeoptionalFor multi-dimensional spectral cubes
Agent activity
3 hits · last 30 days
node
2
OpenAI (training)
1
Resources
specutils — pip install specutils · libregistry