_dispatcher.py 18.7 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
import numpy as np
BO ZHANG's avatar
BO ZHANG committed
2
3
import joblib
from astropy import table
BO ZHANG's avatar
BO ZHANG committed
4
from csst_dfs_client import plan, level0, level1
BO ZHANG's avatar
BO ZHANG committed
5
6
from tqdm import trange

BO ZHANG's avatar
BO ZHANG committed
7
8
from .._csst import csst

BO ZHANG's avatar
BO ZHANG committed
9
10
# from csst_dag._csst import csst

BO ZHANG's avatar
BO ZHANG committed
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
# THESE ARE GENERAL PARAMETERS!
PLAN_PARAMS = {
    "dataset": None,
    "instrument": None,
    "obs_type": None,
    "obs_group": None,
    "obs_id": None,
    "proposal_id": None,
}

LEVEL0_PARAMS = {
    "dataset": None,
    "instrument": None,
    "obs_type": None,
    "obs_group": None,
    "obs_id": None,
    "detector": None,
    "prc_status": -1024,
}

LEVEL1_PARAMS = {
    "dataset": None,
    "instrument": None,
    "obs_type": None,
    "obs_group": None,
    "obs_id": None,
    "detector": None,
    "prc_status": -1024,
    "data_model": None,
    "batch_id": "default_batch",
}

PROC_PARAMS = {
    "priority": 1,
    "batch_id": "default_batch",
    "pmapname": "pmapname",
    "final_prc_status": -2,
    "demo": False,
BO ZHANG's avatar
BO ZHANG committed
49
    # should be capable to extend
BO ZHANG's avatar
BO ZHANG committed
50
51
}

BO ZHANG's avatar
BO ZHANG committed
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
# plan basis keys
PLAN_BASIS_KEYS = (
    "dataset",
    "instrument",
    "obs_type",
    "obs_group",
    "obs_id",
    "n_frame",
    "_id",
)

# data basis keys
DATA_BASIS_KEYS = (
    "dataset",
    "instrument",
    "obs_type",
    "obs_group",
    "obs_id",
    "detector",
    "file_name",
    "_id",
)

# join_type for data x plan
PLAN_JOIN_TYPE = "inner"
"""
References:
    - https://docs.astropy.org/en/stable/api/astropy.table.join.html
    - https://docs.astropy.org/en/stable/table/operations.html#join

Typical types:
    - inner join: Only matching rows from both tables
    - left join: All rows from left table, matching rows from right table
    - right join: All rows from right table, matching rows from left table
    - outer join: All rows from both tables
    - cartesian join: Every combination of rows from both tables
"""

BO ZHANG's avatar
BO ZHANG committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

def override_common_keys(d1: dict, d2: dict) -> dict:
    """
    Construct a new dictionary by updating the values of basis_keys that exists in the first dictionary
    with the values of the second dictionary.

    Parameters
    ----------
    d1 : dict
        The first dictionary.
    d2 : dict
        The second dictionary.

    Returns
    -------
    dict:
        The updated dictionary.
    """
    return {k: d2[k] if k in d2.keys() else d1[k] for k in d1.keys()}


BO ZHANG's avatar
BO ZHANG committed
111
112
113
def extract_basis_table(dlist: list[dict], basis_keys: tuple) -> table.Table:
    """Extract basis key-value pairs from a list of dictionaries."""
    return table.Table([{k: d.get(k) for k in basis_keys} for d in dlist])
BO ZHANG's avatar
BO ZHANG committed
114
115


BO ZHANG's avatar
BO ZHANG committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def split_data_basis(data_basis: table.Table, n_split: int = 1) -> list[table.Table]:
    """Split data basis into n_split parts."""
    assert (
        np.unique(data_basis["dataset"]).size == 1
    ), "Only one dataset is allowed for splitting."
    # sort
    data_basis.sort(keys=["dataset", "obs_id"])
    # get unique obsid
    u_obsid, i_obsid, c_obsid = np.unique(
        data_basis["obs_id"].data, return_index=True, return_counts=True
    )
    # set chunk size
    chunk_size = int(np.fix(len(u_obsid) / n_split))
    # initialize chunks
    chunks = []
    for i_split in range(n_split):
        if i_split < n_split - 1:
            chunks.append(
                data_basis[
                    i_obsid[i_split * chunk_size] : i_obsid[(i_split + 1) * chunk_size]
                ]
            )
        else:
            chunks.append(data_basis[i_obsid[i_split * chunk_size] :])
    # np.unique(table.vstack(chunks)["_id"])
    # np.unique(table.vstack(chunks)["obs_id"])
    return chunks


