wrfrun 0.1.9__py3-none-any.whl → 0.3.0__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 (66) hide show
  1. wrfrun/__init__.py +8 -3
  2. wrfrun/cli.py +74 -31
  3. wrfrun/core/__init__.py +27 -10
  4. wrfrun/core/_config.py +308 -0
  5. wrfrun/core/_constant.py +236 -0
  6. wrfrun/core/_exec_db.py +105 -0
  7. wrfrun/core/_namelist.py +287 -0
  8. wrfrun/core/_record.py +178 -0
  9. wrfrun/core/_resource.py +172 -0
  10. wrfrun/core/base.py +136 -380
  11. wrfrun/core/core.py +196 -0
  12. wrfrun/core/error.py +35 -2
  13. wrfrun/core/replay.py +10 -96
  14. wrfrun/core/server.py +74 -32
  15. wrfrun/core/type.py +171 -0
  16. wrfrun/data.py +312 -149
  17. wrfrun/extension/goos_sst/__init__.py +2 -2
  18. wrfrun/extension/goos_sst/core.py +9 -14
  19. wrfrun/extension/goos_sst/res/__init__.py +0 -1
  20. wrfrun/extension/goos_sst/utils.py +50 -44
  21. wrfrun/extension/littler/core.py +105 -88
  22. wrfrun/extension/utils.py +5 -3
  23. wrfrun/log.py +117 -0
  24. wrfrun/model/__init__.py +11 -7
  25. wrfrun/model/constants.py +52 -0
  26. wrfrun/model/palm/__init__.py +30 -0
  27. wrfrun/model/palm/core.py +145 -0
  28. wrfrun/model/palm/namelist.py +33 -0
  29. wrfrun/model/plot.py +99 -114
  30. wrfrun/model/type.py +116 -0
  31. wrfrun/model/utils.py +9 -19
  32. wrfrun/model/wrf/__init__.py +4 -9
  33. wrfrun/model/wrf/core.py +262 -165
  34. wrfrun/model/wrf/exec_wrap.py +13 -12
  35. wrfrun/model/wrf/geodata.py +116 -99
  36. wrfrun/model/wrf/log.py +103 -0
  37. wrfrun/model/wrf/namelist.py +92 -76
  38. wrfrun/model/wrf/plot.py +102 -0
  39. wrfrun/model/wrf/scheme.py +108 -52
  40. wrfrun/model/wrf/utils.py +39 -24
  41. wrfrun/model/wrf/vtable.py +42 -7
  42. wrfrun/plot/__init__.py +20 -0
  43. wrfrun/plot/wps.py +90 -73
  44. wrfrun/res/__init__.py +115 -5
  45. wrfrun/res/config/config.template.toml +15 -0
  46. wrfrun/res/config/palm.template.toml +23 -0
  47. wrfrun/run.py +121 -77
  48. wrfrun/scheduler/__init__.py +1 -0
  49. wrfrun/scheduler/lsf.py +4 -1
  50. wrfrun/scheduler/pbs.py +4 -1
  51. wrfrun/scheduler/script.py +19 -5
  52. wrfrun/scheduler/slurm.py +4 -1
  53. wrfrun/scheduler/utils.py +14 -2
  54. wrfrun/utils.py +88 -199
  55. wrfrun/workspace/__init__.py +8 -5
  56. wrfrun/workspace/core.py +21 -11
  57. wrfrun/workspace/palm.py +137 -0
  58. wrfrun/workspace/wrf.py +59 -14
  59. wrfrun-0.3.0.dist-info/METADATA +240 -0
  60. wrfrun-0.3.0.dist-info/RECORD +78 -0
  61. wrfrun/core/config.py +0 -767
  62. wrfrun/model/base.py +0 -14
  63. wrfrun-0.1.9.dist-info/METADATA +0 -68
  64. wrfrun-0.1.9.dist-info/RECORD +0 -62
  65. {wrfrun-0.1.9.dist-info → wrfrun-0.3.0.dist-info}/WHEEL +0 -0
  66. {wrfrun-0.1.9.dist-info → wrfrun-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,13 +1,33 @@
1
+ """
2
+ wrfrun.model.wrf.namelist
3
+ #########################
4
+
5
+ Functions to read and change WPS/WRF namelist.
6
+
7
+ .. autosummary::
8
+ :toctree: generated/
9
+
10
+ prepare_wrf_namelist
11
+ prepare_wps_namelist
12
+ prepare_wrfda_namelist
13
+ prepare_dfi_namelist
14
+ get_ungrib_out_prefix
15
+ get_ungrib_out_dir_path
16
+ set_ungrib_out_prefix
17
+ get_metgrid_fg_names
18
+ set_metgrid_fg_names
19
+ """
20
+
1
21
  from datetime import datetime, timedelta
2
- from os.path import exists, dirname, basename
22
+ from os.path import basename, dirname, exists
3
23
  from typing import Union
4
24
 
5
- from wrfrun.core import WRFRUNConfig
25
+ from wrfrun.log import logger
6
26
  from wrfrun.res import NAMELIST_DFI, NAMELIST_WPS, NAMELIST_WRF, NAMELIST_WRFDA
7
- from wrfrun.utils import logger
8
- from wrfrun.workspace.wrf import WORKSPACE_MODEL_WPS
9
- from .scheme import *
27
+ from wrfrun.workspace.wrf import get_wrf_workspace_path
10
28
 
29
+ from ...core.core import WRFRUN
30
+ from .scheme import SchemeCumulus, SchemeLandSurfaceModel, SchemeLongWave, SchemePBL, SchemeShortWave, SchemeSurfaceLayer
11
31
 
12
32
  UNGRIB_OUTPUT_DIR = "./outputs"
13
33
 
@@ -19,8 +39,8 @@ def get_ungrib_out_dir_path() -> str:
19
39
  :return: URI path.
20
40
  :rtype: str
21
41
  """
22
- wif_prefix = WRFRUNConfig.get_namelist("wps")["ungrib"]["prefix"]
23
- wif_path = f"{WORKSPACE_MODEL_WPS}/{dirname(wif_prefix)}"
42
+ wif_prefix = WRFRUN.config.get_namelist("wps")["ungrib"]["prefix"]
43
+ wif_path = f"{get_wrf_workspace_path('wps')}/{dirname(wif_prefix)}"
24
44
 
25
45
  return wif_path
26
46
 
@@ -32,7 +52,7 @@ def get_ungrib_out_prefix() -> str:
32
52
  :return: Prefix string of ungrib output (WRF intermediate file).
33
53
  :rtype: str
34
54
  """
35
- wif_prefix = WRFRUNConfig.get_namelist("wps")["ungrib"]["prefix"]
55
+ wif_prefix = WRFRUN.config.get_namelist("wps")["ungrib"]["prefix"]
36
56
  wif_prefix = basename(wif_prefix)
37
57
  return wif_prefix
38
58
 
@@ -44,11 +64,7 @@ def set_ungrib_out_prefix(prefix: str):
44
64
  :param prefix: Prefix string of ungrib output (WRF intermediate file).
45
65
  :type prefix: str
46
66
  """
47
- WRFRUNConfig.update_namelist(
48
- {
49
- "ungrib": {"prefix": f"{UNGRIB_OUTPUT_DIR}/{prefix}"}
50
- }, "wps"
51
- )
67
+ WRFRUN.config.update_namelist({"ungrib": {"prefix": f"{UNGRIB_OUTPUT_DIR}/{prefix}"}}, "wps")
52
68
 
53
69
 
54
70
  def get_metgrid_fg_names() -> list[str]:
@@ -58,7 +74,7 @@ def get_metgrid_fg_names() -> list[str]:
58
74
  :return: Prefix strings list.
59
75
  :rtype: list
60
76
  """
61
- fg_names = WRFRUNConfig.get_namelist("wps")["metgrid"]["fg_name"]
77
+ fg_names = WRFRUN.config.get_namelist("wps")["metgrid"]["fg_name"]
62
78
  fg_names = [basename(x) for x in fg_names]
63
79
  return fg_names
64
80
 
@@ -71,16 +87,16 @@ def set_metgrid_fg_names(prefix: Union[str, list[str]]):
71
87
  :type prefix: str | list
72
88
  """
73
89
  if isinstance(prefix, str):
74
- prefix = [prefix, ]
90
+ prefix = [
91
+ prefix,
92
+ ]
75
93
  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
- )
94
+ WRFRUN.config.update_namelist({"metgrid": {"fg_name": fg_names}}, "wps")
81
95
 
82
96
 
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]]:
97
+ def _check_start_end_date(
98
+ max_dom: int, start_date: Union[datetime, list[datetime]], end_date: Union[datetime, list[datetime]]
99
+ ) -> tuple[list[datetime], list[datetime]]:
84
100
  """
85
101
  Format start date and end date.
86
102
 
@@ -116,8 +132,8 @@ def prepare_wps_namelist():
116
132
 
117
133
  """
118
134
  # prepare namelist
119
- WRFRUNConfig.read_namelist(WRFRUNConfig.parse_resource_uri(NAMELIST_WPS), "wps")
120
- wrf_config = WRFRUNConfig.get_model_config("wrf")
135
+ WRFRUN.config.read_namelist(WRFRUN.config.parse_resource_uri(NAMELIST_WPS), "wps")
136
+ wrf_config = WRFRUN.config.get_model_config("wrf")
121
137
 
122
138
  # get domain number
123
139
  max_dom = wrf_config["domain"]["domain_num"]
@@ -135,12 +151,7 @@ def prepare_wps_namelist():
135
151
 
136
152
  # generate update settings based on the config file
137
153
  update_value = {
138
- "share": {
139
- "max_dom": max_dom,
140
- "start_date": start_date,
141
- "end_date": end_date,
142
- "interval_seconds": interval_seconds
143
- },
154
+ "share": {"max_dom": max_dom, "start_date": start_date, "end_date": end_date, "interval_seconds": interval_seconds},
144
155
  "geogrid": {
145
156
  "parent_grid_ratio": wrf_config["domain"]["parent_grid_ratio"],
146
157
  "i_parent_start": wrf_config["domain"]["i_parent_start"],
@@ -155,18 +166,18 @@ def prepare_wps_namelist():
155
166
  "truelat1": wrf_config["domain"]["truelat1"],
156
167
  "truelat2": wrf_config["domain"]["truelat2"],
157
168
  "stand_lon": wrf_config["domain"]["stand_lon"],
158
- "geog_data_path": wrf_config["geog_data_path"]
169
+ "geog_data_path": wrf_config["geog_data_path"],
159
170
  },
160
171
  "ungrib": {"prefix": f"{UNGRIB_OUTPUT_DIR}/FILE"},
161
- "metgrid": {"fg_name": f"{UNGRIB_OUTPUT_DIR}/FILE"}
172
+ "metgrid": {"fg_name": f"{UNGRIB_OUTPUT_DIR}/FILE"},
162
173
  }
163
174
 
164
175
  # # update namelist
165
- WRFRUNConfig.update_namelist(update_value, "wps")
176
+ WRFRUN.config.update_namelist(update_value, "wps")
166
177
 
167
178
  # # update settings from custom namelist
168
179
  if wrf_config["user_wps_namelist"] != "" and exists(wrf_config["user_wps_namelist"]):
169
- WRFRUNConfig.update_namelist(wrf_config["user_wps_namelist"], "wps")
180
+ WRFRUN.config.update_namelist(wrf_config["user_wps_namelist"], "wps")
170
181
 
171
182
 
172
183
  def prepare_wrf_namelist():
@@ -175,10 +186,10 @@ def prepare_wrf_namelist():
175
186
 
176
187
  """
177
188
  # read template namelist
178
- WRFRUNConfig.read_namelist(WRFRUNConfig.parse_resource_uri(NAMELIST_WRF), "wrf")
189
+ WRFRUN.config.read_namelist(WRFRUN.config.parse_resource_uri(NAMELIST_WRF), "wrf")
179
190
 
180
191
  # wrf config from config
181
- wrf_config = WRFRUNConfig.get_model_config("wrf")
192
+ wrf_config = WRFRUN.config.get_model_config("wrf")
182
193
 
183
194
  # get debug level
184
195
  debug_level = wrf_config["debug_level"]
@@ -187,7 +198,7 @@ def prepare_wrf_namelist():
187
198
  max_dom = wrf_config["domain"]["domain_num"]
188
199
  start_date = wrf_config["time"]["start_date"]
189
200
  end_date = wrf_config["time"]["end_date"]
190
-
201
+
191
202
  start_date, end_date = _check_start_end_date(max_dom, start_date, end_date)
192
203
 
193
204
  # get the time interval of input data and output data
@@ -251,9 +262,8 @@ def prepare_wrf_namelist():
251
262
  "e_sn": wrf_config["domain"]["e_sn"],
252
263
  "dx": dx,
253
264
  "dy": dy,
254
-
255
265
  },
