Skip to content

Commit 1a758b1

Browse files
committed
Merge pull request #13 from mdboom/pywcs
added Pywcs
2 parents fb2b910 + 54cab0a commit 1a758b1

169 files changed

Lines changed: 132224 additions & 8 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎astropy/setup_helpers.py‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
This module contains a number of utilities for use during
3+
setup/build/packaging that are useful to astropy as a whole.
4+
"""
5+
6+
import os.path
7+
import sys
8+
9+
10+
def write_if_different(filename, data):
11+
"""
12+
Write *data* to *filename*, if the content of the file is
13+
different.
14+
"""
15+
if os.path.exists(filename):
16+
with open(filename, 'rb') as fd:
17+
original_data = fd.read()
18+
else:
19+
original_data = None
20+
21+
if original_data != data:
22+
with open(filename, 'wb') as fd:
23+
fd.write(data)
24+
25+
26+
def check_numpy():
27+
"""
28+
Check that Numpy is installed and it is of the minimum version we
29+
require.
30+
"""
31+
import numpy
32+
33+
major, minor, rest = numpy.__version__.split(".", 2)
34+
if (int(major), int(minor)) < (1, 3):
35+
raise ImportError("numpy version 1.3 or later must be installed to build astropy")
36+
37+
38+
def get_numpy_include_path():
39+
"""
40+
Gets the path to the numpy headers
41+
"""
42+
import numpy
43+
44+
try:
45+
numpy_include = numpy.get_include()
46+
except AttributeError:
47+
numpy_include = numpy.get_numpy_include()
48+
return numpy_include
49+
50+
51+
52+
################################################################################
53+
# Backport of importlib.import_module from 3.x. This backport was provided by
54+
# Brett Cannon and downloaded from here:
55+
# http://pypi.python.org/pypi/importlib/1.0.1
56+
# While not critical (and in no way guaranteed!), it would be nice to keep this
57+
# code compatible with Python 2.3.
58+
59+
try:
60+
from importlib import import_module
61+
except ImportError:
62+
63+
def _resolve_name(name, package, level):
64+
"""Return the absolute name of the module to be imported."""
65+
if not hasattr(package, 'rindex'):
66+
raise ValueError("'package' not set to a string")
67+
dot = len(package)
68+
for x in xrange(level, 1, -1):
69+
try:
70+
dot = package.rindex('.', 0, dot)
71+
except ValueError:
72+
raise ValueError("attempted relative import beyond top-level "
73+
"package")
74+
return "%s.%s" % (package[:dot], name)
75+
76+
77+
def import_module(name, package=None):
78+
"""Import a module.
79+
80+
The 'package' argument is required when performing a relative
81+
import. It specifies the package to use as the anchor point
82+
from which to resolve the relative import to an absolute
83+
import.
84+
"""
85+
if name.startswith('.'):
86+
if not package:
87+
raise TypeError(
88+
"relative imports require the 'package' argument")
89+
level = 0
90+
for character in name:
91+
if character != '.':
92+
break
93+
level += 1
94+
name = _resolve_name(name[level:], package, level)
95+
__import__(name)
96+
return sys.modules[name]

‎astropy/wcs/__init__.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
.. _wcslib: http://www.atnf.csiro.au/~mcalabre/WCS/
3+
.. _pyfits: http://www.stsci.edu/resources/software_hardware/pyfits
4+
.. _Paper IV: http://www.atnf.csiro.au/people/mcalabre/WCS/index.html
5+
.. _SIP: http://ssc.spitzer.caltech.edu/postbcd/doc/shupeADASS.pdf
6+
.. _ds9: http://hea-www.harvard.edu/RD/ds9/
7+
8+
astropy.wcs provides transformations following the `SIP`_ conventions,
9+
`Paper IV`_ table lookup distortion, and the core WCS functionality
10+
provided by `wcslib`_. Each of these transformations can be used
11+
independently or together in a standard pipeline.
12+
13+
The basic workflow is as follows:
14+
15+
1. ``from astropy import wcs``
16+
17+
2. Call the `wcs.WCS` constructor with a `pyfits`_ header
18+
and/or hdulist object.
19+
20+
3. Optionally, if the FITS file uses any deprecated or
21+
non-standard features, you may need to call one of the
22+
`~astropy.wcs.WCS.fix` methods on the object.
23+
24+
4. Use one of the following transformation methods:
25+
26+
- `~WCS.all_pix2sky`: Perform all three transformations from
27+
pixel to sky coordinates.
28+
29+
- `~WCS.wcs_pix2sky`: Perform just the core WCS transformation
30+
from pixel to sky coordinates.
31+
32+
- `~WCS.wcs_sky2pix`: Perform just the core WCS transformation
33+
from sky to pixel coordinates.
34+
35+
- `~WCS.sip_pix2foc`: Convert from pixel to focal plane
36+
coordinates using the `SIP`_ polynomial coefficients.
37+
38+
- `~WCS.sip_foc2pix`: Convert from focal plane to pixel
39+
coordinates using the `SIP`_ polynomial coefficients.
40+
41+
- `~WCS.p4_pix2foc`: Convert from pixel to focal plane
42+
coordinates using the table lookup distortion method
43+
described in `Paper IV`_.
44+
45+
- `~WCS.det2im`: Convert from detector coordinates to image
46+
coordinates. Commonly used for narrow column correction.
47+
"""
48+
49+
from __future__ import division # confidence high
50+
51+
import sys
52+
from .wcs import *
53+
54+
55+
class Wcsprm(Wcsprm):
56+
pass

‎astropy/wcs/_docutil.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
astropy.wcs-specific utilities for generating boilerplate in docstrings.
3+
"""
4+
5+
from __future__ import division # confidence high
6+
7+
8+
def _fix(content, indent=0):
9+
lines = content.split('\n')
10+
indent = '\n' + ' ' * indent
11+
return indent.join(lines)
12+
13+
14+
def TWO_OR_THREE_ARGS(naxis, indent=0):
15+
return _fix(
16+
"""args : flexible
17+
Either two or three arguments may be provided.
18+
19+
- 2 arguments: An *N* x *{0}* array of *x*- and
20+
*y*-coordinates, and an *origin*.
21+
22+
- 3 arguments: 2 one-dimensional arrays of *x* and *y*
23+
coordinates, and an *origin*.
24+
25+
Here, *origin* is the coordinate in the upper left corner of the
26+
image. In FITS and Fortran standards, this is 1. In Numpy and C
27+
standards this is 0.
28+
""".format(naxis), indent)
29+
30+
31+
def RETURNS(out_type, indent=0):
32+
return _fix("""result : array
33+
Returns the {0}. If the input was a single array and
34+
origin, a single array is returned, otherwise a tuple of arrays is
35+
returned.""".format(out_type), indent)
36+
37+
38+
def ORIGIN(indent=0):
39+
return _fix(
40+
"""
41+
origin : int
42+
Specifies the origin of pixel values. The Fortran and FITS
43+
standards use an origin of 1. Numpy and C use array indexing with
44+
origin at 0.
45+
""", indent)
46+
47+
48+
def RA_DEC_ORDER(indent=0):
49+
return _fix(
50+
"""
51+
ra_dec_order : bool, optional
52+
When `True` will ensure that sky coordinates are always given and
53+
returned in as (*ra*, *dec*) pairs, regardless of the order of the
54+
axes specified by the in the ``CTYPE`` keywords.
55+
""", indent)
56+

0 commit comments

Comments
 (0)