msc.py 2.71 KB
Newer Older
BO ZHANG's avatar
tweaks    
BO ZHANG committed
1
2
import json
from ._base_dag import BaseDAG
BO ZHANG's avatar
tweaks  
BO ZHANG committed
3
4
5
from csst_dfs_client import plan, level0


BO ZHANG's avatar
tweaks    
BO ZHANG committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
MSC_MBI_CHIPID = [
    "06",
    "07",
    "08",
    "09",
    "11",
    "12",
    "13",
    "14",
    "15",
    "16",
    "17",
    "18",
    "19",
    "20",
    "22",
    "23",
    "24",
    "25",
]
BO ZHANG's avatar
tweaks  
BO ZHANG committed
26

BO ZHANG's avatar
tweaks    
BO ZHANG committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
MSC_SLS_CHIPID = [
    "01",
    "02",
    "03",
    "04",
    "05",
    "10",
    "21",
    "26",
    "27",
    "28",
    "29",
    "30",
]
BO ZHANG's avatar
BO ZHANG committed
41
MSC_CHIPID = MSC_MBI_CHIPID + MSC_SLS_CHIPID
BO ZHANG's avatar
tweaks    
BO ZHANG committed
42

BO ZHANG's avatar
BO ZHANG committed
43
44
45
46
47
CHIPID_MAP = {
    "csst-msc-l1-mbi": MSC_MBI_CHIPID,
    "csst-msc-l1-sls": MSC_SLS_CHIPID,
    "csst-msc-l1-qc0": MSC_CHIPID,
}
BO ZHANG's avatar
tweaks    
BO ZHANG committed
48

BO ZHANG's avatar
tweaks  
BO ZHANG committed
49

BO ZHANG's avatar
BO ZHANG committed
50
51
52
53
54
55
56
57
58
59
class CsstMscL1(BaseDAG):

    def __init__(self, dag_id: str):
        super().__init__(dag_id)
        self.CHIPID = CHIPID_MAP[dag_id]

    def schedule(self, **kwargs):
        return self._base_schedule(**kwargs)

    def _base_schedule(
BO ZHANG's avatar
tweaks    
BO ZHANG committed
60
        self,
BO ZHANG's avatar
tweaks  
BO ZHANG committed
61
62
63
64
        dataset: str = "csst-msc-c9-25sqdeg-v3",
        obs_type: str = "WIDE",
        project_id="none",
        batch_id: str | None = "default",
BO ZHANG's avatar
BO ZHANG committed
65
66
        initial_prc_status: int = -1024,
        final_prc_status: int = -2,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
67
        demo=True,
BO ZHANG's avatar
tweaks  
BO ZHANG committed
68
69
        **kwargs,
    ):
BO ZHANG's avatar
tweaks    
BO ZHANG committed
70
71
72
73
74
75
        # dataset: str = "csst-msc-c9-25sqdeg-v3"
        # obs_type: str = "WIDE"
        # project_id = "none"
        # batch_id: str | None = "default"

        # no need to query plan
BO ZHANG's avatar
tweaks  
BO ZHANG committed
76

BO ZHANG's avatar
tweaks    
BO ZHANG committed
77
78
79
80
81
82
        # plan.find(
        #     instrument="MSC",
        #     dataset=dataset,
        #     obs_type=obs_type,
        #     project_id=project_id,
        # )
BO ZHANG's avatar
tweaks  
BO ZHANG committed
83

BO ZHANG's avatar
tweaks    
BO ZHANG committed
84
85
86
87
88
        recs = level0.find(
            instrument="MSC",
            dataset=dataset,
            obs_type=obs_type,
            project_id=project_id,
BO ZHANG's avatar
BO ZHANG committed
89
            prc_status=initial_prc_status,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
90
91
92
        )
        assert recs.success, recs.message
        msgs = []
BO ZHANG's avatar
tweaks    
BO ZHANG committed
93
        for this_rec in recs.data:
BO ZHANG's avatar
BO ZHANG committed
94
            if this_rec["detector_no"] in self.CHIPID:
BO ZHANG's avatar
tweaks    
BO ZHANG committed
95
                this_msg = self.gen_msg(
BO ZHANG's avatar
tweaks    
BO ZHANG committed
96
97
98
99
                    dataset=dataset,
                    obs_type=obs_type,
                    project_id=project_id,
                    batch_id=batch_id,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
100
                    obs_id=this_rec["obs_id"],
BO ZHANG's avatar
BO ZHANG committed
101
                    chip_id=this_rec["detector_no"],
BO ZHANG's avatar
tweaks    
BO ZHANG committed
102
                    dag_run_id=self.gen_dag_run_id(),
BO ZHANG's avatar
tweaks    
BO ZHANG committed
103
                    **kwargs,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
104
                )
BO ZHANG's avatar
tweaks    
BO ZHANG committed
105
                if not demo:
BO ZHANG's avatar
BO ZHANG committed
106
107
108
109
110
                    # push and update
                    self.push(this_msg)
                    this_update = level0.update_prc_status(
                        level0_id=this_rec["level0_id"],
                        dag_run_id=this_msg["dag_run_id"],
BO ZHANG's avatar
BO ZHANG committed
111
                        prc_status=final_prc_status,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
112
113
                        dataset=dataset,
                    )
BO ZHANG's avatar
BO ZHANG committed
114
                    assert this_update.success, this_update.message
BO ZHANG's avatar
tweaks    
BO ZHANG committed
115
                msgs.append(this_msg)
BO ZHANG's avatar
tweaks    
BO ZHANG committed
116
        return msgs