Построение полигонов RA/Dec с астропией wcs aplpy ​​FITSFigure

У меня есть несколько многоугольников в сферических координатах RA/Dec, и я пытаюсь построить их с помощью aplpy ​​и объекта системы координат мировой астропии (WCS), но мой скрипт вылетает.

Я могу воспроизвести проблему с помощью этого автономного скрипта:

#!/usr/bin/env python
import astropy
import aplpy, numpy
from numpy import array
import matplotlib.pyplot as plt
from matplotlib import cm, colors
from astropy.wcs import WCS

cent_ra  =   1 # plot center, ra,  deg
cent_dec =  88 # plot center, dec, deg
rad      =   7 # plot radius, deg
rad_pix  = 300 # plot radius, pixels

# two polygons to plot, in ra-dec space
polygons_radec = [ array([[ 1.0, 88.0],[ 2.0, 88.0],[ 2.0, 89.0],[ 1.0, 88.0]]),
                   array([[ 1.0, 88.0],[ 2.0, 88.0],[ 2.0, 87.0],[ 1.0, 88.0]]) ]
zvalues = [5,2]

# setup our radec-pixel coordinate transformation
w = WCS( naxis=2 )
w.naxis1 = 2 * rad_pix
w.naxis2 = 2 * rad_pix
w.wcs.crpix = [rad_pix, rad_pix]  # reference pixel
w.wcs.crval = [ cent_ra, cent_dec ]  # reference pixel's ra/dec coordinate?
w.wcs.cdelt = array([ rad/rad_pix, rad/rad_pix ]) # pixel delta in ra/dec space?
w.wcs.ctype = ['RA--TAN','DEC-TAN']

# convert the ra-dec polygon coordinates to pixel coordinates
polygons = []
for p in polygons_radec :
  polygon = []
  for c in p :
    polygon += [ w.wcs_world2pix( c[0], c[1], 1 ) ]
  polygons += [ array( polygon ) ]
print('polygons:')
print(polygons)
print()

# plot our polygons with colors
cmap1 = cm.YlOrBr
norm1 = colors.Normalize( numpy.min(zvalues), numpy.max(zvalues) )
fig   = aplpy.FITSFigure( w )
for p, c in zip( polygons, zvalues ) :
  fig.show_polygons( [p], facecolor=cmap1(norm1(c)), edgecolor='none', alpha=0.3 )

plt.savefig( 'plot.png' , dpi=300 )

Когда я пытаюсь запустить это, я получаю довольно большой след / исключение:

Traceback (most recent call last):
  File "./test.py", line 46, in <module>
    plt.savefig( 'plot.png' , dpi=300 )
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/pyplot.py", line 696, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/figure.py", line 1563, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/backends/backend_qt5agg.py", line 203, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 2232, in print_figure
    **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py", line 527, in print_png
    FigureCanvasAgg.draw(self)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py", line 474, in draw
    self.figure.draw(self.renderer)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/artist.py", line 62, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/figure.py", line 1159, in draw
    func(*args)
  File "/.../miniconda3/lib/python3.5/site-packages/mpl_toolkits/axes_grid1/parasite_axes.py", line 295, in draw
    self._get_base_axes_attr("draw")(self, renderer)
  File "/.../miniconda3/lib/python3.5/site-packages/mpl_toolkits/axisartist/axislines.py", line 772, in draw
    super(Axes, self).draw(renderer, inframe)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/artist.py", line 62, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/axes/_base.py", line 2319, in draw
    a.draw(renderer)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/artist.py", line 62, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/axis.py", line 1108, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/axis.py", line 951, in _update_ticks
    tick_tups = [t for t in self.iter_ticks()]
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/axis.py", line 951, in <listcomp>
    tick_tups = [t for t in self.iter_ticks()]
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/axis.py", line 898, in iter_ticks
    for i, val in enumerate(majorLocs)]
  File "/.../miniconda3/lib/python3.5/site-packages/matplotlib/axis.py", line 898, in <listcomp>
    for i, val in enumerate(majorLocs)]
  File "/.../miniconda3/lib/python3.5/site-packages/aplpy/labels.py", line 421, in __call__
    label = self.axis.apl_tick_spacing * self.axis.apl_tick_positions_world[ipos]
  File "/.../miniconda3/lib/python3.5/site-packages/aplpy/angle_util.py", line 242, in __mul__
    s = Angle(sexagesimal=(d, m, s), latitude=self.latitude)
  File "/.../miniconda3/lib/python3.5/site-packages/aplpy/angle_util.py", line 52, in __init__
    self._simplify()
  File "/.../miniconda3/lib/python3.5/site-packages/aplpy/angle_util.py", line 88, in _simplify
    degrees")
Exception: latitude should be between -90 and 90

График перекрывает один из полюсов сферической системы координат (Склонение =90 градусов), поэтому мне интересно, вызывает ли это проблему / обнаружение ошибки, или это происходит потому, что я неправильно настроил WCS.

Как я могу заставить полигоны появляться?

0 ответов

Другие вопросы по тегам