Skip to content

Instantly share code, notes, and snippets.

@cdeil
Last active December 14, 2015 04:39
Show Gist options
  • Save cdeil/5029580 to your computer and use it in GitHub Desktop.
Save cdeil/5029580 to your computer and use it in GitHub Desktop.
SIMPLE = T / file does conform to FITS standard BITPIX = 32 / number of bits per data pixel NAXIS = 2 / number of data axes NAXIS1 = 341 / length of data axis 1 NAXIS2 = 291 / length of data axis 2 EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H EXTNAME = 'On ' HDUNAME = 'On ' CTYPE1 = 'GLON-CAR' / Type of co-ordinate on axis 1 CTYPE2 = 'GLAT-CAR' / Type of co-ordinate on axis 2 RADESYS = ' ' / Reference frame for RA/DEC values EQUINOX = 2000. / [yr] Epoch of reference equinox CRPIX1 = -2.630000000000000E+03 / Reference pixel on axis 1 CRPIX2 = 1.705000004656620E+02 / Reference pixel on axis 2 CRVAL1 = 341.010000228882 / Value at ref. pixel on axis 1 CRVAL2 = 0. / Value at ref. pixel on axis 2 CDELT1 = -0.0199966430664062 / Pixel size on axis 1 CDELT2 = 0.0199999809265146 / Pixel size on axis 2 CUNIT1 = 'deg ' / units of CRVAL1 and CDELT1 CUNIT2 = 'deg ' / units of CRVAL2 and CDELT2 BUNIT = 'Count ' BSCALE = 1. BZERO = 0. TELESCOP= 'H.E.S.S.' / name of telescope ORIGIN = 'The H.E.S.S. Collaboration' / organization responsible for the data CREATOR = 'HESS Plotters::FITSTools $Revision: 1.29 $' / software configuration OBJECT = 'ra252.651304 dec-44.480656' / name of observed object DATE = '2012-09-19T23:02:21' / file creation date (YYYY-MM-DDThh:mm:ss UT) HISTORY Created by deil with FITSTools.C $Revision: 1.29 $ on 2012-09-19T23:02: END 
galactic;box(285,-0.5,6,5,0) # color={red} width=5 text={Region1}
galactic;box(285,-0.5,4,3,0) # color={blue} width=5
galactic;circle(285.0,-1.0,1.0) # color={green} width=5 text={Source}
import matplotlib
matplotlib.use('Agg')
from aplpy import FITSFigure
f = FITSFigure('image.fits')
f.set_theme('publication')
f.show_grayscale()
f.show_regions('region.reg')
f.add_colorbar()
f.ticks.set_xspacing(2)
f.ticks.set_yspacing(1)
f.tick_labels.set_xformat('dd.d')
f.tick_labels.set_yformat('dd.d')
f.tick_labels.set_style('colons')
filename = 'region_offset.png'
print('Writing {0}'.format(filename))
f.save(filename)
from aplpy import FITSFigure
f = FITSFigure('image.fits')
f.show_grayscale()
f.show_regions('region.reg')
filename = 'region_rotation_aplpy.png'
print('Writing {0}'.format(filename))
f.save(filename)
from astropy.io import fits
import pywcsgrid2
import pyregion
import matplotlib.pyplot as plt
hdu = fits.open('image.fits')[0]
ax = pywcsgrid2.subplot(111, header=hdu.header)
ax.imshow(hdu.data, origin="lower")
regions = pyregion.open('region.reg').as_imagecoord(header=hdu.header)
#shape_list = pyregion.ShapeList(regions)
patch_list, artist_list = regions.get_mpl_patches_texts()
for p in patch_list:
ax.add_patch(p)
for t in artist_list:
ax.add_artist(t)
filename = 'region_rotation_pywcsgrid2.png'
print('Writing {0}'.format(filename))
plt.savefig(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment