Skip to content

Commit

Permalink
First commit to expose bitmap.
Browse files Browse the repository at this point in the history
The GRIB2 message bitmap (if available) is now exposed as a public
attribute of the Grib2Message class with name, bitmap.

NOTE: The bitmap attribute will not be populated with bitmap data
until data are unpacked, otherwise it is None.

NOTE: When flush_data() method is called, the bitmap is flushed too.
  • Loading branch information
EricEngle-NOAA committed Mar 14, 2024
1 parent 365100b commit fceaed9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/grib2io/_grib2io.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ def __post_init__(self):
except(TypeError):
pass
self.bitMapFlag = templates.Grib2Metadata(self.bitMapFlag,table='6.0')
self.bitmap = None


@property
Expand Down Expand Up @@ -913,6 +914,7 @@ def flush_data(self):
"""Flush the unpacked data values from the Grib2Message object."""
del self._data
self._data = self._ondiskarray
self.bitmap = None


def __getitem__(self, item):
Expand Down Expand Up @@ -1300,7 +1302,6 @@ def _data(
gdt = msg.section3[5:]
drt = msg.section5[2:]
nx, ny = msg.nx, msg.ny
scanModeFlags = msg.scanModeFlags

# Set the fill value according to how we are handling missing values
msg._auto_nans = _AUTO_NANS
Expand All @@ -1320,14 +1321,11 @@ def _data(
filehandle.seek(filehandle.tell()-5)
ipos = 0
bmap,bmapflag = g2clib.unpack6(filehandle.read(bmap_size),msg.section3[1],ipos,np.empty)
msg.bitmap = bmap.reshape((ny,nx)).astype(np.int8)

try:
if scanModeFlags[2]:
storageorder='F'
else:
storageorder='C'
except AttributeError:
raise ValueError('Unsupported grid definition template number %s'%gridDefinitionTemplateNumber)
if hasattr(msg,'scanModeFlags'):
scanModeFlags = msg.scanModeFlags
storageorder = 'F' if scanModeFlags[2] else 'C'

# Position file pointer to the beginning of data section.
filehandle.seek(data_offset)
Expand Down

0 comments on commit fceaed9

Please sign in to comment.