Commit 920aa478 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

fix bugs in File

parent aedd4608
Pipeline #2434 failed with stage
...@@ -55,26 +55,44 @@ class File: ...@@ -55,26 +55,44 @@ class File:
r"(?P<ext>[a-z.]+)" r"(?P<ext>[a-z.]+)"
) )
self.mo = re.fullmatch(pattern, self.file_name) self.mo = re.fullmatch(pattern, self.file_name)
assert self.mo is not None, f"Pattern does not match for file: {self.file_name}" assert self.mo is not None, f"Pattern does not match: {self.file_name}"
# set attributes # set attributes
for k, v in self.mo.groupdict().items(): # for k, v in self.mo.groupdict().items():
self.__setattr__(k, v) # self.__setattr__(k, v)
self.telescope = self.mo.groupdict()["telescope"]
self.instrument = self.mo.groupdict()["instrument"]
self.project = self.mo.groupdict()["project"]
self.obs_type = self.mo.groupdict()["obs_type"]
self.exp_start = self.mo.groupdict()["exp_start"]
self.exp_stop = self.mo.groupdict()["exp_stop"]
self.obs_id = self.mo.groupdict()["obs_id"]
self.detector = self.mo.groupdict()["detector"]
self.level = self.mo.groupdict()["level"]
self.version = self.mo.groupdict()["version"]
self.ext = self.mo.groupdict()["ext"]
def derive( def derive(
self, self,
new_dir=None, ext: Optional[str] = None,
telescope=None, new_dir: Optional[str] = None,
instrument=None, telescope: Optional[str] = None,
project=None, instrument: Optional[str] = None,
obs_type=None, project: Optional[str] = None,
exp_start=None, obs_type: Optional[str] = None,
exp_stop=None, exp_start: Optional[str | int] = None,
obs_id=None, exp_stop: Optional[str | int] = None,
detector=None, obs_id: Optional[str | int] = None,
level=None, detector: Optional[str | int] = None,
version=None, level: Optional[str | int] = None,
ext=None, version: Optional[str | int] = None,
): ):
if ext is None:
ext = self.ext
else:
assert isinstance(ext, str)
if not ext.startswith("."):
ext = "_" + str(ext)
return os.path.join( return os.path.join(
new_dir if new_dir is not None else self.new_dir, new_dir if new_dir is not None else self.new_dir,
f"{self.telescope if telescope is None else str(telescope)}_" f"{self.telescope if telescope is None else str(telescope)}_"
...@@ -87,7 +105,7 @@ class File: ...@@ -87,7 +105,7 @@ class File:
f"{self.detector if detector is None else str(detector)}_" f"{self.detector if detector is None else str(detector)}_"
f"L{self.level if level is None else str(level)}_" f"L{self.level if level is None else str(level)}_"
f"V{self.version if version is None else str(version).zfill(2)}" f"V{self.version if version is None else str(version).zfill(2)}"
f"{self.ext if ext is None else str(ext)}", f"{ext}",
) )
def derive0(self, *args, **kwargs): def derive0(self, *args, **kwargs):
......
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