pygrib icon indicating copy to clipboard operation
pygrib copied to clipboard

Issue replacing values in a gribmessage

Open criedel40 opened this issue 2 years ago • 3 comments

Hello,

I am trying to change the values associated with a gribmessage.

Say I have a GRIB file, call it grib1, that I want to change the values of to a new array that I have created, call it new_arr. I have tried going about directly setting grib1.values = new_arr (or grib1['values'] = new_arr) but neither option works. The resulting grib1.values is not the same as new_arr, rather some strange combination of the old array and new_arr.

Example: Original value in grib file: 2015.5 The value I want in the grib file: 215.6476593 The value that is in the grib file after setting it (grib1.values = new_arr): 216.33317871 Of course the example is just of a single value but it is happening everywhere in the array.

I checked and the precision of arrays all equal float64. Do you have to the same number of significant digits when trying to replace the old values with the new values?

How did you solve this? Any advice is greatly appreciated!

-Chris

criedel40 avatar Sep 26 '22 19:09 criedel40

Sorry typo: Original value in grib file: 215.5

criedel40 avatar Sep 26 '22 19:09 criedel40

might have to do with the grib compression which is 'lossy'

jswhit avatar Oct 02 '22 15:10 jswhit

What is the solution to this, I am having the same issue.

mobhuiyan98 avatar Mar 29 '23 17:03 mobhuiyan98