msc.py 2.46 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
6
from csst_dfs_client import plan, level0

__all__ = ["CsstMscL1Mbi"]

BO ZHANG's avatar
tweaks    
BO ZHANG committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
27

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


class CsstMscL1Mbi(BaseDAG):
BO ZHANG's avatar
tweaks    
BO ZHANG committed
45
46
    def __init__(self):
        super().__init__("csst-msc-l1-mbi")
BO ZHANG's avatar
tweaks  
BO ZHANG committed
47
48

    def schedule(
BO ZHANG's avatar
tweaks    
BO ZHANG committed
49
        self,
BO ZHANG's avatar
tweaks  
BO ZHANG committed
50
51
52
53
        dataset: str = "csst-msc-c9-25sqdeg-v3",
        obs_type: str = "WIDE",
        project_id="none",
        batch_id: str | None = "default",
BO ZHANG's avatar
tweaks    
BO ZHANG committed
54
55
        prc_status: int = -1024,
        demo=True,
BO ZHANG's avatar
tweaks  
BO ZHANG committed
56
57
        **kwargs,
    ):
BO ZHANG's avatar
tweaks    
BO ZHANG committed
58
59
60
61
62
63
        # 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
64

BO ZHANG's avatar
tweaks    
BO ZHANG committed
65
66
67
68
69
70
        # plan.find(
        #     instrument="MSC",
        #     dataset=dataset,
        #     obs_type=obs_type,
        #     project_id=project_id,
        # )
BO ZHANG's avatar
tweaks  
BO ZHANG committed
71

BO ZHANG's avatar
tweaks    
BO ZHANG committed
72
73
74
75
76
        recs = level0.find(
            instrument="MSC",
            dataset=dataset,
            obs_type=obs_type,
            project_id=project_id,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
77
            prc_status=prc_status,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
78
79
80
        )
        assert recs.success, recs.message
        msgs = []
BO ZHANG's avatar
tweaks    
BO ZHANG committed
81
82
83
        for this_rec in recs.data:
            if this_rec["detector_no"] in MSC_MBI_CHIPID:
                this_msg = self.gen_msg(
BO ZHANG's avatar
tweaks    
BO ZHANG committed
84
85
86
87
                    dataset=dataset,
                    obs_type=obs_type,
                    project_id=project_id,
                    batch_id=batch_id,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
88
                    obs_id=this_rec["obs_id"],
BO ZHANG's avatar
BO ZHANG committed
89
                    chip_id=this_rec["detector_no"],
BO ZHANG's avatar
tweaks    
BO ZHANG committed
90
                    dag_run_id=self.gen_dag_run_id(),
BO ZHANG's avatar
tweaks    
BO ZHANG committed
91
                    **kwargs,
BO ZHANG's avatar
tweaks    
BO ZHANG committed
92
                )
BO ZHANG's avatar
tweaks    
BO ZHANG committed
93
                if not demo:
BO ZHANG's avatar
BO ZHANG committed
94
95
96
97
98
                    # 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
tweaks    
BO ZHANG committed
99
100
101
                        prc_status=-2,
                        dataset=dataset,
                    )
BO ZHANG's avatar
BO ZHANG committed
102
                    assert this_update.success, this_update.message
BO ZHANG's avatar
tweaks    
BO ZHANG committed
103
104
                msgs.append(this_msg)
                # self.push(msg)
BO ZHANG's avatar
tweaks    
BO ZHANG committed
105
        return msgs
BO ZHANG's avatar
tweaks    
BO ZHANG committed
106
107
        # push msg
        # update prc_status