From bdf319453459ca9d6f7b01842363b42b4eb1ccf5 Mon Sep 17 00:00:00 2001 From: BO ZHANG Date: Wed, 31 Aug 2022 10:51:42 +0800 Subject: [PATCH] use yaml file for parameters --- README.md | 12 +++- csst_common/data/csst_params.yml | 103 +++++++++++++++++++++++++++++++ csst_common/params.py | 13 +++- requirements.txt | 4 +- setup.py | 2 +- 5 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 csst_common/data/csst_params.yml diff --git a/README.md b/README.md index fa7adff..3c171a0 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ sh -c "$(curl -fsSL https://csst-tb.bao.ac.cn/code/csst-l1/csst_common/-/raw/mai how to import CSST parameters: ```python -from csst_common.params import cp -print(cp) -print(cp.mbi.DETECTOR2FILTER) +from csst_common.params import CSST_PARAMS as CP +print(CP) +print(CP["mbi"]["detector2filter"]) ``` how to use data_manager @@ -69,6 +69,12 @@ dm.l1_detector(detector=6) dm.l1_file("flipped_image.fits") ``` +a shortcut for test dataset +```python +from csst_common.data_manager import CsstMbiDataManager +CsstMbiDataManager.quick_dataset(hostname="dandelion", ver_sim="C5.2", dir_l1=".", exposure_id=100) +``` + ## algorithm description The `csst_common` provides some common modules for CSST pipeline. diff --git a/csst_common/data/csst_params.yml b/csst_common/data/csst_params.yml new file mode 100644 index 0000000..8100a6d --- /dev/null +++ b/csst_common/data/csst_params.yml @@ -0,0 +1,103 @@ +mbi: # multi-band imaging + detectors: + - 6 + - 7 + - 8 + - 9 + - 11 + - 12 + - 13 + - 14 + - 15 + - 16 + - 17 + - 18 + - 19 + - 20 + - 22 + - 23 + - 24 + - 25 + filters: + - 'N' + - 'u' + - 'g' + - 'r' + - 'i' + - 'z' + - 'y' + detector2filter: # used for simulation image path + 6: "y" + 7: "i" + 8: "g" + 9: "r" + 11: "z" + 12: "nuv" + 13: "nuv" + 14: "u" + 15: "y" + 16: "y" + 17: "u" + 18: "nuv" + 19: "nuv" + 20: "z" + 22: "r" + 23: "g" + 24: "i" + 25: "y" + + +sls: # slit-less spectra + detectors: + - 1 + - 2 + - 3 + - 4 + - 5 + - 10 + - 21 + - 26 + - 27 + - 28 + - 29 + - 30 + +sim: # simulation + versions: + - C5.2 + - C5.1 + - C3 + +basic: + detectors: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + - 7 + - 8 + - 9 + - 10 + - 11 + - 12 + - 13 + - 14 + - 15 + - 16 + - 17 + - 18 + - 19 + - 20 + - 21 + - 22 + - 23 + - 24 + - 25 + - 26 + - 27 + - 28 + - 29 + - 30 + diff --git a/csst_common/params.py b/csst_common/params.py index 66d1583..ca34e63 100644 --- a/csst_common/params.py +++ b/csst_common/params.py @@ -1,6 +1,13 @@ +import yaml +from . import PACKAGE_PATH + +with open(PACKAGE_PATH + "/data/csst_params.yml") as f: + CSST_PARAMS = yaml.safe_load(f) + class BasicParams: """ the basic parameter class """ + def __repr__(self): _class_name = self.__class__.__name__ _str = "<{} length={}>".format(_class_name, len(self.__dict__)) @@ -20,6 +27,7 @@ class BasicParams: class CsstParams(BasicParams): """ CSST parameters -- a collection of """ + def __init__(self): """ This class defines the CSST parameters. @@ -50,8 +58,8 @@ class CsstParams(BasicParams): class CsstMbiParams(BasicParams): """ multi-band imaging parameters """ - def __init__(self): + def __init__(self): # define DETECTOR ID list self.DETECTORS = [6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25] @@ -87,13 +95,14 @@ class CsstSlsParams(BasicParams): class CsstSimParams(BasicParams): """ simulation parameters """ + def __init__(self): # define versions of simulation # C denotes for Cycle self.VERSIONS = ["C3", "C5.1", "C5.2"] -cp = CsstParams() +# cp = CsstParams() if __name__ == "__main__": cp = CsstParams() diff --git a/requirements.txt b/requirements.txt index 3b80d37..361a492 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,6 @@ numpy~=1.20.3 joblib~=1.1.0 setuptools~=58.0.4 astropy~=5.1 -pytest \ No newline at end of file +pytest +yaml~=0.2.5 +pyyaml~=6.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 41bb3e8..6b9a2e9 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setuptools.setup( package_dir={'csst': 'csst'}, # include_package_data=True, package_data={"": ["LICENSE", "README.md"], - "csst_common": []}, + "csst_common": ["data/*"]}, # install_requires=['sphinx', # 'numpy', # 'scipy', 'matplotlib', -- GitLab