question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WCS: exception if MJD-OBS missing when some other headers present

See original GitHub issue

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

#!/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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bmerrycommented, Jan 14, 2021

I think one could just proceed with observer = None as already in the case for missing wcs.wcs.obsgeo.

That is one solution I had in mind. An alternative might be to create the observer without an obstime, but I don’t know if that’s just going to cause an exception down the road when you try to change frames (possibly it makes sense for some values of SPECSYS?)

However DATE-AVG/MJD-AVG, and with lower priority -BEG/-END, would certainly acceptable replacements

In fact the spec says “In order to compute the velocities it is necessary to have the date and time of the observation; the keywords DATE-AVG and MJD-AVG are reserved for this purpose.” That sounds like they should be considered before DATE-OBS/MJD-OBS.

1reaction
bmerrycommented, Jan 13, 2021

Whoops, I pasted the sample code twice instead of pasting the traceback. I get the same exception though. I’ll just edit the report to remove the duplicated sample code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intercept @RequestHeader exception for missing header
The response when you access your API without the required request header is: Missing request header 'Authorization' for method parameter of ...
Read more >
WCSLIB: wcshdr.h File Reference
wcspih () is a high-level FITS WCS routine that parses an image header. · wcsbth() is the analogue of wcspih() for use with...
Read more >
Tutorial wcs module — Kapteyn Package (home)
An object of this class is created using the header of the FITS file for which we want WCS transformations. It accepts also...
Read more >
Source code for astropy.wcs.wcsapi.fitswcs
This file includes the definition of a mix-in class that provides the low- # and high-level ... attach_zero_velocities from astropy.utils.exceptions import ...
Read more >
Tutorial wcs module — Kapteyn 3.0.0-beta documentation
An object of this class is created using the header of the FITS file for which we want WCS transformations. It accepts also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found