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
wrfrun/plot/wps.py CHANGED
@@ -1,3 +1,16 @@
1
+ """
2
+ wrfrun.plot.wps
3
+ ###############
4
+
5
+ Functions to plot outputs of ``geogrid.exe``.
6
+
7
+ .. autosummary::
8
+ :toctree: generated/
9
+
10
+ get_cmap_ticks
11
+ draw_geogrid
12
+ """
13
+
1
14
  from typing import Tuple
2
15
 
3
16
  from cartopy import crs
@@ -6,80 +19,83 @@ from matplotlib.collections import QuadMesh
6
19
  from matplotlib.colors import ListedColormap
7
20
  from matplotlib.figure import Figure
8
21
  from netCDF4 import Dataset # type: ignore
9
- from wrf import getvar, latlon_coords, get_cartopy, to_np
10
22
  from xarray import DataArray
11
23
 
12
- from wrfrun.utils import logger
24
+ from wrfrun.log import logger
13
25
 
14
26
  # Here defines the colormap for landuse and soiltype
15
- LANDUSE_CMAP = ListedColormap((
16
- [0, .4, 0], # 1: Evergreen Needleleaf Forest
17
- [0, .4, .2], # 2: Evergreen Broadleaf Forest
18
- [.2, .8, .2], # 3: Deciduous Needleleaf Forest
19
- [.2, .8, .4], # 4: Deciduous Broadleaf Forest
20
- [.2, .6, .2], # 5: Mixed Forests
21
- [.3, .7, 0], # 6: Closed Shrublands
22
- [.82, .41, .12], # 7: Open Shurblands
23
- [.74, .71, .41], # 8: Woody Savannas
24
- [1, .84, .0], # 9: Savannas
25
- [0, 1, 0], # 10: Grasslands
26
- [0, 1, 1], # 11: Permanent Wetlands
27
- [1, 1, 0], # 12: Croplands
28
- [1, 0, 0], # 13: Urban and Built-up
29
- [.7, .9, .3], # 14: Cropland/Natual Vegation Mosaic
30
- [1, 1, 1], # 15: Snow and Ice
31
- [.914, .914, .7], # 16: Barren or Sparsely Vegetated
32
- [.5, .7, 1], # 17: Water (like oceans)
33
- [.86, .08, .23], # 18: Wooded Tundra
34
- [.97, .5, .31], # 19: Mixed Tundra
35
- [.91, .59, .48], # 20: Barren Tundra
36
- [0, 0, .88], # 21: Lake
37
- ))
27
+ LANDUSE_CMAP = ListedColormap(
28
+ (
29
+ [0, 0.4, 0], # 1: Evergreen Needleleaf Forest
30
+ [0, 0.4, 0.2], # 2: Evergreen Broadleaf Forest
31
+ [0.2, 0.8, 0.2], # 3: Deciduous Needleleaf Forest
32
+ [0.2, 0.8, 0.4], # 4: Deciduous Broadleaf Forest
33
+ [0.2, 0.6, 0.2], # 5: Mixed Forests
34
+ [0.3, 0.7, 0], # 6: Closed Shrublands
35
+ [0.82, 0.41, 0.12], # 7: Open Shurblands
36
+ [0.74, 0.71, 0.41], # 8: Woody Savannas
37
+ [1, 0.84, 0.0], # 9: Savannas
38
+ [0, 1, 0], # 10: Grasslands
39
+ [0, 1, 1], # 11: Permanent Wetlands
40
+ [1, 1, 0], # 12: Croplands
41
+ [1, 0, 0], # 13: Urban and Built-up
42
+ [0.7, 0.9, 0.3], # 14: Cropland/Natual Vegation Mosaic
43
+ [1, 1, 1], # 15: Snow and Ice
44
+ [0.914, 0.914, 0.7], # 16: Barren or Sparsely Vegetated
45
+ [0.5, 0.7, 1], # 17: Water (like oceans)
46
+ [0.86, 0.08, 0.23], # 18: Wooded Tundra
47
+ [0.97, 0.5, 0.31], # 19: Mixed Tundra
48
+ [0.91, 0.59, 0.48], # 20: Barren Tundra
49
+ [0, 0, 0.88], # 21: Lake
50
+ )
51
+ )
38
52
 
