Skip to content

Commit

Permalink
Obliterate Kapteyn code. Leave no survivors.
Browse files Browse the repository at this point in the history
Add docs and tests to the Kapteyn-less methods
Addresses astropy#43 and astropy#44, fixes astropy#35
  • Loading branch information
sargas committed Nov 16, 2014
1 parent 5a0ec9d commit cf491a2
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 2,584 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include LICENSE
include LICENSE_kapteyn.txt
include README.md

include ez_setup.py
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ FEATURES
LICENSE
-------

All files (see exception below) are under MIT License. See LICENSE.

* "lib/kapteyn_celestial.py" is from the Kapteyn package
(http://www.astro.rug.nl/software/kapteyn/). See
LICENSE_kapteyn.txt.
All files are under MIT License. See LICENSE.

Status
------
Expand Down
30 changes: 0 additions & 30 deletions licenses/LICENSE_kapteyn.txt

This file was deleted.

118 changes: 36 additions & 82 deletions pyregion/ds9_region_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
RegionPusher, define_expr, define_line,
CoordCommand,
comment_shell_like, define_simple_literals)
from .wcs_helper import (get_kapteyn_projection, sky2sky, UnknownWcs,
image_like_coordformats, select_wcs)
from .ds9_attr_parser import Ds9AttrParser, get_attr
from .wcs_converter import (convert_to_imagecoord,
convert_physical_to_imagecoord)
Expand Down Expand Up @@ -47,6 +45,8 @@
text=wcs_shape(CoordOdd, CoordEven)
)

image_like_coordformats = ["image", "physical", "detector", "logical"]


class RegionParser(RegionPusher):

Expand Down Expand Up @@ -162,104 +162,58 @@ def convert_attr(self, l):
yield l1, c1

@staticmethod
def sky_to_image(l, header, rot_wrt_axis=1):

try: # this is a hack to test if header is fits header of wcs object.
header["NAXIS"]
except (KeyError, TypeError, ValueError):
pc = None
else:
pc = PhysicalCoordinate(header)

wcs_proj = get_kapteyn_projection(header)

for l1, c1 in l:
if isinstance(l1, Shape) and \
(l1.coord_format not in image_like_coordformats):
tgt = wcs_proj.radesys
if l1.coord_format == UnknownWcs:
src = tgt
else:
src = select_wcs(l1.coord_format)
sky_to_sky = sky2sky(src, tgt)
def sky_to_image(shapelist, header, rot_wrt_axis=1):
"""Converts a `ShapeList` into shapes with coordinates in image coordinates
cl = l1.coord_list
fl = ds9_shape_defs[l1.name].args_list
Parameters
----------
shapelist : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header` or `~astropy.wcs.WCS`
Specifies what WCS transformations to use.
rot_wrt_axis : 1 or 2
Specifies whether to measure angles East of North or West of North.
Currently ignored. TODO
# take care of repeated items
if ds9_shape_defs[l1.name].args_repeat:
n1, n2 = ds9_shape_defs[l1.name].args_repeat
else:
n1 = 0
n2 = len(cl)
Yields
-------
shape, comment : Shape, str
Shape with image coordinates and the associated comment
xy0 = None
Note
----
The comments in the original `ShapeList` are unaltered
cl1, fl1 = cl[:n1], fl[:n1]
cl10, xy0 = convert_to_imagecoord(cl1, fl1, wcs_proj,
sky_to_sky, xy0,
rot_wrt_axis=rot_wrt_axis)
"""

nn2 = len(cl) - (len(fl) - n2)
cl2, fl2 = cl[n1:nn2], fl[n1:n2]
cl20, xy0 = convert_to_imagecoord(cl2, fl2, wcs_proj,
sky_to_sky, xy0,
rot_wrt_axis=rot_wrt_axis)
for shape, comment in shapelist:
if isinstance(shape, Shape) and \
(shape.coord_format not in image_like_coordformats):

cl3, fl3 = cl[nn2:], fl[n2:]
cl30, xy0 = convert_to_imagecoord(cl3, fl3, wcs_proj,
sky_to_sky, xy0,
rot_wrt_axis=rot_wrt_axis)
new_coords = convert_to_imagecoord(shape, header,
rot_wrt_axis=rot_wrt_axis)

new_cl = cl10 + cl20 + cl30
l1n = copy.copy(shape)

l1n = copy.copy(l1)

l1n.coord_list = new_cl
l1n.coord_list = new_coords
l1n.coord_format = "image"
yield l1n, c1
yield l1n, comment

elif isinstance(l1, Shape) and (l1.coord_format == "physical"):
elif isinstance(shape, Shape) and shape.coord_format == "physical":

if pc is None:
if header is None:
raise RuntimeError("Physical coordinate is not known.")

cl = l1.coord_list
fl = ds9_shape_defs[l1.name].args_list
new_coordlist = convert_physical_to_imagecoord(shape, header)

# take care of repeated items
if ds9_shape_defs[l1.name].args_repeat:
n1, n2 = ds9_shape_defs[l1.name].args_repeat
else:
n1 = 0
n2 = len(cl)

xy0 = None

cl1, fl1 = cl[:n1], fl[:n1]
cl10 = convert_physical_to_imagecoord(cl1, fl1, pc)
# cl10, xy0 = convert_to_imagecoord(cl1, fl1, wcs_proj,
# sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis)

nn2 = len(cl) - (len(fl) - n2)
cl2, fl2 = cl[n1:nn2], fl[n1:n2]
cl20 = convert_physical_to_imagecoord(cl2, fl2, pc)
# cl20, xy0 = convert_to_imagecoord(cl2, fl2, wcs_proj,
# sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis)

cl3, fl3 = cl[nn2:], fl[n2:]
cl30 = convert_physical_to_imagecoord(cl3, fl3, pc)
l1n = copy.copy(shape)

new_cl = cl10 + cl20 + cl30

l1n = copy.copy(l1)

l1n.coord_list = new_cl
l1n.coord_list = new_coordlist
l1n.coord_format = "image"
yield l1n, c1
yield l1n, comment

else:
yield l1, c1
yield shape, comment

def filter_shape(self, sss):
return [s1[0] for s1 in sss if isinstance(s1[0], Shape)]
Expand Down

0 comments on commit cf491a2

Please sign in to comment.