Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: PyPI

on:
release:
types:
- created

jobs:
job:
name: PyPI
runs-on: ubuntu-latest
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Publish package to PyPI
run: pip install poetry && poetry publish --build
33 changes: 33 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
job:
name: Test (Python ${{ matrix.python }})
runs-on: ubuntu-latest
env:
POETRY_VIRTUALENVS_CREATE: false
strategy:
fail-fast: false
matrix:
python: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install project dependencies
run: pip install poetry && poetry install
- name: Test code's formatting (Black)
run: black --check deshima_rawdata tests
- name: Test code's typing (Pyright)
run: pyright deshima_rawdata tests
- name: Test code's execution (pytest)
run: pytest -v tests
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# rawdata
:truck: DESHIMA raw data and downloader package
DESHIMA raw data and downloader package

# Usage

```
$ pip install deshima-rawdata
$ deshima-rawdata download <obsid>
```

# List of raw data

| Observation ID | File name | Source | Observation type |
| --- | --- | --- | --- |
| 20231108052231 | 20231108052231.tar.gz | Jupiter | contmap |
| 20231109015146 | 20231109015146.tar.gz | Jupiter | zscan |
| 20231109060113 | 20231109060113.tar.gz | Blank sky | skydip |
Binary file added data/20231108052231.tar.gz
Binary file not shown.
Binary file added data/20231109015146.tar.gz
Binary file not shown.
Binary file added data/20231109060113.tar.gz
Binary file not shown.
22 changes: 18 additions & 4 deletions deshima_rawdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


# standard library
import tarfile
from pathlib import Path


Expand All @@ -14,6 +15,7 @@

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


Expand All @@ -22,27 +24,31 @@ def download(
/,
*,
dir: Path = Path(),
progress: bool = True,
extract: bool = False,
progress: bool = False,
tag: str = DEFAULT_TAG,
) -> Path:
"""Download DESHIMA raw data for given observation ID.

Args:
obsid: Observation ID (YYYYmmddHHMMSS).
dir: Directory where the raw data is saved.
extract: Whether to extract the raw data.
progress: Whether to show a progress bar.
tag: Git tag (or branch) of the raw data.

Returns:
Path of the downloaded raw data.

"""
url = f"{GITHUB_URL}/v{__version__}/data/{obsid}.tar.gz"
url = f"{GITHUB_URL}/{tag}/data/{obsid}.tar.gz"

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

bar_options = {
"disable": not progress,
"total": int(response.headers.get("content-length", 0)),
"total": int(response.headers["content-length"]),
"unit": "B",
"unit_scale": True,
}
Expand All @@ -53,7 +59,15 @@ def download(
bar.update(len(data))
f.write(data)

return data_path
if not extract:
return data_path

with tarfile.open(data_path, "r:gz") as tar:
tar.extractall(data_path.parent)
dir_name = tar.getnames()[0]

data_path.unlink(True)
return data_path.parent / dir_name


def main() -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_download() -> None:
pass