39
53
  LANDUSE_LABELS = [
40
- 'Evergreen Needleleaf Forest',
41
- 'Evergreen Broadleaf Forest',
42
- 'Deciduous Needleleaf Forest',
43
- 'Deciduous Broadleaf Forest',
44
- 'Mixed Forests',
45
- 'Closed Shrublands',
46
- 'Open Shrublands',
47
- 'Woody Savannas',
48
- 'Savannas',
49
- 'Grasslands',
50
- 'Permanent Wetlands',
51
- 'Croplands',
52
- 'Urban and Built-Up',
53
- 'Cropland/Natural Vegetation Mosaic',
54
- 'Snow and Ice',
55
- 'Barren or Sparsely Vegetated',
56
- 'Water',
57
- 'Wooded Tundra',
58
- 'Mixed Tundra',
59
- 'Barren Tundra',
60
- 'Lake',
54
+ "Evergreen Needleleaf Forest",
55
+ "Evergreen Broadleaf Forest",
56
+ "Deciduous Needleleaf Forest",
57
+ "Deciduous Broadleaf Forest",
58
+ "Mixed Forests",
59
+ "Closed Shrublands",
60
+ "Open Shrublands",
61
+ "Woody Savannas",
62
+ "Savannas",
63
+ "Grasslands",
64
+ "Permanent Wetlands",
65
+ "Croplands",
66
+ "Urban and Built-Up",
67
+ "Cropland/Natural Vegetation Mosaic",
68
+ "Snow and Ice",
69
+ "Barren or Sparsely Vegetated",
70
+ "Water",
71
+ "Wooded Tundra",
72
+ "Mixed Tundra",
73
+ "Barren Tundra",
74
+ "Lake",
61
75
  ]
62
76
 
63
77
 
64
78
  # Here defines the colormap and labels for soil types
65
- SOILTYPE_CMAP = ListedColormap((
66
- [0, .4, 0], # 1: Sand
67
- [0, .4, .2], # 2: Loamy Sand
68
- [.2, .8, .2], # 3: Sandy Loam
69
- [.2, .8, .4], # 4: Silt Loam
70
- [.2, .6, .2], # 5: Silt
71
- [.3, .7, 0], # 6: Loam
72
- [.82, .41, .12], # 7: Sandy Clay Loam
73
- [.74, .71, .41], # 8: Silty Clay Loam
74
- [1, .84, .0], # 9: Clay Loam
75
- [0, 1, 0], # 10: Sandy Clay
76
- [0, 1, 1], # 11: Silty Clay
77
- [1, 1, 0], # 12: Clay
78
- [1, 0, 0], # 13: Organic Material
79
- [.7, .9, .3], # 14: Water
80
- [1, 1, 1], # 15: Bedrock
81
- [.914, .914, .7] # 16: Other
82
- ))
79
+ SOILTYPE_CMAP = ListedColormap(
80
+ (
81
+ [0, 0.4, 0], # 1: Sand
82
+ [0, 0.4, 0.2], # 2: Loamy Sand
83
+ [0.2, 0.8, 0.2], # 3: Sandy Loam
84
+ [0.2, 0.8, 0.4], # 4: Silt Loam
85
+ [0.2, 0.6, 0.2], # 5: Silt
86
+ [0.3, 0.7, 0], # 6: Loam
87
+ [0.82, 0.41, 0.12], # 7: Sandy Clay Loam
88
+ [0.74, 0.71, 0.41], # 8: Silty Clay Loam
89
+ [1, 0.84, 0.0], # 9: Clay Loam
90
+ [0, 1, 0], # 10: Sandy Clay
91
+ [0, 1, 1], # 11: Silty Clay
92
+ [1, 1, 0], # 12: Clay
93
+ [1, 0, 0], # 13: Organic Material
94
+ [0.7, 0.9, 0.3], # 14: Water
95
+ [1, 1, 1], # 15: Bedrock
96
+ [0.914, 0.914, 0.7], # 16: Other
97
+ )
98
+ )
83
99
 
