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:
r"(?P<ext>[a-z.]+)"
)
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
for k, v in self.mo.groupdict().items():
self.__setattr__(k, v)
# for k, v in self.mo.groupdict().items():
# 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(
self,
new_dir=None,
telescope=None,
instrument=None,
project=None,
obs_type=None,
exp_start=None,
exp_stop=None,
obs_id=None,
detector=None,
level=None,
version=None,
ext=None,
ext: Optional[str] = None,
new_dir: Optional[str] = None,
telescope: Optional[str] = None,
instrument: Optional[str] = None,
project: Optional[str] = None,
obs_type: Optional[str] = None,
exp_start: Optional[str | int] = None,
exp_stop: Optional[str | int] = None,
obs_id: Optional[str | int] = None,
detector: Optional[str | int] = None,
level: Optional[str | int] = 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(
new_dir if new_dir is not None else self.new_dir,
f"{self.telescope if telescope is None else str(telescope)}_"
......@@ -87,7 +105,7 @@ class File:
f"{self.detector if detector is None else str(detector)}_"
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"{self.ext if ext is None else str(ext)}",
f"{ext}",
)
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