File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33
44# standard library
5+ import tarfile
56from pathlib import Path
67
78
1415
1516# constants
1617CHUNK_SIZE = 1024
17- GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
1818DEFAULT_TAG = f"v{ __version__ } "
19+ GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
1920
2021
2122def download (
2223 obsid : str ,
2324 / ,
2425 * ,
2526 dir : Path = Path (),
26- progress : bool = True ,
27+ extract : bool = False ,
28+ progress : bool = False ,
2729 tag : str = DEFAULT_TAG ,
2830) -> Path :
2931 """Download DESHIMA raw data for given observation ID.
3032
3133 Args:
3234 obsid: Observation ID (YYYYmmddHHMMSS).
3335 dir: Directory where the raw data is saved.
36+ extract: Whether to extract the raw data.
3437 progress: Whether to show a progress bar.
3538 tag: Git tag (or branch) of the raw data.
3639
@@ -56,7 +59,15 @@ def download(
5659 bar .update (len (data ))
5760 f .write (data )
5861
59- 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
6071
6172
6273def main () -> None :
You can’t perform that action at this time.
0 commit comments