84
100
  SOILTYPE_LABELS = [
85
101
  "Sand",
@@ -97,7 +113,7 @@ SOILTYPE_LABELS = [
97
113
  "Organic Material",
98
114
  "Water",
99
115
  "Bedrock",
100
- "Other"
116
+ "Other",
101
117
  ]
102
118
 
103
119
 
@@ -159,15 +175,18 @@ def draw_geogrid(data_path: str, field: str, fig: Figure, nrow: int, ncol: int,
159
175
  :return: (GeoAxes, QuadMesh)
160
176
  :rtype: tuple
161
177
  """
178
+ # lazy import
179
+ from wrf import get_cartopy, getvar, latlon_coords, to_np
180
+
162
181
  # take out data
163
- data: DataArray = getvar(Dataset(data_path), field) # type: ignore
182
+ data: DataArray = getvar(Dataset(data_path), field) # type: ignore
164
183
 
165
184
  # soiltype data is different from landuse data
166
185
  if field in ["SOILCTOP", "SOILCBOT"]:
167
- data = data.argmax(dim="soil_cat", keep_attrs=True) # type: ignore
186
+ data = data.argmax(dim="soil_cat", keep_attrs=True) # type: ignore
168
187
  # get data attrs
169
188
  data_attrs = data.attrs
170
- data = data + 1 # type: ignore
189
+ data = data + 1 # type: ignore
171
190
  data.attrs = data_attrs
172
191
 
173
192
  # get latitude and longitude
@@ -183,14 +202,12 @@ def draw_geogrid(data_path: str, field: str, fig: Figure, nrow: int, ncol: int,
183
202
  cmap, labels, ticks = get_cmap_ticks(field)
184
203
 
185
204
  # convert data to numpy
186
- data, lats, lons = to_np(data), to_np(lats), to_np(lons) # type: ignore
205
+ data, lats, lons = to_np(data), to_np(lats), to_np(lons) # type: ignore
187
206
 
188
207
  # plot
189
- im = ax.pcolormesh(
190
- lons, lats, data, vmin=1, vmax=len(labels) + 1, cmap=cmap, transform=crs.PlateCarree()
191
- )
208
+ im = ax.pcolormesh(lons, lats, data, vmin=1, vmax=len(labels) + 1, cmap=cmap, transform=crs.PlateCarree())
192
209
 
193
- return ax, im # type: ignore
210
+ return ax, im # type: ignore
194
211
 
195
212
 
196
213
  __all__ = ["draw_geogrid", "get_cmap_ticks"]
wrfrun/res/__init__.py CHANGED
@@ -1,7 +1,90 @@
1
- from os.path import abspath, dirname
1
+ """
2
+ wrfrun.res
3
+ ##########
4
+
5
+ This module contains resources used by other wrfrun modules.
6
+
7
+ A ``__init__.py`` file will be generated by ``generate_init.py`` when building the package.
8
+
9
+ The main resource directory and each subdirectory has a ``name_map.json`` file,
10
+ which maps real name of files or directories to a simpler name.
11
+ ``generate_init.py`` reads these JSON and generates variable names based on the name inside it.
12
+
13
+ For example, assume we have a directory which structure is like:
14
+
15
+ .. code-block::
16
+
17
+ res
18
+ |
19
+ |---extension
20
+ | |
21
+ | |---plotgrids.ncl
22
+ | ----name_map.json
23
+ |
24
+ |---job_scheduler
25
+ | |
26
+ | |---pbs.template
27
+ | ----name_map.json
28
+ |
29
+ |---config.yaml.template
30
+ ----name_map.json
31
+
32
+ And the content of each ``name_map.json`` is:
33
+
34
+ .. code-block:: json
35
+ :caption: name_map.json
36
+
37
+ {
38
+ "extension": {
39
+ "name": "EXT",
40
+ "type": "dir",
41
+ },
42
+ "job_scheduler": {
43
+ "name": "JOBSYS",
44
+ "type": "dir",
45
+ },
46
+ "config.yaml.template": {
47
+ "name": "CONFIG_TEMPLATE",
48
+ "type": "file",
49
+ }
50
+ }
2
51
 
3
- from wrfrun.core import set_register_func, WRFRunConfig
52
+ .. code-block:: json
53
+ :caption: name_map.json
54
+
55
+ {
56
+ "plotgrids.ncl": {
57
+ "name": "PLOT_DOMAIN_NCL",
58
+ "type": "file",
59
+ }
60
+ }
61
+
62
+ .. code-block:: json
63
+ :caption: name_map.json
64
+
65
+ {
66
+ "pbs.template": {
67
+ "name": "PBS_TEMPLATE",
68
+ "type": "file",
69
+ }
70
+ }
71
+
72
+ Then, the generated variable names in ``__init__.py`` are:
73
+
74
+ .. code-block:: python
75
+ :caption: __init__.py
76
+
77
+ EXT_PLOT_DOMAIN_NCL = "..."
78
+ JOBSYS_PBS_TEMPLATE = "..."
79
+ CONFIG_TEMPLATE = "..."
80
+ """
81
+
82
+ # This file is generated by scripts `wrfrun/res/generate_init.py`.
83
+ # Don't change this file directly.
84
+
85
+ from os.path import abspath, dirname
4
86
 
87
+ from wrfrun.core import WRFRUN, WRFRunConfig
5
88
 
6
89
  RES_PATH = abspath(dirname(__file__))
7
90
 
@@ -10,7 +93,7 @@ def _register_res_uri(wrfrun_config: WRFRunConfig):
10
93
  wrfrun_config.register_resource_uri(wrfrun_config.WRFRUN_RESOURCE_PATH, RES_PATH)
11
94
 
12
95
 
13
- set_register_func(_register_res_uri)
96
+ WRFRUN.set_config_register_func(_register_res_uri)
14
97
 
15
98
 
16
99
  RUN_SH_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/run.template.sh"
@@ -25,13 +108,28 @@ NAMELIST_WRF = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.input.wrf.template"
25
108
  NAMELIST_WPS = ":WRFRUN_RESOURCE_PATH:/namelist/namelist.wps.template"
26
109
  CONFIG_MAIN_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/config.template.toml"
27
110
  CONFIG_WRF_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/wrf.template.toml"
111
+ CONFIG_PALM_TOML_TEMPLATE = ":WRFRUN_RESOURCE_PATH:/config/palm.template.toml"
28
112
 
29
113
 
30
114
  def _set_config_template_path(wrfrun_config: WRFRunConfig):
31
115
  wrfrun_config.set_config_template_path(CONFIG_MAIN_TOML_TEMPLATE)
32
116
 
33
117
 
34
- set_register_func(_set_config_template_path)
118
+ WRFRUN.set_config_register_func(_set_config_template_path)
35
119
 
36
120
 
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"]
121
+ __all__ = [
122
+ "RUN_SH_TEMPLATE",
123
+ "EXT_NCL_PLOT_SCRIPT",
124
+ "SCHEDULER_LSF_TEMPLATE",
125
+ "SCHEDULER_PBS_TEMPLATE",
126
+ "SCHEDULER_SLURM_TEMPLATE",
127
+ "NAMELIST_WRFDA",
128
+ "NAMELIST_DFI",
129
+ "NAMELIST_REAL",
130
+ "NAMELIST_WRF",
131
+ "NAMELIST_WPS",
132
+ "CONFIG_MAIN_TOML_TEMPLATE",
133
+ "CONFIG_WRF_TOML_TEMPLATE",
134
+ "CONFIG_PALM_TOML_TEMPLATE",
135
+ ]
@@ -55,3 +55,11 @@ use = false
55
55
  # You can give both absolute and relative path.
56
56
  # The relative path is resolved based on this configuration file.
57
57
  include = "./configs/wrf.toml"
58
+
59
+ [model.palm]
60
+ # If you want to use PALM model, set use to true.
61
+ use = false
62
+ # Import configurations from another toml file.
63
+ # You can give both absolute and relative path.
64
+ # The relative path is resolved based on this configuration file.
65
+ include = "./configs/palm.toml"
@@ -0,0 +1,23 @@
1
+ # Config for PALM model.
2
+ # PALM model path.
3
+ palm_path = "/path/to/your/PALM/folder"
4
+
5
+ # Place data here.
6
+ data_dir_path = "/path/to/your/data/folder"
7
+
8
+ # Set PALM config identifier here.
9
+ # If you want to use a config identifier you never used before,
10
+ # make sure palm can build successfully.
11
+ config_identifier = "wrfrun"
12
+
13
+ # PALM config file.
14
+ # If empty, use the default config from PALM.
15
+ # You can get a file from PALM_INSTALL_DIR/.palm.config.default
16
+ config_file_path = ""
17
+
18
+ # You can provide topography file here.
19
+ topography_file = '/path/to/your/topography/file'
20
+
21
+ # You need to give your namelist file,
22
+ # cause wrfrun hasn't supported more options in toml config file yet.
23
+ user_namelist = '/path/to/your/namelist/file'