|
4 | 4 |
|
5 | 5 | import errno |
6 | 6 | import os |
| 7 | +import shutil |
7 | 8 | from collections.abc import Iterable |
8 | 9 | from pathlib import Path |
9 | 10 | from typing import Annotated |
|
17 | 18 | from cmip_ref.models import Dataset |
18 | 19 | from cmip_ref.solver import solve_metrics |
19 | 20 | from cmip_ref.testing import SAMPLE_DATA_VERSION, fetch_sample_data |
| 21 | +from cmip_ref_core.dataset_registry import build_reference_data_registry, fetch_all_files |
20 | 22 | from cmip_ref_core.datasets import SourceDatasetType |
21 | 23 |
|
22 | 24 | app = typer.Typer(help=__doc__) |
@@ -149,21 +151,44 @@ def ingest( # noqa: PLR0913 |
149 | 151 |
|
150 | 152 | @app.command(name="fetch-sample-data") |
151 | 153 | def _fetch_sample_data( |
152 | | - version: str = SAMPLE_DATA_VERSION, force_cleanup: bool = False, symlink: bool = False |
| 154 | + version: Annotated[ |
| 155 | + str, |
| 156 | + "The version tag of the sample data to fetch. " |
| 157 | + "Defaults to the current version of data expected by the test suite", |
| 158 | + ] = SAMPLE_DATA_VERSION, |
| 159 | + force_cleanup: Annotated[bool, typer.Option(help="If True, remove any existing files")] = False, |
| 160 | + symlink: Annotated[ |
| 161 | + bool, typer.Option(help="If True, symlink files into the output directory, otherwise perform a copy") |
| 162 | + ] = False, |
153 | 163 | ) -> None: |
154 | 164 | """ |
155 | 165 | Fetch the sample data for the given version. |
156 | 166 |
|
157 | | - Parameters |
158 | | - ---------- |
159 | | - version |
160 | | - The version tag of the sample data to fetch. |
161 | | -
|
162 | | - Defaults to the current version of data expected by the test suite |
163 | | - force_cleanup |
164 | | - If True, remove any existing files. |
165 | | - symlink : bool |
166 | | - If True, symlink in the data otherwise copy the files. |
| 167 | + These data will be written into the test data directory. |
| 168 | + This operation may fail if the test data directory does not exist, |
| 169 | + as is the case for non-source-based installations. |
167 | 170 | """ |
168 | 171 | logger.info(f"Fetching data for version {version}") |
169 | 172 | fetch_sample_data(version=version, force_cleanup=force_cleanup, symlink=symlink) |
| 173 | + |
| 174 | + |
| 175 | +@app.command(name="fetch-obs4ref-data") |
| 176 | +def fetch_obs4ref_data( |
| 177 | + output_directory: Annotated[Path, typer.Option(help="Output directory where files will be saved")], |
| 178 | + force_cleanup: Annotated[bool, typer.Option(help="If True, remove any existing files")] = False, |
| 179 | + symlink: Annotated[ |
| 180 | + bool, typer.Option(help="If True, symlink files into the output directory, otherwise perform a copy") |
| 181 | + ] = False, |
| 182 | +) -> None: |
| 183 | + """ |
| 184 | + Fetch non-published Obs4MIPs data that is used by the REF |
| 185 | +
|
| 186 | + These datasets have been verified to have open licenses |
| 187 | + and are in the process of being added to Obs4MIPs. |
| 188 | + """ |
| 189 | + if force_cleanup and output_directory.exists(): |
| 190 | + logger.warning(f"Removing existing directory {output_directory}") |
| 191 | + shutil.rmtree(output_directory) |
| 192 | + |
| 193 | + data_registry = build_reference_data_registry() |
| 194 | + fetch_all_files(data_registry, output_directory, symlink=symlink) |
0 commit comments