BO ZHANG's avatar
BO ZHANG committed
145
146
147
148
149
150
class Dispatcher:
    """
    A class to dispatch tasks based on the observation type.
    """

    @staticmethod
BO ZHANG's avatar
BO ZHANG committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    def find_plan_basis(**kwargs) -> table.Table:
        """
        Find plan records.
        """
        # query
        qr = plan.find(**override_common_keys(PLAN_PARAMS, kwargs))
        assert qr.success, qr
        # plan basis / obsid basis
        for _ in qr.data:
            _["n_frame"] = (
                _["params"]["n_epec_frame"] if _["instrument"] == "HSTDM" else 1
            )
        plan_basis = extract_basis_table(
            qr.data,
            PLAN_BASIS_KEYS,
BO ZHANG's avatar
BO ZHANG committed
166
        )
BO ZHANG's avatar
BO ZHANG committed
167
        return plan_basis
BO ZHANG's avatar
BO ZHANG committed
168
169

    @staticmethod
BO ZHANG's avatar
BO ZHANG committed
170
171
172
173
174
175
176
177
178
179
180
181
182
    def find_level0_basis(**kwargs) -> table.Table:
        """
        Find level0 records.
        """
        # query
        qr = level0.find(**override_common_keys(LEVEL0_PARAMS, kwargs))
        assert qr.success, qr
        # data basis
        data_basis = extract_basis_table(
            qr.data,
            DATA_BASIS_KEYS,
        )
        return data_basis
BO ZHANG's avatar
BO ZHANG committed
183

BO ZHANG's avatar
BO ZHANG committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    @staticmethod
    def find_level1_basis(**kwargs) -> table.Table:
        """
        Find level1 records.
        """
        # query
        qr = level1.find(**override_common_keys(LEVEL1_PARAMS, kwargs))
        assert qr.success, qr
        # data basis
        data_basis = extract_basis_table(
            qr.data,
            DATA_BASIS_KEYS,
        )
        return data_basis
BO ZHANG's avatar
BO ZHANG committed
198

199
    @staticmethod
200
    def find_plan_level0_basis(**kwargs) -> tuple[table.Table]:
201
202
        data_basis = Dispatcher.find_level0_basis(**kwargs)
        plan_basis = Dispatcher.find_plan_basis(**kwargs)
203
204
        assert len(data_basis) > 0, data_basis
        assert len(plan_basis) > 0, plan_basis
205
206
207
208
209
210
211
        u_data_basis = table.unique(data_basis["dataset", "obs_id"])
        relevant_plan = table.join(
            u_data_basis,
            plan_basis,
            keys=["dataset", "obs_id"],
            join_type=PLAN_JOIN_TYPE,
        )
212
        assert len(relevant_plan) > 0, relevant_plan
213
214
215
        return relevant_plan, data_basis

    @staticmethod
216
    def find_plan_level1_basis(**kwargs) -> tuple[table.Table]:
217
218
        data_basis = Dispatcher.find_level1_basis(**kwargs)
        plan_basis = Dispatcher.find_plan_basis(**kwargs)
219
220
        assert len(data_basis) > 0, data_basis
        assert len(plan_basis) > 0, plan_basis
221
222
223
224
225
226
227
        u_data_basis = table.unique(data_basis["dataset", "obs_id"])
        relevant_plan = table.join(
            u_data_basis,
            plan_basis,
            keys=["dataset", "obs_id"],
            join_type=PLAN_JOIN_TYPE,
        )
228
        assert len(relevant_plan) > 0, relevant_plan
229
230
        return relevant_plan, data_basis

BO ZHANG's avatar
BO ZHANG committed
231
232
233
234
235
    @staticmethod
    def dispatch_file(
        plan_basis: table.Table,
        data_basis: table.Table,
    ) -> list[dict]:
