GeoStat-Framework / PyKrige

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

zero-size array Erro in OrdinaryKriging #280

Open jsbluekitty opened 10 months ago

jsbluekitty commented 10 months ago

I meet a erro like this when i use OrdinaryKriging() zero-size array to reduction operation maximum which has no identity

My code looks like this:

Data = geopandas.read_file('./housepricepoi.shp').to_crs('EPSG:4547')

lons = Data['geometry'].x.values
lons = np.nan_to_num(lons)

lats = Data['geometry'].y.values
lats = np.nan_to_num(lats)

price = Data['price'].values
price = np.nan_to_num(price)

try:
    ok3d = OrdinaryKriging(lons, lats, price, variogram_model='linear')
    k3d1, ss3d = ok3d.execute("grid", grid_lon, grid_lat)
except Exception as e:
    print(e)

The info of data is like:

<class 'geopandas.geodataframe.GeoDataFrame'>
RangeIndex: 9920 entries, 0 to 9919
Data columns (total 2 columns):
 #   Column    Non-Null Count  Dtype   
---  ------    --------------  -----   
 0   price     9920 non-null   int64   
 1   geometry  9920 non-null   geometry
dtypes: geometry(1), int64(1)
memory usage: 155.1 KB

I wonder if it's my data that's causing the problem if you want the data,i will send it to your email.

jsbluekitty commented 10 months ago

And this is my new code:

Data = geopandas.read_file('./housepricepoi.shp').to_crs('EPSG:4547')
Data = Data.drop_duplicates(['geometry'])
ok3d = OrdinaryKriging(Data['geometry'].x, Data['geometry'].y, Data['price'])

k3d1, ss3d = ok3d.execute("grid", grid_lon, grid_lat)

this is the info of Data:

<class 'geopandas.geodataframe.GeoDataFrame'>
Int64Index: 1585 entries, 0 to 9877
Data columns (total 2 columns):
 #   Column    Non-Null Count  Dtype   
---  ------    --------------  -----   
 0   price     1585 non-null   int64   
 1   geometry  1585 non-null   geometry
dtypes: geometry(1), int64(1)
memory usage: 37.1 KB

it's still raise the erro: ValueError: zero-size array to reduction operation maximum which has no identity