Skip to content

Commit 8dde262

Browse files
committed
Merge branch 'main' into comparative-plots-MR
2 parents 1e8ccdf + 6c2835b commit 8dde262

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

codes/utils/data_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ def update_to(self, b=1, bsize=1, tsize=None):
651651
def download_data(dataset_name: str, path: str | None = None, verbose: bool = True):
652652
"""
653653
Download the specified dataset if it is not present, with a progress bar.
654+
The downloaded file is always renamed to 'data.hdf5', regardless of the
655+
filename served by the remote source.
656+
654657
Args:
655658
dataset_name (str): The name of the dataset.
656659
path (str, optional): The path to save the dataset. If None, the default data directory is used.
@@ -661,6 +664,7 @@ def download_data(dataset_name: str, path: str | None = None, verbose: bool = Tr
661664
if path is None
662665
else os.path.abspath(path)
663666
)
667+
664668
if os.path.isfile(data_path):
665669
if verbose:
666670
print(f"Dataset '{dataset_name}' already exists at {data_path}.")
@@ -679,11 +683,16 @@ def download_data(dataset_name: str, path: str | None = None, verbose: bool = Tr
679683

680684
os.makedirs(os.path.dirname(data_path), exist_ok=True)
681685

686+
tmp_path = data_path + ".tmp"
687+
682688
print(f"Downloading dataset '{dataset_name}'...")
683689
with DownloadProgressBar(
684690
unit="B", unit_scale=True, miniters=1, desc=f"Downloading {dataset_name}"
685691
) as t:
686-
urllib.request.urlretrieve(url, data_path, reporthook=t.update_to)
692+
urllib.request.urlretrieve(url, tmp_path, reporthook=t.update_to)
693+
694+
os.replace(tmp_path, data_path)
695+
687696
print(f"Dataset '{dataset_name}' downloaded successfully.")
688697
if verbose:
689698
print_data_info(data_path)

datasets/data_sources.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ branca_large_myr: "https://zenodo.org/records/14243267/files/data.hdf5?download=
1010
coupled_oscillators: "https://zenodo.org/records/14717175/files/data.hdf5?download=1"
1111
lv_parametric: https://zenodo.org/records/15412214/files/data.hdf5?download=1
1212
lv_parametric_no_params: https://zenodo.org/records/15412297/files/data.hdf5?download=1
13+
cloud: https://zenodo.org/records/18018572/files/codes_cloud_data.hdf5?download=1
14+
cloud_parametric: https://zenodo.org/records/18018572/files/codes_cloud_parametric_data.hdf5?download=1
15+
primordial: https://zenodo.org/records/18018572/files/codes_primordial_data.hdf5?download=1
16+
primordial_parametric: https://zenodo.org/records/18018572/files/codes_primordial_parametric_data.hdf5?download=1
17+

0 commit comments

Comments
 (0)