BO ZHANG's avatar
BO ZHANG committed
236
237
        # unique obsid --> useless
        # u_obsid = table.unique(data_basis["dataset", "obs_id"])
BO ZHANG's avatar
BO ZHANG committed
238

BO ZHANG's avatar
BO ZHANG committed
239
240
        # initialize task list
        task_list = []
BO ZHANG's avatar
BO ZHANG committed
241

BO ZHANG's avatar
BO ZHANG committed
242
243
244
245
246
247
248
        # loop over plan
        for i_data_basis in trange(
            len(data_basis),
            unit="task",
            dynamic_ncols=True,
        ):
            # i_data_basis = 1
BO ZHANG's avatar
BO ZHANG committed
249
            this_task = dict(data_basis[i_data_basis])
BO ZHANG's avatar
BO ZHANG committed
250
251
            this_data_basis = data_basis[i_data_basis : i_data_basis + 1]
            this_relevant_plan = table.join(
BO ZHANG's avatar
BO ZHANG committed
252
                this_data_basis,
BO ZHANG's avatar
BO ZHANG committed
253
254
255
256
257
258
259
                plan_basis,
                keys=["dataset", "obs_id"],
                join_type="inner",
            )
            # append this task
            task_list.append(
                dict(
BO ZHANG's avatar
BO ZHANG committed
260
                    task=this_task,
BO ZHANG's avatar
BO ZHANG committed
261
262
263
                    success=True,
                    relevant_plan=this_relevant_plan,
                    relevant_data=data_basis[i_data_basis : i_data_basis + 1],
BO ZHANG's avatar
BO ZHANG committed
264
265
                    n_relevant_plan=len(this_relevant_plan),
                    n_relevant_data=1,
BO ZHANG's avatar
BO ZHANG committed
266
267
                )
            )
BO ZHANG's avatar
BO ZHANG committed
268

BO ZHANG's avatar
BO ZHANG committed
269
        return task_list
BO ZHANG's avatar
BO ZHANG committed
270

BO ZHANG's avatar
BO ZHANG committed
271
272
273
274
275
276
277
    @staticmethod
    def dispatch_detector(
        plan_basis: table.Table,
        data_basis: table.Table,
        n_jobs: int = 1,
    ) -> list[dict]:
        """
BO ZHANG's avatar
BO ZHANG committed
278

BO ZHANG's avatar
BO ZHANG committed
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
        Parameters
        ----------
        plan_basis
        data_basis
        n_jobs

        Returns
        -------

        """
        if n_jobs != 1:
            task_list = joblib.Parallel(n_jobs=n_jobs)(
                joblib.delayed(Dispatcher.dispatch_detector)(plan_basis, _)
                for _ in split_data_basis(data_basis, n_split=n_jobs)
            )
            return sum(task_list, [])

        # unique obsid
        u_obsid = table.unique(data_basis["dataset", "obs_id"])
        relevant_plan = table.join(
            u_obsid,
            plan_basis,
            keys=["dataset", "obs_id"],
BO ZHANG's avatar
BO ZHANG committed
302
            join_type=PLAN_JOIN_TYPE,
BO ZHANG's avatar
BO ZHANG committed
303
304
305
306
307
        )
        print(f"{len(relevant_plan)} relevant plan records")

        u_data_detector = table.unique(
            data_basis[
BO ZHANG's avatar
BO ZHANG committed
308
309
310
311
312
                "dataset",
                "instrument",
                "obs_type",
                "obs_group",
                "obs_id",
BO ZHANG's avatar
BO ZHANG committed
313
314
                "detector",
            ]
BO ZHANG's avatar
BO ZHANG committed
315
        )
