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
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "deshima-rawdata",
"image":"python:3.11",
"onCreateCommand": "pip install poetry==1.6.1",
"postCreateCommand": "poetry install",
"containerEnv": {
"POETRY_VIRTUALENVS_CREATE": "false"
},
"customizations": {
"vscode": {
"extensions": [
"github.vscode-pull-request-github",
"mhutchie.git-graph",
"ms-python.black-formatter",
"ms-python.python",
"streetsidesoftware.code-spell-checker",
"tamasfe.even-better-toml"
],
"settings": {
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"python.languageServer": "Pylance"
}
}
}
}
}
6 changes: 6 additions & 0 deletions deshima_rawdata/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__all__ = ["cli"]
__version__ = "2023.11.0"


# submodules
from . import cli
61 changes: 61 additions & 0 deletions deshima_rawdata/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
__all__ = ["download"]


# standard library
from pathlib import Path


# dependencies
from fire import Fire
from requests import get
from tqdm import tqdm
from . import __version__


# constants
CHUNK_SIZE = 1024
GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"


def download(
obsid: str,
/,
*,
dir: Path = Path(),
progress: bool = True,
) -> Path:
"""Download DESHIMA raw data for given observation ID.

Args:
obsid: Observation ID (YYYYmmddHHMMSS).
dir: Directory where the raw data is saved.
progress: Whether to show a progress bar.

Returns:
Path of the downloaded raw data.

"""
url = f"{GITHUB_URL}/v{__version__}/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)),
"unit": "B",
"unit_scale": True,
}
data_path = Path(dir) / response.url.split("/")[-1]

with tqdm(**bar_options) as bar, open(data_path, "wb") as f:
for data in response.iter_content(CHUNK_SIZE):
bar.update(len(data))
f.write(data)

return data_path


def main() -> None:
"""Entry point of the deshima-rawdata command."""
Fire({"download": download})
Loading