wrfrun 0.1.8__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.
Files changed (50) hide show
  1. wrfrun/cli.py +128 -0
  2. wrfrun/core/base.py +8 -5
  3. wrfrun/core/config.py +81 -150
  4. wrfrun/core/replay.py +1 -1
  5. wrfrun/core/server.py +81 -78
  6. wrfrun/extension/goos_sst/__init__.py +5 -5
  7. wrfrun/extension/goos_sst/core.py +4 -1
  8. wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST +1 -1
  9. wrfrun/extension/goos_sst/res/__init__.py +17 -0
  10. wrfrun/extension/goos_sst/utils.py +21 -5
  11. wrfrun/extension/littler/__init__.py +57 -1
  12. wrfrun/extension/littler/{utils.py → core.py} +326 -40
  13. wrfrun/extension/utils.py +22 -21
  14. wrfrun/model/__init__.py +24 -1
  15. wrfrun/model/plot.py +253 -35
  16. wrfrun/model/utils.py +17 -8
  17. wrfrun/model/wrf/__init__.py +41 -0
  18. wrfrun/model/wrf/core.py +215 -99
  19. wrfrun/model/wrf/exec_wrap.py +49 -35
  20. wrfrun/model/wrf/namelist.py +79 -4
  21. wrfrun/model/wrf/{_metgrid.py → utils.py} +36 -2
  22. wrfrun/model/wrf/vtable.py +2 -1
  23. wrfrun/res/__init__.py +8 -5
  24. wrfrun/res/config/config.template.toml +50 -0
  25. wrfrun/res/{config.toml.template → config/wrf.template.toml} +7 -46
  26. wrfrun/res/run.template.sh +10 -0
  27. wrfrun/res/scheduler/lsf.template +5 -0
  28. wrfrun/res/{job_scheduler → scheduler}/pbs.template +1 -1
  29. wrfrun/res/{job_scheduler → scheduler}/slurm.template +2 -1
  30. wrfrun/run.py +19 -23
  31. wrfrun/scheduler/__init__.py +35 -0
  32. wrfrun/scheduler/env.py +44 -0
  33. wrfrun/scheduler/lsf.py +47 -0
  34. wrfrun/scheduler/pbs.py +48 -0
  35. wrfrun/scheduler/script.py +70 -0
  36. wrfrun/scheduler/slurm.py +48 -0
  37. wrfrun/scheduler/utils.py +14 -0
  38. wrfrun/utils.py +8 -3
  39. wrfrun/workspace/__init__.py +38 -0
  40. wrfrun/workspace/core.py +92 -0
  41. wrfrun/workspace/wrf.py +121 -0
  42. {wrfrun-0.1.8.dist-info → wrfrun-0.1.9.dist-info}/METADATA +3 -2
  43. wrfrun-0.1.9.dist-info/RECORD +62 -0
  44. wrfrun-0.1.9.dist-info/entry_points.txt +3 -0
  45. wrfrun/model/wrf/_ndown.py +0 -39
  46. wrfrun/pbs.py +0 -86
  47. wrfrun/res/run.sh.template +0 -16
  48. wrfrun/workspace.py +0 -88
  49. wrfrun-0.1.8.dist-info/RECORD +0 -51
  50. {wrfrun-0.1.8.dist-info → wrfrun-0.1.9.dist-info}/WHEEL +0 -0
@@ -1,13 +1,30 @@
1
- from os.path import basename
1
+ """
2
+ wrfrun.model.wrf.exec_wrap
3
+ ##########################
4
+
5
+ Function wrapper of WPS / WRF :doc:`Executables </api/model.wrf.core>`.
6
+
7
+ .. autosummary::
8
+ :toctree: generated/
9
+
10
+ geogrid
11
+ ungrib
12
+ metgrid
13
+ real
14
+ wrf
15
+ dfi
16
+ ndown
17
+ """
18
+
2
19
  from typing import Optional, Union
3
20
 
4
21
  from wrfrun import WRFRUNConfig
5
- from .core import DFI, GeoGrid, MetGrid, Real, UnGrib, WRF, NDown
22
+ from .core import DFI, GeoGrid, MetGrid, NDown, Real, UnGrib, WRF
6
23
 
7
24
 
8
25
  def geogrid(geogrid_tbl_file: Union[str, None] = None):
9
26
  """
10
- Interface to execute geogrid.exe.
27
+ Function interface for :class:`GeoGrid <wrfrun.model.wrf.core.GeoGrid>`.
11
28
 
12
29
  :param geogrid_tbl_file: Custom GEOGRID.TBL file path. Defaults to None.
13
30
  """
