FocalPlane.py 4.59 KB
Newer Older
Fang Yuedong's avatar
Fang Yuedong committed
1
2
3
import galsim
import numpy as np

Fang Yuedong's avatar
Fang Yuedong committed
4

Fang Yuedong's avatar
Fang Yuedong committed
5
class FocalPlane(object):
Fang Yuedong's avatar
Fang Yuedong committed
6
    def __init__(self, chip_list=None, survey_type='Photometric', bad_chips=None):
Fang Yuedong's avatar
Fang Yuedong committed
7
8
        """Get the focal plane layout
        """
Fang Yuedong's avatar
Fang Yuedong committed
9
        self.nchips = 42
Fang Yuedong's avatar
Fang Yuedong committed
10
11
        self.ignore_chips = []

Fang Yuedong's avatar
Fang Yuedong committed
12
13
14
15
        if bad_chips == None:
            self.bad_chips = []
        else:
            self.bad_chips = bad_chips
Fang Yuedong's avatar
Fang Yuedong committed
16
17
            for chip_id in bad_chips:
                self.ignore_chips.append(chip_id)
Fang Yuedong's avatar
Fang Yuedong committed
18

Fang Yuedong's avatar
Fang Yuedong committed
19
20
21
22
23
        if chip_list is not None:
            for i in range(42):
                if not (i+1 in chip_list):
                    self.ignore_chips.append(i+1)
        elif survey_type == 'Photometric':
Fang Yuedong's avatar
Fang Yuedong committed
24
25
26
27
28
            for i in range(5):
                self.ignore_chips.append(i+1)
                self.ignore_chips.append(i+26)
            self.ignore_chips.append(10)
            self.ignore_chips.append(21)
Fang Yuedong's avatar
Fang Yuedong committed
29
30
            for i in range(31, 43):
                self.ignore_chips.append(i)
Fang Yuedong's avatar
Fang Yuedong committed
31
32
33
34
35
36
        elif survey_type == 'Spectroscopic':
            for i in range(6, 26):
                if i == 10 or i == 21:
                    continue
                else:
                    self.ignore_chips.append(i)
Fang Yuedong's avatar
Fang Yuedong committed
37
38
39
40
41
            for i in range(31, 43):
                self.ignore_chips.append(i)
        elif survey_type == 'FGS':
            for i in range(1, 31):
                self.ignore_chips.append(i)
Fang Yuedong's avatar
Fang Yuedong committed
42

Fang Yuedong's avatar
Fang Yuedong committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        # if config is not None:
        #     self.nchip_x    = config["nchip_x"]
        #     self.nchip_y    = config["nchip_y"]
        #     self.npix_tot_x = config["npix_tot_x"]
        #     self.npix_tot_y = config["npix_tot_y"]
        #     self.npix_gap_x = config["npix_gap_x"]
        #     self.npix_gap_y = config["npix_gap_y"]
        #     if "chipLabelIDs" in config:
        #         self.chipLabelIDs = config["chipLabelIDs"]
        #     if "bad_chips" in config:
        #         self.bad_chips = config["bad_chips"]
        # else:
        self.nchip_x = 6
        self.nchip_y = 5
        self.npix_tot_x = 59516
        self.npix_tot_y = 49752
        self.npix_gap_x = (534, 1309)
        self.npix_gap_y = 898

Fang Yuedong's avatar
Fang Yuedong committed
62
63
64
65
66
67
68
        self._getCenter()

    def _getCenter(self):
        self.cen_pix_x = 0
        self.cen_pix_y = 0

    def getChipLabel(self, chipID):
Fang Yuedong's avatar
Fang Yuedong committed
69
        return str("0%d" % chipID)[-2:]
Fang Yuedong's avatar
Fang Yuedong committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

    def isBadChip(self, chipID):
        """Check if chip #(chipID) on the focal plane is bad or not
        """
        return (chipID in self.bad_chips)

    def isIgnored(self, chipID):
        return (chipID in self.ignore_chips)

    def getTanWCS(self, ra, dec, img_rot, pix_scale, xcen=None, ycen=None, logger=None):
        """ Get the WCS of the image mosaic using Gnomonic/TAN projection

        Parameter:
            ra, dec:    float
                        (RA, Dec) of pointing of optical axis
            img_rot:    galsim Angle object
                        Rotation of image
            pix_scale:  float
                        Pixel size in unit of as/pix
        Returns:
            WCS of the focal plane
        """
        if logger is not None:
Fang Yuedong's avatar
Fang Yuedong committed
93
94
            logger.info(
                "    Construct the wcs of the entire image mosaic using Gnomonic/TAN projection")
Fang Yuedong's avatar
Fang Yuedong committed
95
96
97
        if (xcen == None) or (ycen == None):
            xcen = self.cen_pix_x
            ycen = self.cen_pix_y
98
99
100
101
102
        # dudx =  -np.cos(img_rot.rad) * pix_scale
        # dudy =  -np.sin(img_rot.rad) * pix_scale
        # dvdx =  -np.sin(img_rot.rad) * pix_scale
        # dvdy =  +np.cos(img_rot.rad) * pix_scale

Fang Yuedong's avatar
Fang Yuedong committed
103
104
105
106
107
        dudx = -np.cos(img_rot.rad) * pix_scale
        dudy = +np.sin(img_rot.rad) * pix_scale
        dvdx = -np.sin(img_rot.rad) * pix_scale
        dvdy = -np.cos(img_rot.rad) * pix_scale

Fang Yuedong's avatar
Fang Yuedong committed
108
        moscen = galsim.PositionD(x=xcen, y=ycen)
Fang Yuedong's avatar
Fang Yuedong committed
109
110
        sky_center = galsim.CelestialCoord(
            ra=ra*galsim.degrees, dec=dec*galsim.degrees)
Fang Yuedong's avatar
Fang Yuedong committed
111
112
113
114
115
116
117
118
119
120
        affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen)
        WCS = galsim.TanWCS(affine, sky_center, units=galsim.arcsec)

        return WCS

    def getSkyCoverage(self, wcs, x0, x1, y0, y1):
        """
        The sky coverage of an area
        """
        r2d = 180.0/np.pi
Fang Yuedong's avatar
Fang Yuedong committed
121
122
123
124
        s1 = wcs.toWorld(galsim.PositionD(x0, y0))
        s2 = wcs.toWorld(galsim.PositionD(x0, y1))
        s3 = wcs.toWorld(galsim.PositionD(x1, y0))
        s4 = wcs.toWorld(galsim.PositionD(x1, y1))
Fang Yuedong's avatar
Fang Yuedong committed
125
126
127
128
        ra = [s1.ra.rad*r2d, s2.ra.rad*r2d, s3.ra.rad*r2d, s4.ra.rad*r2d]
        dec = [s1.dec.rad*r2d, s2.dec.rad*r2d, s3.dec.rad*r2d, s4.dec.rad*r2d]

        return galsim.BoundsD(min(ra), max(ra), min(dec), max(dec))