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
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ message: "If you use this software, please cite it as below."

title: "deshima-rawdata"
abstract: "DESHIMA raw data and downloader package"
version: 2023.11.0
date-released: 2023-11-10
version: 2023.11.1
date-released: 2023-11-16
license: "MIT"
url: "https://github.com/deshima-dev/rawdata"
authors:
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Release](https://img.shields.io/pypi/v/deshima-rawdata?label=Release&color=cornflowerblue&style=flat-square)](https://pypi.org/project/deshima-rawdata/)
[![Python](https://img.shields.io/pypi/pyversions/deshima-rawdata?label=Python&color=cornflowerblue&style=flat-square)](https://pypi.org/project/deshima-rawdata/)
[![Downloads](https://img.shields.io/pypi/dm/deshima-rawdata?label=Downloads&color=cornflowerblue&style=flat-square)](https://pepy.tech/project/deshima-rawdata)
[![Tests](https://img.shields.io/github/actions/workflow/status/deshima-dev/deshima-rawdata/tests.yaml?label=Tests&style=flat-square)](https://github.com/deshima-dev/deshima-rawdata/actions)
[![Tests](https://img.shields.io/github/actions/workflow/status/deshima-dev/rawdata/tests.yaml?label=Tests&style=flat-square)](https://github.com/deshima-dev/rawdata/actions)

DESHIMA raw data and downloader package

Expand All @@ -13,21 +13,25 @@ Please contact [@astropenguin](https://github.com/astropenguin) before using the

## Download the data

```
```shell
$ pip install deshima-rawdata
$ deshima-rawdata download <observation ID>
```

See the command help for more information.

```
```shell
$ deshima-rawdata download --help
```

## List of the data

| Observation ID | File name | Source name | Observation type |
| --- | --- | --- | --- |
| 20231108052231 | 20231108052231.tar.gz | Jupiter | raster |
| 20231109015146 | 20231109015146.tar.gz | Jupiter | zscan |
| 20231109060113 | 20231109060113.tar.gz | Blank sky | skydip |
```shell
$ deshima-rawdata list
```

| Observation ID | File name | Source name | Observation type |
|-----------------:|:----------------------|:--------------|:-------------------|
| 20231108052231 | 20231108052231.tar.gz | Jupiter | raster |
| 20231109015146 | 20231109015146.tar.gz | Jupiter | zscan |
| 20231109060113 | 20231109060113.tar.gz | Blank sky | skydip |
4 changes: 2 additions & 2 deletions deshima_rawdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ["cli", "download"]
__version__ = "2023.11.0"
__all__ = ["cli", "download", "list"]
__version__ = "2023.11.1"


# submodules
Expand Down
51 changes: 42 additions & 9 deletions deshima_rawdata/cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
__all__ = ["download"]
__all__ = ["download", "list"]


# standard library
import tarfile
from pathlib import Path
from typing import Any, Literal, overload


# dependencies
import pandas as pd
from fire import Fire
from requests import get
from tqdm import tqdm
Expand All @@ -15,8 +17,14 @@

# constants
CHUNK_SIZE = 1024
DEFAULT_TAG = f"v{__version__}"
GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
DATA_LIST = pd.read_csv(
Path(__file__).with_name("data.csv"),
index_col=0,
dtype={0: str},
)
DATA_REPO_URL = "https://github.com/deshima-dev/rawdata"
DEFAULT_DATA_REF = f"v{__version__}"
DEFAULT_LIST_FORMAT = "markdown"


def download(
Expand All @@ -26,7 +34,7 @@ def download(
dir: Path = Path(),
extract: bool = False,
progress: bool = False,
tag: str = DEFAULT_TAG,
ref: str = DEFAULT_DATA_REF,
) -> Path:
"""Download DESHIMA raw data for given observation ID.

Expand All @@ -35,13 +43,15 @@ def download(
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.
ref: Reference of the branch or tag for the raw data.
Note that this is for development use only.

Returns:
Path of the downloaded raw data.

"""
url = f"{GITHUB_URL}/{tag}/data/{obsid}.tar.gz"
file_name = DATA_LIST["File name"][str(obsid)] # type: ignore
url = f"{DATA_REPO_URL}/raw/{ref}/data/{file_name}"

if not (response := get(url, stream=True)).ok:
response.raise_for_status()
Expand All @@ -52,7 +62,7 @@ def download(
"unit": "B",
"unit_scale": True,
}
data_path = Path(dir) / response.url.split("/")[-1]
data_path = Path(dir) / file_name

with tqdm(**bar_options) as bar, open(data_path, "wb") as f:
for data in response.iter_content(CHUNK_SIZE):
Expand All @@ -67,9 +77,32 @@ def download(
dir_name = tar.getnames()[0]

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


@overload
def list(format: Literal["csv", "json", "markdown"]) -> str:
...


@overload
def list(format: Literal["dict"]) -> dict[str, str]:
...


def list(format: str = DEFAULT_LIST_FORMAT) -> Any:
"""List DESHIMA raw datasets available in the package.

Args:
format: Format of the list that can be output by pandas.

Returns:
The list of DESHIMA raw datasets with given format.

"""
return getattr(DATA_LIST, f"to_{format}")()


def main() -> None:
"""Entry point of the deshima-rawdata command."""
Fire({"download": download})
Fire({"download": download, "list": list})
4 changes: 4 additions & 0 deletions deshima_rawdata/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Observation ID,File name,Source name,Observation type
20231108052231,20231108052231.tar.gz,Jupiter,raster
20231109015146,20231109015146.tar.gz,Jupiter,zscan
20231109060113,20231109060113.tar.gz,Blank sky,skydip
Empty file added deshima_rawdata/py.typed
Empty file.
Loading