@@ -16,67 +33,66 @@ def geogrid(geogrid_tbl_file: Union[str, None] = None):
16
33
 
17
34
  def ungrib(vtable_file: Union[str, None] = None, input_data_path: Optional[str] = None, prefix="FILE"):
18
35
  """
19
- Interface to execute ungrib.exe.
36
+ Function interface for :class:`UnGrib <wrfrun.model.wrf.core.UnGrib>`.
20
37
 
21
- :param vtable_file: Vtable file used to run ungrib. Defaults to None.
38
+ :param vtable_file: Path of the Vtable file.
39
+ Defaults to :attr:`VtableFiles.ERA_PL <vtable.VtableFiles.ERA_PL>`.
22
40
  :type vtable_file: str
23
- :param input_data_path: Directory path of the input data. If None, ``wrfrun`` will read its value from the config file.
41
+ :param input_data_path: Directory path of input GRIB files.
42
+ Defaults to ``input_data_path`` set in user's config file.
24
43
  :type input_data_path: str
25
- :param prefix: Prefix of ungrib output.
44
+ :param prefix: Prefix of outputs.
26
45
  :type prefix: str
27
46
  """
28
- prefix = basename(prefix)
29
- WRFRUNConfig.set_ungrib_out_prefix(prefix)
30
-
31
- UnGrib(vtable_file, input_data_path)()
47
+ UnGrib(vtable_file, input_data_path).set_ungrib_output_prefix(prefix)()
32
48
 
33
49
 
34
50
  def metgrid(geogrid_data_path: Optional[str] = None, ungrib_data_path: Optional[str] = None, fg_names: Union[str, list[str]] = "FILE"):
35
51
  """
36
- Interface to execute metgrid.exe.
52
+ Function interface for :class:`MetGrid <wrfrun.model.wrf.core.MetGrid>`.
37
53
 
38
- :param geogrid_data_path: Directory path of outputs from geogrid.exe. If None, tries to use the output path specified by config file.
54
+ :param geogrid_data_path: Directory path of :class:`GeoGrid <wrfrun.model.wrf.core.GeoGrid>` outputs.
55
+ If is ``None``, try to use the output path specified by config file.
39
56
  :type geogrid_data_path: str
40
- :param ungrib_data_path: Directory path of outputs from ungrib.exe. If None, tries to use the output path specified by config file.
57
+ :param ungrib_data_path: Directory path of :class:`UnGrib <wrfrun.model.wrf.core.UnGrib>` outputs.
58
+ If is ``None``, try to use the output path specified by config file.
41
59
  :type ungrib_data_path: str
42
- :param fg_names: Set ``fg_name`` of metgrid, a single prefix string or a string list.
60
+ :param fg_names: ``fg_name`` of metgrid, a single prefix string or a string list.
43
61
  :type fg_names: str | list
44
62
  """
45
- if isinstance(fg_names, str):
46
- fg_names = [fg_names, ]
47
- fg_names = [basename(x) for x in fg_names]
48
- WRFRUNConfig.set_metgrid_fg_names(fg_names)
49
-
50
- MetGrid(geogrid_data_path, ungrib_data_path, WRFRUNConfig.get_core_num())()
63
+ MetGrid(
64
+ geogrid_data_path, ungrib_data_path, WRFRUNConfig.get_core_num()
65
+ ).set_metgrid_fg_names(fg_names)()
51
66
 
52
67
 
53
68
  def real(metgrid_data_path: Union[str, None] = None):
54
69
  """
55
- Interface to execute real.exe.
70
+ Function interface for :class:`Real <wrfrun.model.wrf.core.Real>`.
56
71
 
57
- :param metgrid_data_path: The path store output from metgrid.exe. If it is None, the default output path will be used.
72
+ :param metgrid_data_path: Directory path of :class:`MetGrid <wrfrun.model.wrf.core.MetGrid>` outputs.
73
+ If is ``None``, try to use the workspace path or output path in the config file.
58
74
  """
59
75
  Real(metgrid_data_path, WRFRUNConfig.get_core_num())()
60
76
 
61
77
 
62
78
  def wrf(input_file_dir_path: Union[str, None] = None, restart_file_dir_path: Optional[str] = None, save_restarts=False):
