csst_mci_instrument.py 3.61 KB
Newer Older
chenwei@shao.ac.cn's avatar
chenwei@shao.ac.cn committed
1
2
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding: utf-8 -*-

from abc import abstractmethod, ABCMeta
from csst_mci_common.common import CsstMCIInit
from csst_mci_common.mci_status import CsstMCIStatus
from csst_mci_common.mci_result import CsstMCIResult
from csst_mci_common.interface import BasePipelineInterface

csst_mci = CsstMCIInit()


class PipMCIL1RSS(BasePipelineInterface):

    def __init__(self):
        self.result = CsstMCIStatus
        self.logger = csst_mci.logger
        self.status = CsstMCIResult

    def run(self):
        """API, ...

        Parameters
        ----------

        Returns
        -------

        """
        from csst_mci_rss.rss import run_all
        self.exit_code = "200"
        self.additionally_algorithm_01()
        sci_fits_list = list()
        sci_list = csst_mci.config.get_mci_config("path_l0_rss")
        for path_sci in sci_list:
            print(path_sci)
            fits_output = run_all(path_sci)
            for i in [2, 6, 7]:
                sci_fits_list.append(fits_output[i])
        csst_mci.config.set_mci_config("path_l1_rss", sci_fits_list)

    def para_set(self):
        """API, ...

        Parameters
        ----------

        Returns
        -------

        """
        csst_mci.config_mci_rss_env()
        csst_mci.config.set_mci_config(
            "path_RSSlog",
            "/nfsdata/share/pipeline-unittest/csst_mci/data/dfs_dummy/L1/MCI_simData_2023-07-25/rss/path_RSSlog.txt")
        csst_mci.config.set_mci_config(
            "dir_rss_proc", "/nfsdata/share/pipeline-unittest/csst_mci/data/dfs_dummy/L1/MCI_simData_2023-07-25/rss/")
        path_list = csst_mci.get_all_file_path(
            "/nfsdata/share/pipeline-unittest/csst_mci/data/dfs_dummy/L0/MCI_simData_2023-07-25/sky_data_case_1")
        csst_mci.config.set_mci_config("path_l0_rss", path_list)

    def result_check(self):
        """API, ...

        Parameters
        ----------

        Returns
        -------

        """
        something_wrong = True
        if something_wrong:
            status = 2
            assert status in [CsstMCIStatus.PERFECT, CsstMCIStatus.WARNING]

    # 可以或计划被外部调用的方法
    def additionally_algorithm_01(self):
        pass

    # 内部方法,"_"前缀用于添加隐藏属性
    def _additionally_algorithm_02(self):
        pass


class L1Instrument(BasePipelineInterface):

    def __init__(self):
        self.result = CsstMCIStatus
        self.logger = csst_mci.logger
        self.status = CsstMCIResult

    def run(self):
        self.logger.info("instrument running...")
        try:
            fits_output, self.status = self.run_all()
        except Exception as e:
            self.logger.error(e)

        self.logger.info("instrument pipeline finish!")
        print(self.result)
        return self.status

    def para_set(self, list_para):
        env_crds_set_ins_csst1()
        env_dfs_set_l0_csst1(obsid=self.obsid)
        target_detector = csst_mci.config.get_mci_config("target_detector")
        env_dfs_set_ins_csst1(target_detector)

    def result_check(self):
        print(self.result)

    def run_all(self):

        bias_ref = csst_mci.config.get_mci_config("bias_ref")
        dark_ref = csst_mci.config.get_mci_config("dark_ref")
        flat_ref = csst_mci.config.get_mci_config("flat_ref")
        shutter_ref = csst_mci.config.get_mci_config("shutter_ref")
        sci_path = csst_mci.config.get_mci_config("sci_path")
        output_dir = csst_mci.config.get_mci_config("ins_output")

        self.status = inst_corr(
            sci_path, bias_ref, dark_ref, flat_ref, shutter_ref, output_dir, logger=None, os_bias=False, cr_flag=False)

        return self.status