pygrib
pygrib copied to clipboard
segmentation fault with GFS-Flux with Grib2Encode
We are getting a segfault when attempting to write values to this grib message. GDB points to this error coming from line 271 of compack.c:
Starting program: /opt/conda/bin/python test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffdf5d0780 (LWP 788)]
[New Thread 0x7fffdf1cf800 (LWP 789)]
[New Thread 0x7fffdedce880 (LWP 790)]
Program received signal SIGSEGV, Segmentation fault.
compack (fld=<optimized out>, ndpts=<optimized out>, idrsnum=3, idrstmpl=<optimized out>, cpack=0x7fffe6303020 "", lcpack=0x7fffffffe1a0) at g2clib_src/compack.c:271
271 ifld[j]=ifld[j]-gref[ng];
minimal example:
from ncepgrib2 import Grib2Decode, Grib2Encode
import numpy as np
with open('/Downloads/example_grib.grb2', 'rb') as f:
grib_bytes = f.read()
grib_values = np.load('/Downloads/example_ndarray.pickle')
grib_obj = Grib2Decode(grib_bytes, gribmsg=True)
new_obj = Grib2Encode(
discipline=grib_obj.discipline_code,
idsect=grib_obj.identification_section
)
new_obj.addgrid(
gdsinfo=grib_obj.grid_definition_info,
gdtmpl=grib_obj.grid_definition_template
)
new_obj.addfield(
pdtnum=grib_obj.product_definition_template_number,
pdtmpl=grib_obj.product_definition_template,
drtnum=grib_obj.data_representation_template_number,
drtmpl=grib_obj.data_representation_template,
field=grib_values
)
new_obj.end()
Here are the files used: https://storage.googleapis.com/wba-temporary/example_grib.grb2 https://storage.googleapis.com/wba-temporary/example_ndarray.pickle
You just need to change the paths in the sample code to match the location where you put those files.