Skip to content

Commit

Permalink
adapt all cli to use --config arg instead of config
Browse files Browse the repository at this point in the history
  • Loading branch information
leifdenby committed Nov 12, 2024
1 parent b2e0874 commit 772cc20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion neural_lam/create_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def create_graph_from_datastore(
def cli(input_args=None):
parser = ArgumentParser(description="Graph generation arguments")
parser.add_argument(
"config_path",
"--config_path",
type=str,
help="Path to neural-lam configuration file",
)
Expand Down Expand Up @@ -590,6 +590,8 @@ def cli(input_args=None):
)
args = parser.parse_args(input_args)

assert args.config is not None, "Specify your config with --config_path"

# Load neural-lam configuration and datastore to use
_, datastore = load_config_and_datastore(config_path=args.config_path)

Expand Down
17 changes: 13 additions & 4 deletions neural_lam/datastore/plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt

# Local
from .config import load_config_and_datastore
from . import DATASTORES, init_datastore


def plot_example_from_datastore(
Expand Down Expand Up @@ -105,6 +105,13 @@ def _parse_dict(arg_str):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--datastore_kind",
type=str,
choices=DATASTORES.keys(),
default="mdp",
help="Kind of datastore to use",
)
parser.add_argument(
"--datastore_config_path",
type=str,
Expand Down Expand Up @@ -150,6 +157,10 @@ def _parse_dict(arg_str):
)
args = parser.parse_args()

assert (
args.datastore_config_path is not None
), "Specify your datastore config with --datastore_config_path"

selection = dict(args.selection)
index_selection = dict(args.index_selection)

Expand All @@ -161,9 +172,7 @@ def _parse_dict(arg_str):
"column dimension and/or selection."
)

_, datastore = load_config_and_datastore(
config_path=args.datastore_config_path
)
_, datastore = init_datastore(config_path=args.datastore_config_path)

plot_example_from_datastore(
args.category,
Expand Down
3 changes: 2 additions & 1 deletion neural_lam/train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main(input_args=None):
description="Train or evaluate NeurWP models for LAM"
)
parser.add_argument(
"config_path",
"--config_path",
type=str,
help="Path to the configuration for neural-lam",
)
Expand Down Expand Up @@ -209,6 +209,7 @@ def main(input_args=None):
}

# Asserts for arguments
assert args.config is not None, "Specify your config with --config_path"
assert args.model in MODELS, f"Unknown model: {args.model}"
assert args.eval in (
None,
Expand Down

0 comments on commit 772cc20

Please sign in to comment.