wrfrun 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. wrfrun/cli.py +128 -0
  2. wrfrun/core/base.py +8 -5
  3. wrfrun/core/config.py +81 -150
  4. wrfrun/core/replay.py +1 -1
  5. wrfrun/core/server.py +81 -78
  6. wrfrun/extension/goos_sst/__init__.py +5 -5
  7. wrfrun/extension/goos_sst/core.py +4 -1
  8. wrfrun/extension/goos_sst/res/Vtable.ERA_GOOS_SST +1 -1
  9. wrfrun/extension/goos_sst/res/__init__.py +17 -0
  10. wrfrun/extension/goos_sst/utils.py +21 -5
  11. wrfrun/extension/littler/__init__.py +57 -1
  12. wrfrun/extension/littler/{utils.py → core.py} +326 -40
  13. wrfrun/extension/utils.py +22 -21
  14. wrfrun/model/__init__.py +24 -1
  15. wrfrun/model/plot.py +253 -35
  16. wrfrun/model/utils.py +17 -8
  17. wrfrun/model/wrf/__init__.py +41 -0
  18. wrfrun/model/wrf/core.py +215 -99
  19. wrfrun/model/wrf/exec_wrap.py +49 -35
  20. wrfrun/model/wrf/namelist.py +79 -4
  21. wrfrun/model/wrf/{_metgrid.py → utils.py} +36 -2
  22. wrfrun/model/wrf/vtable.py +2 -1
  23. wrfrun/res/__init__.py +8 -5
  24. wrfrun/res/config/config.template.toml +50 -0
  25. wrfrun/res/{config.toml.template → config/wrf.template.toml} +7 -46
  26. wrfrun/res/run.template.sh +10 -0
  27. wrfrun/res/scheduler/lsf.template +5 -0
  28. wrfrun/res/{job_scheduler → scheduler}/pbs.template +1 -1
  29. wrfrun/res/{job_scheduler → scheduler}/slurm.template +2 -1
  30. wrfrun/run.py +19 -23
  31. wrfrun/scheduler/__init__.py +35 -0
  32. wrfrun/scheduler/env.py +44 -0
  33. wrfrun/scheduler/lsf.py +47 -0
  34. wrfrun/scheduler/pbs.py +48 -0
  35. wrfrun/scheduler/script.py +70 -0
  36. wrfrun/scheduler/slurm.py +48 -0
  37. wrfrun/scheduler/utils.py +14 -0
  38. wrfrun/utils.py +8 -3
  39. wrfrun/workspace/__init__.py +38 -0
  40. wrfrun/workspace/core.py +92 -0
  41. wrfrun/workspace/wrf.py +121 -0
  42. {wrfrun-0.1.8.dist-info → wrfrun-0.1.9.dist-info}/METADATA +3 -2
  43. wrfrun-0.1.9.dist-info/RECORD +62 -0
  44. wrfrun-0.1.9.dist-info/entry_points.txt +3 -0
  45. wrfrun/model/wrf/_ndown.py +0 -39
  46. wrfrun/pbs.py +0 -86
  47. wrfrun/res/run.sh.template +0 -16
  48. wrfrun/workspace.py +0 -88
  49. wrfrun-0.1.8.dist-info/RECORD +0 -51
  50. {wrfrun-0.1.8.dist-info → wrfrun-0.1.9.dist-info}/WHEEL +0 -0
@@ -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