256
- "physics": {}
266
+ "physics": {},
257
267
  }
258
268
 
259
269
  # and we need to check the physics scheme option
@@ -266,11 +276,12 @@ def prepare_wrf_namelist():
266
276
  update_values["physics"].update(long_wave_scheme)
267
277
 
268
278
  short_wave_scheme = {
269
- "ra_sw_physics": [SchemeShortWave.get_scheme_id(wrf_config["scheme"]["short_wave_scheme"]["name"]) for _ in range(max_dom)]
279
+ "ra_sw_physics": [
280
+ SchemeShortWave.get_scheme_id(wrf_config["scheme"]["short_wave_scheme"]["name"]) for _ in range(max_dom)
281
+ ]
270
282
  }
271
283
  # # and other related options
272
- short_wave_scheme.update(
273
- wrf_config["scheme"]["short_wave_scheme"]["option"])
284
+ short_wave_scheme.update(wrf_config["scheme"]["short_wave_scheme"]["option"])
274
285
  # update
275
286
  update_values["physics"].update(short_wave_scheme)
276
287
 
@@ -282,49 +293,47 @@ def prepare_wrf_namelist():
282
293
  # update
283
294
  update_values["physics"].update(cumulus_scheme)
284
295
 
285
- pbl_scheme = {
286
- "bl_pbl_physics": [SchemePBL.get_scheme_id(wrf_config["scheme"]["pbl_scheme"]["name"]) for _ in range(max_dom)]
287
- }
296
+ pbl_scheme = {"bl_pbl_physics": [SchemePBL.get_scheme_id(wrf_config["scheme"]["pbl_scheme"]["name"]) for _ in range(max_dom)]}
288
297
  # # and other related options
