Commit 4a87091c authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

to conform pep8

parent 48a6a75a
"""
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 import os
__version__ = "0.0.1" __version__ = "0.0.1"
......
"""
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 os
import glob import glob
import re import re
...@@ -7,6 +17,98 @@ from astropy.io import fits ...@@ -7,6 +17,98 @@ from astropy.io import fits
from .params import CSST_PARAMS as CP 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: class CsstMbiDataManager:
""" this class defines the file format of the input & output of CSST MSC L1 pipeline """ this class defines the file format of the input & output of CSST MSC L1 pipeline
...@@ -92,8 +194,8 @@ class CsstMbiDataManager: ...@@ -92,8 +194,8 @@ class CsstMbiDataManager:
# get info # get info
# print(re.split(r"[_.]", fps[0])) # print(re.split(r"[_.]", fps[0]))
self._instrument, self._survey, \ self._instrument, self._survey, \
self._exp_start, self._exp_id, \ self._exp_start, self._exp_id, \
_detector, self._l0_suffix, _ext = re.split(r"[_.]", fps_img[0]) _detector, self._l0_suffix, _ext = re.split(r"[_.]", fps_img[0])
self._cat_id = re.split(r"[_.]", fps_cat[0])[1] self._cat_id = re.split(r"[_.]", fps_cat[0])[1]
self._exp_start = int(self._exp_start) self._exp_start = int(self._exp_start)
...@@ -107,8 +209,8 @@ class CsstMbiDataManager: ...@@ -107,8 +209,8 @@ class CsstMbiDataManager:
# get info # get info
# print(re.split(r"[_.]", fps[0])) # print(re.split(r"[_.]", fps[0]))
self._telescope, self._instrument, self._survey, self._imagetype, \ self._telescope, self._instrument, self._survey, self._imagetype, \
self._exp_start, self._exp_stop, self._exp_id, \ self._exp_start, self._exp_stop, self._exp_id, \
_detector, self._l0_suffix, self._version, _ext = re.split(r"[_.]", fps_img[0]) _detector, self._l0_suffix, self._version, _ext = re.split(r"[_.]", fps_img[0])
self._cat_id = re.split(r"[_.]", fps_cat[0])[1] self._cat_id = re.split(r"[_.]", fps_cat[0])[1]
self._exp_start = int(self._exp_start) self._exp_start = int(self._exp_start)
......
"""
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 import yaml
from . import PACKAGE_PATH from . import PACKAGE_PATH
...@@ -5,6 +15,7 @@ with open(PACKAGE_PATH + "/data/csst_params.yml") as f: ...@@ -5,6 +15,7 @@ with open(PACKAGE_PATH + "/data/csst_params.yml") as f:
CSST_PARAMS = yaml.safe_load(f) CSST_PARAMS = yaml.safe_load(f)
# DEPRECATED BELOW
class BasicParams: class BasicParams:
""" the basic parameter class """ """ the basic parameter class """
......
"""
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 import unittest
from csst_common.data_manager import CsstMbiDataManager from csst_common.data_manager import CsstMbiDataManager
class TestParams(unittest.TestCase): class TestParams(unittest.TestCase):
def test_params(self): def test_params(self):
self.assertTrue(True) self.assertTrue(True)
def __init__(self):
self.dm = CsstMbiDataManager()
\ No newline at end of file
"""
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 import unittest
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment