Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
4a87091c
Commit
4a87091c
authored
Sep 21, 2022
by
BO ZHANG
🏀
Browse files
to conform pep8
parent
48a6a75a
Changes
5
Show whitespace changes
Inline
Side-by-side
csst_common/__init__.py
View file @
4a87091c
"""
Identifier: KSC-SJ4-csst_common/__init__.py
Name: __init__.py
Description: csst_common package
Author: Bo Zhang
Created: 2022-09-13
Modified-History:
2022-09-13, Bo Zhang, created
2022-09-13, Bo Zhang, fixed a bug
"""
import
os
__version__
=
"0.0.1"
...
...
csst_common/data_manager.py
View file @
4a87091c
"""
Identifier: KSC-SJ4-csst_common/data_manager.py
Name: data_manager.py
Description: file path generator
Author: Bo Zhang
Created: 2022-09-13
Modified-History:
2022-09-13, Bo Zhang, created
2022-09-13, Bo Zhang, fixed a bug
"""
import
os
import
glob
import
re
...
...
@@ -7,6 +17,98 @@ from astropy.io import fits
from
.params
import
CSST_PARAMS
as
CP
class
CsstSlsDataManager
:
def
__init__
(
self
,
ver_sim
=
"C5.2"
,
dir_l0
=
""
,
dir_l1
=
""
,
dir_pcref
=
""
,
path_aux
=
""
,
force_all_detectors
=
False
):
""" initialize the multi-band imaging data manager
Parameters
----------
ver_sim: str
version of simulation data, see csst_common.params.CP
dir_l0: str
L0 directory
dir_l1: str
L1 directory
dir_pcref: str
position calibration data directory
path_aux: str
aux data directory (bias, flat, dark)
force_all_detectors: bool
if True, assert data for all detectors are available
Examples
--------
>>> dm = CsstSlsDataManager(...)
>>> # access L0 directory
>>> dm.dir_l0
>>> # access L1 directory
>>> dm.dir_l1
>>> # access dir_pcref
>>> dm.dir_pcref
>>> # access path_aux
>>> dm.path_aux
>>> # access ver_sim
>>> dm.ver_sim
>>> # access target detectors
>>> dm.target_detectors
>>> # access available detectors
>>> dm.available_detectors
>>> # define an L1 file (detector-specified)
>>> dm.l1_detector(detector=6)
>>> # define an L1 file (non-detector-specified)
>>> dm.l1_file("flipped_image.fits")
"""
assert
ver_sim
in
CP
[
"sim"
][
"versions"
]
self
.
dir_l0
=
dir_l0
self
.
dir_l1
=
dir_l1
self
.
dir_pcref
=
dir_pcref
self
.
path_aux
=
path_aux
self
.
ver_sim
=
ver_sim
self
.
target_detectors
=
[]
self
.
hardcode_history
=
[]
fps_img
=
self
.
glob_image
(
dir_l0
,
ver_sim
=
ver_sim
)
fps_cat
=
self
.
glob_cat
(
dir_l0
,
ver_sim
=
ver_sim
)
if
force_all_detectors
:
assert
len
(
fps_img
)
==
len
(
CP
[
"mbi"
][
"detectors"
])
else
:
assert
len
(
fps_img
)
>
0
if
ver_sim
==
"C3"
:
# get info
# print(re.split(r"[_.]", fps[0]))
self
.
_instrument
,
self
.
_survey
,
\
self
.
_exp_start
,
self
.
_exp_id
,
\
_detector
,
self
.
_l0_suffix
,
_ext
=
re
.
split
(
r
"[_.]"
,
fps_img
[
0
])
self
.
_cat_id
=
re
.
split
(
r
"[_.]"
,
fps_cat
[
0
])[
1
]
self
.
_exp_start
=
int
(
self
.
_exp_start
)
self
.
_exp_id
=
int
(
self
.
_exp_id
)
# available detectors
self
.
available_detectors
=
[
int
(
re
.
split
(
r
"[_.]"
,
fp
)[
4
])
for
fp
in
fps_img
]
self
.
available_detectors
.
sort
()
elif
ver_sim
in
[
"C5.1"
,
"C5.2"
]:
# get info
# print(re.split(r"[_.]", fps[0]))
self
.
_telescope
,
self
.
_instrument
,
self
.
_survey
,
self
.
_imagetype
,
\
self
.
_exp_start
,
self
.
_exp_stop
,
self
.
_exp_id
,
\
_detector
,
self
.
_l0_suffix
,
self
.
_version
,
_ext
=
re
.
split
(
r
"[_.]"
,
fps_img
[
0
])
self
.
_cat_id
=
re
.
split
(
r
"[_.]"
,
fps_cat
[
0
])[
1
]
self
.
_exp_start
=
int
(
self
.
_exp_start
)
self
.
_exp_stop
=
int
(
self
.
_exp_stop
)
self
.
_exp_id
=
int
(
self
.
_exp_id
)
# available detectors
self
.
available_detectors
=
[
int
(
re
.
split
(
r
"[_.]"
,
fp
)[
7
])
for
fp
in
fps_img
]
self
.
available_detectors
.
sort
()
class
CsstMbiDataManager
:
""" this class defines the file format of the input & output of CSST MSC L1 pipeline
...
...
csst_common/params.py
View file @
4a87091c
"""
Identifier: KSC-SJ4-csst_common/params.py
Name: params.py
Description: CSST parameters
Author: Bo Zhang
Created: 2022-09-13
Modified-History:
2022-09-13, Bo Zhang, created
2022-09-13, Bo Zhang, fixed a bug
"""
import
yaml
from
.
import
PACKAGE_PATH
...
...
@@ -5,6 +15,7 @@ with open(PACKAGE_PATH + "/data/csst_params.yml") as f:
CSST_PARAMS
=
yaml
.
safe_load
(
f
)
# DEPRECATED BELOW
class
BasicParams
:
""" the basic parameter class """
...
...
tests/test_data_manager.py
View file @
4a87091c
"""
Identifier: KSC-SJ4-tests/test_data_manager.py
Name: test_data_manager.py
Description: data manager unit test
Author: Bo Zhang
Created: 2022-09-13
Modified-History:
2022-09-13, Bo Zhang, created
2022-09-13, Bo Zhang, fixed a bug
"""
import
unittest
from
csst_common.data_manager
import
CsstMbiDataManager
class
TestParams
(
unittest
.
TestCase
):
def
test_params
(
self
):
self
.
assertTrue
(
True
)
def
__init__
(
self
):
self
.
dm
=
CsstMbiDataManager
()
\ No newline at end of file
tests/test_params.py
View file @
4a87091c
"""
Identifier: KSC-SJ4-tests/test_params.py
Name: test_params.py
Description: unit test for CSST parameters
Author: Bo Zhang
Created: 2022-09-13
Modified-History:
2022-09-13, Bo Zhang, created
2022-09-13, Bo Zhang, fixed a bug
"""
import
unittest
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment