0

I am summing values of a list of grib files after a normalization. After this I overwrite the values on an existing grib file.

data_sum = np.zeros((451, 900))
for grib_file in list_000:
    data = normalization(grib_file)
    data_sum = data_sum + data
print 'printing array'
print data_sum
np.savetxt("data_sum.csv", data_sum, delimiter = ",")

grb['values'] = data_sum
print 'print data_sum on the grib'
print grb['values']


grbout = open('test.grib','wb')
msg = grb.tostring()
grbout.write(msg)
grbout.close()

Checking the output I have noticed that values I have on the array are different from the values I have on the grib file.

These are the output:

printing array
[[ 1.13245029  1.13245029  1.13245029 ...,  1.13245029  1.13245029
   1.13245029]
 [ 1.106688    1.10659579  1.10650334 ...,  1.10706602  1.10693998
   1.10681408]
 [ 1.10806011  1.10786188  1.10766377 ...,  1.10870979  1.10849327
   1.10827666]
 ..., 
 [ 0.16032772  0.16051986  0.16071201 ...,  0.15965874  0.15988178
   0.1601047 ]
 [ 0.16065853  0.16073246  0.1608062  ...,  0.1603807   0.16047323
   0.1605659 ]
 [ 0.15851239  0.15851239  0.15851239 ...,  0.15851239  0.15851239
   0.15851239]]
print data_sum on the grib
[[ 1.13245045  1.13245045  1.13245045 ...,  1.13245045  1.13245045
   1.13245045]
 [ 1.1066879   1.10659587  1.10650336 ...,  1.10706603  1.10694014
   1.10681426]
 [ 1.10806023  1.10786187  1.10766398 ...,  1.10870969  1.1084932
   1.10827672]
 ..., 
 [ 0.16032778  0.16051995  0.16071212 ...,  0.15965878  0.15988194
   0.16010462]
 [ 0.16065871  0.16073262  0.16080605 ...,  0.16038071  0.16047322
   0.16056573]
 [ 0.15851247  0.15851247  0.15851247 ...,  0.15851247  0.15851247
   0.15851247]]

Is some explanation about the data are different? I am not able to understand...

Glori P.
  • 466
  • 1
  • 4
  • 14
  • This code should not produce that output. Are you sure that this is the code you ran cause you are first printing data_sum and then the string 'printing array' – Petar Velev Apr 11 '18 at 10:59
  • @PetarVelev, I made a mistake coping and pasting the code... it is ok now. – Glori P. Apr 11 '18 at 11:09
  • Can you add a simple comparison before and after? `import copy; ds1 = copy.deepcopy(data_sum); ds1 == data_sum`. It shouldn't be different :) – Roelant Apr 11 '18 at 11:44
  • and maybe add the imports etc. What is the grib package you use? :) – Roelant Apr 11 '18 at 11:45
  • I run the code `import copy ds1 = copy.deepcopy(data_sum) if ds1.all() == grb.values.all(): print "true"` and I had true as output... I don't get it: why my printed arrays are different? – Glori P. Apr 11 '18 at 13:13
  • @Roelant I am using pygrib module :) – Glori P. Apr 11 '18 at 13:15

0 Answers0