Skip to content

Commit 39a83d7

Browse files
authored
#4 Merge pull request from deshima-dev/astropenguin/issue3
Add raw data
2 parents 3fb5099 + dc3ec35 commit 39a83d7

8 files changed

Lines changed: 89 additions & 5 deletions

File tree

.github/workflows/pypi.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: PyPI
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
job:
10+
name: PyPI
11+
runs-on: ubuntu-latest
12+
env:
13+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.12"
19+
- name: Publish package to PyPI
20+
run: pip install poetry && poetry publish --build

.github/workflows/tests.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
job:
13+
name: Test (Python ${{ matrix.python }})
14+
runs-on: ubuntu-latest
15+
env:
16+
POETRY_VIRTUALENVS_CREATE: false
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python: ["3.9", "3.10", "3.11", "3.12"]
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: actions/setup-python@v4
24+
with:
25+
python-version: ${{ matrix.python }}
26+
- name: Install project dependencies
27+
run: pip install poetry && poetry install
28+
- name: Test code's formatting (Black)
29+
run: black --check deshima_rawdata tests
30+
- name: Test code's typing (Pyright)
31+
run: pyright deshima_rawdata tests
32+
- name: Test code's execution (pytest)
33+
run: pytest -v tests

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# rawdata
2-
:truck: DESHIMA raw data and downloader package
2+
DESHIMA raw data and downloader package
3+
4+
# Usage
5+
6+
```
7+
$ pip install deshima-rawdata
8+
$ deshima-rawdata download <obsid>
9+
```
10+
11+
# List of raw data
12+
13+
| Observation ID | File name | Source | Observation type |
14+
| --- | --- | --- | --- |
15+
| 20231108052231 | 20231108052231.tar.gz | Jupiter | contmap |
16+
| 20231109015146 | 20231109015146.tar.gz | Jupiter | zscan |
17+
| 20231109060113 | 20231109060113.tar.gz | Blank sky | skydip |

data/20231108052231.tar.gz

70.4 MB
Binary file not shown.

data/20231109015146.tar.gz

27.5 MB
Binary file not shown.

data/20231109060113.tar.gz

43.4 MB
Binary file not shown.

deshima_rawdata/cli.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
# standard library
5+
import tarfile
56
from pathlib import Path
67

78

@@ -14,6 +15,7 @@
1415

1516
# constants
1617
CHUNK_SIZE = 1024
18+
DEFAULT_TAG = f"v{__version__}"
1719
GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
1820

1921

@@ -22,27 +24,31 @@ def download(
2224
/,
2325
*,
2426
dir: Path = Path(),
25-
progress: bool = True,
27+
extract: bool = False,
28+
progress: bool = False,
29+
tag: str = DEFAULT_TAG,
2630
) -> Path:
2731
"""Download DESHIMA raw data for given observation ID.
2832
2933
Args:
3034
obsid: Observation ID (YYYYmmddHHMMSS).
3135
dir: Directory where the raw data is saved.
36+
extract: Whether to extract the raw data.
3237
progress: Whether to show a progress bar.
38+
tag: Git tag (or branch) of the raw data.
3339
3440
Returns:
3541
Path of the downloaded raw data.
3642
3743
"""
38-
url = f"{GITHUB_URL}/v{__version__}/data/{obsid}.tar.gz"
44+
url = f"{GITHUB_URL}/{tag}/data/{obsid}.tar.gz"
3945

4046
if not (response := get(url, stream=True)).ok:
4147
response.raise_for_status()
4248

4349
bar_options = {
4450
"disable": not progress,
45-
"total": int(response.headers.get("content-length", 0)),
51+
"total": int(response.headers["content-length"]),
4652
"unit": "B",
4753
"unit_scale": True,
4854
}
@@ -53,7 +59,15 @@ def download(
5359
bar.update(len(data))
5460
f.write(data)
5561

56-
return data_path
62+
if not extract:
63+
return data_path
64+
65+
with tarfile.open(data_path, "r:gz") as tar:
66+
tar.extractall(data_path.parent)
67+
dir_name = tar.getnames()[0]
68+
69+
data_path.unlink(True)
70+
return data_path.parent / dir_name
5771

5872

5973
def main() -> None:

tests/test_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_download() -> None:
2+
pass

0 commit comments

Comments
 (0)