Skip to content

Expand ktype support in codes_get_array? #135

@TheoMathurin

Description

@TheoMathurin

Is your feature request related to a problem? Please describe.

I installed the 2.43.0 version of the python bindings via pip.

The grib_get_array function allows the user to specify a ktype. Among numerical dtypes, int, float and float32 seem supported:

    if ktype is int:
        result = grib_get_long_array(msgid, key)
    elif ktype is float or ktype is np.float64:
        result = grib_get_double_array(msgid, key)
    elif ktype is np.float32:
        result = grib_get_float_array(msgid, key)
    elif ktype is str:
        result = grib_get_string_array(msgid, key)
    elif ktype is bytes:
        result = grib_get_string_array(msgid, key)

However, I've tried calling it with float32 but received the following error: gribapi.errors.FunctionNotImplementedError: Function not yet implemented

Besides, it would be great to expand to range of integer precisions supported, for instance I have files with int16 and would like to retrieve the values in their native precision.

NB: if ktype is not provided, the grib_get_native_type gets called and its doctrings says possible returned numerical dtypes only include int or float.

Describe the solution you'd like

I'd like the function to accept more dtypes, clearly separating various integer dtypes: at least int/int64, int32 and int16. Also, if confirmed, the bug with float32 should be addressed.

Describe alternatives you've considered

Casting afterwards is possible but inelegant and probably sub-optimal.

Additional context

No response

Organisation

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions