test_PSFmodule.py 2.64 KB
Newer Older
Wei Chengliang's avatar
Wei Chengliang committed
1
2
import unittest

Fang Yuedong's avatar
Fang Yuedong committed
3
4
5
import sys
import os
import math
Wei Chengliang's avatar
Wei Chengliang committed
6
7
8
9
10
from itertools import islice
import numpy as np
import galsim
import yaml

Fang Yuedong's avatar
Fang Yuedong committed
11
12
from observation_sim.instruments import Chip, Filter, FilterParam, FocalPlane
from observation_sim.PSF.PSFInterp import PSFInterp
Wei Chengliang's avatar
Wei Chengliang committed
13
14
15
16
17
18


def defineCCD(iccd, config_file):
    with open(config_file, "r") as stream:
        try:
            config = yaml.safe_load(stream)
Fang Yuedong's avatar
Fang Yuedong committed
19
            # for key, value in config.items():
Wei Chengliang's avatar
Wei Chengliang committed
20
21
22
23
24
25
            #    print (key + " : " + str(value))
        except yaml.YAMLError as exc:
            print(exc)
    chip = Chip(chipID=iccd, config=config)
    chip.img = galsim.ImageF(chip.npix_x, chip.npix_y)
    focal_plane = FocalPlane(chip_list=[iccd])
Fang Yuedong's avatar
Fang Yuedong committed
26
27
    chip.img.wcs = focal_plane.getTanWCS(
        192.8595, 27.1283, -113.4333*galsim.degrees, chip.pix_scale)
Wei Chengliang's avatar
Wei Chengliang committed
28
29
    return chip

Fang Yuedong's avatar
Fang Yuedong committed
30

Wei Chengliang's avatar
Wei Chengliang committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def defineFilt(chip):
    filter_param = FilterParam()
    filter_id, filter_type = chip.getChipFilter()
    filt = Filter(
        filter_id=filter_id,
        filter_type=filter_type,
        filter_param=filter_param,
        ccd_bandpass=chip.effCurve)
    bandpass_list = filt.bandpass_sub_list
    return bandpass_list


class PSFInterpModule_coverage(unittest.TestCase):
    def __init__(self, methodName='runTest'):
        super(PSFInterpModule_coverage, self).__init__(methodName)
Fang Yuedong's avatar
Fang Yuedong committed
46
47
        self.dataPath = os.path.join(
            os.getenv('UNIT_TEST_DATA_ROOT'), 'csst_msc_sim/csst_fz_msc')
Wei Chengliang's avatar
Wei Chengliang committed
48
        self.iccd = 8
Wei Chengliang's avatar
Wei Chengliang committed
49
50
51
52
53
54
55

    def test_loadPSFSet(self):
        config_file = os.path.join(self.dataPath, 'config_test.yaml')
        chip = defineCCD(self.iccd, config_file)
        bandpass = defineFilt(chip)
        print(chip.chipID)
        print(chip.cen_pix_x, chip.cen_pix_y)
Fang Yuedong's avatar
Fang Yuedong committed
56
57
58
59
60
61
62
63

        # "/public/share/yangxuliu/CSSOSDataProductsSims/psfCube/set1_dynamic/"
        pathTemp = self.dataPath
        psfModel = PSFInterp(chip, npsf=900, PSF_data_file=pathTemp,
                             PSF_data_prefix="", HocBuild=True, LOG_DEBUG=True)

        # imgPos[iobj, :] # try get the PSF at some location (1234, 1234) on the chip
        x, y = 4096, 4096
Wei Chengliang's avatar
Wei Chengliang committed
64
65
66
67
        x = x+chip.bound.xmin
        y = y+chip.bound.ymin
        pos_img = galsim.PositionD(x, y)

Fang Yuedong's avatar
Fang Yuedong committed
68
69
70
71
72
73
74
75
76
        psf, _ = psfModel.get_PSF(
            chip=chip, pos_img=pos_img, bandpass=0, galsimGSObject=True)
        psfA = psfModel.get_PSF(
            chip=chip, pos_img=pos_img, bandpass=bandpass[0], galsimGSObject=False)
        psfB = psfModel.get_PSF(
            chip=chip, pos_img=pos_img, findNeighMode='hoclistFind', bandpass=bandpass[0], galsimGSObject=False)

        self.assertTrue(psf != None)
        self.assertTrue(np.max(np.abs(psfA-psfB)) < 1e-6)
Wei Chengliang's avatar
Wei Chengliang committed
77
78
79
80


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