-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathradec_to_chip.py
62 lines (54 loc) · 4.71 KB
/
radec_to_chip.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
import numpy as np
import sys, os
import math
import logging
import time
import yaml
import galsim as galsim
import galsim.wfirst as wfirst
import galsim.des as des
import fitsio as fio
MAX_RAD_FROM_BORESIGHT = 0.009
def radec_to_chip(obsRA, obsDec, obsPA, ptRA, ptDec):
"""
Converted from Chris' c code. Used here to limit ra, dec catalog to objects that fall in each pointing.
"""
AFTA_SCA_Coords = np.array([
0.002689724, 1.000000000, 0.181995021, -0.002070809, -1.000000000, 0.807383134, 1.000000000, 0.004769437, 1.028725015, -1.000000000, -0.000114163, -0.024579913,
0.003307633, 1.000000000, 1.203503349, -0.002719257, -1.000000000, -0.230036847, 1.000000000, 0.006091805, 1.028993582, -1.000000000, -0.000145757, -0.024586416,
0.003888409, 1.000000000, 2.205056241, -0.003335597, -1.000000000, -1.250685466, 1.000000000, 0.007389324, 1.030581048, -1.000000000, -0.000176732, -0.024624426,
0.007871078, 1.000000000, -0.101157485, -0.005906926, -1.000000000, 1.095802866, 1.000000000, 0.009147586, 2.151242511, -1.000000000, -0.004917673, -1.151541644,
0.009838715, 1.000000000, 0.926774753, -0.007965112, -1.000000000, 0.052835488, 1.000000000, 0.011913584, 2.150981875, -1.000000000, -0.006404157, -1.151413352,
0.011694346, 1.000000000, 1.935534773, -0.009927853, -1.000000000, -0.974276664, 1.000000000, 0.014630945, 2.153506744, -1.000000000, -0.007864196, -1.152784334,
0.011758070, 1.000000000, -0.527032681, -0.008410887, -1.000000000, 1.529873670, 1.000000000, 0.012002262, 3.264990040, -1.000000000, -0.008419930, -2.274065453,
0.015128555, 1.000000000, 0.510881058, -0.011918799, -1.000000000, 0.478274989, 1.000000000, 0.016194244, 3.262719942, -1.000000000, -0.011359106, -2.272508364,
0.018323436, 1.000000000, 1.530828790, -0.015281655, -1.000000000, -0.558879607, 1.000000000, 0.020320244, 3.264721809, -1.000000000, -0.014251259, -2.273955111,
-0.002689724, 1.000000000, 0.181995021, 0.002070809, -1.000000000, 0.807383134, 1.000000000, -0.000114163, -0.024579913, -1.000000000, 0.004769437, 1.028725015,
-0.003307633, 1.000000000, 1.203503349, 0.002719257, -1.000000000, -0.230036847, 1.000000000, -0.000145757, -0.024586416, -1.000000000, 0.006091805, 1.028993582,
-0.003888409, 1.000000000, 2.205056241, 0.003335597, -1.000000000, -1.250685466, 1.000000000, -0.000176732, -0.024624426, -1.000000000, 0.007389324, 1.030581048,
-0.007871078, 1.000000000, -0.101157485, 0.005906926, -1.000000000, 1.095802866, 1.000000000, -0.004917673, -1.151541644, -1.000000000, 0.009147586, 2.151242511,
-0.009838715, 1.000000000, 0.926774753, 0.007965112, -1.000000000, 0.052835488, 1.000000000, -0.006404157, -1.151413352, -1.000000000, 0.011913584, 2.150981875,
-0.011694346, 1.000000000, 1.935534773, 0.009927853, -1.000000000, -0.974276664, 1.000000000, -0.007864196, -1.152784334, -1.000000000, 0.014630945, 2.153506744,
-0.011758070, 1.000000000, -0.527032681, 0.008410887, -1.000000000, 1.529873670, 1.000000000, -0.008419930, -2.274065453, -1.000000000, 0.012002262, 3.264990040,
-0.015128555, 1.000000000, 0.510881058, 0.011918799, -1.000000000, 0.478274989, 1.000000000, -0.011359106, -2.272508364, -1.000000000, 0.016194244, 3.262719942,
-0.018323436, 1.000000000, 1.530828790, 0.015281655, -1.000000000, -0.558879607, 1.000000000, -0.014251259, -2.273955111, -1.000000000, 0.020320244, 3.264721809 ])
sort = np.argsort(ptDec)
ptRA = ptRA[sort]
ptDec = ptDec[sort]
# Crude cut of some objects more than some encircling radius away from the boresight - creates a fast dec slice. Probably not worth doing better than this.
begin = np.searchsorted(ptDec, obsDec-MAX_RAD_FROM_BORESIGHT)
end = np.searchsorted(ptDec, obsDec+MAX_RAD_FROM_BORESIGHT)
# Position of the object in boresight coordinates
mX = -np.sin(obsDec)*np.cos(ptDec[begin:end])*np.cos(obsRA-ptRA[begin:end]) + np.cos(obsDec)*np.sin(ptDec[begin:end])
mY = np.cos(ptDec[begin:end])*np.sin(obsRA-ptRA[begin:end])
xi = -(np.sin(obsPA)*mX + np.cos(obsPA)*mY) / 0.0021801102 # Image plane position in chips
yi = (np.cos(obsPA)*mX - np.sin(obsPA)*mY) / 0.0021801102
SCA = np.zeros(end-begin)
for i in range(18):
cptr = AFTA_SCA_Coords
mask = (cptr[0+12*i]*xi+cptr[1+12*i]*yi<cptr[2+12*i]) \
& (cptr[3+12*i]*xi+cptr[4+12*i]*yi<cptr[5+12*i]) \
& (cptr[6+12*i]*xi+cptr[7+12*i]*yi<cptr[8+12*i]) \
& (cptr[9+12*i]*xi+cptr[10+12*i]*yi<cptr[11+12*i])
SCA[mask] = i+1
return np.pad(SCA,(begin,len(ptDec)-end),'constant',constant_values=(0, 0))[np.argsort(sort)] # Pad SCA array with zeros and resort to original indexing