API reference

This page provides an auto-generated summary of pywgrib2’s API. For more details and examples, refer to the relevant chapters in the main part of the documentation.

wgrib2 Interface

Memory Buffer

MemoryBuffer()

Encapsulates wgrib2 memory buffer.

MemoryBuffer.get([rtype])

Returns buffer content.

MemoryBuffer.set(data)

Initialises buffer with data.

MemoryBuffer.close()

Makes buffer free for reuse.

MemoryBuffer.usage()

Returns copy of buffer array.

RPNRegister

RPNRegister()

Encapsulates wgrib2 RPN register.

RPNRegister.get()

Returns content of the register.

RPNRegister.set(arr)

Initialises register with data.

RPNRegister.close()

Makes register free for reuse.

RPNRegister.usage()

Returns copy of register array.

Top-level functions

free_files(*files[, delete])

Closes and removes files from wgrib2 linked list.

status_open()

Prints open files to stderr.

wgrib(*args)

Mimics wgrib2 executable.

read_msg(gribfile, num_or_meta)

Returns single message from GRIB2 file as bytes.

decode_msg(gribfile, meta)

Returns decoded GRIB2 file as numpy array.

write_msg(gribfile, tmplfile, num_or_meta[, …])

Writes message to a GRIB2 file.

iplib Interface

This is a Python interface to NCEP Interpolation library iplib

earth2grid_points(grid, point)

Computes grid coordinates of selected Earth coordinates.

grid2earth_grid(grid)

computes Earth coordinates of all the grid points.

grid2earth_points(grid, xpts, ypts)

Computes Earth coordinates of selected grid points.

ips_grid(data, iptype, grid_in, grid_out[, …])

Interface to NCEP subroutine ipolates.

ips_points(data, iptype, grid, point[, ipopt])

Interface to NCEP subroutine ipolates.

ipv_grid(udata, vdata, iptype, grid_in, grid_out)

Interface to NCEP subroutine ipolatev.

ipv_points(udata, vdata, iptype, grid, point)

Interface to NCEP subroutine ipolatev.

Dataset

Reading GRIB2 files

open_dataset(filenames, template[, chunks, …])

Opens one or more files as a single dataset.

Accessors

Wgrib2DatasetAccessor(xarray_obj)

Provides custom attributes and methods on xarray Dataset.

Wgrib2DatasetAccessor.get_grid()

Returns GRIB2 grid definition as dictionary.

Wgrib2DatasetAccessor.location(points[, iptype])

Remaps all variables to point locations.

Wgrib2DatasetAccessor.grid(grid[, iptype])

Remaps all variables to points specified by longitude and latitude.

Wgrib2DatasetAccessor.winds(winds[, inplace])

Changes vector coordinates to grid/Earth direction.

Inventory

Data structures

MetaData(*args, **kwargs)

GRIB2 message metadata.

MetaData.level_code

Shortcut for self.bot_level_code.

MetaData.level_value

Shortcut for self.bot_level_value.

Creating inventory

make_inventory(file)

Creates inventory for file ‘file’.

save_inventory(inventory, file[, directory])

Saves inventory to a file.

load_inventory(file[, directory])

Retrieves inventory from a file.

load_or_make_inventory(file[, directory, save])

Returns inventory for a GRIB2 file.

Projection

Creating a projection

GRIB2 defines projection in terms of Grid Definition Template (Section 3 in GRIB2 message), which includes also grid parameters such as number of points and cell size. pywgrib2_xr wraps it in a class pywgrib2_xr.Grid.

Point(longitude, latitude[, coord])

Unstructured list of points.

Grid(gdtmpl)

2-dimensional rectangular grid.

grid_fromgds(gdtnum, gdtmpl)

Factory method to create projection from grid definition section.

grid_fromdict(projname[, globe])

Factory method to create projection from dictionary.

grid_fromstring(string[, winds, globe])

Factory method to create projection from wgrib2 style string.

Attributes

Grid.cfname

Class name

Grid.gdtnum

Grid definition template number

Grid.attrs

Grid.coords

Grid.crs

Parameters for cartopy coordinate reference system.

Grid.dims

Grid dimension names.

Grid.globe

Parameters for cartopy globe

Grid.params

GRIB parameters as dictionary

Grid.shape

Grid shape.

Template

Template(commoninfo, var_info_map, …[, …])

Defines dataset structure.

make_template(files, *predicates[, …])

Creates template from GRIB2 files.

Utilities

Functions in this module are used to retrieve data for the test suite and documentation.

utils.localpath(file)

Returns path to file on the disk.

utils.localpaths(pattern)

Returns files in data directory matching pattern.

utils.remotepath(file[, cachedir])

Returns path to file.