"tests/test_io.py" did not exist on "5d32174f0048a245f3c5b6a6e7990001e2953e94"
test_fits.py 1.26 KB
Newer Older
1
2
3
4
5
6
7
"""
Identifier:     tests/test_fits_header_ops.py
Name:           test_fits_header_ops.py
Description:    test append_header
Author:         Bo Zhang
Created:        2023-12-15
Modified-History:
8
    2025-10-23, Bo Zhang, add tests for fits operations
9
10
11
12
13
"""

import os
import unittest

14
import numpy as np
15
16
17
18
19
20
21
22
23
24
from csst_common import fits

test_fits_file = os.path.join(
    os.environ["UNIT_TEST_DATA_ROOT"],
    "csst_common/test_fits/hl.fits",
)


class TestFitsHeaderOps(unittest.TestCase):

25
26
27
28
29
30
31
    def setUp(self):
        hl = fits.HDUList(
            [
                fits.PrimaryHDU(),
                fits.ImageHDU(data=np.random.randn(5, 5)),
            ]
        )
32
        hl.writeto(test_fits_file, overwrite=True)
33

34
35
36
37
38
39
40
41
42
43
44
45
46
    def test_fits_open(self):
        hl = fits.open(test_fits_file)
        self.assertIsInstance(hl, fits.HDUList)

    def test_fits_header(self):
        header = fits.getheader(test_fits_file, ext=0)
        self.assertIsInstance(header, fits.Header)

    def test_fits_getval(self):
        val = fits.getval(test_fits_file, ext=0, keyword="SIMPLE")
        self.assertEqual(val, True)

    def test_fits_getdata(self):
47
        data = fits.getdata(test_fits_file, ext=1)
48
49
        self.assertIsInstance(data, np.ndarray)
        self.assertEqual(data.shape, (5, 5))