astropy / astropy/reproject

Command-line function for healpix reprojection: reproject.grid_size

Open
#87 2 comments 0 reactions 0 assignees View on GitHub
healpix
Dominant language
Python
Stars
127
Forks
74
Avg merge
1d 11h
Merged PRs (30d)
2

Description

It would be of great utility a command-line function to reproject an HEALPix image
just specifying the required resolution of the pixels in degrees.

I'm proposing the function below that would fit in a next release, if it is deemed appropriate.

Bests,
Giuseppe

```
from __future__ import division
import math
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits
from reproject import reproject_from_healpix
from astropy.wcs import WCS
from astropy.coordinates import FK5

class header_reproject:
def __init__ (self, CTYPE, CDELT, input_image, output_image):
"""
Quick reprojection of a LVC Healpix sky map using the plate scale in degrees per pixel (CDELT).
Parameters
----------

CTYPE : string
projection --- e.g. "CAR": Cartesian projection; "MOL": Mollweide projection; "AIT": AITOFF projection

CDELT : float
the plate scale in degrees per pixel; for square pixels, CDELT1 = CDELT2

input_image : string
input LVC HEALPix sky map

output_image : string
clobber=True

Default parameters :
header :
NAXIS = 2
NAXIS1 = (360/CDELT)
NAXIS2 = (180/CDELT)
CRPIX1 = [(360/CDELT)+1]/2
CRVAL1 = 180.0
CDELT1 = -CDELT
CUNIT1 = 'deg'
CRPIX2 = [(180/CDELT)+1]/2
CRVAL2 = 0.0
CDELT2 = CDELT
CUNIT2 = 'deg '
COORDSYS = 'icrs'

nested : True
NESTED pixel ordering is assume

Returns :
the reprojected image in fits format.

Example :
***save the full code as LVC_reproject.py***
from LVC_reproject import reproject
reproject.grid_size(CTYPE='CAR',CDELT=1,input_image='allsky/ligo_simulated.fits.gz',
output_image="reproject_1.fits")
"""
self.CTYPE=CTYPE
self.CDELT=CDELT
self.input_image=input_image
self.output_image=output_image

def grid_size(self,CTYPE,CDELT,input_image,output_image):
self.CTYPE=CTYPE
reference_header['CTYPE1']="RA---"+CTYPE
reference_header['CTYPE2']="DEC--"+CTYPE

self.CDELT=CDELT
reference_header['CDELT1']=-CDELT
reference_header['CDELT2']=CDELT
x_axis=math.ceil(360/CDELT)
y_axis=math.ceil(180/CDELT)

reference_header['NAXIS1']=x_axis
reference_header['CRPIX1']=(int(x_axis)+1)/2

reference_header['NAXIS2']=y_axis
reference_header['CRPIX2']=(int(y_axis)+1)/2

self.input_image=input_image
self.output_image=output_image

def write_image(self):
filename_LVC = get_pkg_data_filename(input_image)
hdu_LVC = fits.open(filename_LVC)[1]

array, footprint = reproject_from_healpix(filename_LVC, reference_header)

reference_wcs = WCS(reference_header)
array, footprint = reproject_from_healpix(filename_LVC, reference_wcs,
shape_out=(240,480))
data = hdu_LVC.data['PROB']
array, footprint = reproject_from_healpix((data, 'icrs'),
reference_header, nested=True)
data = hdu_LVC.data['PROB']
array, footprint = reproject_from_healpix((data, 'icrs'),
reference_header, nested=True)

array, footprint = reproject_from_healpix((data, FK5(equinox='J2010')),
reference_header, nested=True)

fits.writeto(output_image,array,reference_header,clobber=True)

write_image(self)

#loading header parameters to grid_size
file_header="""
NAXIS = 2
NAXIS1 = 360
NAXIS2 = 180
CTYPE1 = ''
CRPIX1 = 180
CRVAL1 = 180.0
CDELT1 = -1.0
CUNIT1 = 'deg'
CTYPE2 = ''
CRPIX2 = 90
CRVAL2 = 0.0
CDELT2 = 1.0
CUNIT2 = 'deg '
COORDSYS= 'icrs'
"""
reference_header=fits.Header.fromstring(file_header, sep='\n')

reproject=header_reproject(CTYPE='',CDELT="",input_image='',output_image="")
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the existing reproject_from_healpix API and the proposed grid_size inputs: CTYPE, CDELT, input_image, and output_image. Check how FITS headers and WCS objects are handled, then define the CLI entry point and verify that it writes the requested reprojected FITS image with the calculated grid dimensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.