Loading csst_common/data_manager.py +14 −22 Original line number Diff line number Diff line Loading @@ -1008,15 +1008,14 @@ CsstMbiDataManager = CsstMsDataManager class CsstMsFile(dict): def __init__(self, filepath, ver_sim="C6.2", dir_l0=".", dir_l1=".", dfs_root=None, **kwargs): def __init__(self, filepath, ver_sim="C6.2", dir_out=".", **kwargs): super(CsstMsFile, self).__init__() self.ver_sim = ver_sim self.dir_l0 = dir_l0 self.dir_l1 = dir_l1 self.dfs_root = dfs_root self.filepath = filepath self.filename = os.path.basename(filepath) self.dir_l0 = os.path.dirname(filepath) self.dir_in = os.path.dirname(filepath) self.dir_out = dir_out # parse filename pattern = re.compile( r"(?P<telescope>[A-Z]+)_" Loading Loading @@ -1046,17 +1045,6 @@ class CsstMsFile(dict): for k, v in kwargs.items(): self.__setattr__(k, v) @property def dir_l0(self): if self.dfs_root is not None: return os.path.join(self.dfs_root, self._dir_l0) else: return self._dir_l0 @dir_l0.setter def dir_l0(self, dir_l0): self._dir_l0 = dir_l0 def fpo(self, post=".fits"): if post.startswith("."): fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \ Loading @@ -1064,13 +1052,13 @@ class CsstMsFile(dict): else: fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \ f"{self.obs_id}_{self.detector}_L1_V{self.version}_{post}" return os.path.join(self.dir_l1, fn) return os.path.join(self.dir_out, fn) def fpi(self): return os.path.join(self.dir_l0, self.filename) return os.path.join(self.dir_in, self.filename) @staticmethod def from_l1id(id=17796, ver_sim="C6.2", dir_l0=".", dir_l1=".", dfs_root=None): def from_l1id(id=17796, ver_sim="C6.2", dir_out=".", dfs_root="/dfsroot"): L1DataApi = Level1DataApi() rec = L1DataApi.get(id=id) try: Loading @@ -1080,10 +1068,14 @@ class CsstMsFile(dict): raise ae header = rec["data"].header return CsstMsFile( filepath=rec["data"].file_path, ver_sim=ver_sim, dir_l0=dir_l0, dir_l1=dir_l1, dfs_root=dfs_root, **header) filepath=os.path.join(dfs_root, rec["data"].file_path), ver_sim=ver_sim, dir_out=dir_out, header=header ) def __repr__(self): return f"CsstMsFile({self.filename})" return f"CsstMsFile(filepath=\"{self.filename}\", ver_sim=\"C6.2\", dir_out=\".\")" # file = CsstMsFile( # "L1/MSC/SCI/62173/10160000108/CSST_MSC_MS_SCI_20290206174352_20290206174622_10160000108_21_L1_V01.fits") # Loading Loading
csst_common/data_manager.py +14 −22 Original line number Diff line number Diff line Loading @@ -1008,15 +1008,14 @@ CsstMbiDataManager = CsstMsDataManager class CsstMsFile(dict): def __init__(self, filepath, ver_sim="C6.2", dir_l0=".", dir_l1=".", dfs_root=None, **kwargs): def __init__(self, filepath, ver_sim="C6.2", dir_out=".", **kwargs): super(CsstMsFile, self).__init__() self.ver_sim = ver_sim self.dir_l0 = dir_l0 self.dir_l1 = dir_l1 self.dfs_root = dfs_root self.filepath = filepath self.filename = os.path.basename(filepath) self.dir_l0 = os.path.dirname(filepath) self.dir_in = os.path.dirname(filepath) self.dir_out = dir_out # parse filename pattern = re.compile( r"(?P<telescope>[A-Z]+)_" Loading Loading @@ -1046,17 +1045,6 @@ class CsstMsFile(dict): for k, v in kwargs.items(): self.__setattr__(k, v) @property def dir_l0(self): if self.dfs_root is not None: return os.path.join(self.dfs_root, self._dir_l0) else: return self._dir_l0 @dir_l0.setter def dir_l0(self, dir_l0): self._dir_l0 = dir_l0 def fpo(self, post=".fits"): if post.startswith("."): fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \ Loading @@ -1064,13 +1052,13 @@ class CsstMsFile(dict): else: fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \ f"{self.obs_id}_{self.detector}_L1_V{self.version}_{post}" return os.path.join(self.dir_l1, fn) return os.path.join(self.dir_out, fn) def fpi(self): return os.path.join(self.dir_l0, self.filename) return os.path.join(self.dir_in, self.filename) @staticmethod def from_l1id(id=17796, ver_sim="C6.2", dir_l0=".", dir_l1=".", dfs_root=None): def from_l1id(id=17796, ver_sim="C6.2", dir_out=".", dfs_root="/dfsroot"): L1DataApi = Level1DataApi() rec = L1DataApi.get(id=id) try: Loading @@ -1080,10 +1068,14 @@ class CsstMsFile(dict): raise ae header = rec["data"].header return CsstMsFile( filepath=rec["data"].file_path, ver_sim=ver_sim, dir_l0=dir_l0, dir_l1=dir_l1, dfs_root=dfs_root, **header) filepath=os.path.join(dfs_root, rec["data"].file_path), ver_sim=ver_sim, dir_out=dir_out, header=header ) def __repr__(self): return f"CsstMsFile({self.filename})" return f"CsstMsFile(filepath=\"{self.filename}\", ver_sim=\"C6.2\", dir_out=\".\")" # file = CsstMsFile( # "L1/MSC/SCI/62173/10160000108/CSST_MSC_MS_SCI_20290206174352_20290206174622_10160000108_21_L1_V01.fits") # Loading