wgrib2: -set_grib_max_bits
Introduction
With most grib packing methods, the grid values are
usually stored as scaled integers. The grib format allows
the scaled integers to have up to 254 bits (simple packing).
This is an unreasonably high precision as wgrib2 converts
the data to a single-precision floating point number which
typically has only 25 bits of precision. To speed up
the encoding and decoding processing, wgrib2 uses 32 bit
integers which limits the maximum size of scaled integers
to 25 after accounting for the limits of the packing and
unpacking routines.
The complex-2 and complex-3 compression schemes also
store scaled integers but different. The complex-1 stores
the scaled intger values, so it is limited to a 25 bit
integers. Hewever, complex-2 stores the delta (the difference
from previously defined grid point). The magnitude of delta
is limited by the original series but the delta can be
either positive or negative. So under worst case, the
deltas need one more bit to store the scaled integers.
So if you scale the grid point values to 24 bits, you
will have a scaled deltas being 25 bits. The complex-3
packing stores the deltas of the delta series. This is
good for smooth fields, but for the worst case could
cause two extra bits to store the original grid data.
So at worst case, the data would need to be scaled at 23
bits.
The extra bits needed for complex-2 and complex-3 are
very rare. It was first encountered in 11/2024 which
is about a decade after the complex packing was introduced.
In 11/2024, code was added to the complex packing to detect
the increase in bits needed and reduce the precision if it
cause the precision to be greater than 25 bits.
Grib fields are usually stored as a scaled integers,
and usually you don't need 25 bits of precision. For
example, temperature to the nearest 0.1 degree, means
that the a temperature range of 50 C can be stored as
500 descrete values and only 7 bits are needed to store
the temperature to the nearest 0.1 degree.
The problem is that people can set the scaling factors
to inappropriate values, using 25 bits of precision will
was (disk) space. Consequently wgrib2 has a resetable limit
of the precision of the scaled integers allowed. If you
exceed the limit, the scaling factors are change so
that the scaled integers are limited.
The -set_grib_max_bits option sets the maximum
number of bits that the scaled integers can have when
encoding data into grib. The value
should never be greater than 25 as that is the limit for wgrib2 encoding.
However, some grib packages may not support 25 bit precision in decoding,
so you may want to limit the precision to 24 to remain compatible with
other software packages.
The -set_grib_max_bits option does not set the
binary precision of the grib output but sets the maximum possible precision
of the numbers.
Usage
-set_grib_max_bits N
N = maximum number of bits used to encode data
the default value is 16, N = 1..25
Comments
The -set_grib_max_bits option does not affect
grib data written using the -grib option because the
-grib option does not encode data but copies
the input grib message.
See alse:
-set_scaling
-set_bin_prec
-grib_max_bits
|