63
79
  """
64
- Interface to execute wrf.exe.
80
+ Function interface for :class:`WRF <wrfrun.model.wrf.core.WRF>`.
65
81
 
66
- :param input_file_dir_path: The path store input data which will be feed into wrf.exe. Defaults to None.
67
- :param restart_file_dir_path: The path store WRF restart files. This parameter will be ignored if ``restart=False`` in your config.
68
- :param save_restarts: Also save restart files to the output directory.
82
+ :param input_file_dir_path: Directory path of input data.
83
+ :param restart_file_dir_path: Directory path of restart files.
84
+ :param save_restarts: If saving restart files. Defaults to False.
69
85
  """
70
86
  WRF(input_file_dir_path, restart_file_dir_path, save_restarts, WRFRUNConfig.get_core_num())()
71
87
 
72
88
 
73
89
  def dfi(input_file_dir_path: Optional[str] = None, update_real_output=True):
74
90
  """
75
- Execute "wrf.exe" to run DFI.
91
+ Function interface for :class:`DFI <wrfrun.model.wrf.core.DFI>`.
76
92
 
77
- :param input_file_dir_path: Path of the directory that stores input data for "wrf.exe".
93
+ :param input_file_dir_path: Directory path of input data.
78
94
  :type input_file_dir_path: str
79
- :param update_real_output: If update the corresponding file in real.exe output directory.
95
+ :param update_real_output: If update corresponding files in :class:`Real <wrfrun.model.wrf.core.Real>` outputs.
80
96
  :type update_real_output: bool
81
97
  """
82
98
  DFI(input_file_dir_path, update_real_output, WRFRUNConfig.get_core_num())()
@@ -84,16 +100,14 @@ def dfi(input_file_dir_path: Optional[str] = None, update_real_output=True):
84
100
 
85
101
  def ndown(wrfout_file_path: str, real_output_dir_path: Optional[str] = None, update_namelist=True):
86
102
  """
87
- Execute "ndown.exe".
103
+ Function interface for :class:`NDown <wrfrun.model.wrf.core.NDown>`.
88
104
 
89
105
  :param wrfout_file_path: wrfout file path.
90
106
  :type wrfout_file_path: str
91
- :param real_output_dir_path: Path of the directory that contains output of "real.exe".
107
+ :param real_output_dir_path: Directory path of :class:`Real <wrfrun.model.wrf.core.Real>` outputs.
92
108
  :type real_output_dir_path: str
93
- :param update_namelist: If update wrf's namelist for the final integral.
109
+ :param update_namelist: If update namelist settings for the final integral.
94
110
  :type update_namelist: bool
95
- :return:
96
- :rtype:
97
111
  """
98
112
  NDown(wrfout_file_path, real_output_dir_path, update_namelist, WRFRUNConfig.get_core_num())()
99
113
 
@@ -1,13 +1,85 @@
1
1
  from datetime import datetime, timedelta
2
- from os.path import exists
2
+ from os.path import exists, dirname, basename
3
3
  from typing import Union
4
4
 
5
5
  from wrfrun.core import WRFRUNConfig
6
6
  from wrfrun.res import NAMELIST_DFI, NAMELIST_WPS, NAMELIST_WRF, NAMELIST_WRFDA
7
7
  from wrfrun.utils import logger
8
+ from wrfrun.workspace.wrf import WORKSPACE_MODEL_WPS
8
9
  from .scheme import *
9
10
 
10
11
 
