csst_common.rst 6.83 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
4
5
Using ``csst_common``
=====================

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

BO ZHANG's avatar
tweaks    
BO ZHANG committed
6
7
``csst_common.data_manager.CsstMsDataManager``
----------------------------------------------
BO ZHANG's avatar
BO ZHANG committed
8
9
10
11
12

A class that helps developers to access simulation files.

.. code-block:: python

BO ZHANG's avatar
tweaks    
BO ZHANG committed
13
    from csst_common.data_manager import CsstMsDataManager
BO ZHANG's avatar
BO ZHANG committed
14
15
16
17
18
19
20
21
22
23
    # 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
24
25
26
27

.. code-block:: python

    # for a quick start ()
BO ZHANG's avatar
BO ZHANG committed
28
29
30
31
32
33
    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
34
35
36

.. code-block:: python

BO ZHANG's avatar
BO ZHANG committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    # 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
56
57
.. code-block:: python

BO ZHANG's avatar
BO ZHANG committed
58
59
60
61
62
63
64
    # to get bias
    dm_mbi.get_bias()
    # to get dark
    dm_mbi.get_dark()
    # to get flat
    dm_mbi.get_flat()

BO ZHANG's avatar
BO ZHANG committed
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
Access code to data products
----------------------------

``Multi-Band Imaging``
^^^^^^^^^^^^^^^^^^^^^^

========================== ===== ========================================================== ==================
Data source                Level File name / access code                                     Notes
========================== ===== ========================================================== ==================
raw                        0     ``dm.l0_detector(detector=detector)``                      sci image
raw                        0     ``dm.l0_crs(detector=detector)``                           cosmic ray image
raw                        0     ``dm.l0_cat(detector=detector)``                           input catalog
raw                        0     ``dm.l0_log(detector=detector)``                           log file
``csst_ms_mbi_instrument`` 1     ``dm.l1_detector(detector=detector, post="img.fits")``     corrected image
``csst_ms_mbi_instrument`` 1     ``dm.l1_detector(detector=detector, post="flg.fits")``     flag image
``csst_ms_mbi_instrument`` 1     ``dm.l1_detector(detector=detector, post="wht.fits")``     weight image
``csst_ms_mbi_instrument`` 1     ``dm.l1_detector(detector=detector, post="img.head")``     L0 fits header
``DFS``                    --    ``dm.l1_file(name="gaia_dfs.fits")``                       reference catalog
``csst_ms_mbi_distortion`` --    ``dm.l1_detector(detector=detector, post="wcs.head")``     fits head with WCS
========================== ===== ========================================================== ==================


``Slit-Less Spectra``
^^^^^^^^^^^^^^^^^^^^^
========================== ===== ========================================================== ==================
Data source                Level File name / access code                                     Notes
========================== ===== ========================================================== ==================
raw                        0     ``dm.l0_detector(detector=detector)``                      sci image
raw                        0     ``dm.l0_crs(detector=detector)``                           cosmic ray image
raw                        0     ``dm.l0_cat(detector=detector)``                           input catalog
raw                        0     ``dm.l0_log(detector=detector)``                           log file
``csst_ms_sls_instrument`` 1     ``dm.l1_detector(detector=detector, post="flt.fits")``     corrected image
========================== ===== ========================================================== ==================

BO ZHANG's avatar
BO ZHANG committed
99

BO ZHANG's avatar
BO ZHANG committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
``csst_common.file_recorder.FileRecorder``
------------------------------------------

Get an empty ``FileRecorder``.
This is initially a ``list``-like object.
Use ``FileRecorder.add_record()`` to add file records.

.. code-block::
    :linenos:

    >>> from csst_common.file_recorder import FileRecorder
    >>> fr = FileRecorder()
    >>> for i in range(3):
    >>>     fr.add_record(filepath="test{:03d}.txt".format(i),
    >>>                   db=True,
    >>>                   comment="Test file {:d}".format(i))
    >>> fr.pprint_all()

    <FileRecorder length=3>
      filepath   db    comment   existence
    ----------- ---- ----------- ---------
    test000.txt True Test file 0     False
    test001.txt True Test file 1     False
    test002.txt True Test file 2     False


BO ZHANG's avatar
BO ZHANG committed
126
127
128
129
130
131
132
``csst_common.logger.get_logger()``
-----------------------------------

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


.. code-block:: python
BO ZHANG's avatar
BO ZHANG committed
133
    :linenos:
BO ZHANG's avatar
BO ZHANG committed
134
135
136
137

    from csst_common.logger import get_logger
    logger = get_logger()

BO ZHANG's avatar
BO ZHANG committed
138
.. warning::
BO ZHANG's avatar
BO ZHANG committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    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
BO ZHANG's avatar
BO ZHANG committed
155
    :linenos:
BO ZHANG's avatar
BO ZHANG committed
156
157
158
159
160
161
162
163
164
165
166

    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
167
168
169
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
170

BO ZHANG's avatar
BO ZHANG committed
171
172
173
Source code
^^^^^^^^^^^

BO ZHANG's avatar
BO ZHANG committed
174
.. literalinclude:: example_interface.py
BO ZHANG's avatar
BO ZHANG committed
175
    :caption: ``example_interface.py``
BO ZHANG's avatar
BO ZHANG committed
176
    :emphasize-lines: 7-10,36-40,84,86-87,90-91,94-95,99,102,148,152-153,156-157,160-161,164-165
BO ZHANG's avatar
BO ZHANG committed
177
178
    :linenos:
    :language: python
BO ZHANG's avatar
BO ZHANG committed
179
180
181
182
183
184
185


Rendered ``docstring``
^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: example_interface
    :members:
BO ZHANG's avatar
tweaks    
BO ZHANG committed
186
187
188
189
190
191
192
193
194
195


``csst_common.params``
----------------------

to be updated

Module Identifier
-----------------

BO ZHANG's avatar
BO ZHANG committed
196
to be updated