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.
Files changed (56) hide show
  1. wrfrun/cli.py +128 -0
  2. wrfrun/core/__init__.py +33 -0
  3. wrfrun/core/base.py +246 -75
  4. wrfrun/core/config.py +286 -236
  5. wrfrun/core/error.py +47 -17
  6. wrfrun/core/replay.py +65 -32
  7. wrfrun/core/server.py +139 -79
  8. wrfrun/data.py +10 -5
  9. wrfrun/extension/__init__.py +28 -0
  10. wrfrun/extension/goos_sst/__init__.py +67 -0
  11. wrfrun/extension/goos_sst/core.py +111 -0
  12. wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST +7 -0
  13. wrfrun/extension/goos_sst/res/__init__.py +26 -0
  14. wrfrun/extension/goos_sst/utils.py +97 -0
  15. wrfrun/extension/littler/__init__.py +57 -1
  16. wrfrun/extension/littler/{utils.py → core.py} +326 -40
  17. wrfrun/extension/utils.py +22 -21
  18. wrfrun/model/__init__.py +24 -1
  19. wrfrun/model/plot.py +253 -35
  20. wrfrun/model/utils.py +17 -8
  21. wrfrun/model/wrf/__init__.py +41 -0
  22. wrfrun/model/wrf/core.py +218 -102
  23. wrfrun/model/wrf/exec_wrap.py +49 -35
  24. wrfrun/model/wrf/namelist.py +82 -11
  25. wrfrun/model/wrf/scheme.py +85 -1
  26. wrfrun/model/wrf/{_metgrid.py → utils.py} +36 -2
  27. wrfrun/model/wrf/vtable.py +2 -1
  28. wrfrun/plot/wps.py +66 -58
  29. wrfrun/res/__init__.py +8 -5
  30. wrfrun/res/config/config.template.toml +50 -0
  31. wrfrun/res/{config.toml.template → config/wrf.template.toml} +10 -47
  32. wrfrun/res/run.template.sh +10 -0
  33. wrfrun/res/scheduler/lsf.template +5 -0
  34. wrfrun/res/{job_scheduler → scheduler}/pbs.template +1 -1
  35. wrfrun/res/{job_scheduler → scheduler}/slurm.template +2 -1
  36. wrfrun/run.py +19 -23
  37. wrfrun/scheduler/__init__.py +35 -0
  38. wrfrun/scheduler/env.py +44 -0
  39. wrfrun/scheduler/lsf.py +47 -0
  40. wrfrun/scheduler/pbs.py +48 -0
  41. wrfrun/scheduler/script.py +70 -0
  42. wrfrun/scheduler/slurm.py +48 -0
  43. wrfrun/scheduler/utils.py +14 -0
  44. wrfrun/utils.py +8 -3
  45. wrfrun/workspace/__init__.py +38 -0
  46. wrfrun/workspace/core.py +92 -0
  47. wrfrun/workspace/wrf.py +121 -0
  48. {wrfrun-0.1.7.dist-info → wrfrun-0.1.9.dist-info}/METADATA +4 -3
  49. wrfrun-0.1.9.dist-info/RECORD +62 -0
  50. wrfrun-0.1.9.dist-info/entry_points.txt +3 -0
  51. wrfrun/model/wrf/_ndown.py +0 -39
  52. wrfrun/pbs.py +0 -86
  53. wrfrun/res/run.sh.template +0 -16
  54. wrfrun/workspace.py +0 -88
  55. wrfrun-0.1.7.dist-info/RECORD +0 -46
  56. {wrfrun-0.1.7.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.
@@ -79,18 +151,16 @@ def prepare_wps_namelist():
79
151
  "dy": wrf_config["domain"]["dy"],
80
152
  "ref_lat": wrf_config["domain"]["ref_lat"],
81
153
  "ref_lon": wrf_config["domain"]["ref_lon"],
154
+ "map_proj": wrf_config["domain"]["map_proj"],
155
+ "truelat1": wrf_config["domain"]["truelat1"],
156
+ "truelat2": wrf_config["domain"]["truelat2"],
82
157
  "stand_lon": wrf_config["domain"]["stand_lon"],
83
158
  "geog_data_path": wrf_config["geog_data_path"]
84
- }
159
+ },
160
+ "ungrib": {"prefix": f"{UNGRIB_OUTPUT_DIR}/FILE"},
161
+ "metgrid": {"fg_name": f"{UNGRIB_OUTPUT_DIR}/FILE"}
85
162
  }
86
163
 
87
- # # use loop to process config of map_proj
88
- for key in wrf_config["domain"]["map_proj"]:
89
- if key == "name":
90
- update_value["geogrid"]["map_proj"] = wrf_config["domain"]["map_proj"][key]
91
- else:
92
- update_value["geogrid"][key] = wrf_config["domain"]["map_proj"][key]
93
-
94
164
  # # update namelist
95
165
  WRFRUNConfig.update_namelist(update_value, "wps")
96
166
 
@@ -111,7 +181,7 @@ def prepare_wrf_namelist():
111
181
  wrf_config = WRFRUNConfig.get_model_config("wrf")
112
182
 
113
183
  # get debug level
114
- debug_level = WRFRUNConfig["model"]["debug_level"]
184
+ debug_level = wrf_config["debug_level"]
115
185
 
116
186
  # get domain number, start_date and end_date
117
187
  max_dom = wrf_config["domain"]["domain_num"]
@@ -374,4 +444,5 @@ def prepare_wrfda_namelist():
374
444
  WRFRUNConfig.update_namelist(user_namelist_data, "wrfda")
375
445
 
376
446
 
377
- __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"]
@@ -308,4 +308,88 @@ class SchemeSurfaceLayer:
308
308
  return integer_label_map[key]
309
309
 
310
310
 
311
- __all__ = ["SchemeCumulus", "SchemeLandSurfaceModel", "SchemeLongWave", "SchemePBL", "SchemeShortWave", "SchemeSurfaceLayer"]
311
+ @dataclass()
312
+ class SchemeMicrophysics:
313
+ """
314
+ Microphysics schemes.
315
+ """
316
+ OFF = 0
317
+ KESSLER = 1
318
+ PURDUE_LIN = 2
319
+ WSM_3_CLASS_ICE = 3
320
+ WSM_5_CLASS = 4
321
+ FERRIER_ETA = 5
322
+ WSM_6_CLASS_GRAUPEL = 6
323
+ GODDARD_4_ICE = 7
324
+ THOMPSON_GRAUPEL = 8
325
+ MILBRANDT_YAU_2_MOMENT = 9
326
+ MORRISON_2_MOMENT = 10
327
+ CAM_V51_5_CLASS = 11
328
+ SBU_YLIN_5_CLASS = 13
329
+ WDM_5_CLASS = 14
330
+ HIGH_FERRIER_ADVECTION = 15
331
+ WDM_6_CLASS = 16
332
+ NSSL_2_MOMENT_4_ICE = 18
333
+ WSM7 = 24
334
+ WDM7 = 26
335
+ AEROSOL_AWARE_THOMPSON = 28
336
+ HUJI = 30
337
+ THOMPSON_HAIL_GRAUPEL_AEROSOL = 38
338
+ MORRISON_WITH_CESM_AEROSOL = 40
339
+ P3_1_ICE_1_MOMENT_QCLOUD = 50
340
+ P3_1_ICE_2_MOMENT_QCLOUD = 51
341
+ P3_2_ICE_2_MOMENT_QCLOUD = 52
342
+ P3_1_ICE_3_MOMENT_ICE_2_MOMENT_QCLOUD = 53
343
+ JENSEN_ISHMAEL = 55
344
+ NTU = 56
345
+
346
+ @classmethod
347
+ def get_scheme_id(cls, key: str = "lin"):
348
+ """Get corresponding integer label for microphysics scheme
349
+
350
+ Args:
351
+ key (str, optional): Name of microphysics scheme. Defaults to "PURDUE_LIN".
352
+ """
353
+ # Here is the map of scheme name and integer label in WRF
354
+ # Reference link: https://www2.mmm.ucar.edu/wrf/users/wrf_users_guide/build/html/namelist_variables.html
355
+ integer_label_map = {
356
+ "off": cls.OFF,
357
+ "kessler": cls.KESSLER,
358
+ "lin": cls.PURDUE_LIN,
359
+ "wsm3": cls.WSM_3_CLASS_ICE,
360
+ "wsm5": cls.WSM_5_CLASS,
361
+ "ferrier": cls.FERRIER_ETA,
362
+ "wsm6": cls.WDM_6_CLASS,
363
+ "goddard4": cls.GODDARD_4_ICE,
364
+ "thompson": cls.THOMPSON_GRAUPEL,
365
+ "milbrandt": cls.MILBRANDT_YAU_2_MOMENT,
366
+ "morrison2": cls.MORRISON_2_MOMENT,
367
+ "cam": cls.CAM_V51_5_CLASS,
368
+ "sbu": cls.SBU_YLIN_5_CLASS,
369
+ "wdm5": cls.WDM_5_CLASS,
370
+ "high_ferrier": cls.HIGH_FERRIER_ADVECTION,
371
+ "wdm6": cls.WDM_6_CLASS,
372
+ "nssl": cls.NSSL_2_MOMENT_4_ICE,
373
+ "wsm7": cls.WSM7,
374
+ "wdm7": cls.WDM7,
375
+ "thompson_aerosol": cls.AEROSOL_AWARE_THOMPSON,
376
+ "cesm_morrison": cls.MORRISON_WITH_CESM_AEROSOL,
377
+ "p311": cls.P3_1_ICE_1_MOMENT_QCLOUD,
378
+ "p312": cls.P3_1_ICE_2_MOMENT_QCLOUD,
379
+ "p322": cls.P3_2_ICE_2_MOMENT_QCLOUD,
380
+ "p3132": cls.P3_1_ICE_3_MOMENT_ICE_2_MOMENT_QCLOUD,
381
+ "jensen": cls.JENSEN_ISHMAEL,
382
+ "ntu": cls.NTU,
383
+ }
384
+
385
+ # check if key is in map
386
+ if key not in integer_label_map:
387
+ logger.error(
388
+ f"Key error: {key}. Valid key: {list(integer_label_map.keys())}"
389
+ )
390
+ raise KeyError
391
+
392
+ return integer_label_map[key]
393
+
394
+
395
+ __all__ = ["SchemeCumulus", "SchemeLandSurfaceModel", "SchemeLongWave", "SchemePBL", "SchemeShortWave", "SchemeSurfaceLayer", "SchemeMicrophysics"]
@@ -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/plot/wps.py CHANGED
@@ -12,29 +12,29 @@ from xarray import DataArray
12
12
  from wrfrun.utils import logger
