reproject

0.19.0 · active · verified Thu Apr 16

The `reproject` package is a Python library designed for re-gridding astronomical images from one World Coordinate System (WCS) to another. It provides a uniform interface for various reprojection techniques, including interpolation-based methods, the adaptive and anti-aliased algorithm by DeForest (2004), and flux-conserving spherical polygon intersection. The library also supports reprojection to and from HEALPIX projections through integration with `astropy-healpix`. It is currently at version 0.19.0 and is actively maintained as part of the Astropy project, with a regular release cadence aligned with Astropy's development cycle.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to reproject a simple 2D NumPy array from one Astropy WCS object to another using the `reproject_interp` function. It creates dummy input data and WCS, defines a target WCS with a different scale and rotation, performs the reprojection, and then visualizes both the original and reprojected images. For real-world applications, input data often comes from FITS files.

import numpy as np
from astropy.wcs import WCS
from reproject import reproject_interp
import matplotlib.pyplot as plt

# 1. Create dummy input data and WCS
data_in = np.arange(100.0).reshape((10, 10)) + 100.0
wcs_in = WCS(naxis=2)
wcs_in.wcs.crpix = [5, 5]
wcs_in.wcs.cdelt = np.array([-0.1, 0.1])
wcs_in.wcs.crval = [0, 0]
wcs_in.wcs.ctype = ["RA---TAN", "DEC--TAN"]

# 2. Create target output WCS with a different projection/scale/rotation
wcs_out = WCS(naxis=2)
wcs_out.wcs.crpix = [10, 10]
wcs_out.wcs.cdelt = np.array([-0.05, 0.05]) # Different pixel scale
wcs_out.wcs.crval = [0, 0]
wcs_out.wcs.ctype = ["RA---TAN", "DEC--TAN"]
wcs_out.wcs.pc = [[np.cos(np.deg2rad(15)), -np.sin(np.deg2rad(15))],
                  [np.sin(np.deg2rad(15)), np.cos(np.deg2rad(15))]] # 15-deg rotation

shape_out = (20, 20) # Target output shape

# 3. Reproject the data using interpolation
data_out, footprint = reproject_interp((data_in, wcs_in), wcs_out, shape_out=shape_out)

# 4. Visualize the results (optional)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1, projection=wcs_in)
plt.imshow(data_in, origin='lower', cmap='viridis')
plt.title('Original Data')
plt.xlabel('X (pixels)')
plt.ylabel('Y (pixels)')

plt.subplot(1, 2, 2, projection=wcs_out)
plt.imshow(data_out, origin='lower', cmap='viridis')
plt.title('Reprojected Data')
plt.xlabel('X (pixels)')
plt.ylabel('Y (pixels)')

plt.tight_layout()
plt.show()

view raw JSON →