Skip to content

Commit

Permalink
Fix minor bugs in data_config.yaml workflow (#40)
Browse files Browse the repository at this point in the history
### Summary
#31 introduced three minor bugs
that are fixed with this PR:

- r"" strings are not required in units of `data_config.yaml`
- dictionaries cannot be passed as argsparse, rather JSON strings. This
bug is related to the flag `var_leads_metrics_watch`

---------

Co-authored-by: joeloskarsson <[email protected]>
  • Loading branch information
sadamov and joeloskarsson authored May 31, 2024
1 parent 879cfec commit 9d558d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions neural_lam/data_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ dataset:
var_units:
- Pa
- Pa
- r"$\mathrm{W}/\mathrm{m}^2$"
- r"$\mathrm{W}/\mathrm{m}^2$"
- $\mathrm{W}/\mathrm{m}^2$
- $\mathrm{W}/\mathrm{m}^2$
- ""
- ""
- K
Expand All @@ -33,9 +33,9 @@ dataset:
- m/s
- m/s
- m/s
- r"$\mathrm{kg}/\mathrm{m}^2$"
- r"$\mathrm{m}^2/\mathrm{s}^2$"
- r"$\mathrm{m}^2/\mathrm{s}^2$"
- $\mathrm{kg}/\mathrm{m}^2$
- $\mathrm{m}^2/\mathrm{s}^2$
- $\mathrm{m}^2/\mathrm{s}^2$
var_longnames:
- pres_heightAboveGround_0_instant
- pres_heightAboveSea_0_instant
Expand Down
2 changes: 1 addition & 1 deletion neural_lam/models/ar_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def create_metric_log_dict(self, metric_tensor, prefix, metric_name):
# Check if metrics are watched, log exact values for specific vars
if full_log_name in self.args.metrics_watch:
for var_i, timesteps in self.args.var_leads_metrics_watch.items():
var = self.config_loader.dataset.var_nums[var_i]
var = self.config_loader.dataset.var_names[var_i]
log_dict.update(
{
f"{full_log_name}_{var}_step_{step}": metric_tensor[
Expand Down
13 changes: 9 additions & 4 deletions train_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Standard library
import json
import random
import time
from argparse import ArgumentParser
Expand Down Expand Up @@ -196,17 +197,21 @@ def main():
)
parser.add_argument(
"--metrics_watch",
type=list,
nargs="+",
default=[],
help="List of metrics to watch, including any prefix (e.g. val_rmse)",
)
parser.add_argument(
"--var_leads_metrics_watch",
type=dict,
default={},
help="Dict with variables and lead times to log watched metrics for",
type=str,
default="{}",
help="""JSON string with variable-IDs and lead times to log watched
metrics (e.g. '{"1": [1, 2], "3": [3, 4]}')""",
)
args = parser.parse_args()
args.var_leads_metrics_watch = {
int(k): v for k, v in json.loads(args.var_leads_metrics_watch).items()
}

config_loader = config.Config.from_file(args.data_config)

Expand Down

0 comments on commit 9d558d1

Please sign in to comment.