HWRF  trunk@4391
Classes | Functions | Variables
hwrf.regrib Namespace Reference

Describes regribbing operations using an algebraic structure. More...

Detailed Description

Describes regribbing operations using an algebraic structure.

This module provides an object-oriented interface to the low-level GRIB manipulation routines in produtil.gribop. It also sits on top of the produtil.datastore module, providing a means to grab GRIB files from Task and Product objects, processing them upon availability.

Classes

class  FixedLocation
 Represents a specific location on the earth as a latitude, longitude pair. More...
 
class  GRIB1Fetcher
 The GRIB1Fetcher is a GRIB1Op subclass that fetches a GRIB1 file from a RegribMany. More...
 
class  GRIB1File
 This subclass of GRIB1Op represents a GRIB1 file on disk that is ALREADY PRESENT. More...
 
class  GRIB1Op
 This subclass of GRIBOp produces GRIB1 files. More...
 
class  GRIB1Product
 This class represents a GRIB1 file produced by this workflow. More...
 
class  GRIB1Selector
 This object produces a GRIB1Op from a call to a Task object's Task.product. More...
 
class  GRIB2File
 This subclass of GRIB2Op represents a GRIB2 file on disk that is ALREADY PRESENT. More...
 
class  GRIB2Op
 This subclass of GRIBOp produces GRIB2 files, and can be converted to GRIB1 via obj*GRIB1 or obj.to_grib1(). More...
 
class  GRIB2Product
 This class represents a GRIB2 file that is produced by this workflow. More...
 
class  GRIBBase
 Base class for the regridding object tree. More...
 
class  GRIBGrid
 This class represents a GRIB1 or GRIB2 grid specification. More...
 
class  GRIBGridBase
 This abstract base class represents something that is able to produce a GRIBGrid object when make() is called. More...
 
class  GRIBGridCompute
 This class represents a GRIBGrid that must be computed from some other input, usually a GRIB file. More...
 
class  GRIBGridFetcher
 This class represents a GRIBGrid that is stored in a RegribMany object. More...
 
class  GRIBOp
 This is the abstract base class for all GRIB1 and GRIB2 files and operators. More...
 
class  GRIBSubsetter
 A GRIBBase that subsets GRIB files, keeping only certain parameters. More...
 
class  GRIBSubsetterFetcher
 This class grabs a GRIBSubsetter from a RegribMany object. More...
 
class  Regrib
 This is a helper class intended to be used internally by RegribMany. More...
 
class  RegribBase
 This is the abstract base class of Regrib and RegribMany and should not be instantiated directly. More...
 
class  RegribMany
 Runs regrib operations on many input times, sending output to an hwrf.gribtask.GRIBTask. More...
 
class  UpstreamGRIB1
 This subclass of GRIB1Op and UpstreamFile represents a GRIB1 file that is produced by an upstream workflow. More...
 

Functions

def checkgrib (regrib, filename)
 Internal function for validating GRIB files. More...
 
def action_grib1to2 (op, regrib, infile, args, kwargs)
 Converts GRIB1 file to GRIB2. More...
 
def action_grib2to1 (op, regrib, infile, args, kwargs)
 Converts GRIB2 files to GRIB1. More...
 
def action_grib1regridmerge (op, regrib, grid, in1, in2, kwargs)
 Performs regridding and merges two files in a single operation. More...
 
def action_grbindex (op, regrib, ingrib, task=None, kwargs)
 Runs the grbindex program on a GRIB1 file. More...
 
def action_grib1merge (op, regrib, in1, in2, kwargs)
 Merges two GRIB1 files that must already have the same grid. More...
 
def action_grib1regrid (op, regrib, infile, ingrid, args, kwargs)
 Regrids a GRIB1 file. More...
 
def action_grib1subset (op, regrib, infile, subsetter, args, kwargs)
 Subsets a GRIB1 file. More...
 
def action_clatlon (op, regrib, name, center, nsres, ewres, nssize, ewsize, nscount, ewcount, scan, kwargs)
 Generates a latitude-longitude grid centered on a GRIB file or specified point. More...
 
def clatlon
 Create a GRIBGridCompute that makes a lat-lon grid. More...
 
def igrb1 (task, kwargs)
 This is a convenient alias for the GRIB1Selector constructor. More...
 

Variables

list __all__
 List of symbols to export by "from hwrf.regrib import *". More...
 
int GRIB1 = 1
 Constant used to represent a request to convert GRIB files to GRIB version 1. More...
 
int GRIB2 = 2
 Constant used to represent a request to convert GRIB files to GRIB version 2. More...
 
int GRIB_FILE_MIN_SIZE = 8
 Eight bytes: the minimum required size of a non-empty GRIB1 or GRIB2 file. More...
 