BO ZHANG's avatar
BO ZHANG committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

        # initialize task list
        task_list = []

        # loop over plan
        for i_data_detector in trange(
            len(u_data_detector),
            unit="task",
            dynamic_ncols=True,
        ):
            # i_data_detector = 1
            this_task = dict(u_data_detector[i_data_detector])
            this_data_detector = u_data_detector[i_data_detector : i_data_detector + 1]

            # join data and plan
            this_data_detector_files = table.join(
                this_data_detector,
                data_basis,
                keys=[
                    "dataset",
                    "instrument",
                    "obs_type",
                    "obs_group",
                    "obs_id",
                    "detector",
                ],
                join_type="inner",
            )
            this_data_detector_plan = table.join(
                this_data_detector,
                relevant_plan,
                keys=[
                    "dataset",
                    "instrument",
                    "obs_type",
                    "obs_group",
                    "obs_id",
                ],
BO ZHANG's avatar
BO ZHANG committed
354
                join_type=PLAN_JOIN_TYPE,
BO ZHANG's avatar
BO ZHANG committed
355
356
357
358
359
360
361
362
            )

            # whether detector effective
            this_detector = this_data_detector["detector"][0]
            this_instrument = this_data_detector["instrument"][0]
            this_detector_effective = (
                this_detector in csst[this_instrument].effective_detector_names
            )
BO ZHANG's avatar
BO ZHANG committed
363
364
365
366
367
368

            n_files_expected = (
                this_data_detector_plan["n_frame"][0]
                if len(this_data_detector_plan) > 0
                else 0
            )
BO ZHANG's avatar
BO ZHANG committed
369
370
371
372
373
374
375
376
377
378
379
380
381
            n_files_found = len(this_data_detector_files)
            # append this task
            task_list.append(
                dict(
                    task=this_task,
                    success=(
                        len(this_data_detector_plan) == 1
                        and len(this_data_detector_files) == 1
                        and this_detector_effective
                        and n_files_found == n_files_expected
                    ),
                    relevant_plan=this_data_detector_plan,
                    relevant_data=this_data_detector_files,
BO ZHANG's avatar
BO ZHANG committed
382
383
                    n_relevant_plan=len(this_data_detector_plan),
                    n_relevant_data=len(this_data_detector_files),
BO ZHANG's avatar
BO ZHANG committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
                )
            )
        return task_list

    @staticmethod
    def dispatch_obsid(
        plan_basis: table.Table,
        data_basis: table.Table,
        n_jobs: int = 1,
    ) -> list[dict]:

        if n_jobs != 1:
            task_list = joblib.Parallel(n_jobs=n_jobs)(
                joblib.delayed(Dispatcher.dispatch_obsid)(plan_basis, _)
                for _ in split_data_basis(data_basis, n_split=n_jobs)
            )
            return sum(task_list, [])

        # unique obsid
        u_obsid = table.unique(data_basis["dataset", "obs_id"])
        relevant_plan = table.join(
            u_obsid,
            plan_basis,
            keys=["dataset", "obs_id"],
BO ZHANG's avatar
BO ZHANG committed
408
            join_type=PLAN_JOIN_TYPE,
BO ZHANG's avatar
BO ZHANG committed
409
410
411
412
413
        )
        print(f"{len(relevant_plan)} relevant plan records")

        u_data_obsid = table.unique(
            data_basis[
BO ZHANG's avatar
BO ZHANG committed
414
415
416
417
418
                "dataset",
                "instrument",
                "obs_type",
                "obs_group",
                "obs_id",
BO ZHANG's avatar
BO ZHANG committed
419
            ]
BO ZHANG's avatar
BO ZHANG committed
420
421
        )

BO ZHANG's avatar
BO ZHANG committed
422
423
424
425
426
427
428
429
430
        # initialize task list
        task_list = []

        # loop over plan
        for i_data_obsid in trange(
            len(u_data_obsid),
            unit="task",
            dynamic_ncols=True,
        ):
BO ZHANG's avatar
BO ZHANG committed
431
            # i_data_obsid = 2
BO ZHANG's avatar
BO ZHANG committed
432
433
434
435
            this_task = dict(u_data_obsid[i_data_obsid])
            this_data_obsid = u_data_obsid[i_data_obsid : i_data_obsid + 1]

            # join data and plan
