From c70ee73ddc83da1aaeca8bcf9ae10ff6fdc4b706 Mon Sep 17 00:00:00 2001 From: BO ZHANG Date: Sat, 27 Aug 2022 14:32:37 +0800 Subject: [PATCH] updated params module --- csst_common/__init__.py | 5 +++++ csst_common/params.py | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/csst_common/__init__.py b/csst_common/__init__.py index e69de29..03b4017 100644 --- a/csst_common/__init__.py +++ b/csst_common/__init__.py @@ -0,0 +1,5 @@ +import os + +__version__ = "0.0.1" + +PACKAGE_PATH = os.path.dirname(__file__) diff --git a/csst_common/params.py b/csst_common/params.py index 5bce9ac..86fbd9c 100644 --- a/csst_common/params.py +++ b/csst_common/params.py @@ -3,9 +3,10 @@ class BasicParams: """ the basic parameter class """ def __repr__(self): _class_name = self.__class__.__name__ - _str = "<{}>\n{}\n".format(_class_name, "-" * (len(_class_name) + 2)) + _str = "<{} length={}>".format(_class_name, len(self.__dict__)) + _str += "\n{}\n".format("-" * len(_str)) for k, v in self.__dict__.items(): - _str += "{}:{} \n".format(k, v) + _str += "{} : {} \n".format(k, v) return _str # def to_dict(self): @@ -20,13 +21,26 @@ class BasicParams: class CsstParams(BasicParams): """ CSST parameters -- a collection of """ def __init__(self): + """ + This class defines the CSST parameters. + + Example + ------- + >>> from csst_common.params import CsstParams + >>> cps = CsstParams() + + See also + -------- + CsstMbiParams, CsstSlsParams, CsstSimParams + """ self.mbi = CsstMbiParams() self.sls = CsstSlsParams() self.sim = CsstSimParams() def __repr__(self): _class_name = self.__class__.__name__ - _str = "<{}>\n{}\n".format(_class_name, "-"*(len(_class_name)+2)) + _str = "<{} length={}>".format(_class_name, len(self.__dict__)) + _str += "\n{}\n".format("-" * len(_str)) for k, v in self.__dict__.items(): _str += "{}: \n".format(k) for kk in self.__getattribute__(k).__dict__.keys(): @@ -79,6 +93,8 @@ class CsstSimParams(BasicParams): self.VER_SIMS = ["C3", "C5.1", "C5.2"] +cp = CsstParams() + if __name__ == "__main__": cp = CsstParams() print(cp) -- GitLab