12
+ UNGRIB_OUTPUT_DIR = "./outputs"
13
+
14
+
15
+ def get_ungrib_out_dir_path() -> str:
16
+ """
17
+ Get the output directory of ungrib output (WRF intermediate file).
18
+
19
+ :return: URI path.
20
+ :rtype: str
21
+ """
22
+ wif_prefix = WRFRUNConfig.get_namelist("wps")["ungrib"]["prefix"]
23
+ wif_path = f"{WORKSPACE_MODEL_WPS}/{dirname(wif_prefix)}"
24
+
25
+ return wif_path
26
+
27
+
28
+ def get_ungrib_out_prefix() -> str:
29
+ """
30
+ Get the prefix string of ungrib output (WRF intermediate file).
31
+
32
+ :return: Prefix string of ungrib output (WRF intermediate file).
33
+ :rtype: str
34
+ """
35
+ wif_prefix = WRFRUNConfig.get_namelist("wps")["ungrib"]["prefix"]
36
+ wif_prefix = basename(wif_prefix)
37
+ return wif_prefix
38
+
39
+
40
+ def set_ungrib_out_prefix(prefix: str):
41
+ """
42
+ Set the prefix string of ungrib output (WRF intermediate file).
43
+
44
+ :param prefix: Prefix string of ungrib output (WRF intermediate file).
45
+ :type prefix: str
46
+ """
47
+ WRFRUNConfig.update_namelist(
48
+ {
49
+ "ungrib": {"prefix": f"{UNGRIB_OUTPUT_DIR}/{prefix}"}
50
+ }, "wps"
51
+ )
52
+
53
+
54
+ def get_metgrid_fg_names() -> list[str]:
55
+ """
56
+ Get prefix strings from "fg_name" in namelist "metgrid" section.
57
+
58
+ :return: Prefix strings list.
59
+ :rtype: list
60
+ """
61
+ fg_names = WRFRUNConfig.get_namelist("wps")["metgrid"]["fg_name"]
62
+ fg_names = [basename(x) for x in fg_names]
63
+ return fg_names
64
+
65
+
66
+ def set_metgrid_fg_names(prefix: Union[str, list[str]]):
67
+ """
68
+ Set prefix strings of "fg_name" in namelist "metgrid" section.
69
+
70
+ :param prefix: Prefix strings list.
71
+ :type prefix: str | list
72
+ """
73
+ if isinstance(prefix, str):
74
+ prefix = [prefix, ]
75
+ fg_names = [f"{UNGRIB_OUTPUT_DIR}/{x}" for x in prefix]
76
+ WRFRUNConfig.update_namelist(
77
+ {
78
+ "metgrid": {"fg_name": fg_names}
79
+ }, "wps"
80
+ )
81
+
82
+
11
83
  def _check_start_end_date(max_dom: int, start_date: Union[datetime, list[datetime]], end_date: Union[datetime, list[datetime]]) -> tuple[list[datetime], list[datetime]]:
12
84
  """
13
85
  Format start date and end date.
@@ -84,7 +156,9 @@ def prepare_wps_namelist():
84
156
  "truelat2": wrf_config["domain"]["truelat2"],
85
157
  "stand_lon": wrf_config["domain"]["stand_lon"],
86
158
  "geog_data_path": wrf_config["geog_data_path"]
87
- }
159
+ },
160
+ "ungrib": {"prefix": f"{UNGRIB_OUTPUT_DIR}/FILE"},
161
+ "metgrid": {"fg_name": f"{UNGRIB_OUTPUT_DIR}/FILE"}
88
162
  }
89
163
 
90
164
  # # update namelist
@@ -107,7 +181,7 @@ def prepare_wrf_namelist():
107
181
  wrf_config = WRFRUNConfig.get_model_config("wrf")
108
182
 
109
183
  # get debug level
110
- debug_level = WRFRUNConfig["model"]["debug_level"]
184
+ debug_level = wrf_config["debug_level"]
111
185
 
112
186
  # get domain number, start_date and end_date
113
187
  max_dom = wrf_config["domain"]["domain_num"]
@@ -370,4 +444,5 @@ def prepare_wrfda_namelist():
370
444
  WRFRUNConfig.update_namelist(user_namelist_data, "wrfda")
371
445
 
372
446
 
373
- __all__ = ["prepare_wrf_namelist", "prepare_wps_namelist", "prepare_wrfda_namelist", "prepare_dfi_namelist"]
447
+ __all__ = ["prepare_wrf_namelist", "prepare_wps_namelist", "prepare_wrfda_namelist", "prepare_dfi_namelist", "get_ungrib_out_prefix", "get_ungrib_out_dir_path",
448
+ "set_ungrib_out_prefix", "get_metgrid_fg_names", "set_metgrid_fg_names"]
@@ -4,7 +4,7 @@ from typing import Dict
4
4
 
5
5
  from xarray import open_dataset
6
6
 
7
- from wrfrun.core import WRFRUNConfig
7
+ from wrfrun import WRFRUNConfig
8
8
  from wrfrun.utils import logger
9
9
 
10
10
 
@@ -68,4 +68,38 @@ def reconcile_namelist_metgrid(metgrid_path: str):
68
68
  WRFRUNConfig.update_namelist(update_values, "wrf")
69
69
 
70
70
 
71
- __all__ = ["get_metgrid_levels", "reconcile_namelist_metgrid"]
71
+ def process_after_ndown():
72
+ """
73
+ After running ndown.exe, namelist settings are supposed to be changed,
74
+ so WRF can simulate a higher resolution domain according to `WRF User's Guide <https://www2.mmm.ucar.edu/wrf/users/wrf_users_guide/build/html/running_wrf.html#wrf-nesting>`_.
75
+ `wrfrun` provide this function to help you change these settings which have multiple values for each domain.
76
+ The first value will be removed to ensure the value of higher resolution domain is the first value.
77
+
78
+ :return:
79
+ """
80
+ namelist_data = WRFRUNConfig.get_namelist("wrf")
81
+
82
+ for section in namelist_data:
83
+ if section in ["bdy_control", "namelist_quilt"]:
84
+ continue
85
+
86
+ for key in namelist_data[section]:
87
+ if key in ["grid_id", "parent_id", "i_parent_start", "j_parent_start", "parent_grid_ratio", "parent_time_step_ratio", "eta_levels"]:
88
+ continue
89
+
90
+ if isinstance(namelist_data[section][key], list):
91
+
92
+ if len(namelist_data[section][key]) > 1:
93
+ namelist_data[section][key] = namelist_data[section][key][1:]
94
+
95
+ namelist_data["domains"]["max_dom"] = 1
96
+
97
+ time_ratio = namelist_data["domains"]["parent_time_step_ratio"][1]
98
+ namelist_data["domains"]["time_step"] = namelist_data["domains"]["time_step"] // time_ratio
99
+
100
+ WRFRUNConfig.update_namelist(namelist_data, "wrf")
101
+
102
+ logger.info(f"Update namelist after running ndown.exe")
103
+
104
+
105
+ __all__ = ["reconcile_namelist_metgrid", "get_metgrid_levels", "process_after_ndown"]
@@ -1,6 +1,7 @@
1
1
  from dataclasses import dataclass
2
2
 
3
3
  from wrfrun.core import WRFRUNConfig
4
+ from wrfrun.workspace.wrf import WORKSPACE_MODEL_WPS
4
5
 
5
6
 
6
7
  VTABLE_URI = ":WRFRUN_VTABLE:"
@@ -59,7 +60,7 @@ class VtableFiles:
59
60
 
60
61
  # register uri
61
62
  if not WRFRUNConfig.check_resource_uri(VTABLE_URI):
62
- WRFRUNConfig.register_resource_uri(VTABLE_URI, f"{WRFRUNConfig.WPS_WORK_PATH}/ungrib/Variable_Tables")
63
+ WRFRUNConfig.register_resource_uri(VTABLE_URI, f"{WORKSPACE_MODEL_WPS}/ungrib/Variable_Tables")
63
64
 
64
65
 
65
66
  __all__ = ["VtableFiles"]
wrfrun/res/__init__.py CHANGED
@@ -6,17 +6,20 @@ from wrfrun.core import WRFRUNConfig
6
6
  RES_PATH = abspath(dirname(__file__))
7
7
  WRFRUNConfig.register_resource_uri(WRFRUNConfig.WRFRUN_RESOURCE_PATH, RES_PATH)
8
8
 
9
- CONFIG_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config.toml.template"
9
+ RUN_SH_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/run.template.sh"
10
10
  EXT_NCL_PLOT_SCRIPT = ":WRFRUN_RESOURCE_PATH:/extension/plotgrids.ncl"
11
- TASKSYS_PBS_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/job_scheduler/pbs.template"
12
- TASKSYS_SLURM_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/job_scheduler/slurm.template"
11
+ SCHEDULER_LSF_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/scheduler/lsf.template"
12
+ SCHEDULER_PBS_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/scheduler/pbs.template"
13
+ SCHEDULER_SLURM_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/scheduler/slurm.template"
13
14
  NAMELIST_WRFDA = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.input.da_wrfvar.template"
14
15
  NAMELIST_DFI = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.input.dfi.template"
15
16
  NAMELIST_REAL = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.input.real.template"
16
17
  NAMELIST_WRF = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.input.wrf.template"
17
18
  NAMELIST_WPS = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.wps.template"
19
+ CONFIG_MAIN_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/config.template.toml"
20
+ CONFIG_WRF_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/wrf.template.toml"
18
21
 
19
- WRFRUNConfig.set_config_template_path(CONFIG_TOML_TEMPLATE)
22
+ WRFRUNConfig.set_config_template_path(CONFIG_MAIN_TOML_TEMPLATE)
20
23
 
21
24
 
22
- __all__ = ["CONFIG_TOML_TEMPLATE", "EXT_NCL_PLOT_SCRIPT", "TASKSYS_PBS_TEMPLATE", "TASKSYS_SLURM_TEMPLATE", "NAMELIST_WRFDA", "NAMELIST_DFI", "NAMELIST_REAL", "NAMELIST_WRF", "NAMELIST_WPS"]
25
+ __all__ = ["RUN_SH_TEMPLATE", "EXT_NCL_PLOT_SCRIPT", "SCHEDULER_LSF_TEMPLATE", "SCHEDULER_PBS_TEMPLATE", "SCHEDULER_SLURM_TEMPLATE", "NAMELIST_WRFDA", "NAMELIST_DFI", "NAMELIST_REAL", "NAMELIST_WRF", "NAMELIST_WPS", "CONFIG_MAIN_TOML_TEMPLATE", "CONFIG_WRF_TOML_TEMPLATE"]
@@ -0,0 +1,50 @@
1
+ # Config template of wrfrun.
2
+ # Path of the directory which contains input data.
3
+ input_data_path = ""
4
+
5
+ # Path of the directory to store all outputs.
6
+ output_path = "./outputs"
7
+ log_path = "./logs"
8
+
9
+ # wrfrun can launch a socket server during NWP execution to report simulation progress.
10
+ # To enable the server, you need to configure the IP address and port on which it will listen to.
11
+ server_host = "localhost"
12
+ server_port = 54321
13
+
14
+ # How many cores you will use.
15
+ # Note that if you use a job scheduler (like PBS), this value means the number of cores each node you use.
16
+ core_num = 36
17
+
18
+
19
+ [job_scheduler]
20
+ # Job scheduler settings.
21
+ # Which job scheduler you want to use
22
+ # wrfrun supports following job schedulers:
23
+ # 1. PBS: "pbs"
24
+ # 2. LSF: "lfs"
25
+ # 3. Slurm: "slurm
26
+ job_scheduler = "pbs"
27
+
28
+ # Which queue should the task be submited to
29
+ queue_name = ""
30
+
31
+ # How many nodes you will use.
32
+ node_num = 1
33
+
34
+ # Custom environment settings
35
+ env_settings = {}
36
+
37
+ # Path of the python interpreter that will be used to run wrfrun.
38
+ # You can also give its name only.
39
+ python_interpreter = "/usr/bin/python3" # or just "python3"
40
+
41
+
42
+ [model]
43
+
44
+ [model.wrf]
45
+ # If you want to use WRF model, set use to true.
46
+ use = false
47
+ # Import configurations from another toml file.
48
+ # You can give both absolute and relative path.
49
+ # The relative path is resolved based on this configuration file.
50
+ include = "./configs/wrf.toml"
@@ -1,46 +1,5 @@
1
- # Config template of wrfrun.
2
- # Path of the directory which contains input data.
3
- input_data_path = ""
4
-
5
- # Path of the directory to store all outputs.
6
- output_path = "./outputs"
7
- log_path = "./logs"
8
-
9
- # wrfrun can launch a socket server during NWP execution to report simulation progress.
10
- # To enable the server, you need to configure the IP address and port on which it will listen to.
11
- server_host = "localhost"
12
- server_port = 54321
13
-
14
- # How many cores you will use.
15
- # Note that if you use a job scheduler (like PBS), this value means the number of cores each node you use.
16
- core_num = 36
17
-
18
-
19
- [job_scheduler]
20
- # Job scheduler settings.
21
- # How many nodes you will use.
22
- node_num = 1
23
-
24
- # Custom environment settings
25
- env_settings = {}
26
-
27
- # Path of the python interpreter that will be used to run wrfrun.
28
- # You can also give its name only.
29
- python_interpreter = "/usr/bin/python3" # or just "python3"
30
-
31
-
32
- [model]
33
- # Model debug level
34
- debug_level = 100
35
-
36
- # ################################################### Only settings above is necessary ###########################################
37
-
38
-
39
- # ####################################### You can give more settings about the NWP you will use ##################################
40
-
41
- [model.wrf]
42
- # Config for WRF
43
- # WRF model path
1
+ # Config for WRF model.
2
+ # WRF model path.
44
3
  wps_path = '/path/to/your/WPS/folder'
45
4
  wrf_path = '/path/to/your/WRF/folder'
46
5
  # WRFDA is optional.
@@ -59,8 +18,10 @@ user_wrfda_namelist = ''
59
18
  # If you make a restart run?
60
19
  restart_mode = false
61
20
 
21
+ # debug level for WRF model
22
+ debug_level = 100
62
23
 
63
- [model.wrf.time]
24
+ [time]
64
25
  # Advance time config for WRF
65
26
  # Set the start and end date. It will be used for all domains.
66
27
  # You can also provide all the dates as a list, with each date for the corresponding domain.
@@ -87,7 +48,7 @@ parent_time_step_ratio = [1, 3, 4]
87
48
  restart_interval = -1
88
49
 
89
50
 
90
- [model.wrf.domain]
51
+ [domain]
91
52
  # Advance domain config for WRF.
92
53
  # Set domain number.
93
54
  domain_num = 3
@@ -119,7 +80,7 @@ ref_lon = 120.5
119
80
  stand_lon = 120.5
120
81
 
121
82
 
122
- [model.wrf.scheme]
83
+ [scheme]
123
84
  # Advance physics scheme config for WRF.
124
85
  # To loop up the nickname for all physics schemes, please see: https://wrfrun.syize.cn.
125
86
  # Option contains many other settings related to the scheme.
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ {SCHEDULER_SETTINGS}
3
+
4
+ ulimit -s unlimited
5
+
6
+ {ENV_SETTINGS}
7
+
8
+ cd {WORK_PATH}
9
+
10
+ {WORK_COMMAND}
@@ -0,0 +1,5 @@
1
+ #BSUB -q {QUEUE_NAME}
2
+ #BSUB -o {STDOUT_LOG_PATH}
3
+ #BSUB -e {STDERR_LOG_PATH}
4
+ #BSUB -n {CORE_NUM}
5
+ #BSUB -J wrfrun
@@ -1,4 +1,4 @@
1
- #PBS -q batch
1
+ #PBS -q {QUEUE_NAME}
2
2
  #PBS -N wrfrun
3
3
  #PBS -o {STDOUT_LOG_PATH}
4
4
  #PBS -e {STDERR_LOG_PATH}
@@ -3,4 +3,5 @@
3
3
  #SBATCH -n{CORE_NUM} %core num
4
4
  #SBATCH --time=9999:00:00 %maximum run time
5
5
  #SBATCH --output={STDOUT_LOG_PATH} %stdout output log path
6
- #SBATCH --error={STDERR_LOG_PATH} %error output log path
6
+ #SBATCH --error={STDERR_LOG_PATH} %error output log path
7
+ #SBATCH -p {QUEUE_NAME}
wrfrun/run.py CHANGED
@@ -4,15 +4,15 @@
4
4
 
5
5
  import sys
6
6
  import threading
7
- from os.path import abspath, dirname, exists
7
+ from os.path import abspath, dirname
8
8
  from typing import Optional, Tuple, Union
9
9
 
10
10
  from .core import ExecConfigRecorder, WRFRUNConfig, WRFRunBasicError, WRFRunServer, WRFRunServerHandler, replay_config_generator, stop_server
11
11
  from .data import prepare_wps_input_data
12
- from .model import clear_model_logs, plot_domain_area
13
- from .pbs import in_pbs, prepare_pbs_script
12
+ from .model import clear_model_logs, generate_domain_area
13
+ from .scheduler import in_job_scheduler, prepare_scheduler_script
14
14
  from .utils import call_subprocess, logger, logger_add_file_handler
15
- from .workspace import prepare_workspace
15
+ from .workspace import prepare_workspace, check_workspace
16
16
 
17
17
 
18
18
  def confirm_model_area():
@@ -20,9 +20,9 @@ def confirm_model_area():
20
20
  Ask user to check domain area.
21
21
 
22
22
  """