289
298
  pbl_scheme.update(wrf_config["scheme"]["pbl_scheme"]["option"])
290
299
  # update
291
300
  update_values["physics"].update(pbl_scheme)
292
301
 
293
302
  land_surface_scheme = {
294
- "sf_surface_physics": [SchemeLandSurfaceModel.get_scheme_id(wrf_config["scheme"]["land_surface_scheme"]["name"]) for _ in range(max_dom)]
303
+ "sf_surface_physics": [
304
+ SchemeLandSurfaceModel.get_scheme_id(wrf_config["scheme"]["land_surface_scheme"]["name"]) for _ in range(max_dom)
305
+ ]
295
306
  }
296
307
  # # and other related options
297
- land_surface_scheme.update(
298
- wrf_config["scheme"]["land_surface_scheme"]["option"])
308
+ land_surface_scheme.update(wrf_config["scheme"]["land_surface_scheme"]["option"])
299
309
  # update
300
310
  update_values["physics"].update(land_surface_scheme)
301
311
 
302
312
  surface_layer_scheme = {
303
- "sf_sfclay_physics": [SchemeSurfaceLayer.get_scheme_id(wrf_config["scheme"]["surface_layer_scheme"]["name"]) for _ in range(max_dom)]
313
+ "sf_sfclay_physics": [
314
+ SchemeSurfaceLayer.get_scheme_id(wrf_config["scheme"]["surface_layer_scheme"]["name"]) for _ in range(max_dom)
315
+ ]
304
316
  }
305
317
  # # and other related options
306
- surface_layer_scheme.update(
307
- wrf_config["scheme"]["surface_layer_scheme"]["option"])
318
+ surface_layer_scheme.update(wrf_config["scheme"]["surface_layer_scheme"]["option"])
308
319
  # update
309
320
  update_values["physics"].update(surface_layer_scheme)
310
321
 
311
322
  # update namelist
312
- WRFRUNConfig.update_namelist(update_values, "wrf")
323
+ WRFRUN.config.update_namelist(update_values, "wrf")
313
324
 
314
325
  # read user real namelist and update value
315
326
  user_namelist_data = wrf_config["user_wrf_namelist"]
316
327
  if user_namelist_data != "" and exists(user_namelist_data):
317
- WRFRUNConfig.update_namelist(user_namelist_data, "wrf")
328
+ WRFRUN.config.update_namelist(user_namelist_data, "wrf")
318
329
 
319
330
 
320
331
  def prepare_dfi_namelist():
321
- """Generate namelist data for DFI running
322
-
323
- """
332
+ """Generate namelist data for DFI running"""
324
333
  # Read template namelist
325
- WRFRUNConfig.read_namelist(WRFRUNConfig.parse_resource_uri(NAMELIST_DFI), "dfi")
334
+ WRFRUN.config.read_namelist(WRFRUN.config.parse_resource_uri(NAMELIST_DFI), "dfi")
326
335
 
327
- wrf_config = WRFRUNConfig.get_model_config("wrf")
336
+ wrf_config = WRFRUN.config.get_model_config("wrf")
328
337
 
329
338
  # Read start date and end date
330
339
  start_date = wrf_config["time"]["start_date"]
@@ -366,7 +375,9 @@ def prepare_dfi_namelist():
366
375
  "end_minute": [start_date.minute],
367
376
  "end_second": [start_date.second],
368
377
  "interval_seconds": input_data_interval,
369
- "auxinput4_interval_s": [input_data_interval, ]
378
+ "auxinput4_interval_s": [
379
+ input_data_interval,
380
+ ],
370
381
  },
371
382
  "domains": {
372
383
  # make sure max_dom = 1
@@ -395,26 +406,24 @@ def prepare_dfi_namelist():
395
406
  "dfi_fwdstop_hour": dfi_end_date.hour,
396
407
  "dfi_fwdstop_minute": dfi_end_date.minute,
397
408
  "dfi_fwdstop_second": dfi_end_date.second,
398
- }
409
+ },
399
410
  }
400
411
 
401
412
  # update namelist data
402
- WRFRUNConfig.update_namelist(update_value, "dfi")
413
+ WRFRUN.config.update_namelist(update_value, "dfi")
403
414
 
404
415
  # read user wrf namelist and update value
405
416
  user_namelist_data = wrf_config["user_wrf_namelist"]
406
417
  if user_namelist_data != "" and exists(user_namelist_data):
407
- WRFRUNConfig.update_namelist(user_namelist_data, "dfi")
418
+ WRFRUN.config.update_namelist(user_namelist_data, "dfi")
408
419
 
409
420
 
410
421
  def prepare_wrfda_namelist():
411
- """Generate namelist for da_wrfvar.exe
412
-
413
- """
422
+ """Generate namelist for da_wrfvar.exe"""
414
423
  # read template namelist
415
- WRFRUNConfig.read_namelist(WRFRUNConfig.parse_resource_uri(NAMELIST_WRFDA), "wrfda")
424
+ WRFRUN.config.read_namelist(WRFRUN.config.parse_resource_uri(NAMELIST_WRFDA), "wrfda")
416
425
 
417
- wrf_config = WRFRUNConfig.get_model_config("wrf")
426
+ wrf_config = WRFRUN.config.get_model_config("wrf")
418
427
 
419
428
  # get wrf start date
420
429
  start_date = wrf_config["time"]["start_date"]
@@ -422,9 +431,7 @@ def prepare_wrfda_namelist():
422
431
 
423
432
  # generate update value
424
433
  update_value = {
425
- "wrfvar18": {
426
- "analysis_date": start_date.strftime("%Y-%m-%d_%H:%M:%S.0000")
427
- },
434
+ "wrfvar18": {"analysis_date": start_date.strftime("%Y-%m-%d_%H:%M:%S.0000")},
428
435
  "wrfvar21": {
429
436
  # one hour before wrf start date
430
437
  "time_window_min": (start_date - timedelta(hours=1)).strftime("%Y-%m-%d_%H:%M:%S.0000")
@@ -432,17 +439,26 @@ def prepare_wrfda_namelist():
432
439
  "wrfvar22": {
433
440
  # one hour after wrf start date
434
441
  "time_window_max": (start_date + timedelta(hours=1)).strftime("%Y-%m-%d_%H:%M:%S.0000")
435
- }
442
+ },
436
443
  }
437
444
 
438
445
  # update namelist
439
- WRFRUNConfig.update_namelist(update_value, "wrfda")
446
+ WRFRUN.config.update_namelist(update_value, "wrfda")
440
447
 
441
448
  # read user wrfda namelist and update value
442
449
  user_namelist_data = wrf_config["user_wrfda_namelist"]
443
450
  if user_namelist_data != "" and exists(user_namelist_data):
444
- WRFRUNConfig.update_namelist(user_namelist_data, "wrfda")
445
-
446
-
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"]
451
+ WRFRUN.config.update_namelist(user_namelist_data, "wrfda")
452
+
453
+
454
+ __all__ = [
455
+ "prepare_wrf_namelist",
456
+ "prepare_wps_namelist",
457
+ "prepare_wrfda_namelist",
458
+ "prepare_dfi_namelist",
459
+ "get_ungrib_out_prefix",
460
+ "get_ungrib_out_dir_path",
461
+ "set_ungrib_out_prefix",
462
+ "get_metgrid_fg_names",
463
+ "set_metgrid_fg_names",
464
+ ]
@@ -0,0 +1,102 @@
1
+ """
2
+ wrfrun.model.wrf.plot
3
+ #####################
4
+
5
+ Functions to generate config to plot domain area.
6
+
7
+ .. autosummary::
8
+ :toctree: generated/
9
+
10
+ domain_settings_from_config_wrf
11
+ domain_settings_from_namelist_wrf
12
+ """
13
+
14
+ from os.path import exists
15
+ from typing import Union
16
+
17
+ import f90nml
18
+
19
+ from wrfrun.core import WRFRUN
20
+ from wrfrun.log import logger
21
+
22
+ from ..type import DomainSetting
23
+
24
+
25
+ def domain_settings_from_config_wrf() -> DomainSetting:
26
+ """
27
+ Generate domain settings based on the config from :doc:`WRFRUN </api/core.core>`.
28
+
29
+ :return: :class:`DomainSetting <wrfrun.model.type.DomainSetting>` object.
30
+ :rtype: DomainSetting
31
+ """
32
+ user_settings = WRFRUN.config.get_model_config("wrf")["domain"]
33
+ domain_settings: DomainSetting = {
34
+ "resolution_x": user_settings["dx"],
35
+ "resolution_y": user_settings["dy"],
36
+ "points_y": user_settings["e_sn"],
37
+ "points_x": user_settings["e_we"],
38
+ "x_parent_index": user_settings["i_parent_start"],
39
+ "y_parent_index": user_settings["j_parent_start"],
40
+ "domain_num": user_settings["domain_num"],
41
+ "grid_spacing_ratio": user_settings["parent_grid_ratio"],
42
+ "reference_lat": user_settings["ref_lat"],
43
+ "reference_lon": user_settings["ref_lon"],
44
+ "true_lat1": user_settings["truelat1"],
45
+ "true_lat2": user_settings["truelat2"],
46
+ "stand_lon": user_settings["stand_lon"],
47
+ "projection_type": user_settings["map_proj"],
48
+ }
49
+
50
+ return domain_settings
51
+
52
+
53
+ def domain_settings_from_namelist_wrf(namelist: Union[str, dict]) -> DomainSetting:
54
+ """
55
+ Read values from WPS/WRF namelist and generate domain settings.
56
+
57
+ You can give either the path of namelist file or the dict returned by ``f90nml``.
58
+
59
+ 1. Parse values in a namelist file.
60
+
61
+ >>> namelist_file_path = "./namelist.wps"
62
+ >>> domain_settings = domain_settings_from_namelist_wrf(namelist_file_path)
63
+
64
+ 2. Parse values from dict.
65
+
66
+ >>> namelist_file_path = "./namelist.wps"
67
+ >>> namelist_data = f90nml.read(namelist_file_path).todict()
68
+ >>> domain_settings = domain_settings_from_namelist_wrf(namelist_data)
69
+
70
+ :param namelist: Path of the namelist file or the dict returned by ``f90nml``.
71
+ :type namelist: str | dict
72
+ :return: :class:`DomainSetting <wrfrun.model.type.DomainSetting>`.
73
+ :rtype: DomainSetting
74
+ """
75
+ if isinstance(namelist, str):
76
+ if not exists(namelist):
77
+ logger.error(f"Namelist file not found: {namelist}")
78
+ raise FileNotFoundError(namelist)
79
+
80
+ namelist = f90nml.read(namelist).todict()
81
+
82
+ domain_setting: DomainSetting = {
83
+ "resolution_x": namelist["geogrid"]["dx"],
84
+ "resolution_y": namelist["geogrid"]["dy"],
85
+ "points_y": namelist["geogrid"]["e_sn"],
86
+ "points_x": namelist["geogrid"]["e_we"],
87
+ "x_parent_index": namelist["geogrid"]["i_parent_start"],
88
+ "y_parent_index": namelist["geogrid"]["j_parent_start"],
89
+ "domain_num": namelist["share"]["max_dom"],
90
+ "grid_spacing_ratio": namelist["geogrid"]["parent_grid_ratio"],
91
+ "reference_lat": namelist["geogrid"]["ref_lat"],
92
+ "reference_lon": namelist["geogrid"]["ref_lon"],
93
+ "true_lat1": namelist["geogrid"]["truelat1"],
94
+ "true_lat2": namelist["geogrid"]["truelat2"],
95
+ "stand_lon": namelist["geogrid"]["stand_lon"],
96
+ "projection_type": namelist["geogrid"]["map_proj"],
97
+ }
98
+
99
+ return domain_setting
100
+
101
+
102
+ __all__ = ["domain_settings_from_config_wrf", "domain_settings_from_namelist_wrf"]