Introduction to AplPy

Installation

pip install aplpy --upgrade

not in Anaconda

Documentation

http://aplpy.readthedocs.io/en/v0.9.12/index.html

Import Package


In [4]:
import aplpy
%matplotlib inline

Show Fits File and Customize Appearance


In [6]:
dwarf = aplpy.FITSFigure('dwarf.fits')
#dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')
# stretch: {‘linear’, ‘log’, ‘sqrt’, ‘arcsinh’, ‘power’}
# smoothing: smooth=7, kernel='gauss'
# interpolation: {‘nearest’, ‘none’, ‘bicubic’, ‘bilinear’} 

#dwarf.show_colorscale(cmap='CMRmap_r', vmin=-10,vmax=300, stretch='arcsinh')
#dwarf.set_nan_color('red')
#dwarf.frame.set_color('blue')
#dwarf.frame.set_linewidth(3)


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Labels


In [65]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')
#dwarf.axis_labels.set_xtext('Right Ascension (J2000)')
#dwarf.axis_labels.set_ytext('Declination (J2000)')
#dwarf.axis_labels.set_xpad(5)
#dwarf.axis_labels.set_ypad(5)
#dwarf.axis_labels.set_xposition('top')
#dwarf.axis_labels.set_yposition('right')
# xposition: 'top', 'bottom' yposition: 'left', 'right'
#dwarf.axis_labels.set_font(size='large', weight='medium', stretch='normal', family='sans-serif', style='normal', variant='normal')
#size: integer or ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’
#style:   ‘normal’, ‘italic’ ‘oblique’
#stretch: ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’
#weight: ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black'
#dwarf.axis_labels.hide()


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Recenter Fits Image


In [210]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.recenter(55.9769, -36.5666, radius=0.01)
#dwarf.recenter(55.9769, -36.5666, width=0.008, height=0.012)
# in decimal degrees


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Ticks


In [222]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.ticks.set_xspacing(0.01) # in degrees
#dwarf.ticks.set_yspacing(0.01) # in degrees
#dwarf.ticks.set_length(10)
#dwarf.ticks.set_linewidth(1)
#dwarf.ticks.set_color('k')
#dwarf.ticks.set_minor_frequency(5)
#dwarf.ticks.hide_x()


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Tick Labels


In [213]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.tick_labels.hide_x()
#dwarf.tick_labels.set_style('plain')
# 'colons', 'plain'
#dwarf.tick_labels.set_xformat('hh:mm:ss')
#dwarf.tick_labels.set_yformat('dd:mm:ss')
# 'ddd.ddddd', 'hh', 'hh:mm', 'hh:mm:ss', 'hh:mm:ss.ss'
# 'ddd.ddddd', 'dd', 'dd:mm', 'dd:mm:ss', 'dd:mm:ss.ss'

#dwarf.tick_labels.set_xposition('top')
#dwarf.tick_labels.set_yposition('right')


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Contours


In [215]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.show_contour(data='dwarf.fits', layer='contours', levels=(2.,3.,4.,5.,10.,15.), filled=False, cmap='RdYlBu',  colors=None, smooth=1, kernel='gauss',overlap=True, linewidths=1.5, linestyles='solid',alpha=0.7)
#dwarf.hide_layer('contours')
#dwarf.remove_layer('contours')


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Labels


In [216]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.add_label(55.976919, -36.5670, 'dwarf galaxy', layer='labels')
#dwarf.add_label(0.875,0.93,'Dwarf', relative=True, color='k', size=15, weight='medium', stretch='normal', family='sans-serif', style='normal', variant='normal', layer='labels')


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Markers


In [217]:
dwarf = aplpy.FITSFigure('dwarf.fits')
import numpy as np
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#ra, dec     = np.genfromtxt('coordinates.dat',   dtype=float, comments='#', delimiter='', missing_values='_', skip_header=0, usecols = (0,1), unpack=True)

#dwarf.show_markers(ra,dec, edgecolor='red', facecolor='red',  marker='o', s=100, linewidth=2, alpha=0.3, layer='markers') 
# markers as in matplotlib.scatter
#dwarf.show_regions('ds9.reg')


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Shapes


In [218]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.show_circles   (55.9769,       -36.5666,       0.003,        linewidth=2, color='blue')
#dwarf.show_ellipses  (55.9769+0.007, -36.5666+0.007,  0.01, 0.005, angle=45, edgecolor='green', facecolor='None', linewidth=3., alpha=0.7)
#dwarf.show_rectangles(55.9769-0.007, -36.5666-0.007, 0.005, 0.005, edgecolor='red', facecolor='None', linewidth=3., alpha=0.75, zorder=1)
#dwarf.remove_layer('shapes')


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Colorbar


In [96]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.add_colorbar()
#dwarf.colorbar.set_location('right')
#'top', 'bottom', 'left', 'right'
#dwarf.colorbar.set_width(0.5)
#dwarf.colorbar.set_pad(0.075)
#dwarf.colorbar.set_axis_label_text('flux [ADU]')
#dwarf.colorbar.set_axis_label_font(size='medium', weight='medium', stretch='normal', family='sans-serif', style='normal', variant='normal')        
#dwarf.colorbar.set_axis_label_pad(7)                                                                                              
#dwarf.colorbar.set_axis_label_rotation(0)                                                                                         
#dwarf.colorbar.set_ticks([0,5,10,20,50,100, 200])


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Grid


In [219]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')

#dwarf.add_grid()
#dwarf.grid.set_color('red')
#dwarf.grid.set_alpha(0.6)
#dwarf.grid.set_linewidth(1.5)
#dwarf.grid.set_linestyle('dashed')
#dwarf.grid.set_xspacing(0.01)
#dwarf.grid.set_yspacing(0.01)
#dwarf.grid.hide()


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Scalebar


In [220]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')
from astropy import units as u

#dwarf.add_scalebar(length=10 * u.arcsecond, label='scalebar label', corner='bottom left', borderpad=2.0, pad=0.0)
#dwarf.scalebar.set(color='k', alpha=0.7)
#dwarf.scalebar.set_linewidth(3)
#dwarf.scalebar.set_font(size='large', weight='medium', stretch='normal', family='sans-serif', style='normal', variant='normal')
#dwarf.remove_scalebar()


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

Beam


In [221]:
dwarf = aplpy.FITSFigure('dwarf.fits')
dwarf.show_colorscale(cmap='gray_r', vmin=-10,vmax=200, stretch='arcsinh')
from astropy import units as u

#dwarf.add_beam(major=5 * u.arcsecond, minor=5 * u.arcsecond, angle=0, corner='bottom left', frame=False, borderpad=2., pad=0.0)
#dwarf.beam.set_alpha(0.8)
#dwarf.beam.set_edgecolor('k')
#dwarf.beam.set_linewidth(1.)
#dwarf.beam.set_facecolor('None')

#dwarf.beam.set_hatch('/////')
# ‘/’, ‘’, ‘|’, ‘-‘, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’


WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]
WARNING: Cannot determine equinox. Assuming J2000. [aplpy.wcs_util]

In [77]:
dwarf.save('dwarf.pdf', dpi=300)

Examples