Python Crash Course Aplpy 3 rd year Bachelors V1.0 dd 06-09-2013 Hour 3.

Post on 13-Jan-2016

236 views 0 download

Transcript of Python Crash Course Aplpy 3 rd year Bachelors V1.0 dd 06-09-2013 Hour 3.

Python Crash CoursePython Crash CourseAplpyAplpy

3rd year Bachelors

V1.0

dd 06-09-2013

Hour 3

APLpyAPLpy

APLpy (the Astronomical Plotting Library in Python) is a Python module aimed at producing publication-quality plots of astronomical imaging data in FITS format. The module uses Matplotlib and is capable of creating output files in several graphical formats, including EPS, PDF, PS, PNG, and SVG.

See http://aplpy.github.io for documentation

Main featuresMain features

• Make plots interactively or using scripts• Show grayscale, colorscale, and 3-color RGB images of FITS files• Generate co-aligned FITS cubes to make 3-color RGB images• Make plots from FITS files with arbitrary WCS (e.g. position-velocity)• Slice multi-dimensional FITS cubes• Overlay any number of contour sets• Overlay markers with fully customizable symbols• Plot customizable shapes like circles, ellipses, and rectangles• Overlay ds9 region files• Overlay coordinate grids• Show colorbars, scalebars, and beams• Customize the appearance of labels and ticks• Hide, show, and remove different contour and marker layers• Pan, zoom, and save any view as a full publication-quality plot• Save plots as EPS, PDF, PS, PNG, and SVG

APLpyAPLpy

• Intro>>> import aplpy

>>> fig = aplpy.FITSFigure('myimage.fits')

>>> fig.show_grayscale()

>>> fig.hide_grayscale()

>>> fig.show_colorscale()

>>> fig.hide_colorscale()

# Scaling and panning

>>> fig.recenter(33.23, 55.33, width=0.3, height=0.2) # degrees

# Overlaying

>>> fig.show_contour('co_data.fits')

# save for publication

>>> fig.save('myplot.eps')

APLpyAPLpy

• Labels and shapes en DS9 Regions

>>> fig.add_label(34.455, 54.112, 'My favorite star')

>>> fig.add_label(0.1, 0.9, '(a)', relative=True)

>>> fig.show_markers(x_world, y_world) # 1D arrays in degrees

>>> fig.show_circles(x_world, y_world, radius)

>>> fig.show_ellipses(x_world, y_world, width, height)

>>> fig.show_rectangles(x_world, y_world, width, height)

>>> fig.show_arrows(x_world, y_world, dx, dy)

>>> fig.show_lines(line_list) # 2xN ndarray’s of vertices in degrees

>>> fig.show_polygons(polygon_list)

>>> fig.show_regions('myregions.reg')

APLpyAPLpy

• Layers

• Coordinates

>>> fig.list_layers()

>>> fig.hide_layer('regions')

>>> fig.show_layer('regions')

>>> layer = fig.get_layer('circles')

>>> fig.remove_layer('rectangles')

>>> x_pix, y_pix = fig.world2pixel(45.3332, 22.1932)

>>> x_world, y_world = fig.pixel2world(np.array([1., 2., 3]), np.array([1., 3., 5.]))

APLpy AnnotationAPLpy Annotation

• Colorbar, Coordinate Grid, Scalebar, Beam>>> fig.add_colorbar()

>>> fig.colorbar.set_width(0.1)

>>> fig.add_grid()

>>> fig.grid.set_xspacing(0.2) # degrees

>>> fig.grid.set_color('white')

>>> fig.add_scalebar()

>>> fig.scalebar.set_length(0.02) # degrees

>>> fig.scalebar.set_label('5 pc')

>>> fig.add_beam()

>>> fig.beam.set_major(0.03) # degrees

>>> fig.beam.set_minor(0.02) # degrees

>>> fig.beam.set_angle(45.) # degrees

APLpy AnnotationAPLpy Annotation

• Axis labels, Tick, Ticks>>> fig.axis_labels.show()

>>> fig.axis_labels.show_x()

>>> fig.axis_labels.set_xtext('Right Ascension (J2000)')

>>> fig.axis_labels.set_xpad(...)

>>> fig.axis_labels.set_ypad(...) # set displacement

>>> fig.axis_labels.set_xposition('bottom')

>>> fig.tick_labels.show()

>>> fig.tick_labels.set_xformat('hh:mm:ss.ss')

>>> fig.tick_labels.set_xposition('top')

>>> fig.ticks.show()

>>> fig.ticks.set_xspacing(0.04) # degrees

>>> fig.ticks.set_color('black')

>>> fig.ticks.set_linewidth(2) # points

APLpy – Practical exampleAPLpy – Practical example

• M33 plot (get data through skycat)>>>import aplpy

gc = aplpy.FITSFigure('/disks/strw2/deul/m33.fits')

gc.show_grayscale()

gc.show_colorscale()

gc.show_colorscale(cmap='gist_heat')

gc.tick_labels.set_font(size='small')

gc.add_grid()

gc.remove_grid()

APLpy – Practical exampleAPLpy – Practical example

• Overplot GSC (get data from http://vizier.u-strasbg.fr/)

from astropy.io.votable import parse

import astropy.io.votable as vot

gsc_table = vot.parse("/home/deul/Documents/m33_gsc.vot")

table = gsc_table.get_first_table()

r=table.array['_RAJ2000']

d=table.array['_DEJ2000']

s = ones(len(r))*0.003

gc.show_circles(r,d,s)

gc.list_layers()

gc.hide_layer('circle_set_1')

gc.show_layer('circle_set_1')

l = gc.get_layer('circle_set_1')

l.set_edgecolor('green')

APLpy – Practical exampleAPLpy – Practical example

• Overplot 2MASS (get data from http://vizier.u-strasbg.fr/)

from astropy.io.votable import parse

import astropy.io.votable as vot

gsc_table = vot.parse("/home/deul/Documents/m33_2mass.vot")

table = gsc_table.get_first_table()

r=table.array['_RAJ2000']

d=table.array['_DEJ2000']

s = ones(len(r))*0.003

gc.show_circles(r,d,s)

gc.list_layers()

gc.hide_layer('circle_set_2')

gc.show_layer('circle_set_2')

l = gc.get_layer('circle_set_2')

l.set_edgecolor(‘blue')

Introduction to languageIntroduction to language

End