-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#160 Merge pull request from deshima-dev/astropenguin/issue115
Add data package parser
- Loading branch information
Showing
7 changed files
with
132 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
__all__ = ["DataPackage", "parse"] | ||
|
||
|
||
# standard library | ||
from collections.abc import Iterator | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Optional, Union | ||
|
||
|
||
# type hints | ||
PathLike = Union[Path, str] | ||
|
||
|
||
@dataclass | ||
class DataPackage: | ||
"""Parsed data package structure.""" | ||
|
||
antenna: Optional[Path] | ||
"""Path of the antenna log (optional).""" | ||
|
||
cabin: Optional[Path] | ||
"""Path of the cabin log (optional).""" | ||
|
||
corresp: Path | ||
"""Path of the KID correspondence (required).""" | ||
|
||
misti: Optional[Path] | ||
"""Path of the MiSTI log (optional).""" | ||
|
||
obsinst: Path | ||
"""Path of the observation instruction (required).""" | ||
|
||
readout: Path | ||
"""Path of the KID readout FITS (required).""" | ||
|
||
skychop: Optional[Path] | ||
"""Path of the sky chopper log (optional).""" | ||
|
||
weather: Optional[Path] | ||
"""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: | ||
return path | ||
|
||
|
||
def parse(data_pack: PathLike, /) -> DataPackage: | ||
"""Parse a data package (data directory).""" | ||
if not (data_pack := Path(data_pack)).exists(): | ||
raise FileNotFoundError(data_pack) | ||
|
||
if (corresp := first(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 (readout := first(data_pack.glob("*.fits*"))) is None: | ||
raise FileNotFoundError(f"KID readout FITS (*.fits).") | ||
|
||
return DataPackage( | ||
antenna=first(data_pack.glob("*.ant")), | ||
cabin=first(data_pack.glob("*.cabin")), | ||
corresp=corresp, | ||
misti=first(data_pack.glob("*.misti")), | ||
obsinst=obsinst, | ||
readout=readout, | ||
skychop=first(data_pack.glob("*.skychopper*")), | ||
weather=first(data_pack.glob("*.wea")), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "demerge" | ||
version = "2024.7.1" | ||
version = "2024.7.2" | ||
description = "DESHIMA merge code for observed datasets" | ||
authors = [ | ||
"Tatsuya Takekoshi <[email protected]>", | ||
|
@@ -46,9 +46,9 @@ pytest = "^8.2" | |
sphinx = "^7.3" | ||
|
||
[tool.poetry.scripts] | ||
demerge = "demerge:cli" | ||
merge = "demerge.merge:cli" | ||
reduce = "demerge.reduce:cli" | ||
demerge = "demerge:demerge_cli" | ||
merge = "demerge.merge:merge_cli" | ||
reduce = "demerge.reduce:reduce_cli" | ||
|
||
[tool.black] | ||
exclude = "demerge/reduce/utils" | ||
|