test_camera.py 2.45 KB
Newer Older
Chen Yili's avatar
Chen Yili committed
1
import unittest
GZhao's avatar
GZhao committed
2
from csst_cpic_sim.camera import CpicVisEmccd
Chen Yili's avatar
Chen Yili committed
3
4
5
6
7
import numpy as np


class TestEMCCD(unittest.TestCase):
    def test_emccd_normal(self):
GZhao's avatar
GZhao committed
8
9
        emccd = CpicVisEmccd()
        image_focal = np.zeros(emccd.flat_shape) + 10
Chen Yili's avatar
Chen Yili committed
10
        iamge_cosmic_ray = np.zeros(emccd.dark_shape)
GZhao's avatar
GZhao committed
11
12
13
        em_set = 200
        expt = 0
        image = emccd.readout(image_focal, em_set, expt, iamge_cosmic_ray)
Chen Yili's avatar
Chen Yili committed
14

GZhao's avatar
GZhao committed
15
16
        self.assertEqual(image.shape[0], emccd.bias_shape[0])
        self.assertEqual(image.shape[1], emccd.bias_shape[1])
Chen Yili's avatar
Chen Yili committed
17
18

    def test_emccd_allclose(self):
GZhao's avatar
GZhao committed
19
20
21
22
23
24
25
        config = {
            'switch': {'shutter': False},
            'dark': 1e-2,
            'cic': 0.2,
            'flat': np.zeros((1024, 1024)),
            'ccd_temp': -200
        }
Chen Yili's avatar
Chen Yili committed
26

GZhao's avatar
GZhao committed
27
28
29
30
31
32
        emccd = CpicVisEmccd(config)
        for key in emccd.switch:
            emccd.switch[key] = False

        image_focal = np.zeros(emccd.flat_shape) + 10
        em_set = 1024
Chen Yili's avatar
Chen Yili committed
33
        expt = 10
GZhao's avatar
GZhao committed
34
        image = emccd.readout(image_focal, em_set, expt)
Chen Yili's avatar
Chen Yili committed
35

GZhao's avatar
GZhao committed
36
37
        self.assertEqual(image.shape[0], emccd.bias_shape[0])
        self.assertEqual(image.shape[1], emccd.bias_shape[1])
Chen Yili's avatar
Chen Yili committed
38
39
40

    def test_emccd_blooming(self):
        import numpy as np
GZhao's avatar
GZhao committed
41
        emccd = CpicVisEmccd()
Chen Yili's avatar
Chen Yili committed
42
        image_focal = np.zeros(emccd.flat_shape) + 1000
GZhao's avatar
GZhao committed
43
        image_focal[100:200, 100:200] = 100_000
Chen Yili's avatar
Chen Yili committed
44
        iamge_cosmic_ray = np.zeros(emccd.dark_shape)
GZhao's avatar
GZhao committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        emgain = 800
        expt = 1
        emccd.ccd_temp = -100
        emccd.time_syn(10, readout=False)
        image = emccd.readout(image_focal, None, expt, iamge_cosmic_ray, emgain=emgain)
        self.assertEqual(image.shape[0], emccd.bias_shape[0])
        self.assertEqual(image.shape[1], emccd.bias_shape[1])
    def test_em_fix_fun(self):
        emccd = CpicVisEmccd()
        emgain = emccd.em_fix_fuc_fit(-5)
        self.assertEqual(emgain, 0.0)

    def test_emccd_update(self):
        emccd = CpicVisEmccd()
        emccd.ccd_temp = -100
        emgain = emccd.emgain_set(1024, ccd_temp=None, self_update=False )
        self.assertAlmostEqual(emgain, 1.23, places=2)
Chen Yili's avatar
Chen Yili committed
62
63


GZhao's avatar
GZhao committed
64
65
# if __name__ == '__main__':
#     unittest.main()
GZhao's avatar
GZhao committed
66
67
68
    # from CpicImgSim.camera import CPIC_VIS_EMCCD
    # emccd = CPIC_VIS_EMCCD()
    # emccd.emgain_fun(1023, -30)
GZhao's avatar
GZhao committed
69

GZhao's avatar
GZhao committed
70
71
72
73
74
75
76
    # bias_images = []
    # for _ in range(10):
    #     bias = emccd.bias_frame(show=True)
    #     bias_images.append(bias)
    # bias_images = np.array(bias_images)
    # from astropy.io import fits
    # fits.writeto("bias.fits", bias_images)
GZhao's avatar
GZhao committed
77
78