BO ZHANG's avatar
BO ZHANG committed
436
            this_data_obsid_file = table.join(
BO ZHANG's avatar
BO ZHANG committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
                this_data_obsid,
                data_basis,
                keys=[
                    "dataset",
                    "instrument",
                    "obs_type",
                    "obs_group",
                    "obs_id",
                ],
                join_type="inner",
            )
            this_data_obsid_plan = table.join(
                this_data_obsid,
                relevant_plan,
                keys=[
                    "dataset",
                    "instrument",
                    "obs_type",
                    "obs_group",
                    "obs_id",
                ],
BO ZHANG's avatar
BO ZHANG committed
458
                join_type=PLAN_JOIN_TYPE,
BO ZHANG's avatar
BO ZHANG committed
459
460
461
462
            )

            # whether effective detectors all there
            this_instrument = this_data_obsid["instrument"][0]
BO ZHANG's avatar
BO ZHANG committed
463
464
            this_n_frame = (
                this_data_obsid_plan["n_frame"] if len(this_data_obsid_plan) > 0 else 0
BO ZHANG's avatar
BO ZHANG committed
465
            )
BO ZHANG's avatar
BO ZHANG committed
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
            this_effective_detector_names = csst[
                this_instrument
            ].effective_detector_names

            if this_instrument == "HSTDM":
                # 不确定以后是1个探测器还是2个探测器
                this_n_file_found = len(this_data_obsid_file)
                this_n_file_expected = (this_n_frame, this_n_frame * 2)
                this_success = this_n_file_found in this_n_file_expected
            else:
                # for other instruments, e.g., MSC
                # n_file_found = len(this_obsgroup_obsid_file)
                # n_file_expected = len(effective_detector_names)
                # this_success &= n_file_found == n_file_expected

                # or more strictly, expected files are a subset of files found
                this_success = set(this_effective_detector_names) <= set(
                    this_data_obsid_file["detector"]
                )
BO ZHANG's avatar
BO ZHANG committed
485
486
487
488
489
490
491

            # append this task
            task_list.append(
                dict(
                    task=this_task,
                    success=this_success,
                    relevant_plan=this_data_obsid_plan,
BO ZHANG's avatar
BO ZHANG committed
492
493
494
                    relevant_data=this_data_obsid_file,
                    n_relevant_plan=len(this_data_obsid_plan),
                    n_relevant_data=len(this_data_obsid_file),
BO ZHANG's avatar
BO ZHANG committed
495
496
497
498
                )
            )

        return task_list
BO ZHANG's avatar
BO ZHANG committed
499

BO ZHANG's avatar
BO ZHANG committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
    @staticmethod
    def dispatch_obsgroup(
        plan_basis: table.Table,
        data_basis: table.Table,
        # n_jobs: int = 1,
    ) -> list[dict]:

        # unique obsgroup basis
        obsgroup_basis = table.unique(
            plan_basis[
                "dataset",
                "instrument",
                "obs_type",
                "obs_group",
            ]
        )
BO ZHANG's avatar
BO ZHANG committed
516

BO ZHANG's avatar
BO ZHANG committed
517
        # initialize task list
BO ZHANG's avatar
BO ZHANG committed
518
519
        task_list = []

BO ZHANG's avatar
BO ZHANG committed
520
521
522
523
524
525
526
527
528
529
530
        # loop over obsgroup
        for i_obsgroup in trange(
            len(obsgroup_basis),
            unit="task",
            dynamic_ncols=True,
        ):

            # i_obsgroup = 1
            this_task = dict(obsgroup_basis[i_obsgroup])
            this_success = True

BO ZHANG's avatar
BO ZHANG committed
531
            this_obsgroup_plan = table.join(
BO ZHANG's avatar
BO ZHANG committed
532
533
534
                obsgroup_basis[i_obsgroup : i_obsgroup + 1],  # this obsgroup
                plan_basis,
                keys=["dataset", "instrument", "obs_type", "obs_group"],
BO ZHANG's avatar
BO ZHANG committed
535
                join_type=PLAN_JOIN_TYPE,
BO ZHANG's avatar
BO ZHANG committed
536
537
            )
            this_obsgroup_file = table.join(
BO ZHANG's avatar
BO ZHANG committed
538
                this_obsgroup_plan,
BO ZHANG's avatar
BO ZHANG committed
539
540
541
542
543
544
545
                data_basis,
                keys=["dataset", "instrument", "obs_type", "obs_group", "obs_id"],
                join_type="inner",
                table_names=["plan", "data"],
            )

            # loop over obsid
