Skip to content

Commit 3547bdd

Browse files
authored
Add user transition guide to 2.0, allow spectral_axis_index = -1 (#1226)
* Allow -1 as spectral_axis_index * Add short note about 2.0 to README * Minor doc tweaks * Changelog
1 parent 30bec7b commit 3547bdd

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ New Features
55
^^^^^^^^^^^^
66

77
- Spectral axis can now be any axis, rather than being forced to be last. See docs
8-
for more details. [#1033]
8+
for more details. [#1033, #1226]
99

1010
- Spectrum now properly handles GWCS input for wcs attribute. [#1074]
1111

@@ -24,6 +24,8 @@ Other Changes and Additions
2424
- Spectrum arithmetic now checks whether the spectral axes of the two operand ``Spectrum``
2525
objects are equal, and fails if they are not. [#1211]
2626

27+
- Added documentation about transitioning from 1.x to 2.x. [#1226]
28+
2729
1.20.0 (unreleased)
2830
-------------------
2931

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ continue to work on Python 2, it is not tested and support cannot be guaranteed
4747
(due to the sunsetting of Python 2 support by the Python and Astropy development
4848
teams).
4949

50+
Migrating from Specutils 1.x to 2.x
51+
-----------------------------------
52+
53+
For details about breaking changes made in 2.0, please see the
54+
`specutils documentation <http://specutils.readthedocs.io/en/latest/>`_.
55+
5056
License
5157
-------
5258

docs/index.rst

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,50 @@ guiding document for spectroscopic development in the Astropy Project.
2727
Changes in version 2
2828
====================
2929

30+
The ``Spectrum1D`` class has been renamed to `~specutils.Spectrum` to reduce confusion
31+
about multi-dimensional flux arrays being supported. The current class name will be
32+
deprecated in version 2.1; importing the old name will work but raise a deprecation
33+
warning until then.
34+
35+
Single-dimensional flux use cases should be mostly unchanged in 2.0, with the exception
36+
being that spectrum arithmetic now checks that the spectral axis of both operands are
37+
equal, rather than simply checking that they are the same length. Thus, you will need
38+
to resample onto a common spectral axis if doing arithmetic on spectra with differing
39+
spectral axes.
40+
3041
Specutils version 2 implemented a major change in that `~specutils.Spectrum`
3142
no longer forces the spectral axis to be last for multi-dimensional data. This
3243
was motivated by the desire for greater flexibility to allow for interoperability
3344
with other packages that may wish to use ``specutils`` classes as the basis for
3445
their own, and by the desire for consistency with the axis order that results
3546
from a simple ``astropy.io.fits.read`` of a file. The legacy behavior can be
3647
replicated by setting ``move_spectral_axis='last'`` when creating a new
37-
`~specutils.Spectrum` object.
38-
39-
For a summary of other changes in version 2, please see the
48+
`~specutils.Spectrum` object. `~specutils.Spectrum` will attempt to automatically
49+
determine which flux axis corresponds to the spectral axis during initialization
50+
based on the WCS (if provided) or the shape of the flux and spectral axis arrays,
51+
but if the spectral axis index is unable to be automatically determined you will
52+
need to specify which flux array axis is the dispersion axis with the
53+
``spectral_axis_index`` keyword. Note that since the ``spectral_axis`` can specify
54+
either bin edges or bin centers, a flux array of shape ``(10,11)`` with spectral axis
55+
of length 11 would be ambigious. In this case you could initialize a
56+
`~specutils.Spectrum` with ``bin_specification`` set to either "edges" or "centers"
57+
to break the degeneracy.
58+
59+
An additional change for multi-dimensional spectra is that previously, initializing
60+
such a `~specutils.Spectrum` with a ``spectral_axis`` specified, but no WCS, would
61+
create a `~specutils.Spectrum` instance with a one-dimensional GWCS that was essentially
62+
a lookup table with the spectral axis values. This case will now result in a GWCS with
63+
dimensionality matching that of the flux array to facilitate use with downstream packages
64+
that expect WCS dimensionality to match that of the data. The resulting spatial axes
65+
transforms are simple pixel to pixel identity operations, since no actual spatial
66+
coordinate information is available.
67+
68+
In addition to the changes to the generated GWCS, handling of input GWCS has also been
69+
improved. This mostly manifests in the full GWCS (including spatial information) being
70+
retained in the resulting `~specutils.Spectrum` objects when reading, e.g., JWST spectral
71+
cubes.
72+
73+
For a summary of the changes in version 2, you many also refer to the
4074
`release notes <https://github.com/astropy/specutils/releases>`_.
4175

4276

specutils/spectra/spectrum.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def __init__(self, flux=None, spectral_axis=None, spectral_axis_index=None,
8686
redshift=None, radial_velocity=None, bin_specification=None,
8787
move_spectral_axis=None, **kwargs):
8888

89+
if spectral_axis_index == -1:
90+
spectral_axis_index = flux.ndim - 1
91+
8992
# If the flux (data) argument is already a Spectrum (as it would
9093
# be for internal arithmetic operations), avoid setup entirely.
9194
if isinstance(flux, Spectrum):

0 commit comments

Comments
 (0)