Commit fe70f366 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

add unittest for focal plane

parent fcfee677
Loading
Loading
Loading
Loading
+771 −771

File changed.

Preview size limit exceeded, changes collapsed.

+36 −33
Original line number Diff line number Diff line
import galsim
import numpy as np


class FocalPlane(object):
    def __init__(self, config=None, chip_list=None, survey_type='Photometric', bad_chips=None):
    def __init__(self, chip_list=None, survey_type='Photometric', bad_chips=None):
        """Get the focal plane layout
        """
        self.nchips = 42
@@ -39,18 +40,18 @@ class FocalPlane(object):
            for i in range(1, 31):
                self.ignore_chips.append(i)

        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:
        # 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
@@ -89,7 +90,8 @@ class FocalPlane(object):
            WCS of the focal plane
        """
        if logger is not None:
            logger.info("    Construct the wcs of the entire image mosaic using Gnomonic/TAN projection")
            logger.info(
                "    Construct the wcs of the entire image mosaic using Gnomonic/TAN projection")
        if (xcen == None) or (ycen == None):
            xcen = self.cen_pix_x
            ycen = self.cen_pix_y
@@ -104,7 +106,8 @@ class FocalPlane(object):
        dvdy = -np.cos(img_rot.rad) * pix_scale

        moscen = galsim.PositionD(x=xcen, y=ycen)
        sky_center = galsim.CelestialCoord(ra=ra*galsim.degrees, dec=dec*galsim.degrees)
        sky_center = galsim.CelestialCoord(
            ra=ra*galsim.degrees, dec=dec*galsim.degrees)
        affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen)
        WCS = galsim.TanWCS(affine, sky_center, units=galsim.arcsec)

+31 −0
Original line number Diff line number Diff line
import unittest
import os
import galsim
from ObservationSim.Instrument import FocalPlane, Chip


class TestFocalPlane(unittest.TestCase):
    def __init__(self, methodName='runTest'):
        super(TestFocalPlane, self).__init__(methodName)
        self.dataPath = os.path.join(
            os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc')
        self.focal_plane = FocalPlane(
            chip_list=['8'])
        self.assertTrue(self.focal_plane.cen_pix_x == 0)
        self.assertTrue(self.focal_plane.cen_pix_y == 0)
        test_focal_plane_phot = FocalPlane(survey_type='Photometric')
        test_focal_plane_spec = FocalPlane(survey_type='Spectroscopic')
        test_focal_plane_FGS = FocalPlane(survey_type='FGS')
        test_focal_plane_bad_chips = FocalPlane(bad_chips=["1"])

    def test_fp_method(self):
        wcs = self.focal_plane.getTanWCS(
            192.8595, 0., 0.*galsim.degrees, 0.0074)
        sky_coverage = self.focal_plane.getSkyCoverage(
            wcs, x0=-1, x1=0, y0=-1, y1=0)
        print(sky_coverage.area())
        self.assertTrue(abs(sky_coverage.area() - 0.0074**2/(3600.**2)) < 1e13)


if __name__ == '__main_':
    unittest.main()