Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make bounding-box optional #289

Merged
merged 2 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion gwcs/coordinate_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@


def get_ctype_from_ucd(ucd):
""" Return the FITS ``CTYPE`` corresponding to a UCD1 value."""
"""
Return the FITS ``CTYPE`` corresponding to a UCD1 value.

Parameters
----------
ucd : str
UCD string, for example one of ```WCS.world_axis_physical_types``.

Returns
-------
CTYPE : str
The corresponding FITS ``CTYPE`` value or an empty string.
"""
return UCD1_TO_CTYPE.get(ucd, "")


Expand Down
21 changes: 14 additions & 7 deletions gwcs/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy.linalg as npla
from astropy.modeling.core import Model # , fix_inputs
from astropy.modeling import utils as mutils
from astropy.modeling.models import (Shift, Polynomial2D, Sky2Pix_TAN,
from astropy.modeling.models import (Shift, Polynomial2D, Sky2Pix_TAN,
RotateCelestial2Native)
from astropy.modeling.fitting import LinearLSQFitter
import astropy.io.fits as fits
Expand Down Expand Up @@ -641,8 +641,8 @@ def fix_inputs(self, fixed):
new_pipeline.extend(self.pipeline[1:])
return self.__class__(new_pipeline)

def to_fits_sip(self, bounding_box, max_pix_error=0.25, degree=None,
max_inv_pix_error=0.25, inv_degree=None,
def to_fits_sip(self, bounding_box=None, max_pix_error=0.25, degree=None,
max_inv_pix_error=0.25, inv_degree=None,
npoints=32, verbose=False):
"""
Construct a SIP-based approximation to the WCS in the form of a FITS header
Expand All @@ -654,7 +654,8 @@ def to_fits_sip(self, bounding_box, max_pix_error=0.25, degree=None,

Parameters
----------
bounding_box : a pair of tuples, each consisting of two numbers
bounding_box : tuple, optional
A pair of tuples, each consisting of two numbers
Represents the range of pixel values in both dimensions
((xmin, xmax), (ymin, ymax))
max_pix_error : float, optional
Expand Down Expand Up @@ -702,7 +703,13 @@ def to_fits_sip(self, bounding_box, max_pix_error=0.25, degree=None,

transform = self.forward_transform
# Determine reference points.
(xmin, xmax), (ymin, ymax) = bounding_box
if bounding_box is not None:
(xmin, xmax), (ymin, ymax) = bounding_box
else:
try:
(xmin, xmax), (ymin, ymax) = self.bounding_box
except KeyError:
raise TypeError("A bounding_box is needed to proceed.")
crpix1 = (xmax - xmin) // 2
crpix2 = (ymax - ymin) // 2
crval1, crval2 = transform(crpix1, crpix2)
Expand Down Expand Up @@ -755,7 +762,7 @@ def to_fits_sip(self, bounding_box, max_pix_error=0.25, degree=None,
detd = cdmat[0][0] * cdmat[1][1] - cdmat[0][1] * cdmat[1][0]
Ud = ( cdmat[1][1] * undist_xd - cdmat[0][1] * undist_yd) / detd
Vd = (-cdmat[1][0] * undist_xd + cdmat[0][0] * undist_yd) / detd

if max_inv_pix_error:
fit_inv_poly_u, fit_inv_poly_v, max_inv_resid = _fit_2D_poly(ntransform,
npoints, None,
Expand Down Expand Up @@ -848,7 +855,7 @@ def _make_sampling_grid(npoints, bounding_box):
u = x - crpix1
v = y - crpix2
return u, v

def _compute_distance_residual(undist_x, undist_y, fit_poly_x, fit_poly_y):
"""
Compute the distance residuals and return the rms and maximum values.
Expand Down