23
- plot_domain_area()
23
+ generate_domain_area()
24
24
 
25
- if not in_pbs():
25
+ if not in_job_scheduler():
26
26
  # ask user
27
27
  logger.warning(f"Check the domain image, is it right?")
28
28
  answer = input("Is it right? [y/N]: ")
@@ -41,14 +41,14 @@ class WRFRun:
41
41
  _instance = None
42
42
  _initialized = False
43
43
 
44
- def __init__(self, config_file: str, init_workspace=True, start_server=False, pbs_mode=False, prepare_wps_data=False, wps_data_area: Optional[Tuple[int, int, int, int]] = None):
44
+ def __init__(self, config_file: str, init_workspace=True, start_server=False, submit_job=False, prepare_wps_data=False, wps_data_area: Optional[Tuple[int, int, int, int]] = None):
45
45
  """
46
46
  WRFRun, a context class to achieve some goals before and after running WRF, like save a copy of config file, start and close WRFRunServer.
47
47
 
48
48
  :param config_file: ``wrfrun`` config file's path.
49
49
  :param init_workspace: If True, clean old files in workspace and re-create it.
50
50
  :param start_server: Whether to start WRFRunServer, defaults to True.
51
- :param pbs_mode: If commit this task to the PBS system, defaults to True.
51
+ :param submit_job: If commit this task to the PBS system, defaults to True.
52
52
  :param prepare_wps_data: If True, download input datas for WPS first.
53
53
  :param wps_data_area: If ``prepare_wps_data==True``, you need to give the area range of input data so download function can download data from ERA5.
54
54
  :return:
@@ -63,7 +63,7 @@ class WRFRun:
63
63
  self._ip = ""
64
64
  self._port = -1
65
65
 
66
- self._pbs_mode = pbs_mode
66
+ self._submit_job = submit_job
67
67
  self._init_workspace = init_workspace
68
68
  self._prepare_wps_data = prepare_wps_data
69
69
  self._wps_data_area = wps_data_area
@@ -89,31 +89,27 @@ class WRFRun:
89
89
 
90
90
  def __enter__(self):
91
91
  # check workspace
92
- check_list = [WRFRUNConfig.WPS_WORK_PATH, WRFRUNConfig.WRF_WORK_PATH, WRFRUNConfig.WRFDA_WORK_PATH]
93
- check_list = [WRFRUNConfig.parse_resource_uri(x) for x in check_list]
94
- for _path in check_list:
95
- if not exists(_path) and not self._init_workspace:
96
- logger.info(f"Force re-create workspace because it is broken.")
97
- self._init_workspace = True
98
- break
92
+ if not check_workspace():
93
+ logger.info(f"Force re-create workspace because it is broken.")
94
+ self._init_workspace = True
99
95
 
100
96
  # here is the condition we need to initialize workspace:
101
- # 1. pbs_mode = True and init_workspace = True, do prepare_workspace before committing the task to the PBS system.
102
- # 2. pbs_mode = False and init_workspace = True, do prepare_workspace.
103
- if self._pbs_mode and not in_pbs():
97
+ # 1. submit_job = True and init_workspace = True, do prepare_workspace before submitting the task to job scheduler.
98
+ # 2. submit_job = False and init_workspace = True, do prepare_workspace.
99
+ if self._submit_job and not in_job_scheduler():
104
100
  if self._init_workspace:
105
101
  prepare_workspace()
106
102
 
107
103
  # ask user before commit the task
108
104
  confirm_model_area()
109
105
 
110
- prepare_pbs_script(self._entry_file_path)
106
+ prepare_scheduler_script(self._entry_file_path)
111
107
 
112
108
  call_subprocess(["qsub", f"{self._entry_file_dir_path}/run.sh"])
113
109
  logger.info(f"Work has been submit to PBS system")
114
110
  exit(0)
115
111
 
116
- elif not self._pbs_mode:
112
+ elif not self._submit_job:
117
113
  if self._init_workspace:
118
114
  prepare_workspace()
119
115
 
@@ -139,7 +135,7 @@ class WRFRun:
139
135
  else:
140
136
  prepare_wps_input_data(self._wps_data_area)
141
137
 
142
- logger.info(r"Enter wrfrun context")
138
+ logger.debug(r"Enter wrfrun context")
143
139
 
144
140
  return self
145
141
 
@@ -157,7 +153,7 @@ class WRFRun:
157
153
 
158
154
  clear_model_logs()
159
155
 
160
- logger.info(r"Exit wrfrun context")
156
+ logger.debug(r"Exit wrfrun context")
161
157
 
162
158
  def _start_wrfrun_server(self):
163
159
  """
