Skip to content

[Bug] get_keepbits returning a negative integer value for .grib datasets #269

@fnhirwa

Description

@fnhirwa
  • xbitinfo version: 0.1.dev587+g10a08dd
  • Python version: 3.9.18
  • Operating System: `macOS Sonoma Version 14.4 (23E214) (Apple M1 Processor)

Description

Was trying the xbitinfo and following the tutorial presented and when compressing the .grib datasets it seems that the compression fails as the get_keepbits function returns negative values.

What I Did

import xbitinfo as xb
import xarray as xr

dataset = xr.tutorial.load_dataset("era5-2mt-2019-03-uk.grib").astype("float32")
info_p_bit = xb.get_bitinformation(dataset, dim="longitude", implementation="python")
keepbits = xb.get_keepbits(
    info_p_bit, 0.99
)  # returns negative number due to lossy compression
ds_bitrounded = xb.xr_bitround(
    dataset, keepbits
)  # raises a warning as keepbits is negative

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions