Spaces:
Build error
Build error
jordancaraballo
commited on
Commit
•
a710522
1
Parent(s):
8857502
Added geogrid full pipeline for single node mpi
Browse files
wildfire_occurrence/model/pipelines/wrf_pipeline.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
import os
|
|
|
2 |
import logging
|
3 |
import datetime
|
|
|
|
|
4 |
from wildfire_occurrence.model.config import Config
|
5 |
from wildfire_occurrence.model.common import read_config
|
6 |
from wildfire_occurrence.model.data_download.ncep_fnl import NCEP_FNL
|
@@ -30,24 +33,36 @@ class WRFPipeline(object):
|
|
30 |
logging.info(f'Created working directory {self.conf.working_dir}')
|
31 |
|
32 |
# Setup working directories and dates
|
33 |
-
self.
|
34 |
self.conf.working_dir,
|
35 |
f'{self.start_date.strftime("%Y-%m-%d")}_' +
|
36 |
f'{self.start_date.strftime("%Y-%m-%d")}'
|
37 |
)
|
38 |
-
os.makedirs(self.
|
39 |
-
logging.info(f'Created output directory {self.
|
40 |
|
41 |
# Setup data_dir
|
42 |
-
self.data_dir = os.path.join(self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# -------------------------------------------------------------------------
|
45 |
-
#
|
46 |
# -------------------------------------------------------------------------
|
47 |
-
def
|
48 |
|
49 |
# Working on the setup of the project
|
50 |
-
logging.info('Starting
|
|
|
|
|
|
|
51 |
|
52 |
# Generate subdirectories to work with WRF
|
53 |
os.makedirs(self.data_dir, exist_ok=True)
|
@@ -61,11 +76,82 @@ class WRFPipeline(object):
|
|
61 |
)
|
62 |
data_downloader.download()
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
return
|
65 |
|
66 |
# -------------------------------------------------------------------------
|
67 |
-
#
|
68 |
# -------------------------------------------------------------------------
|
69 |
-
def
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import shutil
|
3 |
import logging
|
4 |
import datetime
|
5 |
+
from jinja2 import Environment, PackageLoader, select_autoescape
|
6 |
+
|
7 |
from wildfire_occurrence.model.config import Config
|
8 |
from wildfire_occurrence.model.common import read_config
|
9 |
from wildfire_occurrence.model.data_download.ncep_fnl import NCEP_FNL
|
|
|
33 |
logging.info(f'Created working directory {self.conf.working_dir}')
|
34 |
|
35 |
# Setup working directories and dates
|
36 |
+
self.simulation_dir = os.path.join(
|
37 |
self.conf.working_dir,
|
38 |
f'{self.start_date.strftime("%Y-%m-%d")}_' +
|
39 |
f'{self.start_date.strftime("%Y-%m-%d")}'
|
40 |
)
|
41 |
+
os.makedirs(self.simulation_dir, exist_ok=True)
|
42 |
+
logging.info(f'Created output directory {self.simulation_dir}')
|
43 |
|
44 |
# Setup data_dir
|
45 |
+
self.data_dir = os.path.join(self.simulation_dir, 'data')
|
46 |
+
os.makedirs(self.data_dir, exist_ok=True)
|
47 |
+
|
48 |
+
# Setup configuration directory
|
49 |
+
self.conf_dir = os.path.join(self.simulation_dir, 'configs')
|
50 |
+
os.makedirs(self.conf_dir, exist_ok=True)
|
51 |
+
|
52 |
+
# Setup configuration filenames
|
53 |
+
self.wps_conf_filename = os.path.join(self.conf_dir, 'namelist.wps')
|
54 |
+
self.wrf_conf_filename = os.path.join(self.conf_dir, 'namelist.input')
|
55 |
|
56 |
# -------------------------------------------------------------------------
|
57 |
+
# setup
|
58 |
# -------------------------------------------------------------------------
|
59 |
+
def setup(self) -> None:
|
60 |
|
61 |
# Working on the setup of the project
|
62 |
+
logging.info('Starting setup pipeline step')
|
63 |
+
|
64 |
+
# Working on the setup of the project
|
65 |
+
logging.info('Starting download from setup pipeline step')
|
66 |
|
67 |
# Generate subdirectories to work with WRF
|
68 |
os.makedirs(self.data_dir, exist_ok=True)
|
|
|
76 |
)
|
77 |
data_downloader.download()
|
78 |
|
79 |
+
# Generate configuration files for WRF - namelist.wps
|
80 |
+
self.setup_wps_config()
|
81 |
+
|
82 |
+
# Generate configuration files for WRF - namelist.input
|
83 |
+
|
84 |
+
return
|
85 |
+
|
86 |
+
# -------------------------------------------------------------------------
|
87 |
+
# geogrid
|
88 |
+
# -------------------------------------------------------------------------
|
89 |
+
def geogrid(self) -> None:
|
90 |
+
|
91 |
+
logging.info('Preparing to run geogrid.exe')
|
92 |
+
|
93 |
+
# setup WPS directory
|
94 |
+
local_wps_path = os.path.join(self.simulation_dir, 'WPS')
|
95 |
+
if not os.path.exists(local_wps_path):
|
96 |
+
shutil.copytree(
|
97 |
+
self.conf.wps_path, local_wps_path, dirs_exist_ok=True)
|
98 |
+
logging.info(f'Done copying WPS to {local_wps_path}')
|
99 |
+
|
100 |
+
# create configuration file symlink
|
101 |
+
local_wps_conf = os.path.join(local_wps_path, 'namelist.wps')
|
102 |
+
if not os.path.lexists(local_wps_conf):
|
103 |
+
os.symlink(
|
104 |
+
self.wps_conf_filename,
|
105 |
+
local_wps_conf
|
106 |
+
)
|
107 |
+
logging.info(f'Created namelist.wps symlink on {local_wps_path}')
|
108 |
+
|
109 |
+
# go to WPS directory and run wps
|
110 |
+
os.chdir(local_wps_path)
|
111 |
+
logging.info(f'Changed working directory to {local_wps_path}')
|
112 |
+
|
113 |
+
# setup geogrid command
|
114 |
+
geodrid_cmd = \
|
115 |
+
'singularity exec -B /explore/nobackup/projects/ilab,' + \
|
116 |
+
'$NOBACKUP,/lscratch,/panfs/ccds02/nobackup/projects/ilab ' + \
|
117 |
+
f'{self.conf.container_path} ' + \
|
118 |
+
'mpirun -np 40 --oversubscribe ./geogrid.exe'
|
119 |
+
|
120 |
+
# run geogrid command
|
121 |
+
os.system(geodrid_cmd)
|
122 |
+
|
123 |
return
|
124 |
|
125 |
# -------------------------------------------------------------------------
|
126 |
+
# setup_wps_config
|
127 |
# -------------------------------------------------------------------------
|
128 |
+
def setup_wps_config(self, template_filename: str = 'namelist.wps.jinja2'):
|
129 |
+
|
130 |
+
# Setup jinja2 Environment
|
131 |
+
env = Environment(
|
132 |
+
loader=PackageLoader("wildfire_occurrence"),
|
133 |
+
autoescape=select_autoescape()
|
134 |
+
)
|
135 |
+
|
136 |
+
# Get the template of the environment for WPS
|
137 |
+
template = env.get_template(template_filename)
|
138 |
+
|
139 |
+
# Modify configuration to include start and end date
|
140 |
+
self.conf.wps_config['start_date'] = \
|
141 |
+
self.start_date.strftime("%Y-%m-%d_%H:%M:%S")
|
142 |
+
self.conf.wps_config['end_date'] = \
|
143 |
+
self.end_date.strftime("%Y-%m-%d_%H:%M:%S")
|
144 |
+
|
145 |
+
# Fill in elements from the WPS environment and save filename
|
146 |
+
template.stream(self.conf.wps_config).dump(self.wps_conf_filename)
|
147 |
+
logging.info(f'Saved WPS configuration at {self.wps_conf_filename}')
|
148 |
+
|
149 |
return
|
150 |
+
|
151 |
+
# -------------------------------------------------------------------------
|
152 |
+
# setup_wrf_config
|
153 |
+
# -------------------------------------------------------------------------
|
154 |
+
def setup_wrf_config(self):
|
155 |
+
environment = Environment(loader=FileSystemLoader("templates/"))
|
156 |
+
template = environment.get_template("message.txt")
|
157 |
+
return
|
wildfire_occurrence/view/wrf_pipeline_cli.py
CHANGED
@@ -51,10 +51,10 @@ def main():
|
|
51 |
dest='pipeline_step',
|
52 |
help='Pipeline step to perform',
|
53 |
default=[
|
54 |
-
'
|
55 |
'ubgrib', 'real', 'wrf', 'all'],
|
56 |
choices=[
|
57 |
-
'
|
58 |
'ubgrib', 'real', 'wrf', 'all'])
|
59 |
|
60 |
args = parser.parse_args()
|
@@ -77,9 +77,11 @@ def main():
|
|
77 |
pipeline = WRFPipeline(
|
78 |
args.config_file, args.start_date, args.forecast_lenght)
|
79 |
|
80 |
-
#
|
81 |
-
if "
|
82 |
-
pipeline.
|
|
|
|
|
83 |
|
84 |
logging.info(f'Took {(time.time()-timer)/60.0:.2f} min.')
|
85 |
|
|
|
51 |
dest='pipeline_step',
|
52 |
help='Pipeline step to perform',
|
53 |
default=[
|
54 |
+
'setup', 'geogrid',
|
55 |
'ubgrib', 'real', 'wrf', 'all'],
|
56 |
choices=[
|
57 |
+
'setup', 'geogrid',
|
58 |
'ubgrib', 'real', 'wrf', 'all'])
|
59 |
|
60 |
args = parser.parse_args()
|
|
|
77 |
pipeline = WRFPipeline(
|
78 |
args.config_file, args.start_date, args.forecast_lenght)
|
79 |
|
80 |
+
# WRF pipeline steps
|
81 |
+
if "setup" in args.pipeline_step or "all" in args.pipeline_step:
|
82 |
+
pipeline.setup()
|
83 |
+
if "geogrid" in args.pipeline_step or "all" in args.pipeline_step:
|
84 |
+
pipeline.geogrid()
|
85 |
|
86 |
logging.info(f'Took {(time.time()-timer)/60.0:.2f} min.')
|
87 |
|