test_camera.py 2.71 KB
Newer Older
Chen Yili's avatar
Chen Yili committed
1
import unittest
GZhao's avatar
GZhao committed
2
from CpicImgSim.camera import EMCCD
Chen Yili's avatar
Chen Yili committed
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
62
63
64
65
66
67
68
69
70
71
import numpy as np


class TestEMCCD(unittest.TestCase):
    def test_emccd_normal(self):
        emccd = EMCCD()
        emccd.switch['flat'] = True
        emccd.switch['dark'] = True
        emccd.switch['stripe'] = True
        emccd.switch['cic'] = True
        emccd.switch['cte'] = True
        emccd.switch['badcolumn'] = True
        emccd.switch['nonlinear'] = True
        emccd.switch['cosmicray'] = True
        emccd.switch['blooming'] = True

        image_focal = np.zeros(emccd.flat_shape) + 1000
        iamge_cosmic_ray = np.zeros(emccd.dark_shape)
        emgain = 10
        expt = 10
        image = emccd.readout(image_focal, emgain, expt, iamge_cosmic_ray)

        self.assertEqual(image.shape[0], emccd.image_shape[0])
        self.assertEqual(image.shape[1], emccd.image_shape[1])

    def test_emccd_allclose(self):
        emccd = EMCCD()
        emccd.switch['flat'] = False
        emccd.switch['dark'] = False
        emccd.switch['stripe'] = False
        emccd.switch['cic'] = False
        emccd.switch['cte'] = False
        emccd.switch['badcolumn'] = False
        emccd.switch['nonlinear'] = False
        emccd.switch['cosmicray'] = False
        emccd.switch['blooming'] = False

        image_focal = np.zeros(emccd.flat_shape) + 1000
        emgain = 10
        expt = 10
        image = emccd.readout(image_focal, emgain, expt)

        self.assertEqual(image.shape[0], emccd.image_shape[0])
        self.assertEqual(image.shape[1], emccd.image_shape[1])

    def test_emccd_blooming(self):
        import numpy as np
        emccd = EMCCD()
        emccd.switch['flat'] = True
        emccd.switch['dark'] = True,
        emccd.switch['stripe'] = True
        emccd.switch['cic'] = True
        emccd.switch['cte'] = True
        emccd.switch['badcolumn'] = True
        emccd.switch['nonlinear'] = True
        emccd.switch['cosmicray'] = True
        emccd.switch['blooming'] = True

        image_focal = np.zeros(emccd.flat_shape) + 1000
        image_focal[100:200, 100:200] = 500_000
        iamge_cosmic_ray = np.zeros(emccd.dark_shape)
        emgain = 10
        expt = 10
        image = emccd.readout(image_focal, emgain, expt, iamge_cosmic_ray)
        self.assertEqual(image.shape[0], emccd.image_shape[0])
        self.assertEqual(image.shape[1], emccd.image_shape[1])


if __name__ == '__main__':
GZhao's avatar
GZhao committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    # unittest.main()
    from CpicImgSim.camera import CPIC_VIS_EMCCD
    emccd = CPIC_VIS_EMCCD()
    emccd.emgain_fun(1023, -30)

    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)