wrfrun 0.1.8__py3-none-any.whl → 0.2.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 (53) hide show
  1. wrfrun/cli.py +131 -0
  2. wrfrun/core/base.py +52 -19
  3. wrfrun/core/config.py +257 -170
  4. wrfrun/core/error.py +8 -1
  5. wrfrun/core/replay.py +1 -1
  6. wrfrun/core/server.py +91 -71
  7. wrfrun/data.py +14 -16
  8. wrfrun/extension/goos_sst/__init__.py +5 -5
  9. wrfrun/extension/goos_sst/core.py +4 -1
  10. wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST +1 -1
  11. wrfrun/extension/goos_sst/res/__init__.py +17 -0
  12. wrfrun/extension/goos_sst/utils.py +21 -5
  13. wrfrun/extension/littler/__init__.py +57 -1
  14. wrfrun/extension/littler/{utils.py → core.py} +329 -43
  15. wrfrun/extension/utils.py +24 -22
  16. wrfrun/model/__init__.py +24 -1
  17. wrfrun/model/plot.py +259 -36
  18. wrfrun/model/utils.py +19 -9
  19. wrfrun/model/wrf/__init__.py +41 -0
  20. wrfrun/model/wrf/core.py +229 -101
  21. wrfrun/model/wrf/exec_wrap.py +49 -35
  22. wrfrun/model/wrf/geodata.py +2 -1
  23. wrfrun/model/wrf/namelist.py +78 -4
  24. wrfrun/model/wrf/{_metgrid.py → utils.py} +38 -3
  25. wrfrun/model/wrf/vtable.py +9 -5
  26. wrfrun/res/__init__.py +22 -7
  27. wrfrun/res/config/config.template.toml +57 -0
  28. wrfrun/res/{config.toml.template → config/wrf.template.toml} +7 -46
  29. wrfrun/res/run.template.sh +10 -0
  30. wrfrun/res/scheduler/lsf.template +5 -0
  31. wrfrun/res/{job_scheduler → scheduler}/pbs.template +1 -1
  32. wrfrun/res/{job_scheduler → scheduler}/slurm.template +2 -1
  33. wrfrun/run.py +39 -27
  34. wrfrun/scheduler/__init__.py +35 -0
  35. wrfrun/scheduler/env.py +44 -0
  36. wrfrun/scheduler/lsf.py +49 -0
  37. wrfrun/scheduler/pbs.py +50 -0
  38. wrfrun/scheduler/script.py +72 -0
  39. wrfrun/scheduler/slurm.py +50 -0
  40. wrfrun/scheduler/utils.py +14 -0
  41. wrfrun/utils.py +8 -3
  42. wrfrun/workspace/__init__.py +38 -0
  43. wrfrun/workspace/core.py +94 -0
  44. wrfrun/workspace/wrf.py +165 -0
  45. {wrfrun-0.1.8.dist-info → wrfrun-0.2.0.dist-info}/METADATA +3 -2
  46. wrfrun-0.2.0.dist-info/RECORD +62 -0
  47. wrfrun-0.2.0.dist-info/entry_points.txt +3 -0
  48. wrfrun/model/wrf/_ndown.py +0 -39
  49. wrfrun/pbs.py +0 -86
  50. wrfrun/res/run.sh.template +0 -16
  51. wrfrun/workspace.py +0 -88
  52. wrfrun-0.1.8.dist-info/RECORD +0 -51
  53. {wrfrun-0.1.8.dist-info → wrfrun-0.2.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,165 @@
1
+ """
2
+ wrfrun.workspace.wrf
3
+ ####################
4
+
5
+ Functions to prepare workspace for WPS/WRF model.
6
+
7
+ .. autosummary::
8
+ :toctree: generated/
9
+
10
+ get_wrf_workspace_path
11
+ prepare_wrf_workspace
12
+ check_wrf_workspace
13
+ """
14
+
15
+ from os import listdir, makedirs, symlink
16
+ from os.path import exists
17
+ from typing import Literal
18
+
19
+ from wrfrun.core import WRFRunConfig, get_wrfrun_config, set_register_func
20
+ from wrfrun.utils import check_path, logger
21
+
22
+ WORKSPACE_MODEL_WPS = ""
23
+ WORKSPACE_MODEL_WRF = ""
24
+ WORKSPACE_MODEL_WRFDA = ""
25
+
26
+
27
+ def _register_wrf_workspace_uri(wrfrun_config: WRFRunConfig):
28
+ """
29
+ This function doesn't register any URI.
30
+
31
+ This is a hook to initializes some global strings.
32
+
33
+ :param wrfrun_config: ``WRFRunConfig`` instance.
34
+ :type wrfrun_config: WRFRunConfig
35
+ """
36
+ global WORKSPACE_MODEL_WPS, WORKSPACE_MODEL_WRF, WORKSPACE_MODEL_WRFDA
37
+
38
+ WORKSPACE_MODEL_WPS = f"{wrfrun_config.WRFRUN_WORKSPACE_MODEL}/WPS"
39
+ WORKSPACE_MODEL_WRF = f"{wrfrun_config.WRFRUN_WORKSPACE_MODEL}/WRF"
40
+ WORKSPACE_MODEL_WRFDA = f"{wrfrun_config.WRFRUN_WORKSPACE_MODEL}/WRFDA"
41
+
42
+
43
+ set_register_func(_register_wrf_workspace_uri)
44
+
45
+
46
+ def get_wrf_workspace_path(name: Literal["wps", "wrf", "wrfda"]) -> str:
47
+ """
48
+ Get workspace path of WRF model.
49
+
50
+ :param name: Model part name.
51
+ :type name: str
52
+ :return: Workspace path.
53
+ :rtype: str
54
+ """
55
+ match name:
56
+ case "wps":
57
+ return WORKSPACE_MODEL_WPS
58
+
59
+ case "wrf":
60
+ return WORKSPACE_MODEL_WRF
61
+
62
+ case "wrfda":
63
+ return WORKSPACE_MODEL_WRFDA
64
+
65
+
66
+ def prepare_wrf_workspace(model_config: dict):
67
+ """
68
+ Initialize workspace for WPS/WRF model.
69
+
70
+ This function will check following paths,
71
+ and create them or delete old files inside:
72
+
73
+ 1. ``$HOME/.config/wrfrun/model/WPS``
74
+ 2. ``$HOME/.config/wrfrun/model/WRF``
75
+ 3. ``$HOME/.config/wrfrun/model/WRFDA``
76
+
77
+ :param model_config: Model config.
78
+ :type model_config: dict
79
+ """
80
+ logger.info(f"Initialize workspace for WPS/WRF.")
81
+
82
+ WRFRUNConfig = get_wrfrun_config()
83
+
84
+ wps_path = model_config["wps_path"]
85
+ wrf_path = model_config["wrf_path"]
86
+ wrfda_path = model_config["wrfda_path"]
87
+
88
+ if not (wps_path and wrf_path):
89
+ logger.warning(f"No WPS/WRF model installation path given, skip initialization.")
90
+ return
91
+
92
+ if wps_path:
93
+ if not exists(wps_path):
94
+ logger.error(f"Your WPS path is wrong.")
95
+ raise FileNotFoundError(f"Your WPS path is wrong.")
96
+
97
+ wps_work_path = WRFRUNConfig.parse_resource_uri(WORKSPACE_MODEL_WPS)
98
+ check_path(wps_work_path, f"{wps_work_path}/outputs", force=True)
99
+
100
+ file_list = [x for x in listdir(wps_path) if x not in ["geogrid", "namelist.wps"]]
101
+ _ = [symlink(f"{wps_path}/{file}", f"{wps_work_path}/{file}") for file in file_list]
102
+ makedirs(f"{wps_work_path}/geogrid")
103
+ symlink(f"{wps_path}/geogrid/GEOGRID.TBL", f"{wps_work_path}/geogrid/GEOGRID.TBL")
104
+
105
+ if wrf_path:
106
+ if not exists(wrf_path):
107
+ logger.error(f"Your WRF path is wrong.")
108
+ raise FileNotFoundError(f"Your WRF path is wrong.")
109
+
110
+ wrf_work_path = WRFRUNConfig.parse_resource_uri(WORKSPACE_MODEL_WRF)
111
+ check_path(wrf_work_path, force=True)
112
+
113
+ file_list = [x for x in listdir(f"{wrf_path}/run") if not x.startswith("namelist")]
114
+ _ = [symlink(f"{wrf_path}/run/{file}", f"{wrf_work_path}/{file}") for file in file_list]
115
+
116
+ if wrfda_path:
117
+ if not exists(wrfda_path):
118
+ logger.error(f"Your WRFDA path is wrong.")
119
+ raise FileNotFoundError(f"Your WRFDA path is wrong.")
120
+
121
+ wrfda_work_path = WRFRUNConfig.parse_resource_uri(WORKSPACE_MODEL_WRFDA)
122
+ check_path(wrfda_work_path, force=True)
123
+
124
+ file_list = ["da_wrfvar.exe", "da_update_bc.exe"]
125
+ _ = [symlink(f"{wrfda_path}/var/build/{file}", f"{wrfda_work_path}/{file}") for file in file_list]
126
+
127
+ file_list = listdir(f"{wrfda_path}/var/run")
128
+ _ = [symlink(f"{wrfda_path}/var/run/{file}", f"{wrfda_work_path}/{file}") for file in file_list]
129
+
130
+ symlink(f"{wrfda_path}/run/LANDUSE.TBL", f"{wrfda_work_path}/LANDUSE.TBL")
131
+
132
+
133
+ def check_wrf_workspace(model_config: dict) -> bool:
134
+ """
135
+ Check if WPS/WRF workspace exists.
136
+
137
+ :param model_config: Model config.
138
+ :type model_config: dict
139
+ :return: ``True`` if WPS/WRF workspace exists, ``False`` otherwise.
140
+ :rtype: bool
141
+ """
142
+ WRFRUNConfig = get_wrfrun_config()
143
+
144
+ wps_path = model_config["wps_path"]
145
+ wrf_path = model_config["wrf_path"]
146
+ wrfda_path = model_config["wrfda_path"]
147
+
148
+ flag = True
149
+
150
+ if wps_path:
151
+ wps_work_path = WRFRUNConfig.parse_resource_uri(WORKSPACE_MODEL_WPS)
152
+ flag = flag & exists(wps_work_path)
153
+
154
+ if wrf_path:
155
+ wrf_work_path = WRFRUNConfig.parse_resource_uri(WORKSPACE_MODEL_WRF)
156
+ flag = flag & exists(wrf_work_path)
157
+
158
+ if wrfda_path:
159
+ wrfda_work_path = WRFRUNConfig.parse_resource_uri(WORKSPACE_MODEL_WRFDA)
160
+ flag = flag & exists(wrfda_work_path)
161
+
162
+ return flag
163
+
164
+
165
+ __all__ = ["get_wrf_workspace_path", "prepare_wrf_workspace", "check_wrf_workspace"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wrfrun
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: wrfrun is a comprehensive toolkit for managing and using WRF
5
5
  Keywords: WRF
6
6
  Author-Email: Syize <syizeliu@gmail.com>
@@ -11,7 +11,7 @@ Project-URL: repository, https://github.com/Syize/wrfrun
11
11
  Project-URL: documentation, https://wrfrun.syize.cn
12
12
  Project-URL: Bug Tracker, https://github.com/Syize/wrfrun/issues
13
13
  Requires-Python: >=3.10
14
- Requires-Dist: numpy<2.0.0
14
+ Requires-Dist: numpy
15
15
  Requires-Dist: xarray
16
16
  Requires-Dist: netCDF4
17
17
  Requires-Dist: rich
@@ -24,6 +24,7 @@ Requires-Dist: wrf-python
24
24
  Requires-Dist: cfgrib
25
25
  Requires-Dist: tomli
26
26
  Requires-Dist: tomli-w
27
+ Requires-Dist: haversine
27
28
  Description-Content-Type: text/markdown
28
29
 
29
30
  # wrfrun: A toolkit to control WRF
@@ -0,0 +1,62 @@
1
+ wrfrun-0.2.0.dist-info/METADATA,sha256=v05u5wToeTsctm_vmFeK8z1I29iWTjauvJmbTOkZ9lI,2932
2
+ wrfrun-0.2.0.dist-info/WHEEL,sha256=5J4neoE7k6LMgx4Fz1FHgBiO3YevhJGtNQ3muDrdLQM,75
3
+ wrfrun-0.2.0.dist-info/entry_points.txt,sha256=G3358n6wW1qZF3hSH9umxrWHJewN-6N1BUloacN2tks,50
4
+ wrfrun/__init__.py,sha256=l2zGk2qDWa3EXIlwvzqBYZHOU9273TN75Rmvx_7PAYM,58
5
+ wrfrun/cli.py,sha256=3N4QCKfBQ9pKV7MP0fEN9BygEOiUJVMTqW47cl1ZpHY,4347
6
+ wrfrun/data.py,sha256=NqpxZ_qDGodJdgdqVUKtJwbyZo0DG7l3_vTZ-2Unbgw,14817
7
+ wrfrun/run.py,sha256=WgTaFRRAEZ83SKzPkrOyXtxlea3DUtU-5zR6zS0dS_c,9458
8
+ wrfrun/utils.py,sha256=BdGP5u2Y2e3tqU0dawfHsTeqZ0q4Ic4MCGR8RU4FJ90,8388
9
+ wrfrun/core/__init__.py,sha256=zsitfcmbO_Qf_Uh0FzZ4rceZAo3WEYev32jSjgRjtkw,1325
10
+ wrfrun/core/base.py,sha256=1aqZIiYuVEYWTGOUKnrFZUb9ihM2H6TVaUOOQ4AfwHQ,31414
11
+ wrfrun/core/config.py,sha256=sW4g9ovy1I31g4dHnzKQdk7h3TQhjbqfys5ngPOKCvs,32834
12
+ wrfrun/core/error.py,sha256=mrwwgvxMH0v4GL0GEG7JjMxDV1S3D_KiRmKTTCZfCBc,2523
13
+ wrfrun/core/replay.py,sha256=jZWN68IgUroxuCzg7EO0FXxe2zwokxJnquu4t81hp7Y,4782
14
+ wrfrun/core/server.py,sha256=CDU6VmWwFg1BVlA1plCagG7fDWUev19T9Q3pJ_WDf1s,8936
15
+ wrfrun/extension/__init__.py,sha256=YDYCS0KD3e-uLvf1K08ktNfP2sUSKpbgkHrvXj21EPQ,913
16
+ wrfrun/extension/utils.py,sha256=xf3WquF8w7J-vYfgkTFOhVVrEEuO3oRgMoNaRVhec9k,2501
17
+ wrfrun/extension/goos_sst/__init__.py,sha256=QsVheVVL5K0_k-eg8-xe2MLAJ845iivXzGHbp2qARh4,2101
18
+ wrfrun/extension/goos_sst/core.py,sha256=_s53vq0nAwnwWxExD8-73p5seCWLO1XVzRh5T8JofAw,3870
19
+ wrfrun/extension/goos_sst/utils.py,sha256=bomXbhpOuNOYm2rL1SiOeSxVbSaKWfVxX51KoODgBn0,3469
20
+ wrfrun/extension/goos_sst/res/__init__.py,sha256=-Ey6iFHzQYZNOGhVrSkMjOwiXVgt3P6eaumq7pOmh_E,511
21
+ wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST,sha256=UfbzWKEE2pnQO4Q2mkMmkl7pv_bDSxVGaN2jEYfMVzE,534
22
+ wrfrun/extension/littler/__init__.py,sha256=bLiGIpB_FpTyio44CjIzwwcahyFWxGW-gECfBOIG9Y8,2032
23
+ wrfrun/extension/littler/core.py,sha256=fS4F0RNs36VL3ej-9WsAn-n8C8nJb29XOQvVYpLaeOM,34192
24
+ wrfrun/model/__init__.py,sha256=PYA6ZUwL4u3heRIMX_qkLvAA6jDrY4kugD8rCvnl-2Y,803
25
+ wrfrun/model/base.py,sha256=WnVNu12ICJgThfZR7kK6_XLCQWVYFsHrdyAz8wl_YRc,218
26
+ wrfrun/model/plot.py,sha256=2owjhCxRKpQDbaJ4zCpCcvUdMx-6rkYhqrTaHmIVrwg,10588
27
+ wrfrun/model/utils.py,sha256=IZOd_yTPnxgPMBBROrhDS_WYdnUW6egEEooo4skSkEE,1263
28
+ wrfrun/model/wrf/__init__.py,sha256=KJij1JMTcj3i5e2LcJJJudA99LrsJIVHeMj9ktT9Y_4,1752
29
+ wrfrun/model/wrf/core.py,sha256=Dhab9jbMRhq5FNYp2yOPBF3ZbZjzo7wa7pLFRisokLs,36335
30
+ wrfrun/model/wrf/exec_wrap.py,sha256=REOtNLCc6IcM2yaaSXoXGgXFA-xjMHmoTiA9B3ZezEA,4418
31
+ wrfrun/model/wrf/geodata.py,sha256=2-B7hkMfB-MmSy3mMHbKqTYAlpcmSNVp26XW_VkPWu4,9784
32
+ wrfrun/model/wrf/namelist.py,sha256=CSOjoKKzniZ1wJVNL8jfBBVufmDUFwT0ZEoTsLZkGuc,16930
33
+ wrfrun/model/wrf/scheme.py,sha256=8y85Dbu-GajwjHr3Spw8_tN21xAloD-SnmxJd11nXKE,11254
34
+ wrfrun/model/wrf/utils.py,sha256=FsLy6Hah58aMbQlR-z3W72lhHXAdhBbQzu58y2dmHOw,3760
35
+ wrfrun/model/wrf/vtable.py,sha256=6FtbdEugJrN0_Ta4LqtoHyYzu6bbFxDFvuqkrW51DCw,2620
36
+ wrfrun/plot/__init__.py,sha256=9Kn0IgkX10sHEqHJwk7mZV-dP14XMNcvXN8znO89FIw,19
37
+ wrfrun/plot/wps.py,sha256=pvkxbh5760AAM4KaPteMzhFniZZFtkYF31xhzSBa7lo,5552
38
+ wrfrun/res/__init__.py,sha256=18wHJhgDd0hwITHe79xBNwgM4A3yEUJOz2ubcYKeBZI,1669
39
+ wrfrun/res/run.template.sh,sha256=k-r4lOOarscmSdiBXGHPnv3oeiRe-qW-VhOBia27ZGU,101
40
+ wrfrun/res/config/config.template.toml,sha256=BTDGDm8aXqXbZM-gpXdGXNZEFFIWmeXd5pLdasWuT38,1593
41
+ wrfrun/res/config/wrf.template.toml,sha256=qQS3OHAXBMaKWgj2qT7jLeDu6tyngPgin7Q-XcE3ZkQ,3189
42
+ wrfrun/res/extension/plotgrids.ncl,sha256=B0mvH1H1j_w7EEana9HmU1XJZtG0w9IccQ54zXpbQG0,7546
43
+ wrfrun/res/namelist/namelist.input.da_wrfvar.template,sha256=Cwc-XPu_spJeQte4duWrulPBOLRMEBtn0mIn0pgMmKY,4912
44
+ wrfrun/res/namelist/namelist.input.dfi.template,sha256=E7MVbIvMopkAM7xGUC4vniC1WOUVbIbdLfkTKHqzX_o,6591
45
+ wrfrun/res/namelist/namelist.input.real.template,sha256=DDUiArtBFmzBwVjkZW4NOrBR34eIOk1vV0VsyL0stsk,6214
46
+ wrfrun/res/namelist/namelist.input.wrf.template,sha256=myrKi79sQ8ABBsmQJkcgN0WLbWJdtMVPIjuAC1MTMuM,6213
47
+ wrfrun/res/namelist/namelist.wps.template,sha256=HlA7-SHs4C-cKRb3h6D0Kl1Y-5VSJ1Lw9hLiXWGAN0Q,1017
48
+ wrfrun/res/namelist/parame.in.template,sha256=vR8JSix20FAKGqj6jK8QuEAeWkGvg8_iptdVlzjPX6o,259
49
+ wrfrun/res/scheduler/lsf.template,sha256=KorLfqTFTqTTctDE9Edgkixi7JLWrcDNRpZknXuxbEQ,111
50
+ wrfrun/res/scheduler/pbs.template,sha256=kP4pGMAq2uz0OZUAWii7dO4ECLC924c8SnciFeBL5QY,155
51
+ wrfrun/res/scheduler/slurm.template,sha256=sQNjkKzOftipDD4kYmzhZkh8fg0M9uaQsdLjDakCVwA,336
52
+ wrfrun/scheduler/__init__.py,sha256=pOqnCAl2-_yC7zPS2VQL5RMltQN4zc0koYS_MESKtHo,1130
53
+ wrfrun/scheduler/env.py,sha256=N_K5yZFRXMEXvW3yjSideEDPWZzoWpbRhFS9LJoZ3R8,1262
54
+ wrfrun/scheduler/lsf.py,sha256=ajpYnWWryEMMguEBz5H0CONaJmM7AhDV8SOwD1DKkdI,1203
55
+ wrfrun/scheduler/pbs.py,sha256=A0nAOsgU8xzrPZZYrmQI00wUj5P8E_QY_LhDKFvua-Q,1219
56
+ wrfrun/scheduler/script.py,sha256=DdTAGK3gWFuD_3jbQb9cfXI6q0pW3Z_YW6EgWh7I3rU,2448
57
+ wrfrun/scheduler/slurm.py,sha256=SedEq8zV-bfCwWw28UOWJ6qMmP0TkTjJZ9HlMC7gYf0,1241
58
+ wrfrun/scheduler/utils.py,sha256=iIH2abTptzyw7KYmQYYAwCqzfvfZ6FinTNq33e06zvw,223
59
+ wrfrun/workspace/__init__.py,sha256=e7ijFWaYRMmBbso0pXnsAc0oUnkQ3t3UguhY3a0U6Qk,1456
60
+ wrfrun/workspace/core.py,sha256=R-jp5Le_MAZ7I9abImqK3zyGbFG_8wPVQ632hzeIg2k,2705
61
+ wrfrun/workspace/wrf.py,sha256=prZEdJwyMPguLsafNT9v4vNcq2R_I7WuJsKsvq_NE-4,5140
62
+ wrfrun-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ wrfrun = wrfrun.cli:main_entry
3
+
@@ -1,39 +0,0 @@
1
- from wrfrun.core import WRFRUNConfig
2
- from wrfrun.utils import logger
3
-
4
-
5
- def process_after_ndown():
6
- """
7
- After running ndown.exe, namelist settings are supposed to be changed,
8
- 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>`_.
9
- `wrfrun` provide this function to help you change these settings which have multiple values for each domain.
10
- The first value will be removed to ensure the value of higher resolution domain is the first value.
11
-
12
- :return:
13
- """
14
- namelist_data = WRFRUNConfig.get_namelist("wrf")
15
-
16
- for section in namelist_data:
17
- if section in ["bdy_control", "namelist_quilt"]:
18
- continue
19
-
20
- for key in namelist_data[section]:
21
- if key in ["grid_id", "parent_id", "i_parent_start", "j_parent_start", "parent_grid_ratio", "parent_time_step_ratio", "eta_levels"]:
22
- continue
23
-
24
- if isinstance(namelist_data[section][key], list):
25
-
26
- if len(namelist_data[section][key]) > 1:
27
- namelist_data[section][key] = namelist_data[section][key][1:]
28
-
29
- namelist_data["domains"]["max_dom"] = 1
30
-
31
- time_ratio = namelist_data["domains"]["parent_time_step_ratio"][1]
32
- namelist_data["domains"]["time_step"] = namelist_data["domains"]["time_step"] // time_ratio
33
-
34
- WRFRUNConfig.update_namelist(namelist_data, "wrf")
35
-
36
- logger.info(f"Update namelist after running ndown.exe")
37
-
38
-
39
- __all__ = ["process_after_ndown"]
wrfrun/pbs.py DELETED
@@ -1,86 +0,0 @@
1
- from os import environ
2
- from os.path import exists, dirname, abspath
3
-
4
- from .core import WRFRUNConfig
5
- from .res import TASKSYS_PBS_TEMPLATE
6
- from .utils import logger
7
-
8
-
9
- def prepare_pbs_script(main_file_path: str):
10
- """Prepare the bash script to be submitted to PBS work system.
11
-
12
- Args:
13
- main_file_path (str): The path of main Python file.
14
- """
15
- # check main file
16
- if not exists(main_file_path):
17
- logger.error(f"Wrong path of main Python file: {main_file_path}")
18
- raise FileNotFoundError
19
-
20
- # get absolute path of parent directory
21
- dir_path = abspath(dirname(main_file_path))
22
-
23
- # read log path and PBS setting from config
24
- log_path = WRFRUNConfig.get_log_path()
25
- PBS_setting = WRFRUNConfig.get_job_scheduler_config()
26
-
27
- # set PBS log path
28
- stdout_log_path = f"{log_path}/PBS.log"
29
- stderr_log_path = f"{log_path}/PBS.log"
30
-
31
- # set environment parameter
32
- env_settings = ''
33
- if len(PBS_setting["env_settings"]) != 0:
34
- for key in PBS_setting["env_settings"]:
35
- env_settings += f"{key}={PBS_setting['env_settings'][key]}\n"
36
-
37
- # set command
38
- exec_cmd = f"{PBS_setting['python_interpreter']} {main_file_path}"
39
-
40
- # read template and write to file
41
- pbs_template_path = WRFRUNConfig.parse_resource_uri(TASKSYS_PBS_TEMPLATE)
42
- with open(f"{dir_path}/run.sh", "w") as f:
43
-
44
- with open(pbs_template_path, "r") as f_template:
45
- template = f_template.read()
46
-
47
- template = template.format(
48
- STDOUT_LOG_PATH=stdout_log_path,
49
- STDERR_LOG_PATH=stderr_log_path,
50
- NODE_NUM=PBS_setting["node_num"],
51
- CORE_NUM=PBS_setting["core_num"],
52
- ENV_SETTINGS=env_settings,
53
- WORK_PATH=dir_path,
54
- WORK_COMMAND=exec_cmd
55
- )
56
-
57
- f.write(template)
58
-
59
- logger.info(
60
- f"PBS script has been generated and write to file {dir_path}/run.sh. Check it and submit it to PBS system to run wrfrun.")
61
-
62
-
63
- def get_core_num() -> int:
64
- """Read core num from config.
65
-
66
- Returns:
67
- int: Core number.
68
- """
69
- return WRFRUNConfig["core_num"]
70
-
71
-
72
- def in_pbs() -> bool:
73
- """Check if we're in a PBS work.
74
-
75
- Returns:
76
- bool: True if we're in, False is we aren't.
77
- """
78
- # check if we're a PBS task
79
- if "PBS_ENVIRONMENT" in environ:
80
- # we're in a PBS task
81
- return True
82
- else:
83
- return False
84
-
85
-
86
- __all__ = ["prepare_pbs_script", "get_core_num", "in_pbs"]
@@ -1,16 +0,0 @@
1
- #!/bin/bash
2
- #PBS -q batch
3
- ##PBS -q odasc
4
- #PBS -N py-wrfrun
5
- #PBS -o {STDOUT_LOG_PATH}
6
- #PBS -e {STDERR_LOG_PATH}
7
- #PBS -l nodes={NODE_NUM}:ppn={CORE_NUM}
8
- #PBS -l walltime=9999:00:00
9
-
10
- ulimit -s unlimited
11
-
12
- {ENV_SETTINGS}
13
-
14
- cd {WORK_PATH}
15
-
16
- {WORK_COMMAND}
wrfrun/workspace.py DELETED
@@ -1,88 +0,0 @@
1
- """
2
- This file contains functions to interact with WRF workspace
3
- """
4
-
5
- from os import listdir, makedirs, symlink
6
- from os.path import exists
7
-
8
- from .core import WRFRUNConfig
9
- from .utils import check_path, logger
10
-
11
-
12
- def prepare_workspace():
13
- """Initialize workspace
14
-
15
- """
16
- logger.info(f"Initialize workspace...")
17
-
18
- # extract WRF path
19
- wrf_config = WRFRUNConfig.get_model_config("wrf")
20
- wps_path = wrf_config["wps_path"]
21
- wrf_path = wrf_config["wrf_path"]
22
- wrfda_path = wrf_config["wrfda_path"]
23
-
24
- WRFRUN_TEMP_PATH = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRFRUN_TEMP_PATH)
25
- WORK_PATH = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRFRUN_WORKSPACE_PATH)
26
- REPLAY_WORK_PATH = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRFRUN_REPLAY_WORK_PATH)
27
- WPS_WORK_PATH = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WPS_WORK_PATH)
28
- WRF_WORK_PATH = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRF_WORK_PATH)
29
- WRFDA_WORK_PATH = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRFDA_WORK_PATH)
30
- output_path = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRFRUN_OUTPUT_PATH)
31
-
32
- # check folder
33
- check_path(WRFRUN_TEMP_PATH)
34
- check_path(REPLAY_WORK_PATH, force=True)
35
- check_path(output_path)
36
-
37
- if exists(wrfda_path):
38
- WRFRUNConfig.USE_WRFDA = True
39
-
40
- # create folder to run WPS, and WRF
41
- # check the path
42
- if not (exists(wps_path) and exists(wrf_path)):
43
- logger.error(f"Your WPS or WRF path is wrong")
44
- raise FileNotFoundError(f"Your WPS or WRF path is wrong")
45
-
46
- # remove old file
47
- if exists(WORK_PATH):
48
- logger.info(f"Remove old files...")
49
- check_path(WPS_WORK_PATH, f"{WPS_WORK_PATH}/outputs",
50
- WRF_WORK_PATH, WRFDA_WORK_PATH, force=True)
51
- logger.info(f"Link essential files...")
52
-
53
- # link {wps_path}/*
54
- # collect file except folder geogrid
55
- file_list = [
56
- x for x in listdir(wps_path) if x not in ["geogrid", "namelist.wps"]
57
- ]
58
- for file in file_list:
59
- symlink(f"{wps_path}/{file}", f"{WPS_WORK_PATH}/{file}")
60
-
61
- # create folder geogrid and link default GEOGRID file
62
- makedirs(f"{WPS_WORK_PATH}/geogrid")
63
- symlink(
64
- f"{wps_path}/geogrid/GEOGRID.TBL", f"{WPS_WORK_PATH}/geogrid/GEOGRID.TBL"
65
- )
66
-
67
- # # link {wrf_path}/run/*, except namelist.input
68
- file_list = [x for x in listdir(
69
- f"{wrf_path}/run") if not x.startswith("namelist")]
70
- for file in file_list:
71
- symlink(f"{wrf_path}/run/{file}", f"{WRF_WORK_PATH}/{file}")
72
-
73
- if WRFRUNConfig.USE_WRFDA:
74
- # # link {wrfda_path}/bin/*.exe
75
- file_list = ["da_wrfvar.exe", "da_update_bc.exe"]
76
- for file in file_list:
77
- symlink(f"{wrfda_path}/var/build/{file}", f"{WRFDA_WORK_PATH}/{file}")
78
-
79
- # # link {wrfda_path}/var/run/*
80
- file_list = listdir(f"{wrfda_path}/var/run")
81
- for file in file_list:
82
- symlink(f"{wrfda_path}/var/run/{file}", f"{WRFDA_WORK_PATH}/{file}")
83
-
84
- # # link {wrfda_path}/run/LANDUSE.TBL
85
- symlink(f"{wrfda_path}/run/LANDUSE.TBL", f"{WRFDA_WORK_PATH}/LANDUSE.TBL")
86
-
87
-
88
- __all__ = ["prepare_workspace"]
@@ -1,51 +0,0 @@
1
- wrfrun-0.1.8.dist-info/METADATA,sha256=_Y0huf7Q8hAsLFsgIlPZYF8FDmZ_DKqsGMxcBaewcpQ,2913
2
- wrfrun-0.1.8.dist-info/WHEEL,sha256=5J4neoE7k6LMgx4Fz1FHgBiO3YevhJGtNQ3muDrdLQM,75
3
- wrfrun/__init__.py,sha256=l2zGk2qDWa3EXIlwvzqBYZHOU9273TN75Rmvx_7PAYM,58
4
- wrfrun/data.py,sha256=W6IhopHpp0lhvVo-beuO6NsbfsGDmN5MNf8Bqkt7xsA,14845
5
- wrfrun/pbs.py,sha256=gzRHbYqpU-c8lynu39TUKNvmPntvrPwfQVxK337yvjw,2454
6
- wrfrun/run.py,sha256=0mvuI98gLjq1gP1eaLUZiU1LJMCjtL668aKZTwu3n2g,9114
7
- wrfrun/utils.py,sha256=v3ZRu3Rd8-pZjo7I0PrJtgBN1zIBAt_nVPs0BP_DFwY,8118
8
- wrfrun/workspace.py,sha256=5tWIIFxwAE4hkdg_wJALGDc3P0bfwb_IRTIyPIjN-tE,3105
9
- wrfrun/core/__init__.py,sha256=zsitfcmbO_Qf_Uh0FzZ4rceZAo3WEYev32jSjgRjtkw,1325
10
- wrfrun/core/base.py,sha256=zix413Nc0YrgIR6oakVhTN405KUmZ7OKlJTgL0fNUVc,30307
11
- wrfrun/core/config.py,sha256=g021WEkRZpvsLyzVHlahL9WtAP7zKG9polW3B84eT3k,29252
12
- wrfrun/core/error.py,sha256=etnImryyqDUggfZOKK1ynOm71GRSFJVGGOwhuiZahTI,2383
13
- wrfrun/core/replay.py,sha256=nqVmR3Hb4zO6PnROssv3PKw7gvvdi-UqIsjX-NV1WLI,4782
14
- wrfrun/core/server.py,sha256=RjzFVlRZg60rLMy4Gy5UhZWPUOQP307rT4ttpvbcecQ,8640
15
- wrfrun/extension/__init__.py,sha256=YDYCS0KD3e-uLvf1K08ktNfP2sUSKpbgkHrvXj21EPQ,913
16
- wrfrun/extension/utils.py,sha256=OBIAlAXakbh1QhrF2BFlYAFV062ZfJjX0mYJkmcU_RI,2751
17
- wrfrun/extension/goos_sst/__init__.py,sha256=M8LWGLXqHyPUWijl5925jFmwJ1ih3kHfT2jTxZzwMBA,2126
18
- wrfrun/extension/goos_sst/core.py,sha256=D0po6PjBqcEareVQO1VjdIUrFz9lJrnAZ5q2sax78Tw,3794
19
- wrfrun/extension/goos_sst/utils.py,sha256=h0OBCwxS67kG6YNclZLvyPYnT7uNZd3Uq9f6Vg2EaMc,3052
20
- wrfrun/extension/goos_sst/res/__init__.py,sha256=M-qN-WI0EIvhYo2hwnnIK_fXL3TbR12KzSC9fvjgDaY,164
21
- wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST,sha256=aX8RSTWL8GVdxf2TgvIoQx5xDVuLi0F5_Eg2e8Gaa-E,529
22
- wrfrun/extension/littler/__init__.py,sha256=pG-YPVG0gJIJ6s4xcAz9S_CnUxpUcz33wl9eNUSgxGk,20
23
- wrfrun/extension/littler/utils.py,sha256=TsN3GiAFszPWF7RNM_hYdARRY_OLL8mYm87UyZupUtU,21615
24
- wrfrun/model/__init__.py,sha256=lQNNnh3evXZytLAjdnhlIEFWerP1L0XAgDAUQhqIRyE,119
25
- wrfrun/model/base.py,sha256=WnVNu12ICJgThfZR7kK6_XLCQWVYFsHrdyAz8wl_YRc,218
26
- wrfrun/model/plot.py,sha256=Hh-GxQPDzpwAEAq-rFh0VcIWzgMDxZVT0c40SIRa6_o,1582
27
- wrfrun/model/utils.py,sha256=Pyj9D9NMKw3wQcZcM7pJaLG09Vov447AxFKoVeZZU2s,1155
28
- wrfrun/model/wrf/__init__.py,sha256=T3S1BD9QDoW4uq871QW4_8-2BvCRWYEecz71EcdbMaI,136
29
- wrfrun/model/wrf/core.py,sha256=srOD7KFF5TgPAcWTw0PLHFjkGjDzb8PYbxuPx5B4bQE,32140
30
- wrfrun/model/wrf/exec_wrap.py,sha256=gIsGZDAjzRzxt24eo8t-laIK4UBiyKf_ysfAZLlE1og,3918
31
- wrfrun/model/wrf/geodata.py,sha256=X9OUOm0__5NI7sl2z1F9_ur5wZ4P0HkpBNcRZQYKof0,9740
32
- wrfrun/model/wrf/_metgrid.py,sha256=i2qILM_1LkdnBZqXXL3swVhMRvhFvq4bOcRPGI6kSzg,2248
33
- wrfrun/model/wrf/namelist.py,sha256=T9b5H6pCljhKUhoR9qwTbdMF04Hrdp3mHwCP-VuhFWE,14791
34
- wrfrun/model/wrf/_ndown.py,sha256=ZcWttGXiT5FzGCAohmbeNU6bi8GUOUleiTK0ivn2BaI,1548
35
- wrfrun/model/wrf/scheme.py,sha256=8y85Dbu-GajwjHr3Spw8_tN21xAloD-SnmxJd11nXKE,11254
36
- wrfrun/model/wrf/vtable.py,sha256=0V4fo0Limnx4oJ2NByq_eHPzj8L4mnHNlrKL34Buw1A,2432
37
- wrfrun/plot/__init__.py,sha256=9Kn0IgkX10sHEqHJwk7mZV-dP14XMNcvXN8znO89FIw,19
38
- wrfrun/plot/wps.py,sha256=pvkxbh5760AAM4KaPteMzhFniZZFtkYF31xhzSBa7lo,5552
39
- wrfrun/res/__init__.py,sha256=YBcVaM2EZZJkDDvyKdk-WZmcFQoTFENZKCwcIQzEf3I,1133
40
- wrfrun/res/config.toml.template,sha256=LTCEwXSFF2QXnwGRoB0Jw5Qs_vXwdb6Zd7fQtNAz9Uw,4374
41
- wrfrun/res/run.sh.template,sha256=ZN7k0a9ONOtZUQ67JiTva-0DNVJG5O7BdOXQ8-LCscs,247
42
- wrfrun/res/extension/plotgrids.ncl,sha256=B0mvH1H1j_w7EEana9HmU1XJZtG0w9IccQ54zXpbQG0,7546
43
- wrfrun/res/namelist/namelist.input.da_wrfvar.template,sha256=Cwc-XPu_spJeQte4duWrulPBOLRMEBtn0mIn0pgMmKY,4912
44
- wrfrun/res/namelist/namelist.input.dfi.template,sha256=E7MVbIvMopkAM7xGUC4vniC1WOUVbIbdLfkTKHqzX_o,6591
45
- wrfrun/res/namelist/namelist.input.real.template,sha256=DDUiArtBFmzBwVjkZW4NOrBR34eIOk1vV0VsyL0stsk,6214
46
- wrfrun/res/namelist/namelist.input.wrf.template,sha256=myrKi79sQ8ABBsmQJkcgN0WLbWJdtMVPIjuAC1MTMuM,6213
47
- wrfrun/res/namelist/namelist.wps.template,sha256=HlA7-SHs4C-cKRb3h6D0Kl1Y-5VSJ1Lw9hLiXWGAN0Q,1017
48
- wrfrun/res/namelist/parame.in.template,sha256=vR8JSix20FAKGqj6jK8QuEAeWkGvg8_iptdVlzjPX6o,259
49
- wrfrun/res/job_scheduler/pbs.template,sha256=m7eyvZkzQRpjs43CvSeZ1biHYNyEJJkgXt3IU5ZhCmg,148
50
- wrfrun/res/job_scheduler/slurm.template,sha256=BrKL8DcHfpFfv0y0z7Qe_cqjwfzMyF-3V6vM72ehr9Y,312
51
- wrfrun-0.1.8.dist-info/RECORD,,
File without changes