Skip to content

Commit

Permalink
#169 Use the last log if multiple logs exist in a data package
Browse files Browse the repository at this point in the history
  • Loading branch information
astropenguin committed Sep 10, 2024
1 parent e1a4b46 commit 231cb05
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions demerge/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class DataPackage:
"""Path of the weather log (optional)."""


def first(glob_results: Iterator[Path], /) -> Optional[Path]:
"""Return the first Path.glob result if exists."""
for path in glob_results:
def last(glob_results: Iterator[Path], /) -> Optional[Path]:
"""Return the last Path.glob result if exists."""
for path in reversed(sorted(glob_results)):
return path


Expand All @@ -52,22 +52,22 @@ def parse(data_pack: PathLike, /) -> DataPackage:
if not (data_pack := Path(data_pack)).exists():
raise FileNotFoundError(data_pack)

if (corresp := first(data_pack.glob("*.json"))) is None:
if (corresp := last(data_pack.glob("*.json"))) is None:
raise FileNotFoundError("KID correspondence (*.json).")

if (obsinst := first(data_pack.glob("*.obs"))) is None:
raise FileNotFoundError(f"Observation instruction (*.obs).")
if (obsinst := last(data_pack.glob("*.obs"))) is None:
raise FileNotFoundError("Observation instruction (*.obs).")

if (readout := first(data_pack.glob("*.fits*"))) is None:
raise FileNotFoundError(f"KID readout FITS (*.fits).")
if (readout := last(data_pack.glob("*.fits*"))) is None:
raise FileNotFoundError("KID readout FITS (*.fits).")

return DataPackage(
antenna=first(data_pack.glob("*.ant")),
cabin=first(data_pack.glob("*.cabin")),
antenna=last(data_pack.glob("*.ant")),
cabin=last(data_pack.glob("*.cabin")),
corresp=corresp,
misti=first(data_pack.glob("*.misti")),
misti=last(data_pack.glob("*.misti")),
obsinst=obsinst,
readout=readout,
skychop=first(data_pack.glob("*.skychopper*")),
weather=first(data_pack.glob("*.wea")),
skychop=last(data_pack.glob("*.skychopper*")),
weather=last(data_pack.glob("*.wea")),
)

0 comments on commit 231cb05

Please sign in to comment.