29 import nwpservice.wps.namelistwps
30 import nwpservice.wps.geogrid
39 '''Class for managing preparation and execution of geogrid components
44 wpswrf_distro_path=None,
52 '''Initialises the class
54 Brings in the projection, nest and WPS geog_data path information.
56 Assembles into a single dict ready for running
58 Note that at some later time I should probably want to add in some
59 verifications of projection, nest, etc., for its suitability with
64 wpswrf_distro_path : str
65 (Optional) Full path to the WPS/WRF distribution to be used.
66 This is assumed to have been installed in a way that is compatible
67 with the nwpservice module. If arg is not present, uses a default
69 projection_dict : dict
70 Collection of projection parameters for the domain
72 Collection of WPS-style nesting parameters
74 (Optional) Path to the geog files used by WPS. This might be a
75 relative path, and will ultimately be inserted into namelist.wps
76 as written. If arg is not present, uses a default value
78 (Optional) Full path to a directory (assumed to have already
79 been created), to be used as scratch space for setting up and
80 running this geogrid instance. If arg is not present, uses a
83 (Optional) Number of MPI tasks to use for running this instance
84 of geogrid. If arg is not present, non-MPI execution is assumed.
86 Python logging level (e.g. logging.INFO)
91 These are examples of the projection and nest dictionaries (one- and
97 'map_proj' : 'lambert',
107 'parent_grid_ratio' : [1],
108 'i_parent_start' : [1],
109 'j_parent_start' : [1],
112 'geog_data_res' : ['10m'],
118 'parent_id' : [1, 1],
119 'parent_grid_ratio' : [1, 3],
120 'i_parent_start' : [1, 38],
121 'j_parent_start' : [1, 77],
124 'geog_data_res' : ['10m', '30s'],
140 LOGGER.debug(
'started')
146 if not wpswrf_distro_path:
147 wpswrf_distro_path = DEFAULTS.wpswrf_distro_path()
151 raise FileNotFoundError(
'wpswrf_distro_path not found: %s' %
154 if not geog_data_path:
155 geog_data_path = DEFAULTS.wps_geog_data_dir()
167 if not working_rootdir:
168 working_rootdir = DEFAULTS.working_scratch_rootdir()
171 raise FileNotFoundError(
'working_rootdir not found: %s' %
182 if 1 <= num_mpi_tasks <= DEFAULTS.max_mpi_tasks():
184 mpirunpath = DEFAULTS.mpirun_path()
185 if os.path.isfile(mpirunpath)
and \
186 os.access(mpirunpath, os.X_OK):
189 raise FileNotFoundError(
'mpirun not executable: %s' %
192 raise ValueError(
'Bad num_mpi_tasks value: %d' % num_mpi_tasks)
207 max_dom = len(nest_dict[
'i_parent_start'])
209 raise ValueError(
'Problem getting max_dom value')
211 if not 0 < max_dom <= DEFAULTS.max_dom_supported():
212 raise ValueError(
'Bad max_dom value: %d' % max_dom)
216 geogrid_sect = nest_dict
217 geogrid_sect[
'projection'] = projection_dict
218 geogrid_sect[
'geog_data_path'] = geog_data_path
231 '''Set up and run, via nwpservice module, instance of geogrid
235 geogrid_output_stagedir : str
236 (Optional) Full path to dir where geogrid files will be staged.
237 If not specified, no staging will be done. If specified, we
238 assume the dir already exists.
243 Dictionary with manifest of the geogrid files and the location
244 (if applicable) of staged files
248 LOGGER.debug(
'Start _run_geogrid()')
266 'geogrid_namelist.wps')
267 LOGGER.debug(
'namelist_wps_path: %s' % namelist_wps_path)
271 myobj = nwpservice.wps.namelistwps.NamelistWpsWriter(
272 destpath=namelist_wps_path,
275 LOGGER.debug(
'Writing namelist: %s' % namelist_wps_path)
280 str(uuid.uuid4()) +
'_geogridrun')
285 'wpswrf_rundir' : domainpath,
286 'namelist_wps' : namelist_wps_path,
287 'output_dir' : geogrid_output_stagedir,
294 nwpgeogrid_args[
'mpirun_path'] = DEFAULTS.mpirun_path()
296 geogrid_obj = nwpservice.wps.geogrid.Geogrid(**nwpgeogrid_args)
298 geogrid_obj = nwpservice.wps.geogrid.Geogrid(
299 wpswrf_distro_path=self._wpswrf_distro_path,
300 wpswrf_rundir=domainpath,
301 namelist_wps=namelist_wps_path,
302 output_dir=geogrid_output_stagedir,
303 log_level=DEFAULT_LOG_LEVEL
308 output_manifest = geogrid_obj.run()
309 LOGGER.debug(
'output_manifest: %s' % output_manifest)
313 stage_success = geogrid_obj.stage_output(auxfiles=
False)
315 staging_dir = geogrid_output_stagedir
320 'geogrid_output_manifest' : output_manifest,
321 'staging_dir' : staging_dir
324 LOGGER.debug(
'return_dict: %s' % return_dict)