Skip to content

Commit

Permalink
Changes from trial runs on Gadi
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-turner-1 committed Jan 24, 2025
1 parent 2454711 commit 9f922c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/access_nri_intake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,15 @@ def use_esm_datastore(argv: Sequence[str] | None = None) -> int:
"--cat-dir",
type=str,
help=(
"Directory in which to place the catalog.json file. This file is the descriptor of the catalog,"
" and provides references to the data locations where the catalog data itself is stored."
"Directory in which to place the catalog.json file."
" Defaults to the value of --expt-dir if not set."
),
)

args = parser.parse_args(argv)
builder = args.builder
experiment_dir = Path(args.expt_dir)
catalog_dir = args.cat_dir or experiment_dir
catalog_dir = Path(args.cat_dir) or experiment_dir

builder = getattr(builders, builder)

Expand All @@ -498,6 +497,6 @@ def use_esm_datastore(argv: Sequence[str] | None = None) -> int:
f"Builder {builder} is not a valid builder. Please choose from {builders.__all__}"
)

use_datastore(builder, experiment_dir, open_ds=False)
use_datastore(builder, experiment_dir, catalog_dir, open_ds=False)

return 0
14 changes: 11 additions & 3 deletions src/access_nri_intake/experiment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def use_datastore(
The directory containing the experiment.
catalog_dir : Path, optional
The directory containing/to write the catalog to, if it differs from the
experiment directory. If None, it will default to the experiment directory.
experiment directory. If None, the catalog will be written to the experiment
directory.
open_ds : bool
Whether to open the datastore after building it.
Expand Down Expand Up @@ -89,7 +90,12 @@ def use_datastore(

if not ds_info.valid:
builder_instance: Builder = builder(path=str(experiment_dir))
print(f"{Fore.BLUE}Building esm-datastore...{Style.RESET_ALL}")
builder_instance.build()
print(f"{Fore.GREEN}Sucessfully built esm-datastore!{Style.RESET_ALL}")
print(
f"{Fore.BLUE}Saving esm-datastore to {Fore.CYAN}{Style.BRIGHT}{str(catalog_dir)}{Style.NORMAL}{Fore.BLUE}...{Style.RESET_ALL}"
)
builder_instance.save(
name=datastore_name,
description=description
Expand All @@ -106,14 +112,16 @@ def use_datastore(

if open_ds:
return intake.open_esm_datastore(
str(experiment_dir / "catalog.json"),
str(catalog_dir / f"{datastore_name}.json"),
columns_with_iterables=["variable"],
)
else:
print(
f"{Fore.BLUE}To open the datastore, run `{Fore.CYAN}{Style.BRIGHT}intake.open_esm_datastore({str(experiment_dir / 'catalog.json')},"
f"{Fore.BLUE}To open the datastore, run `{Fore.CYAN}{Style.BRIGHT}intake.open_esm_datastore({str(catalog_dir /f'{datastore_name}.json')},"
f" columns_with_iterables=['variable']){Fore.BLUE}{Style.NORMAL}` in a Python session."
)

print(f"{Style.RESET_ALL}")
return None


Expand Down

0 comments on commit 9f922c4

Please sign in to comment.