|
241 | 241 | " time_step=np.timedelta64(24, \"h\"),\n",
|
242 | 242 | " options={\n",
|
243 | 243 | " \"input_dir\": domain_dir,\n",
|
244 |
| - " \"budget_type\": None,\n", |
| 244 | + " \"budget_type\": \"error\",\n", |
245 | 245 | " \"netcdf_output_dir\": nb_output_dir / \"nhm_memory\",\n",
|
246 | 246 | " },\n",
|
247 | 247 | ")\n",
|
|
349 | 349 | "source": [
|
350 | 350 | "run_dir = pl.Path(nb_output_dir / \"nhm_yaml\")\n",
|
351 | 351 | "run_dir.mkdir(exist_ok=True)\n",
|
352 |
| - "control_yaml_file = run_dir / \"control.yml\"\n", |
353 |
| - "control.to_yaml(control_yaml_file)" |
| 352 | + "control_yaml_file = run_dir / \"control.yaml\"\n", |
| 353 | + "control_yaml = deepcopy(control)\n", |
| 354 | + "control_yaml.options[\"netcdf_output_dir\"] = nb_output_dir / \"nhm_yaml\"\n", |
| 355 | + "control_yaml.to_yaml(control_yaml_file)" |
354 | 356 | ]
|
355 | 357 | },
|
356 | 358 | {
|
|
366 | 368 | "We add the option `netcdf_output_dir` to the control since we assume we wont be able to do so at run time. Note that this option and the `input_dir` option are `pathlib.Path` objects. These are not what we want to write to file. We want their string version. We could do `str()` on each one by hand, but it will be more handy to write a small, recursive function to do this on a supplied dictionary since this will be a recurring task with the model dictionary we will create after the control YAML file."
|
367 | 369 | ]
|
368 | 370 | },
|
| 371 | + { |
| 372 | + "cell_type": "code", |
| 373 | + "execution_count": null, |
| 374 | + "id": "8044016c-7728-4149-9be5-f52b8f43975d", |
| 375 | + "metadata": {}, |
| 376 | + "outputs": [], |
| 377 | + "source": [ |
| 378 | + "control" |
| 379 | + ] |
| 380 | + }, |
369 | 381 | {
|
370 | 382 | "cell_type": "code",
|
371 | 383 | "execution_count": null,
|
|
471 | 483 | "metadata": {},
|
472 | 484 | "outputs": [],
|
473 | 485 | "source": [
|
474 |
| - "model_dict_yaml_file = run_dir / \"model_dict.yml\"\n", |
| 486 | + "model_dict_yaml_file = run_dir / \"model_dict.yaml\"\n", |
475 | 487 | "with open(model_dict_yaml_file, \"w\") as file:\n",
|
476 | 488 | " _ = yaml.dump(model_dict, file)"
|
477 | 489 | ]
|
|
491 | 503 | "metadata": {},
|
492 | 504 | "outputs": [],
|
493 | 505 | "source": [
|
494 |
| - "! cat 01_multi-process_models/nhm_yaml/control.yml" |
| 506 | + "! cat 01_multi-process_models/nhm_yaml/control.yaml" |
495 | 507 | ]
|
496 | 508 | },
|
497 | 509 | {
|
|
501 | 513 | "metadata": {},
|
502 | 514 | "outputs": [],
|
503 | 515 | "source": [
|
504 |
| - "! cat 01_multi-process_models/nhm_yaml/model_dict.yml" |
| 516 | + "! cat 01_multi-process_models/nhm_yaml/model_dict.yaml" |
505 | 517 | ]
|
506 | 518 | },
|
507 | 519 | {
|
|
519 | 531 | "metadata": {},
|
520 | 532 | "outputs": [],
|
521 | 533 | "source": [
|
522 |
| - "model_yml = pws.Model.from_yaml(model_dict_yaml_file)\n", |
523 |
| - "model_yml" |
| 534 | + "model_yaml = pws.Model.from_yaml(model_dict_yaml_file)\n", |
| 535 | + "model_yaml" |
524 | 536 | ]
|
525 | 537 | },
|
526 | 538 | {
|
|
533 | 545 | "show_params = not (platform == \"darwin\" and processor() == \"arm\")\n",
|
534 | 546 | "try:\n",
|
535 | 547 | " pws.analysis.ModelGraph(\n",
|
536 |
| - " model_yml,\n", |
| 548 | + " model_yaml,\n", |
537 | 549 | " hide_variables=False,\n",
|
538 | 550 | " process_colors=palette,\n",
|
539 | 551 | " show_params=show_params,\n",
|
|
558 | 570 | "outputs": [],
|
559 | 571 | "source": [
|
560 | 572 | "%%time\n",
|
561 |
| - "model_yml.run()\n", |
562 |
| - "model_yml.finalize()" |
| 573 | + "model_yaml.run()\n", |
| 574 | + "model_yaml.finalize()" |
563 | 575 | ]
|
564 | 576 | },
|
565 | 577 | {
|
|
584 | 596 | "outputs": [],
|
585 | 597 | "source": [
|
586 | 598 | "mem_out_dir = nb_output_dir / \"nhm_memory\"\n",
|
587 |
| - "yml_out_dir = nb_output_dir / \"nhm_yaml\"\n", |
| 599 | + "yaml_out_dir = nb_output_dir / \"nhm_yaml\"\n", |
588 | 600 | "mem_files = sorted(mem_out_dir.glob(\"*.nc\"))\n",
|
589 |
| - "yml_files = sorted(yml_out_dir.glob(\"*.nc\"))\n", |
| 601 | + "yaml_files = sorted(yaml_out_dir.glob(\"*.nc\"))\n", |
590 | 602 | "# We get all the same output files\n",
|
591 |
| - "assert set([ff.name for ff in mem_files]) == set([ff.name for ff in yml_files])" |
| 603 | + "assert set([ff.name for ff in mem_files]) == set(\n", |
| 604 | + " [ff.name for ff in yaml_files]\n", |
| 605 | + ")" |
| 606 | + ] |
| 607 | + }, |
| 608 | + { |
| 609 | + "cell_type": "code", |
| 610 | + "execution_count": null, |
| 611 | + "id": "310a8d35-5ddb-4ef1-b4a1-65a823d4aa7c", |
| 612 | + "metadata": {}, |
| 613 | + "outputs": [], |
| 614 | + "source": [ |
| 615 | + "set([ff.name for ff in yaml_files]) - set([ff.name for ff in mem_files])" |
592 | 616 | ]
|
593 | 617 | },
|
594 | 618 | {
|
|
604 | 628 | "Now compare the values of all variables:"
|
605 | 629 | ]
|
606 | 630 | },
|
| 631 | + { |
| 632 | + "cell_type": "code", |
| 633 | + "execution_count": null, |
| 634 | + "id": "523633e0-bb6e-4fa7-8a7a-bd2de3d602b0", |
| 635 | + "metadata": {}, |
| 636 | + "outputs": [], |
| 637 | + "source": [ |
| 638 | + "nb_output_dir.resolve()" |
| 639 | + ] |
| 640 | + }, |
607 | 641 | {
|
608 | 642 | "cell_type": "code",
|
609 | 643 | "execution_count": null,
|
610 | 644 | "id": "db0d920e-0227-45ba-92c6-8ffacab9ca3c",
|
611 | 645 | "metadata": {},
|
612 | 646 | "outputs": [],
|
613 | 647 | "source": [
|
614 |
| - "for mf, yf in zip(mem_files, yml_files):\n", |
| 648 | + "for mf, yf in zip(mem_files, yaml_files):\n", |
615 | 649 | " var = mf.with_suffix(\"\").name\n",
|
616 |
| - " # print(var)\n", |
| 650 | + "\n", |
| 651 | + " if \"budget\" in var.lower():\n", |
| 652 | + " continue\n", |
| 653 | + "\n", |
617 | 654 | " mda = xr.open_dataset(mf)[var]\n",
|
618 | 655 | " yda = xr.open_dataset(yf)[var]\n",
|
619 | 656 | " xr.testing.assert_equal(mda, yda)\n",
|
|
681 | 718 | "metadata": {},
|
682 | 719 | "outputs": [],
|
683 | 720 | "source": [
|
684 |
| - "run_dir = pl.Path(nb_output_dir / \"yml_less_output\").resolve()\n", |
| 721 | + "run_dir = pl.Path(nb_output_dir / \"yaml_less_output\").resolve()\n", |
685 | 722 | "run_dir.mkdir(exist_ok=True)"
|
686 | 723 | ]
|
687 | 724 | },
|
|
704 | 741 | "]\n",
|
705 | 742 | "print(control_cp) # .to_dict(), sort_dicts=False)\n",
|
706 | 743 | "\n",
|
707 |
| - "control_yaml_file = run_dir / \"control.yml\"\n", |
| 744 | + "control_yaml_file = run_dir / \"control.yaml\"\n", |
708 | 745 | "control_cp.to_yaml(control_yaml_file)"
|
709 | 746 | ]
|
710 | 747 | },
|
|
725 | 762 | "source": [
|
726 | 763 | "model_dict_copy = deepcopy(model_dict)\n",
|
727 | 764 | "model_dict_copy[\"control\"] = str(control_yaml_file)\n",
|
728 |
| - "model_dict_yaml_file = run_dir / \"model_dict.yml\"" |
| 765 | + "model_dict_yaml_file = run_dir / \"model_dict.yaml\"" |
729 | 766 | ]
|
730 | 767 | },
|
731 | 768 | {
|
|
928 | 965 | "control_cp = deepcopy(control)\n",
|
929 | 966 | "control_cp.options[\"input_dir\"] = yaml_output_dir.resolve()\n",
|
930 | 967 | "control_cp.options[\"netcdf_output_dir\"] = run_dir.resolve()\n",
|
931 |
| - "control_yaml_file = run_dir / \"control.yml\"\n", |
| 968 | + "control_yaml_file = run_dir / \"control.yaml\"\n", |
932 | 969 | "control_cp.to_yaml(control_yaml_file)\n",
|
933 | 970 | "pprint(control.to_dict(), sort_dicts=False)"
|
934 | 971 | ]
|
|
949 | 986 | "outputs": [],
|
950 | 987 | "source": [
|
951 | 988 | "model_dict[\"control\"] = str(control_yaml_file)\n",
|
952 |
| - "model_dict_yaml_file = run_dir / \"model_dict.yml\"\n", |
| 989 | + "model_dict_yaml_file = run_dir / \"model_dict.yaml\"\n", |
953 | 990 | "keep_procs = [\"prms_soilzone\", \"prms_groundwater\", \"prms_channel\"]\n",
|
954 | 991 | "model_dict[\"model_order\"] = keep_procs\n",
|
955 | 992 | "for kk in list(model_dict.keys()):\n",
|
|
1205 | 1242 | "* Regan, R. S., Markstrom, S. L., Hay, L. E., Viger, R. J., Norton, P. A., Driscoll, J. M., & LaFontaine, J. H. (2018). Description of the national hydrologic model for use with the precipitation-runoff modeling system (prms) (No. 6-B9). US Geological Survey.\n",
|
1206 | 1243 | "* Regan, R.S., Markstrom, S.L., LaFontaine, J.H., 2022, PRMS version 5.2.1: Precipitation-Runoff Modeling System (PRMS): U.S. Geological Survey Software Release, 02/10/2022."
|
1207 | 1244 | ]
|
1208 |
| - }, |
1209 |
| - { |
1210 |
| - "cell_type": "code", |
1211 |
| - "execution_count": null, |
1212 |
| - "id": "ff4dbac1-046f-4354-94e6-2610269c2de4", |
1213 |
| - "metadata": {}, |
1214 |
| - "outputs": [], |
1215 |
| - "source": [] |
1216 | 1245 | }
|
1217 | 1246 | ],
|
1218 | 1247 | "metadata": {
|
|
0 commit comments