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.

Ra/Dec axes not appearing with WCS

See original GitHub issue

Description

When using an image where WCS coords are aligned with the CCD coords the RA/Dec axes do not appear

Expected behavior

Have Ra/Dec axes when plotting with projection=wcs

Actual behavior

The Ra/Dec axes do not appear

Steps to Reproduce

1.Import relevant packages

import matplotlib.pyplot as plt
import os
from astropy.wcs import WCS
from astropy.io import fits
from astropy import units as u
from astropy.visualization import ZScaleInterval
from astropy.utils import data
  1. Download the data

remote_url = 'https://lsst.ncsa.illinois.edu/~scichris/postISRCCD_LSSTComCam_r_03_CC_H_20211231_006002_R22_S01_run1.fits'
file_path = data.download_file(remote_url)
print(f'Using {file_path}')

  1. Get the WCS and data from fits file
hdul = fits.open(file_path)
wcs = WCS(hdul[1].header)
data = hdul[1].data
zscale = ZScaleInterval()
vmin, vmax = zscale.get_limits(data)
  1. Plot the data
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(1, 1, 1, projection=wcs)
ax.imshow(data,  origin='lower', vmin=vmin, vmax=vmax,cmap='Greys',)
ax.grid(color='yellow', ls='solid')
ax.set_xlabel('Right Ascension')
ax.set_ylabel('Declination')
  1. Other plot commands tried (that were recommended but did not solve the issue):
# obtain the axes 
ra = ax.coords['ra']
dec = ax.coords['dec']
# change the spacing to be more narrow
ra.set_ticks(spacing=2 * u.arcmin, color='white')
dec.set_ticks(spacing=2 * u.arcmin, color='white')
# set the axis label
ra.set_axislabel('RA', minpad=0.3)
dec.set_axislabel('DEC', minpad=0.3)
# se the tick label 
ra.set_ticklabel_position('b')
ra.set_axislabel_position('b')

System Details

Linux-3.10.0-1160.15.2.el7.x86_64-x86_64-with-glibc2.10 Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27) [GCC 9.3.0] Numpy 1.20.2 astropy 4.2.1 Scipy 1.6.3 Matplotlib 3.4.2

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
embraycommented, May 21, 2021

Thanks for the detailed report. I was able to reproduce the problem. While playing around with it I got it to correctly display the axis labels and titles exactly once and then it never worked again. I have no idea how.

0reactions
suberlakcommented, May 21, 2021

Ok, thank you! I expected RA to be on the bottom, but if I use

ra =  ax.coords['ra']
ra.set_ticklabel_position('b')
ra.set_axislabel_position('b')
ra.set_axislabel('RA')

I get nothing. The only way for axes to appear was

ra = ax.coords['ra']
ra.set_ticklabel_position('l')
ra.set_axislabel_position('l')
ra.set_axislabel('RA')
dec  = ax.coords['ra']
dec.set_ticklabel_position('b')
dec.set_axislabel_position('b')
dec.set_axislabel('DEC')
It's interesting, reading issue #7180 I see some similarities. It is phosim-simulated data so it is possible that the WCS is off (in fact that's what I was fixing by changing the `ROTANG` in the header), but perhaps I also needed to change the CD matrix. Is it possible to rotate the CD matrix with 'astropy.wcs' (same question as https://github.com/astropy/astropy/issues/7180#issuecomment-520088274 but I didn't find an answer in the thread) . Thanks!
Read more comments on GitHub >

github_iconTop Results From Across the Web

WCS — Astropy v5.2
If an axis does not have a name, an empty string should be returned (this is the default behavior for all axes if...
Read more >
WCS — Astropy v1.0.4
The order of the axes for the input world array is determined by the CTYPEia keywords in the FITS header, therefore it may...
Read more >
plot RA/Dec polygons with astropy wcs aplpy FITSFigure
plot RA/Dec polygons with astropy wcs aplpy FITSFigure ... zvalues = [5,2] # setup our radec-pixel coordinate transformation w = WCS( ...
Read more >
World Coordinate Systems — GalSim 2.4.6 documentation
RaDecFunction. AstropyWCS ... toWorld(image_pos) is not implemented for a particular WCS class, ... This is basically the semi-major axis of the Jacobian.
Read more >
From sky coordinates to pixels (and back) - Joseph Long
To plot on axes labeled with the celestial coordinates for our image, we pass projection=wcs when creating our axes.
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