wrfrun 0.1.9__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.
- wrfrun/cli.py +7 -4
- wrfrun/core/base.py +44 -14
- wrfrun/core/config.py +184 -28
- wrfrun/core/error.py +8 -1
- wrfrun/core/server.py +27 -10
- wrfrun/data.py +14 -16
- wrfrun/extension/littler/core.py +3 -3
- wrfrun/extension/utils.py +3 -2
- wrfrun/model/plot.py +7 -2
- wrfrun/model/utils.py +4 -3
- wrfrun/model/wrf/core.py +49 -37
- wrfrun/model/wrf/geodata.py +2 -1
- wrfrun/model/wrf/namelist.py +3 -4
- wrfrun/model/wrf/utils.py +3 -2
- wrfrun/model/wrf/vtable.py +9 -6
- wrfrun/res/__init__.py +15 -3
- wrfrun/res/config/config.template.toml +7 -0
- wrfrun/run.py +21 -5
- wrfrun/scheduler/lsf.py +3 -1
- wrfrun/scheduler/pbs.py +3 -1
- wrfrun/scheduler/script.py +4 -2
- wrfrun/scheduler/slurm.py +3 -1
- wrfrun/scheduler/utils.py +2 -2
- wrfrun/workspace/core.py +4 -2
- wrfrun/workspace/wrf.py +50 -6
- {wrfrun-0.1.9.dist-info → wrfrun-0.2.0.dist-info}/METADATA +1 -1
- {wrfrun-0.1.9.dist-info → wrfrun-0.2.0.dist-info}/RECORD +29 -29
- {wrfrun-0.1.9.dist-info → wrfrun-0.2.0.dist-info}/WHEEL +0 -0
- {wrfrun-0.1.9.dist-info → wrfrun-0.2.0.dist-info}/entry_points.txt +0 -0
wrfrun/data.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from os import makedirs
|
|
3
|
-
from os.path import
|
|
4
|
-
from typing import
|
|
3
|
+
from os.path import dirname, exists
|
|
4
|
+
from typing import List, Tuple, Union
|
|
5
5
|
|
|
6
6
|
from pandas import date_range
|
|
7
|
-
# from seafog import goos_sst_find_data
|
|
8
7
|
|
|
9
|
-
from .core
|
|
8
|
+
from .core import get_wrfrun_config
|
|
10
9
|
from .utils import logger
|
|
11
10
|
|
|
11
|
+
# from seafog import goos_sst_find_data
|
|
12
|
+
|
|
12
13
|
# lazy initialize
|
|
13
14
|
CDS_CLIENT = None
|
|
14
15
|
|
|
@@ -264,8 +265,7 @@ def find_era5_data(date: Union[List[str], List[datetime]], area: Tuple[int, int,
|
|
|
264
265
|
# check if we need to add pressure_level to params dict
|
|
265
266
|
if dataset == ERA5CONFIG.DATASET_ERA5_PRESSURE_LEVEL:
|
|
266
267
|
if pressure_level is None:
|
|
267
|
-
logger.error(
|
|
268
|
-
f"You need to provide pressure levels to download data")
|
|
268
|
+
logger.error("You need to provide pressure levels to download data")
|
|
269
269
|
exit(1)
|
|
270
270
|
# convert value to str
|
|
271
271
|
if not isinstance(pressure_level, list):
|
|
@@ -277,12 +277,11 @@ def find_era5_data(date: Union[List[str], List[datetime]], area: Tuple[int, int,
|
|
|
277
277
|
if _check_pressure_level(pressure_level): # type: ignore
|
|
278
278
|
params_dict["pressure_level"] = pressure_level
|
|
279
279
|
else:
|
|
280
|
-
logger.error(
|
|
281
|
-
f"You have passed wrong pressure level to download data, check it")
|
|
280
|
+
logger.error("You have passed wrong pressure level to download data, check it")
|
|
282
281
|
exit(1)
|
|
283
282
|
|
|
284
283
|
# download data
|
|
285
|
-
logger.info(f"Downloading data to {save_path}, it may take several tens of minutes, please wait...")
|
|
284
|
+
logger.info(f"Downloading data to '{save_path}', it may take several tens of minutes, please wait...")
|
|
286
285
|
|
|
287
286
|
if CDS_CLIENT is None:
|
|
288
287
|
import cdsapi
|
|
@@ -299,29 +298,28 @@ def prepare_wps_input_data(area: Tuple[int, int, int, int]):
|
|
|
299
298
|
Args:
|
|
300
299
|
area (Tuple[int, int, int, int]): Range of longitude and latitude, `[lon1, lon2, lat1, lat2]`.
|
|
301
300
|
"""
|
|
302
|
-
wrf_config =
|
|
301
|
+
wrf_config = get_wrfrun_config().get_model_config("wrf")
|
|
303
302
|
# get start and end date from config
|
|
304
303
|
start_date = wrf_config["time"]["start_date"]
|
|
305
304
|
end_date = wrf_config["time"]["end_date"]
|
|
306
305
|
|
|
307
306
|
# remove second part
|
|
308
|
-
start_date = start_date
|
|
309
|
-
end_date = end_date
|
|
307
|
+
start_date = start_date.strftime("%Y-%m-%d %H:%M")
|
|
308
|
+
end_date = end_date.strftime("%Y-%m-%d %H:%M")
|
|
310
309
|
|
|
311
310
|
# get hour step
|
|
312
311
|
hour_step = wrf_config["time"]["input_data_interval"] // 3600
|
|
313
312
|
|
|
314
313
|
# get data save path
|
|
315
|
-
|
|
316
|
-
sst_save_path = wrf_config["near_goos_data_folder"]
|
|
314
|
+
data_save_path = get_wrfrun_config().get_input_data_path()
|
|
317
315
|
|
|
318
316
|
# download data
|
|
319
317
|
logger.info(f"Download background data of surface level...")
|
|
320
|
-
download_data(start_date, end_date, hour_step, area, f"{
|
|
318
|
+
download_data(start_date, end_date, hour_step, area, f"{data_save_path}/surface.grib",
|
|
321
319
|
data_format="grib", data_type="surface", overwrite=True)
|
|
322
320
|
|
|
323
321
|
logger.info(f"Download background data of pressure level...")
|
|
324
|
-
download_data(start_date, end_date, hour_step, area, f"{
|
|
322
|
+
download_data(start_date, end_date, hour_step, area, f"{data_save_path}/pressure.grib",
|
|
325
323
|
data_format="grib", data_type="pressure", overwrite=True)
|
|
326
324
|
|
|
327
325
|
# logger.info(f"Download NearGOOS data...")
|
wrfrun/extension/littler/core.py
CHANGED
|
@@ -20,7 +20,7 @@ from zipfile import ZipFile
|
|
|
20
20
|
from pandas import DataFrame, read_csv
|
|
21
21
|
import numpy as np
|
|
22
22
|
|
|
23
|
-
from wrfrun.core import
|
|
23
|
+
from wrfrun.core import get_wrfrun_config
|
|
24
24
|
from wrfrun.utils import logger
|
|
25
25
|
|
|
26
26
|
|
|
@@ -849,7 +849,7 @@ class LittleR(LittleRData):
|
|
|
849
849
|
if not file_path.endswith(".zlr"):
|
|
850
850
|
file_path = f"{file_path}.zlr"
|
|
851
851
|
|
|
852
|
-
file_path =
|
|
852
|
+
file_path = get_wrfrun_config().parse_resource_uri(file_path)
|
|
853
853
|
|
|
854
854
|
with ZipFile(file_path, "w") as zip_file:
|
|
855
855
|
with zip_file.open("header", "w") as header_file:
|
|
@@ -868,7 +868,7 @@ class LittleR(LittleRData):
|
|
|
868
868
|
:return: ``LittleR`` instance.
|
|
869
869
|
:rtype: LittleR
|
|
870
870
|
"""
|
|
871
|
-
file_path =
|
|
871
|
+
file_path = get_wrfrun_config().parse_resource_uri(file_path)
|
|
872
872
|
|
|
873
873
|
with ZipFile(file_path, "r") as zip_file:
|
|
874
874
|
with zip_file.open("header", "r") as header_file:
|
wrfrun/extension/utils.py
CHANGED
|
@@ -15,7 +15,7 @@ from os.path import exists
|
|
|
15
15
|
from shutil import copyfile
|
|
16
16
|
from typing import List, Optional
|
|
17
17
|
|
|
18
|
-
from wrfrun.core import
|
|
18
|
+
from wrfrun.core import get_wrfrun_config
|
|
19
19
|
from wrfrun.utils import check_path, logger
|
|
20
20
|
|
|
21
21
|
|
|
@@ -23,7 +23,7 @@ def extension_postprocess(output_dir: str, extension_id: str, outputs: Optional[
|
|
|
23
23
|
"""
|
|
24
24
|
This function provides a unified postprocessing interface for all extensions.
|
|
25
25
|
|
|
26
|
-
This function will save
|
|
26
|
+
This function will save outputs and logs in ``output_dir`` to the ``{output_path}/extension_id`` and ``{output_path}/extension_id/logs``,
|
|
27
27
|
in which ``output_path`` is defined in ``config.toml``.
|
|
28
28
|
Files end with ``.log`` are treated as log files, while others are treated as outputs.
|
|
29
29
|
You can save specific outputs by giving their names through the argument ``outputs``.
|
|
@@ -37,6 +37,7 @@ def extension_postprocess(output_dir: str, extension_id: str, outputs: Optional[
|
|
|
37
37
|
:param outputs: A list contains multiple filenames. Files in this will be treated as outputs.
|
|
38
38
|
:type outputs: list
|
|
39
39
|
"""
|
|
40
|
+
WRFRUNConfig = get_wrfrun_config()
|
|
40
41
|
output_path = WRFRUNConfig.WRFRUN_OUTPUT_PATH
|
|
41
42
|
output_save_path = f"{output_path}/{extension_id}"
|
|
42
43
|
log_save_path = f"{output_path}/{extension_id}/logs"
|
wrfrun/model/plot.py
CHANGED
|
@@ -9,7 +9,7 @@ from cartopy.mpl.geoaxes import GeoAxes
|
|
|
9
9
|
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
|
|
10
10
|
from haversine.haversine import Direction, Unit, inverse_haversine
|
|
11
11
|
|
|
12
|
-
from wrfrun.core import
|
|
12
|
+
from wrfrun.core import get_wrfrun_config
|
|
13
13
|
from wrfrun.utils import check_path, logger
|
|
14
14
|
|
|
15
15
|
|
|
@@ -183,7 +183,7 @@ def plot_domain_area(
|
|
|
183
183
|
logger.error("You need to give 'model_name' if `domain_settings == None`")
|
|
184
184
|
raise ValueError("You need to give 'model_name' if `domain_settings == None`")
|
|
185
185
|
|
|
186
|
-
user_settings =
|
|
186
|
+
user_settings = get_wrfrun_config().get_model_config(model_name)["domain"]
|
|
187
187
|
domain_settings: DomainSetting = {
|
|
188
188
|
"dx": user_settings["dx"],
|
|
189
189
|
"dy": user_settings["dy"],
|
|
@@ -241,6 +241,10 @@ def plot_domain_area(
|
|
|
241
241
|
end_lat, _ = inverse_haversine((ref_lat, ref_lon), false_northing, direction=Direction.NORTH, unit=Unit.METERS)
|
|
242
242
|
ax.set_extent([start_lon, end_lon, start_lat, end_lat])
|
|
243
243
|
|
|
244
|
+
case crs.LambertConformal:
|
|
245
|
+
false_easting, false_northing = _calculate_x_y_offset(domain_settings)
|
|
246
|
+
ax.set_extent([0, false_easting * 2, 0, false_northing * 2], crs=proj)
|
|
247
|
+
|
|
244
248
|
case _:
|
|
245
249
|
logger.error(f"Unsupported project type: {type(proj)}")
|
|
246
250
|
|
|
@@ -253,6 +257,7 @@ def generate_domain_area():
|
|
|
253
257
|
:return:
|
|
254
258
|
:rtype:
|
|
255
259
|
"""
|
|
260
|
+
WRFRUNConfig = get_wrfrun_config()
|
|
256
261
|
save_path = WRFRUNConfig.parse_resource_uri(WRFRUNConfig.WRFRUN_OUTPUT_PATH)
|
|
257
262
|
check_path(save_path)
|
|
258
263
|
save_path = abspath(save_path)
|
wrfrun/model/utils.py
CHANGED
|
@@ -13,9 +13,9 @@ Utility functions used by models.
|
|
|
13
13
|
from os import listdir
|
|
14
14
|
from shutil import move
|
|
15
15
|
|
|
16
|
-
from ..core import
|
|
16
|
+
from ..core import get_wrfrun_config
|
|
17
17
|
from ..utils import check_path, logger
|
|
18
|
-
from ..workspace.wrf import
|
|
18
|
+
from ..workspace.wrf import get_wrf_workspace_path
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def clear_model_logs():
|
|
@@ -23,8 +23,9 @@ def clear_model_logs():
|
|
|
23
23
|
This function can automatically collect unsaved log files,
|
|
24
24
|
and save them to the corresponding output directory of the ``Executable``.
|
|
25
25
|
"""
|
|
26
|
+
WRFRUNConfig = get_wrfrun_config()
|
|
26
27
|
work_status = WRFRUNConfig.WRFRUN_WORK_STATUS
|
|
27
|
-
work_path = WRFRUNConfig.parse_resource_uri(
|
|
28
|
+
work_path = WRFRUNConfig.parse_resource_uri(get_wrf_workspace_path("wrf"))
|
|
28
29
|
|
|
29
30
|
log_files = [x for x in listdir(work_path) if x.startswith("rsl.") or x.endswith(".log")]
|
|
30
31
|
|
wrfrun/model/wrf/core.py
CHANGED
|
@@ -24,13 +24,12 @@ from os.path import abspath, basename, exists
|
|
|
24
24
|
from shutil import copyfile, move, rmtree
|
|
25
25
|
from typing import Optional, Union
|
|
26
26
|
|
|
27
|
-
from wrfrun.core import ExecutableBase, FileConfigDict, InputFileError, NamelistIDError, WRFRUNConfig, WRFRUNExecDB
|
|
28
|
-
from wrfrun.workspace.wrf import WORKSPACE_MODEL_WPS, WORKSPACE_MODEL_WRF
|
|
27
|
+
from wrfrun.core import ExecutableBase, FileConfigDict, InputFileError, NamelistIDError, WRFRUNConfig, WRFRUNExecDB, get_wrfrun_config
|
|
29
28
|
from wrfrun.utils import logger
|
|
30
|
-
from .
|
|
31
|
-
from .namelist import (prepare_dfi_namelist, prepare_wps_namelist, prepare_wrf_namelist,
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
from wrfrun.workspace.wrf import get_wrf_workspace_path
|
|
30
|
+
from .namelist import (get_ungrib_out_dir_path, get_ungrib_out_prefix, prepare_dfi_namelist, prepare_wps_namelist, prepare_wrf_namelist, prepare_wrfda_namelist,
|
|
31
|
+
set_metgrid_fg_names, set_ungrib_out_prefix)
|
|
32
|
+
from .utils import process_after_ndown, reconcile_namelist_metgrid
|
|
34
33
|
from .vtable import VtableFiles
|
|
35
34
|
from ..base import NamelistName
|
|
36
35
|
|
|
@@ -40,13 +39,14 @@ def _check_and_prepare_namelist():
|
|
|
40
39
|
This function check if namelists needed by WPS/WRF have been loaded,
|
|
41
40
|
and prepare namelist if check fails.
|
|
42
41
|
"""
|
|
43
|
-
|
|
42
|
+
wrfrun_config = get_wrfrun_config()
|
|
43
|
+
if not wrfrun_config.check_namelist("wps"):
|
|
44
44
|
prepare_wps_namelist()
|
|
45
45
|
|
|
46
|
-
if not
|
|
46
|
+
if not wrfrun_config.check_namelist("wrf"):
|
|
47
47
|
prepare_wrf_namelist()
|
|
48
48
|
|
|
49
|
-
if not
|
|
49
|
+
if not wrfrun_config.check_namelist("wrfda"):
|
|
50
50
|
prepare_wrfda_namelist()
|
|
51
51
|
|
|
52
52
|
|
|
@@ -78,7 +78,7 @@ class GeoGrid(ExecutableBase):
|
|
|
78
78
|
mpi_cmd = "mpirun"
|
|
79
79
|
mpi_core_num = core_num
|
|
80
80
|
|
|
81
|
-
super().__init__(name="geogrid", cmd="./geogrid.exe", work_path=
|
|
81
|
+
super().__init__(name="geogrid", cmd="./geogrid.exe", work_path=get_wrf_workspace_path('wps'), mpi_use=mpi_use, mpi_cmd=mpi_cmd, mpi_core_num=mpi_core_num)
|
|
82
82
|
|
|
83
83
|
self.geogrid_tbl_file = geogrid_tbl_file
|
|
84
84
|
|
|
@@ -112,14 +112,14 @@ class GeoGrid(ExecutableBase):
|
|
|
112
112
|
if not WRFRUNConfig.IS_IN_REPLAY:
|
|
113
113
|
if self.geogrid_tbl_file is not None:
|
|
114
114
|
tbl_file: FileConfigDict = {
|
|
115
|
-
"file_path": self.geogrid_tbl_file, "save_path": f"{
|
|
115
|
+
"file_path": self.geogrid_tbl_file, "save_path": f"{get_wrf_workspace_path('wps')}/geogrid",
|
|
116
116
|
"save_name": "GEOGRID.TBL", "is_data": False, "is_output": False
|
|
117
117
|
}
|
|
118
118
|
self.add_input_files(tbl_file)
|
|
119
119
|
|
|
120
120
|
super().before_exec()
|
|
121
121
|
|
|
122
|
-
WRFRUNConfig.write_namelist(f"{
|
|
122
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wps')}/{NamelistName.WPS}", "wps")
|
|
123
123
|
|
|
124
124
|
# print debug logs
|
|
125
125
|
logger.debug("Namelist settings of 'geogrid':")
|
|
@@ -149,7 +149,7 @@ class LinkGrib(ExecutableBase):
|
|
|
149
149
|
"""
|
|
150
150
|
self._link_grib_input_path = "./input_grib_data_dir"
|
|
151
151
|
|
|
152
|
-
super().__init__(name="link_grib", cmd=["./link_grib.csh", f"{self._link_grib_input_path}/*", "."], work_path=
|
|
152
|
+
super().__init__(name="link_grib", cmd=["./link_grib.csh", f"{self._link_grib_input_path}/*", "."], work_path=get_wrf_workspace_path('wps'))
|
|
153
153
|
self.grib_dir_path = grib_dir_path
|
|
154
154
|
|
|
155
155
|
def generate_custom_config(self):
|
|
@@ -170,7 +170,7 @@ class LinkGrib(ExecutableBase):
|
|
|
170
170
|
logger.error(f"GRIB file directory not found: {_grib_dir_path}")
|
|
171
171
|
raise FileNotFoundError(f"GRIB file directory not found: {_grib_dir_path}")
|
|
172
172
|
|
|
173
|
-
save_path = f"{
|
|
173
|
+
save_path = f"{get_wrf_workspace_path('wps')}/{self._link_grib_input_path}"
|
|
174
174
|
save_path = WRFRUNConfig.parse_resource_uri(save_path)
|
|
175
175
|
if exists(save_path):
|
|
176
176
|
rmtree(save_path)
|
|
@@ -178,7 +178,7 @@ class LinkGrib(ExecutableBase):
|
|
|
178
178
|
for _file in listdir(_grib_dir_path):
|
|
179
179
|
_file_config: FileConfigDict = {
|
|
180
180
|
"file_path": f"{_grib_dir_path}/{_file}",
|
|
181
|
-
"save_path": f"{
|
|
181
|
+
"save_path": f"{get_wrf_workspace_path('wps')}/{self._link_grib_input_path}",
|
|
182
182
|
"save_name": _file, "is_data": True, "is_output": False,
|
|
183
183
|
}
|
|
184
184
|
self.add_input_files(_file_config)
|
|
@@ -202,7 +202,7 @@ class UnGrib(ExecutableBase):
|
|
|
202
202
|
Defaults to ``input_data_path`` set in user's config file.
|
|
203
203
|
:type input_data_path: str
|
|
204
204
|
"""
|
|
205
|
-
super().__init__(name="ungrib", cmd="./ungrib.exe", work_path=
|
|
205
|
+
super().__init__(name="ungrib", cmd="./ungrib.exe", work_path=get_wrf_workspace_path('wps'))
|
|
206
206
|
|
|
207
207
|
self.vtable_file = vtable_file
|
|
208
208
|
self.input_data_path = input_data_path
|
|
@@ -263,7 +263,7 @@ class UnGrib(ExecutableBase):
|
|
|
263
263
|
|
|
264
264
|
_file_config: FileConfigDict = {
|
|
265
265
|
"file_path": self.vtable_file,
|
|
266
|
-
"save_path":
|
|
266
|
+
"save_path": get_wrf_workspace_path('wps'),
|
|
267
267
|
"save_name": "Vtable",
|
|
268
268
|
"is_data": False,
|
|
269
269
|
"is_output": False
|
|
@@ -272,7 +272,7 @@ class UnGrib(ExecutableBase):
|
|
|
272
272
|
|
|
273
273
|
super().before_exec()
|
|
274
274
|
|
|
275
|
-
WRFRUNConfig.write_namelist(f"{
|
|
275
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wps')}/{NamelistName.WPS}", "wps")
|
|
276
276
|
|
|
277
277
|
# print debug logs
|
|
278
278
|
logger.debug("Namelist settings of 'ungrib':")
|
|
@@ -325,7 +325,7 @@ class MetGrid(ExecutableBase):
|
|
|
325
325
|
mpi_cmd = "mpirun"
|
|
326
326
|
mpi_core_num = core_num
|
|
327
327
|
|
|
328
|
-
super().__init__(name="metgrid", cmd="./metgrid.exe", work_path=
|
|
328
|
+
super().__init__(name="metgrid", cmd="./metgrid.exe", work_path=get_wrf_workspace_path('wps'), mpi_use=mpi_use, mpi_cmd=mpi_cmd, mpi_core_num=mpi_core_num)
|
|
329
329
|
|
|
330
330
|
self.geogrid_data_path = geogrid_data_path
|
|
331
331
|
self.ungrib_data_path = ungrib_data_path
|
|
@@ -377,7 +377,7 @@ class MetGrid(ExecutableBase):
|
|
|
377
377
|
if not WRFRUNConfig.IS_IN_REPLAY and not WRFRUNConfig.FAKE_SIMULATION_MODE:
|
|
378
378
|
# check input of metgrid.exe
|
|
379
379
|
# try to search input files in the output path if workspace is clear.
|
|
380
|
-
file_list = listdir(WRFRUNConfig.parse_resource_uri(
|
|
380
|
+
file_list = listdir(WRFRUNConfig.parse_resource_uri(get_wrf_workspace_path('wps')))
|
|
381
381
|
|
|
382
382
|
if "geo_em.d01.nc" not in file_list:
|
|
383
383
|
|
|
@@ -394,7 +394,7 @@ class MetGrid(ExecutableBase):
|
|
|
394
394
|
for _file in geogrid_file_list:
|
|
395
395
|
_file_config = {
|
|
396
396
|
"file_path": f"{self.geogrid_data_path}/{_file}",
|
|
397
|
-
"save_path":
|
|
397
|
+
"save_path": get_wrf_workspace_path('wps'),
|
|
398
398
|
"save_name": _file,
|
|
399
399
|
"is_data": True,
|
|
400
400
|
"is_output": True
|
|
@@ -427,7 +427,11 @@ class MetGrid(ExecutableBase):
|
|
|
427
427
|
|
|
428
428
|
super().before_exec()
|
|
429
429
|
|
|
430
|
-
WRFRUNConfig.write_namelist(f"{
|
|
430
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wps')}/{NamelistName.WPS}", "wps")
|
|
431
|
+
|
|
432
|
+
# print debug logs
|
|
433
|
+
logger.debug("Namelist settings of 'metgrid':")
|
|
434
|
+
logger.debug(WRFRUNConfig.get_namelist("wps"))
|
|
431
435
|
|
|
432
436
|
def after_exec(self):
|
|
433
437
|
if not WRFRUNConfig.IS_IN_REPLAY:
|
|
@@ -470,7 +474,7 @@ class Real(ExecutableBase):
|
|
|
470
474
|
|
|
471
475
|
_check_and_prepare_namelist()
|
|
472
476
|
|
|
473
|
-
super().__init__(name="real", cmd="./real.exe", work_path=
|
|
477
|
+
super().__init__(name="real", cmd="./real.exe", work_path=get_wrf_workspace_path('wrf'), mpi_use=mpi_use, mpi_cmd=mpi_cmd, mpi_core_num=mpi_core_num)
|
|
474
478
|
|
|
475
479
|
self.metgrid_data_path = metgrid_data_path
|
|
476
480
|
|
|
@@ -511,7 +515,7 @@ class Real(ExecutableBase):
|
|
|
511
515
|
for _file in file_list:
|
|
512
516
|
_file_config: FileConfigDict = {
|
|
513
517
|
"file_path": f"{self.metgrid_data_path}/{_file}",
|
|
514
|
-
"save_path":
|
|
518
|
+
"save_path": get_wrf_workspace_path('wrf'),
|
|
515
519
|
"save_name": _file,
|
|
516
520
|
"is_data": True,
|
|
517
521
|
"is_output": True
|
|
@@ -520,7 +524,11 @@ class Real(ExecutableBase):
|
|
|
520
524
|
|
|
521
525
|
super().before_exec()
|
|
522
526
|
|
|
523
|
-
WRFRUNConfig.write_namelist(f"{
|
|
527
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wrf')}/{NamelistName.WRF}", "wrf")
|
|
528
|
+
|
|
529
|
+
# print debug logs
|
|
530
|
+
logger.debug("Namelist settings of 'real':")
|
|
531
|
+
logger.debug(WRFRUNConfig.get_namelist("wrf"))
|
|
524
532
|
|
|
525
533
|
def after_exec(self):
|
|
526
534
|
if not WRFRUNConfig.IS_IN_REPLAY:
|
|
@@ -566,7 +574,7 @@ class WRF(ExecutableBase):
|
|
|
566
574
|
|
|
567
575
|
_check_and_prepare_namelist()
|
|
568
576
|
|
|
569
|
-
super().__init__(name="wrf", cmd="./wrf.exe", work_path=
|
|
577
|
+
super().__init__(name="wrf", cmd="./wrf.exe", work_path=get_wrf_workspace_path('wrf'), mpi_use=mpi_use, mpi_cmd=mpi_cmd, mpi_core_num=mpi_core_num)
|
|
570
578
|
|
|
571
579
|
self.input_file_dir_path = input_file_dir_path
|
|
572
580
|
self.restart_file_dir_path = restart_file_dir_path
|
|
@@ -625,7 +633,7 @@ class WRF(ExecutableBase):
|
|
|
625
633
|
for _file in file_list:
|
|
626
634
|
_file_config: FileConfigDict = {
|
|
627
635
|
"file_path": f"{self.input_file_dir_path}/{_file}",
|
|
628
|
-
"save_path":
|
|
636
|
+
"save_path": get_wrf_workspace_path('wrf'),
|
|
629
637
|
"save_name": _file,
|
|
630
638
|
"is_data": True,
|
|
631
639
|
"is_output": is_output
|
|
@@ -647,7 +655,7 @@ class WRF(ExecutableBase):
|
|
|
647
655
|
for _file in file_list:
|
|
648
656
|
_file_config: FileConfigDict = {
|
|
649
657
|
"file_path": f"{self.restart_file_dir_path}/{_file}",
|
|
650
|
-
"save_path":
|
|
658
|
+
"save_path": get_wrf_workspace_path('wrf'),
|
|
651
659
|
"save_name": _file,
|
|
652
660
|
"is_data": True,
|
|
653
661
|
"is_output": False
|
|
@@ -656,7 +664,11 @@ class WRF(ExecutableBase):
|
|
|
656
664
|
|
|
657
665
|
super().before_exec()
|
|
658
666
|
|
|
659
|
-
WRFRUNConfig.write_namelist(f"{
|
|
667
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wrf')}/{NamelistName.WRF}", "wrf")
|
|
668
|
+
|
|
669
|
+
# print debug logs
|
|
670
|
+
logger.debug("Namelist settings of 'wrf':")
|
|
671
|
+
logger.debug(WRFRUNConfig.get_namelist("wrf"))
|
|
660
672
|
|
|
661
673
|
def after_exec(self):
|
|
662
674
|
if not WRFRUNConfig.IS_IN_REPLAY:
|
|
@@ -701,7 +713,7 @@ class DFI(ExecutableBase):
|
|
|
701
713
|
mpi_cmd = "mpirun"
|
|
702
714
|
mpi_core_num = core_num
|
|
703
715
|
|
|
704
|
-
super().__init__(name="dfi", cmd="./wrf.exe", work_path=
|
|
716
|
+
super().__init__(name="dfi", cmd="./wrf.exe", work_path=get_wrf_workspace_path('wrf'), mpi_use=mpi_use, mpi_cmd=mpi_cmd, mpi_core_num=mpi_core_num)
|
|
705
717
|
|
|
706
718
|
self.input_file_dir_path = input_file_dir_path
|
|
707
719
|
self.update_real_output = update_real_output
|
|
@@ -755,7 +767,7 @@ class DFI(ExecutableBase):
|
|
|
755
767
|
for _file in file_list:
|
|
756
768
|
_file_config: FileConfigDict = {
|
|
757
769
|
"file_path": f"{self.input_file_dir_path}/{_file}",
|
|
758
|
-
"save_path":
|
|
770
|
+
"save_path": get_wrf_workspace_path('wrf'),
|
|
759
771
|
"save_name": _file,
|
|
760
772
|
"is_data": True,
|
|
761
773
|
"is_output": is_output
|
|
@@ -769,7 +781,7 @@ class DFI(ExecutableBase):
|
|
|
769
781
|
prepare_dfi_namelist()
|
|
770
782
|
|
|
771
783
|
super().before_exec()
|
|
772
|
-
WRFRUNConfig.write_namelist(f"{
|
|
784
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wrf')}/{NamelistName.WRF}", "dfi")
|
|
773
785
|
|
|
774
786
|
def after_exec(self):
|
|
775
787
|
if not WRFRUNConfig.IS_IN_REPLAY:
|
|
@@ -823,7 +835,7 @@ class NDown(ExecutableBase):
|
|
|
823
835
|
|
|
824
836
|
_check_and_prepare_namelist()
|
|
825
837
|
|
|
826
|
-
super().__init__(name="ndown", cmd="./ndown.exe", work_path=
|
|
838
|
+
super().__init__(name="ndown", cmd="./ndown.exe", work_path=get_wrf_workspace_path('wrf'), mpi_use=mpi_use, mpi_cmd=mpi_cmd, mpi_core_num=mpi_core_num)
|
|
827
839
|
|
|
828
840
|
self.wrfout_file_path = wrfout_file_path
|
|
829
841
|
self.real_output_dir_path = real_output_dir_path
|
|
@@ -853,7 +865,7 @@ class NDown(ExecutableBase):
|
|
|
853
865
|
"""
|
|
854
866
|
self.real_output_dir_path = self.custom_config["real_output_dir_path"]
|
|
855
867
|
self.update_namelist = self.custom_config["update_namelist"]
|
|
856
|
-
WRFRUNConfig.update_namelist(self.custom_config["namelist"])
|
|
868
|
+
WRFRUNConfig.update_namelist(self.custom_config["namelist"], "wrf")
|
|
857
869
|
|
|
858
870
|
def before_exec(self):
|
|
859
871
|
WRFRUNConfig.check_wrfrun_context(True)
|
|
@@ -872,14 +884,14 @@ class NDown(ExecutableBase):
|
|
|
872
884
|
|
|
873
885
|
wrfndi_file_config: FileConfigDict = {
|
|
874
886
|
"file_path": f"{self.real_output_dir_path}/wrfinput_d02",
|
|
875
|
-
"save_path":
|
|
887
|
+
"save_path": get_wrf_workspace_path('wrf'),
|
|
876
888
|
"save_name": "wrfndi_d02",
|
|
877
889
|
"is_data": True,
|
|
878
890
|
"is_output": is_output
|
|
879
891
|
}
|
|
880
892
|
wrfout_file_config: FileConfigDict = {
|
|
881
893
|
"file_path": self.wrfout_file_path,
|
|
882
|
-
"save_path":
|
|
894
|
+
"save_path": get_wrf_workspace_path('wrf'),
|
|
883
895
|
"save_name": "wrfout_d01",
|
|
884
896
|
"is_data": True,
|
|
885
897
|
"is_output": False
|
|
@@ -889,7 +901,7 @@ class NDown(ExecutableBase):
|
|
|
889
901
|
|
|
890
902
|
super().before_exec()
|
|
891
903
|
|
|
892
|
-
WRFRUNConfig.write_namelist(f"{
|
|
904
|
+
WRFRUNConfig.write_namelist(f"{get_wrf_workspace_path('wrf')}/{NamelistName.WRF}", "wrf")
|
|
893
905
|
|
|
894
906
|
def after_exec(self):
|
|
895
907
|
self.add_output_files(save_path=self._log_save_path, startswith="rsl.", outputs="namelist.input")
|
wrfrun/model/wrf/geodata.py
CHANGED
|
@@ -5,7 +5,7 @@ from typing import OrderedDict, Union
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
from xarray import DataArray
|
|
7
7
|
|
|
8
|
-
from wrfrun.core import
|
|
8
|
+
from wrfrun.core import get_wrfrun_config
|
|
9
9
|
from wrfrun.utils import logger
|
|
10
10
|
|
|
11
11
|
# for example: 00001-00200.00201-00400
|
|
@@ -75,6 +75,7 @@ def parse_geographical_data_index(index_path: str) -> OrderedDict:
|
|
|
75
75
|
# since the index file is very similar to fortran namelist file,
|
|
76
76
|
# we can manually add "&index" and "/" and parse it as a namelist
|
|
77
77
|
# temp file store path
|
|
78
|
+
WRFRUNConfig = get_wrfrun_config()
|
|
78
79
|
temp_file = f"{WRFRUNConfig.WRFRUN_TEMP_PATH}/geogrid_data.index"
|
|
79
80
|
temp_file = WRFRUNConfig.parse_resource_uri(temp_file)
|
|
80
81
|
|
wrfrun/model/wrf/namelist.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from datetime import datetime, timedelta
|
|
2
|
-
from os.path import
|
|
2
|
+
from os.path import basename, dirname, exists
|
|
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
|
|
8
|
+
from wrfrun.workspace.wrf import get_wrf_workspace_path
|
|
9
9
|
from .scheme import *
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
UNGRIB_OUTPUT_DIR = "./outputs"
|
|
13
12
|
|
|
14
13
|
|
|
@@ -20,7 +19,7 @@ def get_ungrib_out_dir_path() -> str:
|
|
|
20
19
|
:rtype: str
|
|
21
20
|
"""
|
|
22
21
|
wif_prefix = WRFRUNConfig.get_namelist("wps")["ungrib"]["prefix"]
|
|
23
|
-
wif_path = f"{
|
|
22
|
+
wif_path = f"{get_wrf_workspace_path('wps')}/{dirname(wif_prefix)}"
|
|
24
23
|
|
|
25
24
|
return wif_path
|
|
26
25
|
|
wrfrun/model/wrf/utils.py
CHANGED
|
@@ -4,7 +4,7 @@ from typing import Dict
|
|
|
4
4
|
|
|
5
5
|
from xarray import open_dataset
|
|
6
6
|
|
|
7
|
-
from wrfrun import
|
|
7
|
+
from wrfrun import get_wrfrun_config
|
|
8
8
|
from wrfrun.utils import logger
|
|
9
9
|
|
|
10
10
|
|
|
@@ -65,7 +65,7 @@ def reconcile_namelist_metgrid(metgrid_path: str):
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
get_wrfrun_config().update_namelist(update_values, "wrf")
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
def process_after_ndown():
|
|
@@ -77,6 +77,7 @@ def process_after_ndown():
|
|
|
77
77
|
|
|
78
78
|
:return:
|
|
79
79
|
"""
|
|
80
|
+
WRFRUNConfig = get_wrfrun_config()
|
|
80
81
|
namelist_data = WRFRUNConfig.get_namelist("wrf")
|
|
81
82
|
|
|
82
83
|
for section in namelist_data:
|
wrfrun/model/wrf/vtable.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
2
|
|
|
3
|
-
from wrfrun.core import
|
|
4
|
-
from wrfrun.workspace.wrf import
|
|
5
|
-
|
|
3
|
+
from wrfrun.core import WRFRunConfig, set_register_func
|
|
4
|
+
from wrfrun.workspace.wrf import get_wrf_workspace_path
|
|
6
5
|
|
|
7
6
|
VTABLE_URI = ":WRFRUN_VTABLE:"
|
|
8
7
|
|
|
@@ -58,9 +57,13 @@ class VtableFiles:
|
|
|
58
57
|
UKMO_NO_HEIGHTS = f"{VTABLE_URI}/Vtable.UKMO_no_heights"
|
|
59
58
|
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
def _register_vtable_uri(wrfrun_config: WRFRunConfig):
|
|
61
|
+
# register uri
|
|
62
|
+
if not wrfrun_config.check_resource_uri(VTABLE_URI):
|
|
63
|
+
wrfrun_config.register_resource_uri(VTABLE_URI, f"{get_wrf_workspace_path('wps')}/ungrib/Variable_Tables")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
set_register_func(_register_vtable_uri)
|
|
64
67
|
|
|
65
68
|
|
|
66
69
|
__all__ = ["VtableFiles"]
|
wrfrun/res/__init__.py
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
from os.path import abspath, dirname
|
|
2
2
|
|
|
3
|
-
from wrfrun.core import
|
|
3
|
+
from wrfrun.core import set_register_func, WRFRunConfig
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
RES_PATH = abspath(dirname(__file__))
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _register_res_uri(wrfrun_config: WRFRunConfig):
|
|
10
|
+
wrfrun_config.register_resource_uri(wrfrun_config.WRFRUN_RESOURCE_PATH, RES_PATH)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
set_register_func(_register_res_uri)
|
|
14
|
+
|
|
8
15
|
|
|
9
16
|
RUN_SH_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/run.template.sh"
|
|
10
17
|
EXT_NCL_PLOT_SCRIPT = ":WRFRUN_RESOURCE_PATH:/extension/plotgrids.ncl"
|
|
@@ -19,7 +26,12 @@ NAMELIST_WPS = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.wps.template"
|
|
|
19
26
|
CONFIG_MAIN_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/config.template.toml"
|
|
20
27
|
CONFIG_WRF_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/wrf.template.toml"
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
|
|
30
|
+
def _set_config_template_path(wrfrun_config: WRFRunConfig):
|
|
31
|
+
wrfrun_config.set_config_template_path(CONFIG_MAIN_TOML_TEMPLATE)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
set_register_func(_set_config_template_path)
|
|
23
35
|
|
|
24
36
|
|
|
25
37
|
__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"]
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
# Config template of wrfrun.
|
|
2
|
+
|
|
3
|
+
# Work directory.
|
|
4
|
+
# By setting work directory, you can let wrfrun work and save runtime files in a single directory.
|
|
5
|
+
# You can also set work_dir="" to let wrfrun work in the standard path.
|
|
6
|
+
work_dir = "./.wrfrun"
|
|
7
|
+
|
|
8
|
+
|
|
2
9
|
# Path of the directory which contains input data.
|
|
3
10
|
input_data_path = ""
|
|
4
11
|
|