Skip to content

Commit

Permalink
fix archive_to_fdb (#130)
Browse files Browse the repository at this point in the history
- io.BytesIO is missing the raw attribute
- pyfdb should be an optional dependency of idpi
  • Loading branch information
cfkanesan authored Apr 11, 2024
1 parent 8a9c703 commit 78adca6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/idpi/grib_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ def load_fieldnames(
return self.load(reqs, extract_pv)


def save(field: xr.DataArray, file_handle: io.BufferedWriter, bits_per_value: int = 16):
def save(
field: xr.DataArray,
file_handle: io.BufferedWriter | io.BytesIO,
bits_per_value: int = 16,
):
"""Write field to file in GRIB format.
Parameters
Expand Down
7 changes: 4 additions & 3 deletions src/idpi/mch_model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os

# Third-party
import pyfdb # type: ignore
import xarray as xr

# Local
Expand Down Expand Up @@ -116,9 +115,11 @@ def archive_to_fdb(
Bits per value encoded in the archived data. (Default: 16)
"""
# Third-party
import pyfdb # type: ignore

buffer = io.BytesIO()
handle = io.BufferedWriter(buffer.raw)
grib_decoder.save(field, handle, bits_per_value)
grib_decoder.save(field, buffer, bits_per_value)
fdb = pyfdb.FDB()
req = request.to_fdb() if request is not None else None
if request is not None:
Expand Down

0 comments on commit 78adca6

Please sign in to comment.