Package ncepgrib2 :: Class Grib2Message

Class Grib2Message

source code

Class for accessing data in a GRIB Edition 2 message.

The Grib2Decode function returns a list of these class instances, one for each grib message in the file.

When a class instance is created, metadata in the GRIB2 file is decoded and used to set various instance variables.

Instance Methods
 
__init__(self, **kwargs)
create a Grib2Decode class instance given a GRIB Edition 2 filename.
source code
 
__repr__(self) source code
 
data(self, fill_value=1e+30, masked_array=True, expand=True, order=None)
returns an unpacked data grid.
source code
 
grid(self)
return lats,lons (in degrees) of grid.
source code
Instance Variables
  angle_of_pole_rotation
The angle of rotation in degrees about the new polar axis (measured clockwise when looking from the southern to the northern pole) of the coordinate system.
  bitmap_indicator_flag
flag to indicate whether a bit-map is used (0 for yes, 255 for no).
  center_wmo_code
4 character wmo code for originating center.
  data_representation_template
data representation template from section 5.
  data_representation_template_number
data representation template number from section 5 (Table 5.0)
  discipline_code
product discipline code for grib message (Table 0.0).
  earthRmajor
major (equatorial) earth radius.
  earthRminor
minor (polar) earth radius.
  grid_definition_info
grid definition section information from section 3.
  grid_definition_template
grid definition template from section 3.
  grid_definition_template_number
grid definition template number from section 3 (Table 3.1).
  gridlength_in_x_direction
x (or longitudinal) direction grid length.
  gridlength_in_y_direction
y (or latitudinal) direction grid length.
  has_local_use_section
True if grib message contains a local use section.
  identification_section
data from identification section (section 1).
  latitude_first_gridpoint
latitude of first grid point on grid.
  latitude_last_gridpoint
latitude of last grid point on grid.
  latitude_of_southern_pole
the geographic latitude in degrees of the southern pole of the coordinate system (for rotated lat/lon or gaussian grids).
  longitude_first_gridpoint
longitude of first grid point on grid.
  longitude_last_gridpoint
longitude of last grid point on grid.
  longitude_of_southern_pole
the geographic longitude in degrees of the southern pole of the coordinate system (for rotated lat/lon or gaussian grids).
  missing_value
primary missing value (for data_representation_template_numbers 2 and 3).
  missing_value2
secondary missing value (for data_representation_template_numbers 2 and 3).
  number_of_data_points_to_unpack
total number of data points in grib message.
  originating_center
name of national/international originating center.
  points_in_x_direction
number of points in the x (longitudinal) direction.
  points_in_y_direction
number of points in the y (latitudinal) direction.
  product_definition_template
product definition template from section 4.
  product_definition_template_number
product definition template number from section 4 (Table 4.0).
  proj4_
instance variables with this prefix are used to set the map projection parameters for PROJ.4.
  scanmodeflags
scanning mode flags from Table 3.4 (Table 3.4).
  shape_of_earth
string describing the shape of the earth (e.g.
  spectral_truncation_parameters
pentagonal truncation parameters that describe the spherical harmonic truncation (only relevant for grid_definition_template_numbers 50-52).
Method Details

__init__(self, **kwargs)
(Constructor)

source code 

create a Grib2Decode class instance given a GRIB Edition 2 filename.

(used by Grib2Decode function - not directly called by user)

data(self, fill_value=1e+30, masked_array=True, expand=True, order=None)

source code 

returns an unpacked data grid.

Parameters:
  • fill_value - missing or masked data is filled with this value (default 1.e30).
  • masked_array - if True, return masked array if there is bitmap for missing or masked data (default True).
  • expand - if True (default), ECMWF 'reduced' gaussian grids are expanded to regular gaussian grids.
  • order - if 1, linear interpolation is used for expanding reduced gaussian grids. if 0, nearest neighbor interpolation is used. Default is 0 if grid has missing or bitmapped values, 1 otherwise.
Returns:
data, a float32 numpy regular or masked array with shape (nlats,lons) containing the request grid.

grid(self)

source code 

return lats,lons (in degrees) of grid. currently can handle reg. lat/lon, global gaussian, mercator, stereographic, lambert conformal, albers equal-area, space-view and azimuthal equidistant grids.

Returns:
lats,lons, float32 numpy arrays containing latitudes and longitudes of grid (in degrees).

Instance Variable Details

angle_of_pole_rotation

The angle of rotation in degrees about the new polar axis (measured clockwise when looking from the southern to the northern pole) of the coordinate system. For rotated lat/lon or gaussian grids.

grid_definition_info

grid definition section information from section 3. See Grib2Encode.addgrid for details.

has_local_use_section

True if grib message contains a local use section. If True the actual local use section is contained in the _local_use_section instance variable, as a raw byte string.

identification_section

data from identification section (section 1). See Grib2Encode.__init__ for details.

scanmodeflags

scanning mode flags from Table 3.4 (Table 3.4).
  • bit 1:

    0 - Points in the first row or column scan in the +i (+x) direction

    1 - Points in the first row or column scan in the -i (-x) direction

  • bit 2:

    0 - Points in the first row or column scan in the -j (-y) direction

    1 - Points in the first row or column scan in the +j (+y) direction

  • bit 3:

    0 - Adjacent points in the i (x) direction are consecutive (row-major order).

    1 - Adjacent points in the j (y) direction are consecutive (column-major order).

  • bit 4:

    0 - All rows scan in the same direction

    1 - Adjacent rows scan in the opposite direction

shape_of_earth

string describing the shape of the earth (e.g. 'Oblate Spheroid', 'Spheroid').

spectral_truncation_parameters

pentagonal truncation parameters that describe the spherical harmonic truncation (only relevant for grid_definition_template_numbers 50-52). For triangular truncation, all three of these numbers are the same.