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