-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre.py
69 lines (53 loc) · 1.89 KB
/
pre.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from __future__ import print_function
import sys
import os
import numpy as np
import pyfits
#import fitsio
from astrometry.util.fits import fits_table, merge_tables
from astrometry.util.util import Sip
if __name__ == '__main__':
args = sys.argv[1:]
print('Args', args)
if len(args) != 3:
print('Usage: chip1.gst.fits chip2.gst.fits out.gst.fits')
sys.exit(-1)
gst1, gst2, gstout = args
flt1 = gst1.replace('.gst.fits', '.fits').replace('.st.fits', '.fits')
flt2 = gst2.replace('.gst.fits', '.fits').replace('.st.fits', '.fits')
fltout = gstout.replace('.gst.fits', '.fits').replace('.st.fits', '.fits')
print('Reading', gst1)
T1 = fits_table(gst1)
print('Read', len(T1))
T1.about()
print('Reading', gst2)
T2 = fits_table(gst2)
print('Read', len(T2))
T2.about()
print('Reading WCS from', flt1)
wcs1 = Sip(flt1, 0)
wcs1.ensure_inverse_polynomials()
# print('Reading WCS from', flt2)
# wcs2 = Sip(flt2, 0)
# wcs2.ensure_inverse_polynomials()
print('T1 X,Y ranges', T1.x.min(), T1.x.max(), T1.y.min(), T1.y.max())
print('T2 X,Y ranges', T2.x.min(), T2.x.max(), T2.y.min(), T2.y.max())
# ~ 1e-6, 0.0006
# ok,x,y = wcs2.radec2pixelxy(T2.ra, T2.dec)
# print('Scatter wcs x vs catalog x:', np.mean(x - T2.x), np.std(x - T2.x))
# print('Scatter wcs y vs catalog y:', np.mean(y - T2.y), np.std(y - T2.y))
ok,x,y = wcs1.radec2pixelxy(T2.ra, T2.dec)
print('Converted X,Y ranges:', x.min(), x.max(), y.min(), y.max())
T2.x = x
T2.y = y
TT = merge_tables([T1,T2])
TT.writeto(gstout)
print('Wrote', gstout)
hdr = pyfits.open(flt1)[0].header
hdr['IMAGEW'] = 4096
hdr['IMAGEH'] = 4096
pyfits.writeto(fltout, None, header=hdr, clobber=True)
print('Wrote', fltout)
#cmd = 'cp "%s" "%s"' % (flt1, fltout)
#print(cmd)
#os.system(cmd)