Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ndcube/wcs/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def unwrap_wcs_to_fitswcs(wcs):
offset[kept_wcs_axes] = low_level_wrapper._offset
fitswcs = _resample_fitswcs(fitswcs, factor, offset)
else:
raise TypeError("Unrecognized/unsupported WCS Wrapper type: {type(low_level_wrapper)}")
raise TypeError(f"Unrecognized/unsupported WCS Wrapper type: {type(low_level_wrapper)}")
return fitswcs, dropped_data_axes


Expand Down Expand Up @@ -185,4 +185,13 @@ def _resample_fitswcs(fitswcs, factor, offset=0):
fitswcs.wcs.cdelt *= factor
fitswcs.wcs.crpix = (fitswcs.wcs.crpix + offset) / factor
fitswcs._naxis = list(np.round(np.array(fitswcs._naxis) / factor).astype(int))
# TODO: Add some context about why this correction is made
if hasattr(fitswcs.wcs, 'pc'):
scaling_matrix = np.eye(fitswcs.wcs.naxis)
for i in range(fitswcs.wcs.naxis):
for j in range(fitswcs.wcs.naxis):
scaling_matrix[i,j] = factor[j] / factor[i]
fitswcs.wcs.pc *= scaling_matrix
if hasattr(fitswcs.wcs, 'cd'):
fitswcs.wcs.cd *= factor
return fitswcs
Loading