Commit 2a541db2 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

add CsstMsFile

parent 03f43f98
...@@ -1008,15 +1008,14 @@ CsstMbiDataManager = CsstMsDataManager ...@@ -1008,15 +1008,14 @@ CsstMbiDataManager = CsstMsDataManager
class CsstMsFile(dict): 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__() super(CsstMsFile, self).__init__()
self.ver_sim = ver_sim self.ver_sim = ver_sim
self.dir_l0 = dir_l0 self.filepath = filepath
self.dir_l1 = dir_l1
self.dfs_root = dfs_root
self.filename = os.path.basename(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 # parse filename
pattern = re.compile( pattern = re.compile(
r"(?P<telescope>[A-Z]+)_" r"(?P<telescope>[A-Z]+)_"
...@@ -1046,17 +1045,6 @@ class CsstMsFile(dict): ...@@ -1046,17 +1045,6 @@ class CsstMsFile(dict):
for k, v in kwargs.items(): for k, v in kwargs.items():
self.__setattr__(k, v) 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"): def fpo(self, post=".fits"):
if post.startswith("."): if post.startswith("."):
fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \ fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \
...@@ -1064,13 +1052,13 @@ class CsstMsFile(dict): ...@@ -1064,13 +1052,13 @@ class CsstMsFile(dict):
else: else:
fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_{self.exp_stop}_" \ 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}" 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): def fpi(self):
return os.path.join(self.dir_l0, self.filename) return os.path.join(self.dir_in, self.filename)
@staticmethod @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() L1DataApi = Level1DataApi()
rec = L1DataApi.get(id=id) rec = L1DataApi.get(id=id)
try: try:
...@@ -1080,10 +1068,14 @@ class CsstMsFile(dict): ...@@ -1080,10 +1068,14 @@ class CsstMsFile(dict):
raise ae raise ae
header = rec["data"].header header = rec["data"].header
return CsstMsFile( 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): def __repr__(self):
return f"CsstMsFile({self.filename})" return f"CsstMsFile(filepath=\"{self.filename}\", ver_sim=\"C6.2\", dir_out=\".\")"
# file = CsstMsFile( # file = CsstMsFile(
# "L1/MSC/SCI/62173/10160000108/CSST_MSC_MS_SCI_20290206174352_20290206174622_10160000108_21_L1_V01.fits") # "L1/MSC/SCI/62173/10160000108/CSST_MSC_MS_SCI_20290206174352_20290206174622_10160000108_21_L1_V01.fits")
# #
......
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