@@ -0,0 +1,35 @@
1
+ """
2
+ wrfrun.scheduler
3
+ ################
4
+
5
+ ``wrfrun`` provides functions to help users take care of the job scheduler.
6
+
7
+ Submodules
8
+ **********
9
+
10
+ ======================================= ===========================================================
11
+ :doc:`env </api/scheduler.env>` Functions to manage environment variables in job scheduler.
12
+ :doc:`lsf </api/scheduler.lsf>` Scheduler interface for LSF job scheduler.
13
+ :doc:`pbs </api/scheduler.pbs>` Scheduler interface for PBS job scheduler.
14
+ :doc:`script </api/scheduler.script>` Generate shell scripts for job scheduler.
15
+ :doc:`slurm </api/scheduler.slurm>` Scheduler interface for Slurm job scheduler.
16
+ :doc:`utils </api/scheduler.utils>` Utility functions.
17
+ ======================================= ===========================================================
18
+
19
+ .. toctree::
20
+ :maxdepth: 1
21
+ :hidden:
22
+
23
+ env <scheduler.env>
24
+ lsf <scheduler.lsf>
25
+ pbs <scheduler.pbs>
26
+ slurm <scheduler.slurm>
27
+ utils <scheduler.utils>
28
+ """
29
+
30
+ from .env import *
31
+ from .lsf import *
32
+ from .pbs import *
33
+ from .script import *
34
+ from .slurm import *
35
+ from .utils import *