GeoStat-Framework / PyKrige

Kriging Toolkit for Python
https://pykrige.readthedocs.io
BSD 3-Clause "New" or "Revised" License
765 stars 189 forks source link

bug? #12

Closed aleksandervines closed 7 years ago

aleksandervines commented 8 years ago

I'm not sure if I'm misunderstanding something, or if I've discovered a bug. But I got a small code example to reproduce it: We start with these data:

y/x 0 1 2
2 n 5 n
1 0 n n
0 1 n n
from pykrige.ok import OrdinaryKriging
import numpy as np
import pykrige.kriging_tools as kt
z = [[0,0,1],
     [0,1,0],
     [1,2,5]]
data = np.array(z)
gridx = np.arange(0.0, 2.1, 0.5)
gridy = np.arange(0.0, 2.1, 0.5)
OK = OrdinaryKriging(data[:, 0], data[:, 1], data[:, 2], variogram_model='linear',
                     verbose=False, enable_plotting=False)
z, _ = OK.execute('grid', gridx, gridy)
kt.write_asc_grid(gridx, gridy, z, filename="output.asc")

I would assume the output would be (preserving the three original values, with interpolated x values):

y/x 0 0.5 1 1.5 2
2 x x 5 x x
1.5 x x x x x
1 0 x x x x
0.5 x x x x x
0 1 x x x x

But the output file contains the following:

NCOLS          5         
NROWS          5         
XLLCENTER      0.00      
YLLCENTER      0.00      
DX             0.50      
DY             0.50      
NODATA_VALUE   -999.00   
2.67            5.00            2.67            2.53            2.44            
2.28            2.29            2.28            2.25            2.23            
1.86            -0.00           1.86            1.96            2.02            
1.62            1.54            1.62            1.74            1.83            
1.50            1.00            1.50            1.60            1.69            

From my interpretation of this, the original values have all been placed at X=0.5

bsmurphy commented 8 years ago

Well that's really weird. The problem is that your data array is an array of integers. I tried to recreate your problem: by making the data array an array of floats, I recover the correct answer, but by making that array all integers, I get the (wrong) answer that you got. I'm not sure why this is happening. Probably something weird happening with ints vs. floats deep in the code that I didn't anticipate. Are you using Python 2.x? In the mean time, I'd say just make sure you're working all with arrays of floats. But thanks for bringing this to my attention, I'll have to look into this more.

bsmurphy commented 7 years ago

This was addressed in PR #47, so closing the issue.