fits.py 832 Bytes
Newer Older
Wei Shoulin's avatar
Wei Shoulin committed
1
2
3
4
5
from astropy_healpix import HEALPix
from astropy.coordinates import ICRS
from astropy import units as u
from astropy.coordinates import SkyCoord

Wei Shoulin's avatar
Wei Shoulin committed
6
7
def get_header_value(key: str, header, default_value = None):
    try:
Wei Shoulin's avatar
Wei Shoulin committed
8
9
10
11
        v = header[key]
        if type(v) == str:
            return v.strip()
        return v
Wei Shoulin's avatar
Wei Shoulin committed
12
    except Exception as e:
Wei Shoulin's avatar
Wei Shoulin committed
13
14
15
16
17
        return default_value

def get_healpix_id(ra, dec, nside=32):
    hp = HEALPix(nside=nside, order='nested', frame=ICRS())
    coord = SkyCoord(ra = ra * u.deg, dec = dec * u.deg, frame='icrs')
Wei Shoulin's avatar
h    
Wei Shoulin committed
18
19
20
21
22
23
    return hp.skycoord_to_healpix(coord)

def get_healpix_ids(ra, dec, radius, nside=32):
    hp = HEALPix(nside=nside, order='nested', frame=ICRS())
    coord = SkyCoord(ra = ra * u.deg, dec = dec * u.deg, frame='icrs')
    return hp.cone_search_skycoord(coord, radius = radius * u.deg)