Tutorial inspired from http://aplpy.readthedocs.org/en/latest/quickstart.html
You can download the following file and put in the current working directory http://aplpy.github.com/downloads/tutorial.tar.gz
#%matplotlib inline
import matplotlib.pyplot as plt
import aplpy
import numpy
If you want the code right now:
gc = aplpy.FITSFigure('2MASS_k.fits')
gc.show_rgb('2MASS_arcsinh_color.png')
gc.tick_labels.set_font(size='small')
gc.show_contour('mips_24micron.fits', colors='white')
data = numpy.loadtxt('yso_wcs_only.txt')
ra, dec = data[:, 0], data[:, 1]
gc.show_markers(ra, dec, layer='marker_set_1', edgecolor='red',
facecolor='none', marker='o', s=10, alpha=0.5)
gc.save('myfirstplot.png')
/home/david/anaconda3/lib/python3.5/site-packages/matplotlib/artist.py:221: MatplotlibDeprecationWarning: This has been deprecated in mpl 1.5, please use the axes property. A removal date has not been set. warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1)
(HERE the code will NOT run, it is just aimed to explain line by line)
To start off, use the FITSfigure class to create a canvas to where your data will be plotted:
and display the image using a grayscale stretch:
Use the following command to show a colorscale image instead:
The colormap used for the colorscale image can be changed. Try the following:
to show the image showing a ‘heat’ map. You can find more information in the show_grayscale() and show_colorscale() documentation. For example, you can control the minimum and maximum pixel values to show and the stretch function to use.
It is possible to use APLpy to show 3-color images. To do this, you need a FITS file with the image - this is used for the information relating to the coordinates - and a PNG file containing the 3-color image. Both files need to have exactly the same dimensions and the pixels from the PNG file have to match those from the FITS file. An example is provided in the tutorial files. Try the following:
It is very easy to modify the font properties of the various labels. For example, in this case, we can change the font size of the tick labels to be smaller than the default:
APLpy can be used to overlay contours onto a grayscale/colorscale/3-color image. Try typing the following command:
There are a number of arguments that can be passed to show_contour() to control the appearance of the contours as well as the number of levels to show. For more information, see the see the show_contour() documentation.
Display a coordinate grid using:
and hide it again using:
Let’s overplot positions from a source list. Here we will use loadtxt to read in the coordinates from a file, but in general you can pass any pair of lists or numpy arrays that are already defined:
For more information, see the show_markers() documentation.
It’s often the case that you might want to change the look of a contour or markers, but if you run show_contour() or show_markers() a second time, it will overplot rather than replacing. To solve this problem APLpy has ‘layers’ which can be manipulated in a basic way. Type:
You can use remove_layer(), hide_layer(), and show_layer() to manipulate the layers, and you can also specify the layer=name argument to show_contour() or show_markers(). Using the latter forces APLpy to name the layer you are creating with the name provided, and can also be used to replace an existing layer. For example, let’s change the color of the markers from green to red:
Note the presence of the layer='marker_set_1' which means that the current markers plot will be replaced. To view active layers, you can use the list_layers() documentation.
To save the plot to a file, type the following:
You can of course save it as a PS/EPS, PDF, or SVG file instead. The EPS output is suitable for publication.
To summarize, the above plot was made using the following commands:
#import aplpy
#import numpy
gc = aplpy.FITSFigure('mips_24micron.fits')
gc.show_grayscale()
/home/david/anaconda3/lib/python3.5/site-packages/matplotlib/artist.py:221: MatplotlibDeprecationWarning: This has been deprecated in mpl 1.5, please use the axes property. A removal date has not been set. warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1) INFO:astropy:Auto-setting vmin to -1.461e+02 INFO:astropy:Auto-setting vmax to 1.827e+03
INFO: Auto-setting vmin to -1.461e+02 [aplpy.core] INFO: Auto-setting vmax to 1.827e+03 [aplpy.core]
/home/david/anaconda3/lib/python3.5/site-packages/aplpy/normalize.py:115: RuntimeWarning: invalid value encountered in less negative = result < 0.
#import aplpy
#import numpy
gc = aplpy.FITSFigure('2MASS_k.fits')
gc.show_colorscale()
/home/david/anaconda3/lib/python3.5/site-packages/matplotlib/artist.py:221: MatplotlibDeprecationWarning: This has been deprecated in mpl 1.5, please use the axes property. A removal date has not been set. warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1) INFO:astropy:Auto-setting vmin to 3.554e+02 INFO:astropy:Auto-setting vmax to 1.798e+03
INFO: Auto-setting vmin to 3.554e+02 [aplpy.core] INFO: Auto-setting vmax to 1.798e+03 [aplpy.core]
#from astropy.io import fits
#data,header=fits.getdata('mips_24micron.fits',header =True)
#header ,data
#import aplpy
#import numpy
gc = aplpy.FITSFigure('2MASS_k.fits')
#gc.show_grayscale()
gc.show_rgb('2MASS_arcsinh_color.png')
#gc.tick_labels.set_font(size='small')
#gc.show_contour('mips_24micron.fits', colors='white',levels=5,returnlevels=True)
gc.show_contour('mips_24micron.fits',levels=[50.0,400.0,1500.0],layers=['1','2','3'],kernel='gauss',colors=['blue','green','red'],returnlevels=True)
gc.show_contour(levels=1)
data = numpy.loadtxt('yso_wcs_only.txt')
ra, dec = data[:, 0], data[:, 1]
gc.show_markers(ra, dec, layer='marker_set_1', edgecolor='yellow',
facecolor='none', marker='o', s=10, alpha=0.5)
#gc.save('myfirstplot.png')
/home/david/anaconda3/lib/python3.5/site-packages/matplotlib/artist.py:221: MatplotlibDeprecationWarning: This has been deprecated in mpl 1.5, please use the axes property. A removal date has not been set. warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1)