13
13
 
14
14
  # Here defines the colormap for landuse and soiltype
15
- LANDUSE_CMAP = ListedColormap([
16
- [0, .4, 0], # 1 Evergreen Needleleaf Forest
17
- [0, .4, .2], # 2 Evergreen Broadleaf Forest
18
- [.2, .8, .2], # 3 Deciduous Needleleaf Forest
19
- [.2, .8, .4], # 4 Deciduous Broadleaf Forest
20
- [.2, .6, .2], # 5 Mixed Forests
21
- [.3, .7, 0], # 6 Closed Shrublands
22
- [.82, .41, .12], # 7 Open Shurblands
23
- [.74, .71, .41], # 8 Woody Savannas
24
- [1, .84, .0], # 9 Savannas
25
- [0, 1, 0], # 10 Grasslands
26
- [0, 1, 1], # 11 Permanant Wetlands
27
- [1, 1, 0], # 12 Croplands
28
- [1, 0, 0], # 13 Urban and Built-up
29
- [.7, .9, .3], # 14 Cropland/Natual Vegation Mosaic
30
- [1, 1, 1], # 15 Snow and Ice
31
- [.914, .914, .7], # 16 Barren or Sparsely Vegetated
32
- [.5, .7, 1], # 17 Water (like oceans)
33
- [.86, .08, .23], # 18 Wooded Tundra
34
- [.97, .5, .31], # 19 Mixed Tundra
35
- [.91, .59, .48], # 20 Barren Tundra
36
- [0, 0, .88], # 21 Lake
37
- ])
15
+ LANDUSE_CMAP = ListedColormap((
16
+ [0, .4, 0], # 1: Evergreen Needleleaf Forest
17
+ [0, .4, .2], # 2: Evergreen Broadleaf Forest
18
+ [.2, .8, .2], # 3: Deciduous Needleleaf Forest
19
+ [.2, .8, .4], # 4: Deciduous Broadleaf Forest
20
+ [.2, .6, .2], # 5: Mixed Forests
21
+ [.3, .7, 0], # 6: Closed Shrublands
22
+ [.82, .41, .12], # 7: Open Shurblands
23
+ [.74, .71, .41], # 8: Woody Savannas
24
+ [1, .84, .0], # 9: Savannas
25
+ [0, 1, 0], # 10: Grasslands
26
+ [0, 1, 1], # 11: Permanent Wetlands
27
+ [1, 1, 0], # 12: Croplands
28
+ [1, 0, 0], # 13: Urban and Built-up
29
+ [.7, .9, .3], # 14: Cropland/Natual Vegation Mosaic
30
+ [1, 1, 1], # 15: Snow and Ice
31
+ [.914, .914, .7], # 16: Barren or Sparsely Vegetated
32
+ [.5, .7, 1], # 17: Water (like oceans)
33
+ [.86, .08, .23], # 18: Wooded Tundra
34
+ [.97, .5, .31], # 19: Mixed Tundra
35
+ [.91, .59, .48], # 20: Barren Tundra
36
+ [0, 0, .88], # 21: Lake
37
+ ))
38
38
 
