Skip to content

Commit

Permalink
invert affine matrix to x-first before computing FITS keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-simpson committed Aug 12, 2020
1 parent c74abab commit 958b5e2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions astrodata/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ def gwcs_to_fits(ndd, hdr=None):
wcs_dict['FITS-WCS'] = ('APPROXIMATE', 'FITS WCS is approximate')

affine = calculate_affine_matrices(transform, ndd.shape)
# Convert to x-first order
affine_matrix = affine.matrix[::-1, ::-1]
# Require an inverse to write out
if np.linalg.det(affine.matrix) == 0:
affine.matrix[-1, -1] = 1.
wcs_dict.update({f'CD{i+1}_{j+1}': affine.matrix[j, i]
if np.linalg.det(affine_matrix) == 0:
affine_matrix[-1, -1] = 1.
wcs_dict.update({f'CD{i+1}_{j+1}': affine_matrix[j, i]
for i, _ in enumerate(world_axes)
for j, _ in enumerate(world_axes)})
# Don't overwrite CTYPEi keywords we've already created
Expand Down

0 comments on commit 958b5e2

Please sign in to comment.