Releases: NOAA-MDL/grib2io
grib2io v1.0.3
grib2io v1.0.2
grib2io Version v1.0.2 Release Notes
- Reverted change from v1.0.1. Now checking for the potentially bad value in the grid definition template for regular and Gaussian lat/lon grids in the grib2io module. In v1.0.1, the check was occurring in g2clib Cython extension module.
grib2io v1.0.1
grib2io Version v1.0.1 Release Notes
Bug Fixes:
- Fixed bug in g2clib Cython extension module that was causing bad latitude and longitude values when generated. The bad values were limited to Regular and Gaussian Lat/Lon grids.
grib2io v1.0.0
grib2io Version v1.0.0 Release Notes
Introduction:
grib2io is a Python package that provides an interface to the NCEP GRIB2 C library (g2c) and is the successor to ncepgrib2. The grib2io module interfaces with an internal g2clib Cython module which is a wrapper to the internal v1.6.4 of the g2c library.
The following are quick descripion of features. Please see the official documentation for more detailed information.
Features:
-
Support for reading and writing GRIB2 messages.
-
When reading a file containing GRIB2 messages, the messages are automatically indexed for faster selection of fields by certain metadata.
-
GRIB2 messages can be selected by message number, range of numbers, or by variable
shortName
using index notation. Messages can also be selected using thegrib2io.open.select()
method. -
GRIB2 message sections are unpacked by g2c library functions. The unpacked integer code values can further be decoded into plain language metadata by looking up values against NCEP GRIB2 code tables.
-
NCEP GRIB2 tables are provided by grib2io as dictionaries.
-
Support for the creation of new GRIB2 messages from scratch. No existing GRIB2 message is needed.
-
Data compression is performed by g2clib library functions and has native support for GRIB2 Simple, Complex, and Complex with Spatial Differencing compression schemes. JPEG and PNG compression schemes are supported, but are optional and dependent upon how grib2io is built and availablility of those libraries.
-
Integer data values that represent a categorical value can be mapped to the categorical defintion.
-
Support for decoding NWS NDFD and MDL Wx strings.
Known Issues:
- Using decimal scaling with JPEG compression can lead to bad values packed. At this time, I cannot determine the cause.
grib2io v0.9.3
grib2io Version 0.9.3 Release Notes
New Features:
-
Implementation of a wgrib2-formatted probability threshold string generated by new function,
grib2io.utils.get_wgrib2_prob_string()
. The string is stored ingrib2io.open._index['probString']
and in instances ofGrib2Message
as thethreshold
attribute. The logic for generation of the probability threshold string originates from wgrib2 source, Prob.c. (#16) -
The
grib2io.open.select()
method now accepts keyword argumentsthreshold=
that accepts a wgrib2-formatted probability threshold string andpercentile=
that accepts a integer representing the percentile value. (#16 and #17) -
The
grib2.open
class__init__
method now accepts a boolean keyword argumentdecode=
(default isTrue
) to provide user control of whether or not to decode GRIB2 integer code values from the GRIB2 definition sections to 'plain language" metadata. (#18)
Bug Fixes:
- Fixed issue decoding probability threshold values from GRIB2 message witih product definition template numbers 4.5 and 4.9. (#15)
grib2io v0.9.2
grib2io Version 0.9.2 Release Notes
-
In
setup.py
, added support to automatically find JPEG and PNG library and include paths when thesetup.cfg
and/or library-specific environment variables are not used. This will allow for JPEG and PNG compression support out-of-the-box when installed by package systems likepip
. This has been tested on macOS 12 (Monterey) and Linux (Fedora, openSUSE, and Ubuntu). -
New module function,
show_config()
, to print information about compression support and external compression library information. -
Implementation of a wgrib2-formatted level/layer string generated by new function,
grib2io.tables.get_wgrib2_level_string()
. The string is stored ingrib2io.open._index['levelString']
and in instances ofGrib2Message
as thelevel
attribute. This allows for level and layer matching. (#13) -
New table dictionary ,
wgrib2_level_string
, containing level code values as keys. Values are a list containing formatting string given a level or layer. The contents of this table dictionary are replicated from wgrib2 source file, Level.c. -
Added new attribute,
levels
, to thegrib2io.open
class that holds a tuple of unique wgrib2-formatted level/layer strings.
grib2io v0.9.1
grib2io Version 0.9.1 Release Notes
New Features:
- Added JPEG compression support with the OpenJPEG Library.
grib2io
now supports building the bundled g2c library using either Jasper or OpenJPEG libs. - Added support to select GRIB2 fields at the ground/surface level. (#12)
Bug Fixes
- Added missing
Grib2Message
attribute,scaledValueOfSecondFixedSurface
(#11)
grib2io v0.9.0
grib2io Version 0.9.0 Release Notes
This is a minor pre-release. Alot of the code amd documentation has been cleaned up. At this release, the Python package classifier Development Status has been bumped to level 4 - Beta.
New Features:
-
Added ability to write a GRIB2 Local Use Section (Section 2) to new Grib2Message objects using new Grib2Message method,
addlocal()
. The GRIB2 Local Use Section can contain anything you wish to put into the GRIB2 Message. (#9) -
All Grib2Message class attributes that originate from a GRIB2 metadata and link to a GRIB2 code table are now a Grib2Metadata object. This gives users the choice to work with metadata as the coded value (
Grib2Metadata.value
) or the definition (Grib2Metadata.definition
). -
Added ability to select GRIB2 messages from
grib2io.open
file object via theshortName
import grib2io
g = grib2io.open('test.grib2')
msgs = g['APCP'] # Returns all GRIB2 message with shortName = 'APCP'
Class Updates:
grib2io.Grib2Message
-
new method,
to_bytes()
, that returns the GRIB2 Message as abytes
object. -
new method,
addlocal()
, to add a Local Use Section (Section 2) to the new Grib2Message object. In order for this to work, a few function,grib2_addlocal()
ing2clib.pyx
was created to interface to the g2c function,g2_addlocal()
. -
updated
__getitem__()
to allow for key of typestr
.
Changes / Updates:
-
Python 3.10 support
-
GitPod support
-
Added NCEP GRIB2 Table 4.228
grib2io release 0.8.0
Release Notes
New Features:
-
Grib2Message
creation from "scratch" (i.e. not read from an existing file). The logic to create a GRIB2 message remains largely the same from grib2io's predecessor, ncepgrib2. However, withgrib2io
, the creation of a new GRIB2 message is done through instantiation of thegrib2io.Grib2Message
class. When the class is instantiated with appropriate values to the keyword argumentsdiscipline
andidsect
, an empty instance ofGrib2Message
is created. Then you callGrib2Message
methods:addgrid()
to add the grid definition section;addfield()
to add the production definition, data representation, bitmap, and data sections; and finallyend()
to formally end the GRIB2 message. -
Write GRIB2 message to file. Class
grib2io.open
now contains awrite()
method that accepts aGrib2Message
object. -
Decode GRIB2 messages that contain MDL (Gridded MOS) and NDFD Weather Strings. The gridded data are integer values that represent an index of a lookup table that contain weather strings. The lookup table is unique for each GRIB2 message and is stored in section 2 (Local Use Section) of each message. New functions,
utils.decode_mdl_wx_strings()
andutils.decode_ndfd_wx_strings()
have been created to perform the decoding of the lookup tables. Different functions are required because the decoding is slightly different between MDL and NDFD. To decode weather strings while unpacking data, provideGrib2Message.data()
method with themap_keys=True
keyword argument. -
GRIB2 metadata attributes of the
Grib2Message
can now hold their coded integer value and the plain language defintion for that value. Where necessary,Grib2Message
object attributes will be of typeGrib2Metadata
which stores the code value invalue
and the plain language definition indefinition
. See the following example using theGrib2Message.discipline
:
>>> import grib2io
>>> g = grib2io.open('test.grib2')
>>> msg = g[50][0] # Get the 50th GRIB2 message
>>> type(msg.discipline)
<class 'grib2io._grib2io.Grib2Metadata'>
>>> msg.discipline.value
0
>>> msg.discipline.definition
'Meteorological Products'
>>> msg.discipline == 0
True
>>> 'Met' in msg.discipline.definition
True
>>> print(msg.discipline)
0 - Meteorological Products
>>> msg.discipline()
0
Class Updates:
grib2io.Grib2Message
-
new method,
unpack()
. This method handles the unpacking of the binary data from the GRIB2 message and creates the GRIB2 section values. -
new method,
decode()
. This method performs the decoding of packed GRIB2 values from each section into metadata variables (i.e. instance variables ofGrib2Message
). Where available, the code values are futher deciphered into their plain language defintions. Both the code value its definition are stored as an instance of classGrib2Metadata
. -
new method,
addgrid()
. Adds Grid Definition Section information. -
new method,
addfield()
. Adds the Production Definition, Data Representation, Bitmap, and Data Sections. -
new method,
end()
. Add the End Section. This formally terminates the packed GRIB2 message. -
updated
__init__
to accommodatediscipline
andidsect
keyword arguments (both have the default value ofNone
). When both of these are specified and are notNone
, an emptyGrib2Message
object is created. NOTE: all other keyword arguments are ignored. -
updated
data()
to addmap_keys
keyword for decoding data values to MDL or NDFD Wx Strings.
grib2io.Grib2Metadata
(NEW)
- New class to store decoded GRIB2 metadata as the coded value in instance vairable
value
and its plain language definition in instance variabledefinition
. - Class comparison methods use the
value
attribute. For__contains__
, thedefinition
atrribute is used. For__call__
,value
is returned.
Changes:
- Renamed
utils.get_varname_from_table()
toutils.get_varinfo_from_table()
. utils.get_table()
now returns an empty dictionary when the specified table is not found.utils.get_value_from_table()
now returns['Unknown','Unknown','Unknown']
when a value from a table is not found.- Updates to docstrings
- NCEP GRIB2 tables updated to latest as of 8/31/2021. Logic added to table generation scripts to remove "(See Note *)" strings.
- Included NCEP G2C Library updated to verison 1.6.2.
Bug Fixes:
- Set ONE_MB to the correct value representing 1 MB in units of bytes.
- Fixed issues with decoding metadata for GRIB2 messages with production definition template number = 9.
grib2io release 0.3.0
Release Notes
Class grib2io.open():
- New
select()
method for selection/filtering of GRIB2 Messages. Currently supported keyword arguments are:‘duration’
,‘leadTime’
,‘level’
,'refDate'
, and‘shortName’
. These arguments only accept single values at this time. Please see documentation for usage of these keyword arguments. Thelevel
keyword, only supports the following surfaces: isobaric surface, height above/below ground, and sigma are supported at this time. A future update will allow for multiple values per keyword. The following example will select GRIB2 Messages that are Geopotential Height at the 500mb level, with a lead time of 24-hours.
>>> import grib2io
>>> g = grib2io.open("test.grib2")
>>> msgs = g.select(shortName="HGT",level="500mb",leadTime=24)
-
New
_find_level()
“private” method to parse the user provided level= kwarg in the select() method. The value is parsed and searched for. -
New class attribute,
‘shortNames’
, containing a tuple of unique shortName strings contained in the GRIB2 file.
Class grib2io.Grib2Message():
-
New
latlons()
method that will return latitude and longitude values of thegrib2io.Grib2Message
instance. An alias for this method namedgrid()
is also available. -
Fixed an issue where the incorrect lead time would be set for GRIB2 message using Product Definition Templates 4.8,9,10,11,12. There are time interval messages (i.e. Accumulated Precipitation; "APCP").
Sub-module grib2io.utils:
-
New
getleadtime()
function to compute the lead time given GRIB2 Indentification Section (1), Product Definition Template (section 4) and Number. For time interval messages, the lead time value returned here is the ending hour. -
New
getduration()
function to compute the duration time given GRIB2 Product Definition Template (Section 4) and Number. GRIB2 Messages describing data at an instance in time have a duration = 0.
Miscellaneous:
-
Added directory
make_grib2_tables/
at the repository root that contains shell and Python scripts to scrape the NCEP GRIB2 HTML tables and generate Python dictionary-based tables. IMPORTANT: The Python scripts use Pandas for HTML reading and processing, but Pandas is not required forgrib2io
. Releases ofgrib2io
will contain the latest version of the tables at the time of release. The ability to update tables is provided here. -
Documentation generation has been changed to use pdoc.
-
Applied a temporary patch in grib2.h in the bundled NCEP g2c library. The patch adds function definitions for g2_unpack* functions. This allow for successful build using Apple's LLVM clang.