BO ZHANG's avatar
BO ZHANG committed
546
            for i_obsid in range(len(this_obsgroup_plan)):
BO ZHANG's avatar
BO ZHANG committed
547
548
                # i_obsid = 1
                # print(i_obsid)
BO ZHANG's avatar
BO ZHANG committed
549
550
551
552
553
                this_instrument = this_obsgroup_plan[i_obsid]["instrument"]
                this_n_frame = this_obsgroup_plan[i_obsid]["n_frame"]
                this_effective_detector_names = csst[
                    this_instrument
                ].effective_detector_names
BO ZHANG's avatar
BO ZHANG committed
554
555

                this_obsgroup_obsid_file = table.join(
BO ZHANG's avatar
BO ZHANG committed
556
                    this_obsgroup_plan[i_obsid : i_obsid + 1],  # this obsid
BO ZHANG's avatar
BO ZHANG committed
557
558
559
560
                    data_basis,
                    keys=["dataset", "instrument", "obs_type", "obs_group", "obs_id"],
                    join_type="inner",
                    table_names=["plan", "data"],
BO ZHANG's avatar
BO ZHANG committed
561
                )
BO ZHANG's avatar
BO ZHANG committed
562

BO ZHANG's avatar
BO ZHANG committed
563
564
565
566
567
                if this_instrument == "HSTDM":
                    # 不确定以后是1个探测器还是2个探测器
                    this_n_file_found = len(this_obsgroup_obsid_file)
                    this_n_file_expected = (this_n_frame, this_n_frame * 2)
                    this_success &= this_n_file_found in this_n_file_expected
BO ZHANG's avatar
BO ZHANG committed
568
                else:
BO ZHANG's avatar
BO ZHANG committed
569
570
571
572
573
574
575
576
                    # for other instruments, e.g., MSC
                    # n_file_found = len(this_obsgroup_obsid_file)
                    # n_file_expected = len(effective_detector_names)
                    # this_success &= n_file_found == n_file_expected

                    # or more strictly, expected files are a subset of files found
                    this_success &= set(this_effective_detector_names) <= set(
                        this_obsgroup_obsid_file["detector"]
BO ZHANG's avatar
BO ZHANG committed
577
578
                    )

BO ZHANG's avatar
BO ZHANG committed
579
580
581
582
583
            # append this task
            task_list.append(
                dict(
                    task=this_task,
                    success=this_success,
BO ZHANG's avatar
BO ZHANG committed
584
                    relevant_plan=this_obsgroup_plan,
BO ZHANG's avatar
BO ZHANG committed
585
                    relevant_data=this_obsgroup_file,
BO ZHANG's avatar
BO ZHANG committed
586
587
                    n_relevant_plan=len(this_obsgroup_plan),
                    n_relevant_data=this_obsgroup_file,
BO ZHANG's avatar
BO ZHANG committed
588
589
590
                )
            )
        return task_list
BO ZHANG's avatar
BO ZHANG committed
591
592

    @staticmethod
BO ZHANG's avatar
BO ZHANG committed
593
594
595
596
597
598
599
600
601
602
603
    def load_test_data() -> tuple:
        import joblib

        plan_recs = joblib.load("dagtest/csst-msc-c9-25sqdeg-v3.plan.dump")
        data_recs = joblib.load("dagtest/csst-msc-c9-25sqdeg-v3.level0.dump")
        print(f"{len(plan_recs.data)} plan records")
        print(f"{len(data_recs.data)} data records")
        for _ in plan_recs.data:
            _["n_frame"] = (
                _["params"]["n_epec_frame"] if _["instrument"] == "HSTDM" else 1
            )
BO ZHANG's avatar
BO ZHANG committed
604
        # 未来如果HSTDM的设定简化一些,这里n_frame可以改成n_file,更直观
BO ZHANG's avatar
BO ZHANG committed
605
606
607
608
609
610
611
612
613
        plan_basis = extract_basis_table(
            plan_recs.data,
            PLAN_BASIS_KEYS,
        )
        data_basis = extract_basis_table(
            data_recs.data,
            DATA_BASIS_KEYS,
        )
        return plan_basis, data_basis