From 20053b697cca95742cbc18ead55750ff51283917 Mon Sep 17 00:00:00 2001 From: BO ZHANG Date: Thu, 18 May 2023 11:40:01 +0800 Subject: [PATCH] raise FileNotFoundError when dm cannot find files --- csst_common/data_manager.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/csst_common/data_manager.py b/csst_common/data_manager.py index d6cab35..4c42cec 100644 --- a/csst_common/data_manager.py +++ b/csst_common/data_manager.py @@ -463,7 +463,8 @@ class CsstMsDataManager: assert detector in self.available_detectors fn = f"{self.instrument}_{self.obs_id}_chip_{detector:02d}_filt_{self.detector2filter[detector]}.cat" fp = os.path.join(self.dir_l0, fn) - assert os.path.exists(fp) + if not os.path.exists(fp): + raise FileNotFoundError(f"File not found: {fp}") return fp def l0_log(self, detector=6): @@ -471,7 +472,8 @@ class CsstMsDataManager: assert detector in self.available_detectors fn = f"{self.instrument}_{self.obs_id}_chip_{detector:02d}_filt_{self.detector2filter[detector]}.log" fp = os.path.join(self.dir_l0, fn) - assert os.path.exists(fp) + if not os.path.exists(fp): + raise FileNotFoundError(f"File not found: {fp}") return fp def l0_detector(self, detector=6): @@ -484,8 +486,9 @@ class CsstMsDataManager: fn = f"{self.telescope}_{self.instrument}_{self.project}_{self.obs_type}_{self.exp_start}_" \ f"{self.exp_stop}_{self.obs_id}_{detector:02d}_L{self.level}_V{self.version}.{self.ext}" fp = os.path.join(self.dir_l0, fn) - assert os.path.exists(fp) - return os.path.join(self.dir_l0, fn) + if not os.path.exists(fp): + raise FileNotFoundError(f"File not found: {fp}") + return fp def l0_crs(self, detector=6): """ L0 cosmic ray file path """ @@ -497,8 +500,9 @@ class CsstMsDataManager: fn = f"{self.telescope}_{self.instrument}_{self.project}_CRS_{self.exp_start}_" \ f"{self.exp_stop}_{self.obs_id}_{detector:02d}_L{self.level}_V{self.version}.{self.ext}" fp = os.path.join(self.dir_l0, fn) - assert os.path.exists(fp) - return os.path.join(self.dir_l0, fn) + if not os.path.exists(fp): + raise FileNotFoundError(f"File not found: {fp}") + return fp def l1_detector(self, detector=6, post="IMG.fits"): """ generate L1 file path -- GitLab