Skip to content

Instantly share code, notes, and snippets.

@cdeil
Created August 3, 2016 10:49
Show Gist options
  • Save cdeil/91ef8dedaa9e9fafc4e460ba1355c6af to your computer and use it in GitHub Desktop.
Save cdeil/91ef8dedaa9e9fafc4e460ba1355c6af to your computer and use it in GitHub Desktop.
from __future__ import print_function
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
import regions
import pyregion
region_string = '''
fk5
circle(0:00:00.000,00:00:00.00,36000")
circle(3:00:00.000,75:00:00.00,36000")
'''
region = pyregion.parse(region_string)
region2 = regions.ds9_string_to_objects(region_string)
region2 = region2[0] & region2[1]
ra, dec = -141, 15
wcs = WCS(naxis=2)
wcs.wcs.radesys = 'ICRS'
wcs.wcs.ctype = ['RA---TAN', 'DEC--TAN']
wcs.wcs.cunit = ['deg', 'deg']
wcs.wcs.crpix = [1, 1]
wcs.wcs.cdelt = [-0.0003, 0.0003]
wcs.wcs.crval = [ra, dec]
header = wcs.to_header()
filter = region.get_filter(header=header)
inside_pyregion = filter.inside1(1, 1)
inside_regions = region2.contains(SkyCoord(ra, dec, frame='fk5', unit='deg'))
print(ra, dec, inside_pyregion, inside_regions)
print(wcs)
print(repr(header))
print(filter)
print(region.as_imagecoord(header=header))
# import IPython; IPython.embed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment