-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-astropy-proj.py
36 lines (29 loc) · 1.12 KB
/
generate-astropy-proj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from astropy.io import fits
from astropy.wcs import WCS
from astropy.coordinates import SkyCoord
import astropy.units as u
import glob
import numpy as np
input_files = glob.glob('./examples/*.fits')
print(input_files)
for filename in input_files:
print(filename)
# Load the FITS hdulist using astropy.io.fits
hdulist = fits.open(filename)
# Parse the WCS keywords in the primary HDU
w = WCS(hdulist[0].header)
naxis1 = hdulist[0].header.get("NAXIS1")
naxis2 = hdulist[0].header.get("NAXIS2")
naxis3 = hdulist[0].header.get("NAXIS3")
# Get random sky coordinates
X = np.random.random(100) * naxis1
Y = np.random.random(100) * naxis2
Z = np.random.random(100) * 0
try:
coord = w.wcs_pix2world(np.vstack((X, Y)).T, 1)
ra, dec = ((coord[:, 0] * u.deg).to_value(u.rad), (coord[:, 1] * u.deg).to_value(u.rad))
except:
coord = w.wcs_pix2world(np.vstack((X, Y, Z)).T, 1)
ra, dec = ((coord[:, 0] * u.deg).to_value(u.rad), (coord[:, 1] * u.deg).to_value(u.rad))
tab = np.column_stack((ra, dec, X, Y))
np.savetxt(filename + ".csv", tab, delimiter=",")