`SpectralCoord` does not concatenate properly
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 75
Description
### Description
While I can pass an iterable of `SpectralCoord`s to `np.concatenate` and get something that seems mostly correct back, the resulting object is not self-consistent.
### Expected behavior
Concatenating `SpectralCoord`s should result in a `SpectralCoord` with the correct number of `radial_velocity` elements.
### How to Reproduce
```python
import numpy as np
from astropy.coordinates import (
SpectralCoord,
SkyCoord,
CartesianRepresentation,
CartesianDifferential,
ICRS,
)
import astropy.units as U
coords = CartesianRepresentation(
[[1, 2, 3], [4, 5, 6]] * U.Mpc,
xyz_axis=1,
differentials={
"s": CartesianDifferential(
[[10, 20, 30], [40, 50, 60]] * U.km / U.s, xyz_axis=1
)
},
)
skycoords = SkyCoord(coords, frame=ICRS(), copy=True)
origin_skycoord = SkyCoord(
x=0 * U.kpc,
y=0 * U.kpc,
z=0 * U.kpc,
v_x=0 * U.km / U.s,
v_y=0 * U.km / U.s,
v_z=0 * U.km / U.s,
representation_type="cartesian",
differential_type="cartesian",
frame=ICRS(),
)
spectralcoords = SpectralCoord(
skycoords.radial_velocity,
doppler_convention="radio",
doppler_rest=1.4 * U.GHz,
target=skycoords,
observer=origin_skycoord,
)
concatenated_spectralcoords = np.concatenate((spectralcoords, spectralcoords))
assert concatenated_spectralcoords.size == spectralcoords.size * 2
assert (
concatenated_spectralcoords.radial_velocity.size
== spectralcoords.radial_velocity.size * 2
)
```
The `size` attribute of the `SpectralCoord` itself makes sense, but the `radial_velocity` attribute still has the size of just one of the concatenated `SpectralCoord` objects.
### Versions
```
platform
--------
platform.platform() = 'Linux-6.17.10-100.fc41.x86_64-x86_64-with-glibc2.40'
platform.version() = '#1 SMP PREEMPT_DYNAMIC Mon Dec 1 16:10:21 UTC 2025'
platform.python_version() = '3.13.9'
packages
--------
astropy 7.2.0
numpy 2.3.4
scipy 1.17.1
matplotlib 3.10.3
pandas 2.2.3
pyerfa 2.0.1.5
```
Contributor guide
Research direction
Start by reproducing the issue with the provided SpectralCoord, SkyCoord, and np.concatenate example, then trace SpectralCoord concatenation and the radial_velocity property. Done means the concatenated object's size and radial_velocity size both equal twice the original size, with tests covering the regression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100