README.md 11.6 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
## csst_proto 
BO ZHANG's avatar
BO ZHANG committed
2
[![Documentation Status](https://readthedocs.org/projects/csst-proto/badge/?version=latest)](https://csst-proto.readthedocs.io/en/latest/?badge=latest)
BO ZHANG's avatar
BO ZHANG committed
3
 
BO ZHANG's avatar
BO ZHANG committed
4
CSST L1 pipeline prototype.
BO ZHANG's avatar
BO ZHANG committed
5

BO ZHANG's avatar
BO ZHANG committed
6
## homepage
BO ZHANG's avatar
BO ZHANG committed
7

BO ZHANG's avatar
BO ZHANG committed
8
This code is available at *CSST GitLab*:
BO ZHANG's avatar
BO ZHANG committed
9
- [https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto](https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto).
BO ZHANG's avatar
BO ZHANG committed
10

BO ZHANG's avatar
BO ZHANG committed
11
## documentation
BO ZHANG's avatar
BO ZHANG committed
12

BO ZHANG's avatar
BO ZHANG committed
13
14
A sphinx-based documentation is available at
- [https://csst-proto.readthedocs.io/en/latest/](https://csst-proto.readthedocs.io/en/latest/)
BO ZHANG's avatar
BO ZHANG committed
15

BO ZHANG's avatar
BO ZHANG committed
16
17
18
19
20
21
## dependency

- numpy~=1.20.3
- joblib~=1.1.0
- astropy~=5.1

BO ZHANG's avatar
BO ZHANG committed
22
## installation
BO ZHANG's avatar
BO ZHANG committed
23

BO ZHANG's avatar
BO ZHANG committed
24
25
26
27
`csst_proto` can be installed with the following shell command

```bash
git clone https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto.git
BO ZHANG's avatar
BO ZHANG committed
28
cd csst_proto
BO ZHANG's avatar
BO ZHANG committed
29
30
31
32
33
34
35
36
pip install -r requirements.txt
python setup.py install
```

or a single-line command

```bash
sh -c "$(curl -fsSL https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto/-/raw/main/install.sh)"
BO ZHANG's avatar
BO ZHANG committed
37
38
```

BO ZHANG's avatar
BO ZHANG committed
39
40
41
42
43
## instruction

A simple example on how to use this package:

```python
BO ZHANG's avatar
BO ZHANG committed
44
from csst_proto.top_level_interface import flip_image
BO ZHANG's avatar
BO ZHANG committed
45
46
47
from astropy.io import fits

# read an L0 image
BO ZHANG's avatar
BO ZHANG committed
48
img = fits.getdata("CSST_MS_SCI_06_L0_img.fits")
BO ZHANG's avatar
BO ZHANG committed
49
50
51
52
# flip the image
img_flipped = flip_image(img=img)
```

BO ZHANG's avatar
BO ZHANG committed
53
## algorithm description
BO ZHANG's avatar
BO ZHANG committed
54
55

The `csst_proto` uses an awesome algorithm based on `numpy.ndarray` indices to flip images.
BO ZHANG's avatar
BO ZHANG committed
56

BO ZHANG's avatar
BO ZHANG committed
57
---
BO ZHANG's avatar
BO ZHANG committed
58

BO ZHANG's avatar
BO ZHANG committed
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
## `git`: connecting collaborators

A very brief example of using `git`:

```bash
# global setting for git (name and email address)
git config --global user.name "BO ZHANG"
git config --global user.email "bozhang@nao.cas.cn"

# initialize a repository with main branch
git init --initial-branch=main
# clone a remote repository
git clone https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto.git
# add some_module.py to version control system
git add ./some_module.py       
# commit the changes  
git commit -m "added some_module" 
# add remote repository link
git remote add origin https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto.git
# push changes to remote repository
git push origin main
# pull remote updates
git pull origin main
```

BO ZHANG's avatar
BO ZHANG committed
84
85
## timeline

BO ZHANG's avatar
BO ZHANG committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
| file / directory   | description                     | urgent | C6  | C7  |
|--------------------|---------------------------------|--------|-----|-----|
| `csst_proto/`      | source code & data              | √√     | √   |     |
| `doc/`             | sphinx-based documentation      |        |     | √   |
| `example/`         | code examples                   | -      | -   | -   |
| `tests/`           | unit tests                      |        |     | √   |
| `.gitignore`       | git file                        |        | √   |     |
| `.gitlab-ci.yml`   | gitlab CI/CD pipeline           |        |     | √   |
| `LICENSE`          | code license                    |        | √   |     |
| `README.md`        | readme file                     | √√     | √   |     |
| `install.sh`       | single-line installation script |        | √   |     |
| `install_local.sh` | local installation script       |        | √   |     |
| `readthedocs.yml`  | readthedocs.io configuration    |        |     | √   |
| `requirements.txt` | code requirements               | √      | √   |     |
| `setup.py`         | sphinx-based documentation      | √√     | √   |     |
BO ZHANG's avatar
BO ZHANG committed
101

BO ZHANG's avatar
BO ZHANG committed
102
## important stages
BO ZHANG's avatar
BO ZHANG committed
103
104
105
106
107
108
109
110
- stage 1:
  - finished main code
  - good code style
  - `top_level_interface` available
- stage 2:
  - finished `setup.py`
  - can be installed with `pip install <package_name/package_link>` from gitlab
- stage 3:
BO ZHANG's avatar
BO ZHANG committed
111
  - **complete docstrings** for functions & classes
BO ZHANG's avatar
BO ZHANG committed
112
113
114
115
116
117
118
119
120
  - finished instruction
  - `README.md`
- stage 4:
  - finished unittest
  - local unit test passed with `pytest`
- stage 5:
  - gitlab CI/CD pipeline available
  - auto unit tests passed with `.gitlab-ci.yml`
- stage 6:
BO ZHANG's avatar
BO ZHANG committed
121
  - sphinx-based documentation available
BO ZHANG's avatar
BO ZHANG committed
122
123
124
125
126
  - `doc/`
  - `readthedocs.yml`

## progress

BO ZHANG's avatar
BO ZHANG committed
127
128
129
| module name                 | stage 1<br>(source code) | stage 2<br>(packaging) | stage 3<br>(instruction) | stage 4<br>(unit tests) | stage 5<br>(gitlab pipeline) | stage 6<br>(sphinx doc) |
|-----------------------------|--------------------------|------------------------|--------------------------|-------------------------|------------------------------|-------------------------|
| `csst_proto`                | √                        | √                      | √                        | √                       | √                            | √                       |
BO ZHANG's avatar
tweaks    
BO ZHANG committed
130
131
| `csst_common`               | √                        | √                      | √                        |                         |                              |                         |
| `csst_l1`                   | √                        | √                      | √                        |                         |                              |                         |
BO ZHANG's avatar
BO ZHANG committed
132
| `csst_ms_mbi_instrument`    | √                        | √                      |                          |                         |                              |                         |
BO ZHANG's avatar
tweaks    
BO ZHANG committed
133
| `csst_ms_mbi_distortion`    | √                        | √                      |                          |                         |                              |                         |
BO ZHANG's avatar
BO ZHANG committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
| `csst_ms_mbi_position`      | √                        | √                      |                          |                         |                              |                         |
| `csst_ms_mbi_flux`          | √                        | √                      |                          |                         |                              |                         |
| `csst_ms_mbi_photometry`    | √                        | √                      |                          |                         |                              |                         |
| `csst_ms_sls_instrument`    | √                        |                        |                          |                         |                              |                         |
| `csst_ms_sls_mosaic`        | √                        |                        |                          |                         |                              |                         |
| `csst_ms_sls_position`      | √                        |                        |                          |                         |                              |                         |
| `csst_ms_sls_directimage`   | √ ️                      |                        |                          |                         |                              |                         |
| `csst_ms_sls_sky`           | √                        |                        |                          |                         |                              |                         |
| `csst_ms_sls_objextraction` | √                        |                        |                          |                         |                              |                         |
| `csst_ms_sls_axe`           | √                        |                        |                          |                         |                              |                         |
| `csst_ms_sls_cde`           | √                        |                        |                          |                         |                              |                         |
| `csst_ms_qc0`               | √                        |                        |                          |                         |                              |                         |
| `csst_cpic`                 | √                        |                        |                          |                         |                              |                         |
| `csst_thz_dp1`              | √                        |                        |                          |                         |                              |                         |
| `csst_mci_distortion`       | √                        |                        |                          |                         |                              |                         |
| `csst_mci_instrument`       | √                        |                        |                          |                         |                              |                         |
| `csst_mci_astrometry`       | √                        |                        |                          |                         |                              |                         |
| `csst_mci_flux`             | √                        |                        |                          |                         |                              |                         |
| `csst_mci_photometry`       | √                        |                        |                          |                         |                              |                         |
| `csst_ifs_rss`              | √                        |                        |                          |                         |                              |                         |
| `csst_ifs_cube`             | √                        |                        |                          |                         |                              |                         |
| `csst_ifs_wcs`              | √                        |                        |                          |                         |                              |                         |


BO ZHANG's avatar
BO ZHANG committed
158

BO ZHANG's avatar
BO ZHANG committed
159

BO ZHANG's avatar
BO ZHANG committed
160
## useful links
BO ZHANG's avatar
BO ZHANG committed
161
162
163
164
165
166
167
- python packaging user guide: https://packaging.python.org/en/latest/
- packaging binary extensions (C/C++): https://packaging.python.org/en/latest/guides/packaging-binary-extensions
- `setuptools`: https://packaging.python.org/en/latest/tutorials/installing-packages/
- recommended IDEs
  - PyCharm: https://www.jetbrains.com/pycharm/
  - VS Code: https://code.visualstudio.com/
- `git`: https://git-scm.com/
BO ZHANG's avatar
BO ZHANG committed
168
169
170
171
  - Pro Git: https://git-scm.com/book/en/v2
- Numpydoc: https://numpydoc.readthedocs.io/en/latest/format.html
  - for C: https://peps.python.org/pep-0007/
  - for Python: https://peps.python.org/pep-0008/
BO ZHANG's avatar
BO ZHANG committed
172
    - example.py: https://numpydoc.readthedocs.io/en/latest/example.html#example
BO ZHANG's avatar
BO ZHANG committed
173
174
175
176
177
- `unittest`: https://docs.python.org/3.8/library/unittest.html
- gitlab CI/CD pipeline: https://docs.gitlab.com/ee/ci/pipelines/
- gitlab runners: https://docs.gitlab.com/runner/
- `sphinx`: https://www.sphinx-doc.org/en/master/index.html
- markdown: https://www.markdownguide.org/
BO ZHANG's avatar
BO ZHANG committed
178
- restructured text: https://docutils.sourceforge.io/rst.html
BO ZHANG's avatar
BO ZHANG committed
179
- readthedocs: https://readthedocs.io/ or https://rtfd.io/
BO ZHANG's avatar
BO ZHANG committed
180

BO ZHANG's avatar
BO ZHANG committed
181
## `data manager` for MS MBI
BO ZHANG's avatar
BO ZHANG committed
182
183
184

```python
import os
BO ZHANG's avatar
BO ZHANG committed
185
186
from csst_common.data_manager import CsstMbiDataManager
from csst_common.params import CSST_PARAMS
BO ZHANG's avatar
BO ZHANG committed
187
188

# initialize data manager
BO ZHANG's avatar
BO ZHANG committed
189
dm = CsstMbiDataManager(
BO ZHANG's avatar
BO ZHANG committed
190
191
    ver_sim="C5.1", dir_l0="/data/sim_data/MSC_0000100", dir_l1="/home/user/L1Pipeline/msc/work")
# process all CCDs
BO ZHANG's avatar
BO ZHANG committed
192
dm.set_detectors()
BO ZHANG's avatar
BO ZHANG committed
193

BO ZHANG's avatar
BO ZHANG committed
194
195
196
print("----- available detectors -----")
print(dm.available_detectors)
for detector in dm.target_detectors:
BO ZHANG's avatar
BO ZHANG committed
197
    print("----- L0 images -----")
BO ZHANG's avatar
BO ZHANG committed
198
199
    print(dm.l0_detector(detector=detector))
    print(os.path.exists(dm.l0_ccd(detector=detector)))
BO ZHANG's avatar
BO ZHANG committed
200
    print("----- L0 crs -----")
BO ZHANG's avatar
BO ZHANG committed
201
202
    print(dm.l0_crs(detector=detector))
    print(os.path.exists(dm.l0_ccd(detector=detector)))
BO ZHANG's avatar
BO ZHANG committed
203
    print("----- L0 input cat -----")
BO ZHANG's avatar
BO ZHANG committed
204
205
    print(dm.l0_cat(detector=detector))
    print(os.path.exists(dm.l0_cat(detector=detector)))
BO ZHANG's avatar
BO ZHANG committed
206
    print("----- L0 input log -----")
BO ZHANG's avatar
BO ZHANG committed
207
208
    print(dm.l0_log(detector=detector))
    print(os.path.exists(dm.l0_log(detector=detector)))
BO ZHANG's avatar
BO ZHANG committed
209
    print("----- L1 images -----")
BO ZHANG's avatar
tweaks    
BO ZHANG committed
210
211
212
213
    print(dm.l1_detector(detector, post="img.fits"))
    print("----- L1 file -----")
    print(dm.l1_file("flipped_image.fits"))
```