wrfrun 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wrfrun/cli.py +128 -0
- wrfrun/core/__init__.py +33 -0
- wrfrun/core/base.py +246 -75
- wrfrun/core/config.py +286 -236
- wrfrun/core/error.py +47 -17
- wrfrun/core/replay.py +65 -32
- wrfrun/core/server.py +139 -79
- wrfrun/data.py +10 -5
- wrfrun/extension/__init__.py +28 -0
- wrfrun/extension/goos_sst/__init__.py +67 -0
- wrfrun/extension/goos_sst/core.py +111 -0
- wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST +7 -0
- wrfrun/extension/goos_sst/res/__init__.py +26 -0
- wrfrun/extension/goos_sst/utils.py +97 -0
- wrfrun/extension/littler/__init__.py +57 -1
- wrfrun/extension/littler/{utils.py → core.py} +326 -40
- wrfrun/extension/utils.py +22 -21
- wrfrun/model/__init__.py +24 -1
- wrfrun/model/plot.py +253 -35
- wrfrun/model/utils.py +17 -8
- wrfrun/model/wrf/__init__.py +41 -0
- wrfrun/model/wrf/core.py +218 -102
- wrfrun/model/wrf/exec_wrap.py +49 -35
- wrfrun/model/wrf/namelist.py +82 -11
- wrfrun/model/wrf/scheme.py +85 -1
- wrfrun/model/wrf/{_metgrid.py → utils.py} +36 -2
- wrfrun/model/wrf/vtable.py +2 -1
- wrfrun/plot/wps.py +66 -58
- wrfrun/res/__init__.py +8 -5
- wrfrun/res/config/config.template.toml +50 -0
- wrfrun/res/{config.toml.template → config/wrf.template.toml} +10 -47
- wrfrun/res/run.template.sh +10 -0
- wrfrun/res/scheduler/lsf.template +5 -0
- wrfrun/res/{job_scheduler → scheduler}/pbs.template +1 -1
- wrfrun/res/{job_scheduler → scheduler}/slurm.template +2 -1
- wrfrun/run.py +19 -23
- wrfrun/scheduler/__init__.py +35 -0
- wrfrun/scheduler/env.py +44 -0
- wrfrun/scheduler/lsf.py +47 -0
- wrfrun/scheduler/pbs.py +48 -0
- wrfrun/scheduler/script.py +70 -0
- wrfrun/scheduler/slurm.py +48 -0
- wrfrun/scheduler/utils.py +14 -0
- wrfrun/utils.py +8 -3
- wrfrun/workspace/__init__.py +38 -0
- wrfrun/workspace/core.py +92 -0
- wrfrun/workspace/wrf.py +121 -0
- {wrfrun-0.1.7.dist-info → wrfrun-0.1.9.dist-info}/METADATA +4 -3
- wrfrun-0.1.9.dist-info/RECORD +62 -0
- wrfrun-0.1.9.dist-info/entry_points.txt +3 -0
- wrfrun/model/wrf/_ndown.py +0 -39
- wrfrun/pbs.py +0 -86
- wrfrun/res/run.sh.template +0 -16
- wrfrun/workspace.py +0 -88
- wrfrun-0.1.7.dist-info/RECORD +0 -46
- {wrfrun-0.1.7.dist-info → wrfrun-0.1.9.dist-info}/WHEEL +0 -0
wrfrun/cli.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from os import makedirs
|
|
4
|
+
from os.path import abspath, dirname, exists
|
|
5
|
+
from shutil import copyfile
|
|
6
|
+
|
|
7
|
+
import tomli
|
|
8
|
+
import tomli_w
|
|
9
|
+
|
|
10
|
+
from .core import WRFRUNConfig
|
|
11
|
+
from .res import CONFIG_MAIN_TOML_TEMPLATE, CONFIG_WRF_TOML_TEMPLATE
|
|
12
|
+
from .utils import logger
|
|
13
|
+
|
|
14
|
+
MODEL_MAP = {
|
|
15
|
+
"wrf": CONFIG_WRF_TOML_TEMPLATE
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _entry_init(args: argparse.Namespace):
|
|
20
|
+
"""
|
|
21
|
+
Initialize a wrfrun project.
|
|
22
|
+
|
|
23
|
+
:param args: Arguments namespace.
|
|
24
|
+
:type args: argparse.Namespace
|
|
25
|
+
"""
|
|
26
|
+
args = vars(args)
|
|
27
|
+
|
|
28
|
+
project_name = args["name"]
|
|
29
|
+
models = args["models"]
|
|
30
|
+
|
|
31
|
+
if exists(project_name):
|
|
32
|
+
logger.error(f"{project_name} already exists.")
|
|
33
|
+
exit(1)
|
|
34
|
+
|
|
35
|
+
makedirs(f"{project_name}/configs")
|
|
36
|
+
makedirs(f"{project_name}/data")
|
|
37
|
+
|
|
38
|
+
copyfile(WRFRUNConfig.parse_resource_uri(CONFIG_MAIN_TOML_TEMPLATE), f"{project_name}/config.toml")
|
|
39
|
+
|
|
40
|
+
if models is not None:
|
|
41
|
+
for _model in models:
|
|
42
|
+
src_path = WRFRUNConfig.parse_resource_uri(MODEL_MAP[_model])
|
|
43
|
+
copyfile(src_path, f"{project_name}/configs/{_model}.toml")
|
|
44
|
+
|
|
45
|
+
logger.info(f"Created project {project_name}.")
|
|
46
|
+
logger.info(f"Use command `wrfrun add MODEL_NAME` to add a new model to project.")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _entry_model(args: argparse.Namespace):
|
|
50
|
+
"""
|
|
51
|
+
Manage models used by wrfrun project.
|
|
52
|
+
|
|
53
|
+
:param args: Arguments namespace.
|
|
54
|
+
:type args: argparse.Namespace
|
|
55
|
+
"""
|
|
56
|
+
args = vars(args)
|
|
57
|
+
new_models = args["add"]
|
|
58
|
+
config_path = args["config"]
|
|
59
|
+
|
|
60
|
+
if not exists(config_path):
|
|
61
|
+
logger.error(f"Can't find '{config_path}', initialize this project first.")
|
|
62
|
+
exit(1)
|
|
63
|
+
|
|
64
|
+
model_config_map = {
|
|
65
|
+
"wrf": CONFIG_WRF_TOML_TEMPLATE
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for _new_model in new_models:
|
|
69
|
+
if _new_model not in model_config_map:
|
|
70
|
+
logger.error(f"Unknow model type: '{_new_model}'")
|
|
71
|
+
exit(1)
|
|
72
|
+
|
|
73
|
+
config_dir_path = f"{abspath(dirname(config_path))}/configs"
|
|
74
|
+
|
|
75
|
+
if not exists(config_dir_path):
|
|
76
|
+
makedirs(config_dir_path)
|
|
77
|
+
|
|
78
|
+
with open(config_path, "rb") as f:
|
|
79
|
+
main_config = tomli.load(f)
|
|
80
|
+
|
|
81
|
+
for _new_model in new_models:
|
|
82
|
+
if _new_model not in main_config["model"]:
|
|
83
|
+
main_config["model"][_new_model] = {
|
|
84
|
+
"note": "Config of this model is generated by wrfrun cli command. DO NOT ADD CUSTOM CONFIG IN THIS SECTION because they may be overwrite by wrfrun cli tools.",
|
|
85
|
+
"use": True,
|
|
86
|
+
"include": f"./configs/{_new_model}.toml"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
else:
|
|
90
|
+
if not ("use" in main_config["model"] and main_config["model"]["use"]):
|
|
91
|
+
main_config["model"][_new_model] = {
|
|
92
|
+
"note": "Config of this model is generated by wrfrun cli command. DO NOT ADD CUSTOM CONFIG IN THIS SECTION because they may be overwrite by wrfrun cli tools.",
|
|
93
|
+
"use": True,
|
|
94
|
+
"include": f"./configs/{_new_model}.toml"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for _new_model in new_models:
|
|
98
|
+
copyfile(WRFRUNConfig.parse_resource_uri(model_config_map[_new_model]), f"{config_dir_path}/{_new_model}.toml")
|
|
99
|
+
|
|
100
|
+
with open(config_path, "wb") as f:
|
|
101
|
+
tomli_w.dump(main_config, f)
|
|
102
|
+
|
|
103
|
+
logger.info(f"Added models: {new_models}")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def main_entry():
|
|
107
|
+
"""
|
|
108
|
+
CLI entry point.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
args_parser = argparse.ArgumentParser()
|
|
112
|
+
subparsers = args_parser.add_subparsers(title="Subcommands", description="Valid Subcommands", help="Subcommands")
|
|
113
|
+
|
|
114
|
+
init_parser = subparsers.add_parser("init", help="Initialize a wrfrun project.", add_help=True)
|
|
115
|
+
init_parser.add_argument("-n", "--name", type=str, required=True, help="Name of the wrfrun project.")
|
|
116
|
+
init_parser.add_argument("--models", nargs="*", type=str, help="List of models to use.", choices=["wrf"])
|
|
117
|
+
init_parser.set_defaults(func=_entry_init)
|
|
118
|
+
|
|
119
|
+
model_parser = subparsers.add_parser("model", help="Manage models used by wrfrun project.", add_help=True)
|
|
120
|
+
model_parser.add_argument("-c", "--config", type=str, default="config.toml", help="Path of the main config file.")
|
|
121
|
+
model_parser.add_argument("-a", "--add", nargs="+", required=True, type=str, help="Add models to the project.")
|
|
122
|
+
model_parser.set_defaults(func=_entry_model)
|
|
123
|
+
|
|
124
|
+
args = args_parser.parse_args(args=None if sys.argv[1:] else ["--help"])
|
|
125
|
+
args.func(args)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
__all__ = ["main_entry"]
|
wrfrun/core/__init__.py
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
"""
|
|
2
|
+
wrfrun.core
|
|
3
|
+
###########
|
|
4
|
+
|
|
5
|
+
The core functionalities of ``wrfrun`` are all implemented in the submodule ``wrfrun.core``,
|
|
6
|
+
such as processing namelist files, managing resource files required during model's running (e.g., VTable files),
|
|
7
|
+
calling the numerical model and process its output and log files, monitoring simulation process via model's log,
|
|
8
|
+
recording and replaying the simulation.
|
|
9
|
+
|
|
10
|
+
The functionalities are split into several submodules, which are listed in the table below.
|
|
11
|
+
|
|
12
|
+
Submodules
|
|
13
|
+
**********
|
|
14
|
+
|
|
15
|
+
================================ ========================================================
|
|
16
|
+
:doc:`base </api/core.base>` Executable base class and related classes.
|
|
17
|
+
:doc:`config </api/core.config>` ``wrfrun`` config classes.
|
|
18
|
+
:doc:`error </api/core.error>` ``wrfrun`` error classes.
|
|
19
|
+
:doc:`replay </api/core.replay>` Functions and classes to record and replay simulations.
|
|
20
|
+
:doc:`server </api/core.server>` Functions and classes to start socket server.
|
|
21
|
+
================================ ========================================================
|
|
22
|
+
|
|
23
|
+
.. toctree::
|
|
24
|
+
:maxdepth: 1
|
|
25
|
+
:hidden:
|
|
26
|
+
|
|
27
|
+
base <core.base>
|
|
28
|
+
config <core.config>
|
|
29
|
+
error <core.error>
|
|
30
|
+
replay <core.replay>
|
|
31
|
+
server <core.server>
|
|
32
|
+
"""
|
|
33
|
+
|
|
1
34
|
from .base import *
|
|
2
35
|
from .config import *
|
|
3
36
|
from .error import *
|