wrf module

The wrf module contains functions related to WRF/WPS.

class wrf.wps_domains.WPSDomainLCC(dom_id, cfg, parent=None)[source]

A top-level Lambert Conic Conformal projection domain.

latlon_to_ij(lat, lon)[source]

Convert latitude and longitude into grid coordinates.

If this is a child domain, it asks it’s parent to do the projectiona and then remaps it into its own coordinate system via parent_start and cell size ratio.

Parameters:
  • lat – latitude
  • lon – longitude
Returns:

the i, j position in grid coordinates

update_inputnl(nml)[source]

Update the WRF input namelist according to the domain configuration.

Parameters:nml – the namelist dictionary
update_wpsnl(nml)[source]

Update the share and geogrid section of the WPS namelist.

Parameters:nml_geogrid – a dictionary containing the geogrid section of the WPS namelist
class wrf.wps_domains.WPSDomainConf(cfg)[source]

Represents a domain configuration for WPS, that is one or more domains with one top-level domain.

prepare_for_geogrid(wps_nml, input_nml=None, wrfxpy_dir=None, wps_dir=None)[source]

Update the namelists for geogrid processing - write the domain configurations. Additionally

Parameters:
  • wps_nml – the WPS namelist
  • input_nml – the input namelist, if None that skipped
  • wrfxpy_dir – the installation directory of wrfxpy (if None, no linking is done)
  • wps_dir – the WPS working directory
prepare_for_metgrid(wps_nml)[source]

Set all domains that we use to active.

Parameters:wps_nml – the WPS namelist
class wrf.wrf_data.WRFModelData(path, variables=['T2', 'Q2', 'PSFC', 'RAINNC', 'RAINC'])[source]

This class represents information obtained from a wrfout or wrfinput as generated by WPS or WRF. Methods for loading data and deriving new variables on the fly are provided.

check_variable(V, name, mn, mx)[source]

Check if the variable V is outside the range [mn,mx].

compute_rainfall_per_timestep()[source]

Compute the rainfall per timestep at each grid point from WRF variables RAINNC and RAINC.

equilibrium_moisture()[source]

Uses the fields of the WRF model to compute the equilibrium field.

get_domain_extent()[source]

Return smallest enclosing aligned rectangle of domain. return is a tuple (min(lon), min(lat), max(lon), max(lat)).

get_field(field_name)[source]

Return the field with the name field_name.

get_gmt_times()[source]

Returns the local time (depends on time zone set).

get_lats()[source]

Return lattitute of grid points.

get_lons()[source]

Return longitude of grid points.

get_moisture_equilibria()[source]

Return the drying and wetting equilibrium.

load_data(var_names)[source]

Loads selected variables from the wrfinput/wrfoutput file.

The spatiotemporal information is always loaded: ‘XLAT’, ‘XLONG’, ‘Times’.

Parameters:var_names – list of variables to load (beyond ‘XLAT’, ‘XLONG’ and ‘Times’)
slice_field(field_name)[source]

Remove the temporal dimension from the field by only keeping the field for the first time instant.

exception wrf.wrf_exec.OutputCheckFailed[source]

Carries info about the failure of a subprocess execution.

class wrf.wrf_exec.Executor(work_dir, exec_name)[source]

A class that handles execution of external processes for the system with make-like functionality.

This class works for serially (not using MPI) and synchronously (not using a queuing system) launched executables.

execute()[source]

Execute the file in given working directory.

The execute method first checks whether the expected output is present and if it indicates success, if yes, nothing is executed. If not, the file is executed and its output is redirected: stdout goes to <exec_name>.stdout, stderr goes to <exec_name>.stderr Then the output is checked for markers indicating success, if found, function returns. Otherwise an exception is raised indicating the external process failed.

Returns:raises OutputCheckFailed if return code is non-zero
class wrf.wrf_exec.Geogrid(work_dir)[source]

Handles geogrid.exe execution.

check_output()[source]

Checks if the output file for geogrid contains the string “Successful completion of geogrid.”

Returns:returns self on success, else raises OutputCheckFailed
class wrf.wrf_exec.Ungrib(work_dir)[source]

Handles ungrib.exe execution.

check_output()[source]

Checks if the output file for ungrib contains the string “Successful completion of ungrib.”

Returns:raises OutputCheckFailed
class wrf.wrf_exec.Metgrid(work_dir)[source]

Handles metgrid.exe execution.

check_output()[source]

Checks if the output file for metgrid contains the string “Successful completion of metgrid.”

Returns:raises OutputCheckFailed
class wrf.wrf_exec.Real(work_dir)[source]

Handles real.exe execution.

check_output()[source]

Checks if the output file for real contains the string “SUCCESS COMPLETE REAL_EM INIT”

Returns:raises OutputCheckFailed
execute()[source]

Execute real.exe in given working directory.

This method is redefined here as real.exe needs special treatment. DMPAR compilation of WRF causes real.exe to output stdout and stderr into rsl.out.0000 and rsl.error.0000 respectively. We don’t redirect these (we can’t) but we rename the output files after the fact.

NOTE: on some machines it is OK to run real.exe from command line, but generally mpirun is required!

Returns:raises OutputCheckFailed if return code is non-zero
class wrf.wrf_exec.Submitter(work_dir, qsys_id)[source]

Class that abstract jobs that must be submitted to a queue manager.

submit(task_id, exec_path, nodes, ppn, wall_time_hrs)[source]

Build a job script and submit it to the queue manager.

Parameters:
  • task_id – the name of the task in the queue
  • exec_path – the path to the parallel executable
  • nodes – number of nodes to request for parallel job
  • ppn – processors per nodes to request
  • wall_time_hrs – wall time to request for job
Returns:

job number string to be used in further queue manager commands

class wrf.wrf_exec.WRF(work_dir, qman)[source]

Handles job submission for wrf.exe into a job manager.

submit(task_id, nodes, ppn, wall_time_hrs)[source]

Submits a WRF job with the given parameters via queue manager setup during construction.

Fills out executable name and lets submitter do the heavy lifting.

Parameters:
  • task_id – the name of the task in the queue
  • nodes – number of nodes to request for parallel job
  • ppn – processors per nodes to request
  • wall_time_hrs – wall time to request for job
Returns:

job number string to be used in further queue manager commands