tuple quarterDegree = GRIBGrid('Quarter_Degree_Grid_193','193',None)
 A special GRIBGrid representing grid 193, which is a quarter degree regular lat-lon grid the NCEP GFS model uses as output. More...
 

Function Documentation

def hwrf.regrib.action_clatlon (   op,
  regrib,
  name,
  center,
  nsres,
  ewres,
  nssize,
  ewsize,
  nscount,
  ewcount,
  scan,
  kwargs 
)

Generates a latitude-longitude grid centered on a GRIB file or specified point.

This is an internal implementation function that should not be called directly. It queries the center object's nscenter and ewcenter properties to get the objects location. It then adds a border around that, creating a GRIB1 grid 255 grid specification centered on the center object.

Parameters
opThe GRIBBase operation running this funciton.
centerThe GRIBBase operation on which to center the grid
regriba Regrib for data information
namethe name of the resulting grid, for storage in a RegribMany
nsres,ewresGRIB1 grid 255 resolution information
nssize,ewsizeGRIB1 grid 255 size information, but in degrees. It will be converted to millidegrees for passing to underlying GRIB manipulation programs.
nscount,ewcountNumber of gridpoints in each direction, for the GRIB1 grid 255 information.
scanGRIB1 grid 255 scanning mode byte
kwargsIgnored
Returns
a new GRIBGrid for the new grid

Definition at line 1059 of file regrib.py.

Referenced by hwrf.regrib.action_grib1subset().

def hwrf.regrib.action_grbindex (   op,
  regrib,
  ingrib,
  task = None,
  kwargs 
)

Runs the grbindex program on a GRIB1 file.

This is a low-level implementation function. It should not be called directly. This function adds a grbindex output to the specified input file's product, unless one is already available. Unlike most action_* functions, this one does not create a new GRIBFile or GRIBProduct, instead it modifies the existing one to add the location of the grbindex output.

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
ingribThe input GRIBBase that represents the input file.
taskAn hwrf.hwrftask.HWRFTask to provide the path to grbindex
kwargsIgnored
Returns
ingrib

Definition at line 884 of file regrib.py.

def hwrf.regrib.action_grib1merge (   op,
  regrib,
  in1,
  in2,
  kwargs 
)

Merges two GRIB1 files that must already have the same grid.

This is a low-level implementation function. It should not be called directly. This function is sent as a parameter to GRIB1Op to do a copygb merge (-xM) of two GRIB1 files to produce a single GRIB1 file. It requires that at least one of the files have a known grid, and if both have a known grid then their grids must mach.

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
in1,in2The input GRIBGrid objects that provide filenames
kwargsIgnored
Returns
The resulting GRIB1File, which may be in1, in2 or a new GRIB1File
Bug:
This function calls pwd and ls -l if things go wrong. It needs to use produtil.listing instead.

Definition at line 921 of file regrib.py.

def hwrf.regrib.action_grib1regrid (   op,
  regrib,
  infile,
  ingrid,
  args,
  kwargs 
)

Regrids a GRIB1 file.

This is a low-level implementation function. It should not be called directly. This is sent as a parameter to GRIB1Op to convert a GRIB1 file from one grid to another. The output has a known grid, so it can be sent into an action_grib1merge.

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
infileThe input filename.
ingridInput GRIB1Grid that specifies the target grid.
args,kwargsIgnored
Returns
a new GRIB1File for the output file

Definition at line 989 of file regrib.py.

def hwrf.regrib.action_grib1regridmerge (   op,
  regrib,
  grid,
  in1,
  in2,
  kwargs 
)

Performs regridding and merges two files in a single operation.

This is a low-level implementation function. It should not be called directly. This function is sent as a parameter to GRIB1Op to do a copygb regrid AND merge in a single operation (one call to the copygb program). The grid argument is the target grid, and the in1 and in2 arguments are the input GRIB1 files.

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
in1,in2The input filenames.
gridThe GRIBGrid that provides grid information.
kwargsIgnored
Returns
a GRIB1File for the output file, which may be in1 or in2, or a new GRIB1File

Definition at line 828 of file regrib.py.

def hwrf.regrib.action_grib1subset (   op,
  regrib,
  infile,
  subsetter,
  args,
  kwargs 
)

Subsets a GRIB1 file.

This is a low-level implementation function. It should not be called directly. It subsets a GRIB1 file infile using the given subsetter. The subsetter should have a list of strings accessible via subsetter.grib1sub. It should also have a name accessible through subsetter.subsetname. The wgrib -s output of infile is scanned. Any line in wgrib -s's output that contains the entirety of any line in the subsetter.grib1sub is retained. The subsetting is done via wgrib -i -grib (infile) -o (outfile).

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
infileThe input filename.
subsetterA GRIBSubsetter that chooses the fields to keep.
args,kwargsIgnored
Returns
a new GRIB1File for the output file

