__init__.py 2.31 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
4
import itertools

from astropy import table

BO ZHANG's avatar
tweaks  
BO ZHANG committed
5
from ._base_dag import BaseDAG
BO ZHANG's avatar
BO ZHANG committed
6
7
from ._dispatcher import Dispatcher
from .._csst import csst
BO ZHANG's avatar
tweaks  
BO ZHANG committed
8
9


BO ZHANG's avatar
BO ZHANG committed
10
def generate_permutations(**kwargs) -> table.Table:
BO ZHANG's avatar
BO ZHANG committed
11
    """
BO ZHANG's avatar
BO ZHANG committed
12
13
14
15
16
17
18
    生成关键字参数所有值的排列组合字典列表

    参数:
        **kwargs: 关键字参数,值应为可迭代对象(如列表)

    返回:
        list[dict]: 每个字典代表一种排列组合
BO ZHANG's avatar
BO ZHANG committed
19
    """
BO ZHANG's avatar
BO ZHANG committed
20
21
22
23
    # 验证输入值是否为可迭代对象
    for key, values in kwargs.items():
        if not isinstance(values, (list, tuple, set)):
            kwargs[key] = [values]  # 如果不是可迭代对象,转换为列表
BO ZHANG's avatar
tweaks  
BO ZHANG committed
24

BO ZHANG's avatar
BO ZHANG committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    # 提取键和对应的值列表
    keys = list(kwargs.keys())
    value_lists = [kwargs[key] for key in keys]

    # 生成笛卡尔积(所有值组合)
    permutations = []
    for combination in itertools.product(*value_lists):
        # 将每个组合转换为字典 {键: 值}
        perm_dict = dict(zip(keys, combination))
        permutations.append(perm_dict)

    return table.Table(permutations)


CSST_DAGS = {
    "csst-msc-l1-qc0": BaseDAG(
        dag="csst-msc-l1-qc0",
        pattern=generate_permutations(
            instrument=["MSC"],
            obs_type=["BIAS", "DARK", "FLAT"],
BO ZHANG's avatar
BO ZHANG committed
45
        ),
BO ZHANG's avatar
BO ZHANG committed
46
47
48
49
50
51
52
53
        dispatcher=Dispatcher.dispatch_file,
    ),
    "csst-msc-l1-mbi": BaseDAG(
        dag="csst-msc-l1-mbi",
        pattern=generate_permutations(
            instrument=["MSC"],
            obs_type=["WIDE", "DEEP"],
            detector=csst["MSC"]["MBI"].effective_detector_names,
BO ZHANG's avatar
BO ZHANG committed
54
        ),
BO ZHANG's avatar
BO ZHANG committed
55
56
57
58
59
60
61
    ),
    "csst-msc-l1-ast": BaseDAG(
        dag="csst-msc-l1-ast",
        pattern=generate_permutations(
            instrument=["MSC"],
            obs_type=["WIDE", "DEEP"],
            detector=csst["MSC"]["MBI"].effective_detector_names,
BO ZHANG's avatar
BO ZHANG committed
62
        ),
BO ZHANG's avatar
BO ZHANG committed
63
64
65
66
67
68
69
    ),
    "csst-msc-l1-sls": BaseDAG(
        dag="csst-msc-l1-sls",
        pattern=generate_permutations(
            instrument=["MSC"],
            obs_type=["WIDE", "DEEP"],
            detector=csst["MSC"]["SLS"].effective_detector_names,
BO ZHANG's avatar
BO ZHANG committed
70
        ),
BO ZHANG's avatar
BO ZHANG committed
71
72
73
74
75
76
77
    ),
    "csst-msc-l1-ooc": BaseDAG(
        dag="csst-msc-l1-ooc",
        pattern=generate_permutations(
            instrument=["MSC"],
            obs_type=["BIAS", "DARK", "FLAT"],
            detector=csst["MSC"].effective_detector_names,
BO ZHANG's avatar
BO ZHANG committed
78
        ),
BO ZHANG's avatar
BO ZHANG committed
79
80
    ),
}