WCS: exception if MJD-OBS missing when some other headers present
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 74
Description
### Description
If a FITS header has a spectral axis and OBSGEO-* keywords but no MJD-DATE, then `_get_components_and_classes` crashes because it tries to construct a Time from a NaN MJD. I'm not aware of any requirement in the FITS specification to provide this header, but I didn't comb the entire spec.
### Expected behavior
I'm not familiar with the details of SpectralCoord at all so I don't know what the appropriate fix is, but I would expect the resulting WCS to be basically usable.
### Actual behavior
When running the test code below, received an exception (see first comment - I forgot to paste it when filing the bug).
### Steps to Reproduce
```python
#!/usr/bin/env python3
import astropy.wcs
import astropy.io.fits
header = astropy.io.fits.Header()
header['OBSGEO-X'] = 5109360.133321234
header['OBSGEO-Y'] = 2006852.586042906
header['OBSGEO-Z'] = -3238948.127478876
header['DATE'] = '2020-05-14T08:03:43.930'
header['SPECSYS'] = 'TOPOCENT'
header['TIMESYS'] = 'UTC'
header['EQUINOX'] = 2000.0
header['RADESYS'] = 'FK5'
header['NAXIS'] = 3
header['NAXIS1'] = 100
header['NAXIS2'] = 100
header['NAXIS3'] = 1
header['BUNIT'] = 'Jy/beam'
header['CDELT1'] = 1.0
header['CDELT2'] = 1.0
header['CDELT4'] = 1.0
header['CUNIT1'] = 'deg'
header['CUNIT2'] = 'deg'
header['CUNIT3'] = 'Hz'
header['CTYPE1'] = 'RA---SIN'
header['CTYPE2'] = 'DEC--SIN'
header['CTYPE3'] = 'FREQ'
header['CRVAL1'] = 0.0
header['CRVAL2'] = 0.0
header['CRVAL3'] = 1e9
header['CRPIX1'] = 50.0
header['CRPIX2'] = 50.0
header['CRPIX3'] = 1.0
wcs = astropy.wcs.WCS(header)
wcs.world_axis_object_classes
```
### System Details
Linux-5.4.0-60-generic-x86_64-with-glibc2.29
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
Numpy 1.19.1
astropy 4.3.dev450+gaa71c2f45
Scipy 1.5.2
Matplotlib 3.3.0
Contributor guide
Research direction
Start by reproducing the example header and inspecting `_get_components_and_classes`, where the WCS construction attempts to create a Time from a missing MJD. Review the surrounding comment discussion to determine the appropriate behavior, then verify that the example constructs a usable WCS without raising an exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100