csst_common.rst 3.01 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Using ``csst_common``
=====================

Some usages of the functions / classes in ``csst_common``. (To be updated)

``CsstMsDataManager``
---------------------

A class that helps developers to access simulation files.

.. code-block:: python

    # for full basic initialization
    dm_mbi = CsstMsDataManager(
        ver_sim="C5.2",                 # version of simulation, "C5.2" is the latest
        dir_l0="",                      # the L0/input directory
        dir_l1="",                      # the L1/output directory
        dir_pcref="",                   # position calibration reference (will be deprecated)
        path_aux="",                    # aux file paths (master bias, dark, flat)
        assert_all_detectors=False,     # if True, assert all detectors are available
        datatype="mbi",                 # "mbi" or "sls"
    )
BO ZHANG's avatar
tweaks    
BO ZHANG committed
23
24
25
26

.. code-block:: python

    # for a quick start ()
BO ZHANG's avatar
BO ZHANG committed
27
28
29
30
31
32
    dm_mbi = CsstMsDataManager.quickstart(
        ver_sim="C5.2",
        datatype="mbi",
        dir_l1=".",
        exposure_id=100                 # the 100th exposure
    )
BO ZHANG's avatar
tweaks    
BO ZHANG committed
33
34
35

.. code-block:: python

BO ZHANG's avatar
BO ZHANG committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    # access L0 directory
    dm_mbi.dir_l0
    # access L1 directory
    dm_mbi.dir_l1
    # access dir_pcref
    dm_mbi.dir_pcref
    # access path_aux
    dm_mbi.path_aux
    # access ver_sim
    dm_mbi.ver_sim
    # access target detectors
    dm_mbi.target_detectors
    # access available detectors
    dm_mbi.available_detectors
    # define an L1 file (detector-specified)
    dm_mbi.l1_detector(detector=6)
    # define an L1 file (non-detector-specified)
    dm_mbi.l1_file("flipped_image.fits")

BO ZHANG's avatar
tweaks    
BO ZHANG committed
55
56
.. code-block:: python

BO ZHANG's avatar
BO ZHANG committed
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
    # to get bias
    dm_mbi.get_bias()
    # to get dark
    dm_mbi.get_dark()
    # to get flat
    dm_mbi.get_flat()


``csst_common.logger.get_logger()``
-----------------------------------

Get the default configured ``logging.Logger``.


.. code-block:: python

    from csst_common.logger import get_logger
    logger = get_logger()

.. note::
    Developers should NOT use ``print`` function extensively in code.
    Generally ``print`` can be replaced with ``logger.debug("msg")``.
    For important information, use ``logger.info("msg")``.
    For warnings, use ``logger.warning("msg")``.
    For errors, use ``logger.error("msg")``.
    Conf https://docs.python.org/3/library/logging.html for more information
    about the usage of ``logging.Logger``.


``csst_common.status.CsstStatus``
---------------------------------

Developers should use ``csst_common.status.CsstStatus`` to return the
status of their interfaces.

.. code-block:: python

    from csst_common.status import CsstStatus
    # presently 3 kinds of status are available, they are
    CsstStatus.PERFECT
    CsstStatus.WARNING
    CsstStatus.ERROR


An example interface
--------------------

BO ZHANG's avatar
tweaks    
BO ZHANG committed
104
105
106
We recommend our developers to use the code structure used in the example interfaces,
e.g., ``process_single_image`` and ``process_multiple_images``.
The example code is shown below.
BO ZHANG's avatar
BO ZHANG committed
107
108
109
110

.. literalinclude:: ./example_interface.py
    :linenos:
    :language: python