Definition at line 1020 of file regrib.py.

def hwrf.regrib.action_grib1to2 (   op,
  regrib,
  infile,
  args,
  kwargs 
)

Converts GRIB1 file to GRIB2.

This is a low-level implementation function. It should not be called directly. This function is sent as a parameter to GRIB1Op to produce a GRIB2 version of a GRIB1 file. It uses regrib.cnvgrib_g12 to perform the conversion.

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
infileThe input filename.
args,kwargsIgnored
Returns
a new GRIB2File for the output file

Definition at line 776 of file regrib.py.

def hwrf.regrib.action_grib2to1 (   op,
  regrib,
  infile,
  args,
  kwargs 
)

Converts GRIB2 files to GRIB1.

This is a low-level implementation function. It should not be called directly. This function is sent as a parameter to GRIB2Op to produce a GRIB1 version of a GRIB2 file. It uses regrib.cnvgrib_g21 to do the conversion.

Parameters
opThe GRIBBase operation running this funciton.
regriba Regrib for data information
infileThe input filename.
args,kwargsIgnored
Returns
a new GRIB1File for the output file
Warning
This is not used by any HWRF configuration and has not been tested in a while.

Definition at line 801 of file regrib.py.

def hwrf.regrib.checkgrib (   regrib,
  filename 
)

Internal function for validating GRIB files.

This is a low-level implementation function. It should not be called directly. This checks a file to make sure it exists, is a regular file (or symlink to a regular file) and is large enough to plausibly contain some GRIB1 or GRIB2 data. Returns True for such plausible files and False otherwise. Does not open the file, and performs only a single stat. Uses errno ENOENT (no such file or directory) and ELOOP (too many symbolic links) to detect non-existence. Other exceptions will be passed to the caller.

Parameters
regriba regrib for logging information
filenamethe name of the file of interest

Definition at line 731 of file regrib.py.

Referenced by hwrf.regrib.action_grib1merge(), hwrf.regrib.action_grib1regrid(), and hwrf.regrib.action_grib1regridmerge().

def hwrf.regrib.clatlon (   center,
  res,
  size,
  n,
  scan = 136,
  name = None 
)

Create a GRIBGridCompute that makes a lat-lon grid.

Returns a GRIBGridCompute that will produce a lat-lon grid centered on the given object. The provided object must have nscenter and ewcenter properties that produce real lats and lons that are positive North and positive East. The res parameter is a two element array containing the resolution in degrees.

Parameters
namethe new grid's name
centerAn object on which to center. Must have nscenter and ewcenter properties.
resThe GRIB1 grid 255 resolution information in a two-element array.
sizeThe size parameter is a two-element array containing the extent in degrees.
nThe n parameter contains the number of gridpoints.
scanThe "scan" parameter is the scanning mode parameter: 128 means E-W are reversed, 64 means N-S are reversed, and 32 means the data is transposed.
Note
All three, res, size and n, are two element arrays with the N-S value first and the E-W value second. These are turned into a GRIB1 grid 255 specification.

Definition at line 1334 of file regrib.py.

def hwrf.regrib.igrb1 (   task,
  kwargs 
)

This is a convenient alias for the GRIB1Selector constructor.

Parameters
task,kwargsPassed to GRIB1Selector.__init__()

Definition at line 1956 of file regrib.py.

Variable Documentation

hwrf.regrib.__all__
Initial value:
1 = ['GRIBOp','GRIB2Op','GRIB1Op','GRIBGrid','GRIBSubsetter',
2  'GRIB1Merge','Regrib','GRIB1','GRIB2','GRIB1File',
3  'GRIB2File','UpstreamGRIB1','GRIB2Product','quarterDegree']

List of symbols to export by "from hwrf.regrib import *".

Definition at line 22 of file regrib.py.

hwrf.regrib.GRIB1 = 1

Constant used to represent a request to convert GRIB files to GRIB version 1.

Definition at line 28 of file regrib.py.

hwrf.regrib.GRIB2 = 2

Constant used to represent a request to convert GRIB files to GRIB version 2.

Definition at line 32 of file regrib.py.

hwrf.regrib.GRIB_FILE_MIN_SIZE = 8

Eight bytes: the minimum required size of a non-empty GRIB1 or GRIB2 file.

This size is chosen because it is not possible for a file to be smaller than this and still meet the GRIB standard. Realistically, the file should be much larger.

Definition at line 725 of file regrib.py.

hwrf.regrib.quarterDegree = GRIBGrid('Quarter_Degree_Grid_193','193',None)

A special GRIBGrid representing grid 193, which is a quarter degree regular lat-lon grid the NCEP GFS model uses as output.

Definition at line 1210 of file regrib.py.