Loading csst_common/__init__.py +10 −0 Original line number Diff line number Diff line """ 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" Loading csst_common/data_manager.py +106 −4 Original line number Diff line number Diff line """ 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 Loading @@ -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 Loading csst_common/params.py +11 −0 Original line number Diff line number Diff line """ 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 Loading @@ -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 """ Loading tests/test_data_manager.py +11 −3 Original line number Diff line number Diff line """ 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 +10 −0 Original line number Diff line number Diff line """ 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 Loading Loading
csst_common/__init__.py +10 −0 Original line number Diff line number Diff line """ 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" Loading
csst_common/data_manager.py +106 −4 Original line number Diff line number Diff line """ 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 Loading @@ -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 Loading
csst_common/params.py +11 −0 Original line number Diff line number Diff line """ 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 Loading @@ -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 """ Loading
tests/test_data_manager.py +11 −3 Original line number Diff line number Diff line """ 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 +10 −0 Original line number Diff line number Diff line """ 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 Loading