39
39
  LANDUSE_LABELS = [
40
40
  'Evergreen Needleleaf Forest',
@@ -61,25 +61,25 @@ LANDUSE_LABELS = [
61
61
  ]
62
62
 
63
63
 
64
- # Here defines the colormap and labels for soil type
65
- SOILTYPE_CMAP = ListedColormap([
66
- [0, .4, 0], # 1 Sand
67
- [0, .4, .2], # 2 Loamy Sand
68
- [.2, .8, .2], # 3 Sandy Loam
69
- [.2, .8, .4], # 4 Silt Loam
70
- [.2, .6, .2], # 5 Silt
71
- [.3, .7, 0], # 6 Loam
72
- [.82, .41, .12], # 7 Sandy Clay Loam
73
- [.74, .71, .41], # 8 Silty Clay Loam
74
- [1, .84, .0], # 9 Clay Loam
75
- [0, 1, 0], # 10 Sandy Clay
76
- [0, 1, 1], # 11 Silty Clay
77
- [1, 1, 0], # 12 Clay
78
- [1, 0, 0], # 13 Organic Material
79
- [.7, .9, .3], # 14 Water
80
- [1, 1, 1], # 15 Bedrock
81
- [.914, .914, .7] # 16 Other
82
- ])
64
+ # Here defines the colormap and labels for soil types
65
+ SOILTYPE_CMAP = ListedColormap((
66
+ [0, .4, 0], # 1: Sand
67
+ [0, .4, .2], # 2: Loamy Sand
68
+ [.2, .8, .2], # 3: Sandy Loam
69
+ [.2, .8, .4], # 4: Silt Loam
70
+ [.2, .6, .2], # 5: Silt
71
+ [.3, .7, 0], # 6: Loam
72
+ [.82, .41, .12], # 7: Sandy Clay Loam
73
+ [.74, .71, .41], # 8: Silty Clay Loam
74
+ [1, .84, .0], # 9: Clay Loam
75
+ [0, 1, 0], # 10: Sandy Clay
76
+ [0, 1, 1], # 11: Silty Clay
77
+ [1, 1, 0], # 12: Clay
78
+ [1, 0, 0], # 13: Organic Material
79
+ [.7, .9, .3], # 14: Water
80
+ [1, 1, 1], # 15: Bedrock
81
+ [.914, .914, .7] # 16: Other
82
+ ))
83
83
 
84
84
  SOILTYPE_LABELS = [
85
85
  "Sand",
@@ -102,13 +102,13 @@ SOILTYPE_LABELS = [
102
102
 
103
103
 
104
104
  def get_cmap_ticks(name: str) -> tuple:
105
- """Get corresponding colormap, labels and ticks.
106
-
107
- Args:
108
- name (str): Field name.
105
+ """
106
+ Get corresponding colormap, labels and ticks.
109
107
 
110
- Returns:
111
- tuple: (colormap, labels, ticks)
108
+ :param name: File name.
109
+ :type name: str
110
+ :return: (colormap, labels, ticks)
111
+ :rtype: tuple
112
112
  """
113
113
  # name map
114
114
  cmap_ticks_map = {
@@ -141,15 +141,23 @@ def get_cmap_ticks(name: str) -> tuple:
141
141
 
142
142
 
143
143
  def draw_geogrid(data_path: str, field: str, fig: Figure, nrow: int, ncol: int, index: int) -> Tuple[GeoAxes, QuadMesh]:
144
- """Draw specific data in geo_em*
145
-
146
- Args:
147
- data_path (str): data path.
148
- field (str): Which field you want to draw.
149
- fig (Figure): Matplotlib figure object.
150
- nrow (int): Row number of axes.
151
- ncol (int): Column number of axes.
152
- index (int): Index of axes.
144
+ """
145
+ Draw specific data in geogrid outputs.
146
+
147
+ :param data_path: Data path.
148
+ :type data_path: str
149
+ :param field: Which field you want to draw.
150
+ :type field: str
151
+ :param fig: Matplotlib figure object.
152
+ :type fig: Figure
153
+ :param nrow: Row number of axes.
154
+ :type nrow: int
155
+ :param ncol: Column number of axes.
156
+ :type ncol: int
157
+ :param index: Index of axes.
158
+ :type index: int
159
+ :return: (GeoAxes, QuadMesh)
160
+ :rtype: tuple
153
161
  """
154
162
  # take out data
155
163
  data: DataArray = getvar(Dataset(data_path), field) # type: ignore
@@ -159,7 +167,7 @@ def draw_geogrid(data_path: str, field: str, fig: Figure, nrow: int, ncol: int,
159
167
  data = data.argmax(dim="soil_cat", keep_attrs=True) # type: ignore
160
168
  # get data attrs
161
169
  data_attrs = data.attrs
162
- data = data + 1
170
+ data = data + 1 # type: ignore
163
171
  data.attrs = data_attrs
164
172
 
165
173
  # get latitude and longitude
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"