Skip to content

Commit ef9b4a9

Browse files
authored
#10 Merge pull request from deshima-dev/astropenguin/issue9
#9 Add list command
2 parents e066e0a + 6b84a4b commit ef9b4a9

File tree

9 files changed

+353
-43
lines changed

9 files changed

+353
-43
lines changed

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ message: "If you use this software, please cite it as below."
33

44
title: "deshima-rawdata"
55
abstract: "DESHIMA raw data and downloader package"
6-
version: 2023.11.0
7-
date-released: 2023-11-10
6+
version: 2023.11.1
7+
date-released: 2023-11-16
88
license: "MIT"
99
url: "https://github.com/deshima-dev/rawdata"
1010
authors:

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Release](https://img.shields.io/pypi/v/deshima-rawdata?label=Release&color=cornflowerblue&style=flat-square)](https://pypi.org/project/deshima-rawdata/)
44
[![Python](https://img.shields.io/pypi/pyversions/deshima-rawdata?label=Python&color=cornflowerblue&style=flat-square)](https://pypi.org/project/deshima-rawdata/)
55
[![Downloads](https://img.shields.io/pypi/dm/deshima-rawdata?label=Downloads&color=cornflowerblue&style=flat-square)](https://pepy.tech/project/deshima-rawdata)
6-
[![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)
6+
[![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)
77

88
DESHIMA raw data and downloader package
99

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

1414
## Download the data
1515

16-
```
16+
```shell
1717
$ pip install deshima-rawdata
1818
$ deshima-rawdata download <observation ID>
1919
```
2020

2121
See the command help for more information.
2222

23-
```
23+
```shell
2424
$ deshima-rawdata download --help
2525
```
2626

2727
## List of the data
2828

29-
| Observation ID | File name | Source name | Observation type |
30-
| --- | --- | --- | --- |
31-
| 20231108052231 | 20231108052231.tar.gz | Jupiter | raster |
32-
| 20231109015146 | 20231109015146.tar.gz | Jupiter | zscan |
33-
| 20231109060113 | 20231109060113.tar.gz | Blank sky | skydip |
29+
```shell
30+
$ deshima-rawdata list
31+
```
32+
33+
| Observation ID | File name | Source name | Observation type |
34+
|-----------------:|:----------------------|:--------------|:-------------------|
35+
| 20231108052231 | 20231108052231.tar.gz | Jupiter | raster |
36+
| 20231109015146 | 20231109015146.tar.gz | Jupiter | zscan |
37+
| 20231109060113 | 20231109060113.tar.gz | Blank sky | skydip |

deshima_rawdata/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
__all__ = ["cli", "download"]
2-
__version__ = "2023.11.0"
1+
__all__ = ["cli", "download", "list"]
2+
__version__ = "2023.11.1"
33

44

55
# submodules

deshima_rawdata/cli.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
__all__ = ["download"]
1+
__all__ = ["download", "list"]
22

33

44
# standard library
55
import tarfile
66
from pathlib import Path
7+
from typing import Any, Literal, overload
78

89

910
# dependencies
11+
import pandas as pd
1012
from fire import Fire
1113
from requests import get
1214
from tqdm import tqdm
@@ -15,8 +17,14 @@
1517

1618
# constants
1719
CHUNK_SIZE = 1024
18-
DEFAULT_TAG = f"v{__version__}"
19-
GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
20+
DATA_LIST = pd.read_csv(
21+
Path(__file__).with_name("data.csv"),
22+
index_col=0,
23+
dtype={0: str},
24+
)
25+
DATA_REPO_URL = "https://github.com/deshima-dev/rawdata"
26+
DEFAULT_DATA_REF = f"v{__version__}"
27+
DEFAULT_LIST_FORMAT = "markdown"
2028

2129

2230
def download(
@@ -26,7 +34,7 @@ def download(
2634
dir: Path = Path(),
2735
extract: bool = False,
2836
progress: bool = False,
29-
tag: str = DEFAULT_TAG,
37+
ref: str = DEFAULT_DATA_REF,
3038
) -> Path:
3139
"""Download DESHIMA raw data for given observation ID.
3240
@@ -35,13 +43,15 @@ def download(
3543
dir: Directory where the raw data is saved.
3644
extract: Whether to extract the raw data.
3745
progress: Whether to show a progress bar.
38-
tag: Git tag (or branch) of the raw data.
46+
ref: Reference of the branch or tag for the raw data.
47+
Note that this is for development use only.
3948
4049
Returns:
4150
Path of the downloaded raw data.
4251
4352
"""
44-
url = f"{GITHUB_URL}/{tag}/data/{obsid}.tar.gz"
53+
file_name = DATA_LIST["File name"][str(obsid)] # type: ignore
54+
url = f"{DATA_REPO_URL}/raw/{ref}/data/{file_name}"
4555

4656
if not (response := get(url, stream=True)).ok:
4757
response.raise_for_status()
@@ -52,7 +62,7 @@ def download(
5262
"unit": "B",
5363
"unit_scale": True,
5464
}
55-
data_path = Path(dir) / response.url.split("/")[-1]
65+
data_path = Path(dir) / file_name
5666

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

6979
data_path.unlink(True)
70-
return data_path.parent / dir_name
80+
return data_path.with_name(dir_name)
81+
82+
83+
@overload
84+
def list(format: Literal["csv", "json", "markdown"]) -> str:
85+
...
86+
87+
88+
@overload
89+
def list(format: Literal["dict"]) -> dict[str, str]:
90+
...
91+
92+
93+
def list(format: str = DEFAULT_LIST_FORMAT) -> Any:
94+
"""List DESHIMA raw datasets available in the package.
95+
96+
Args:
97+
format: Format of the list that can be output by pandas.
98+
99+
Returns:
100+
The list of DESHIMA raw datasets with given format.
101+
102+
"""
103+
return getattr(DATA_LIST, f"to_{format}")()
71104

72105

73106
def main() -> None:
74107
"""Entry point of the deshima-rawdata command."""
75-
Fire({"download": download})
108+
Fire({"download": download, "list": list})

deshima_rawdata/data.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Observation ID,File name,Source name,Observation type
2+
20231108052231,20231108052231.tar.gz,Jupiter,raster
3+
20231109015146,20231109015146.tar.gz,Jupiter,zscan
4+
20231109060113,20231109060113.tar.gz,Blank sky,skydip

deshima_rawdata/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)