GeostatsGuy / GeostatsPy

GeostatsPy Python package for spatial data analytics and geostatistics. Started as a reimplementation of GSLIB, Geostatistical Library (Deutsch and Journel, 1992) from Fortran to Python, Geostatistics in a Python package. Now with many additional methods. I hope this resources is helpful, Prof. Michael Pyrcz
https://pypi.org/project/geostatspy/
MIT License
467 stars 178 forks source link

IndexError: index 4 is out of bounds for axis 0 with size 4 #38

Open EChenevert opened 2 years ago

EChenevert commented 2 years ago

I am trying to implement the declustering function on my dataframe which consists of longitude, latitude, and sediment accumulation variables, but I am getting an out of index error. I am having trouble fixing this error myself, could someone help me figure this out? Below is the traceback:

Traceback (most recent call last): File "", line 1, in File "C:\Users\etachen\AppData\Local\JetBrains\PyCharm 2021.2.2\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py", line 198, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Users\etachen\AppData\Local\JetBrains\PyCharm 2021.2.2\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/etachen/PycharmProjects/ai_algo_tests/declustering_medium_test.py", line 21, in W, Csize, Dmean = geostat.declus(df,'Longitude', 'Latitude', 'Average Accretion (mm)', File "C:\Users\etachen\Anaconda3\envs\ai_algo_tests\lib\site-packages\geostatspy\geostats.py", line 1607, in declus cellwt[icell] = cellwt[icell] + 1.0 IndexError: index 4 is out of bounds for axis 0 with size 4

EChenevert commented 2 years ago

Okay I was able to find a solution by reducing the noff parameter to only 5. Any value greater than 5 gave me back the same error

jonm3D commented 10 months ago

I am also getting this error, but changing noff doesn't fix the issue for me. I'm using a geodataframe with dimension (515,20) and the following DECLUS inputs:

weights, cell_sizes, dmeans = geostats.declus(ddf,'X','Y','dZ', iminmax = 1, noff= 10, ncell=1000, cmin=1, cmax=50)

The problematic dataframe can be downloaded here (link to download gpkg from box).

I've tried resetting the dataframe index, using a different subset of rows/columns, converting to a standard Dataframe, varying the values for iminmax/noff/ncell/cmin/cmax but I haven't been able to isolate the cause.

Here is the specific error message I am getting:


IndexError                                Traceback (most recent call last)
Cell In [33], line 1
----> 1 weights, cell_sizes, dmeans = geostats.declus(ddf.loc[:, ['X', 'Y', 'dZ']],'X','Y','dZ',
      2                                           iminmax = 1, 
      3                                           noff= 10, ncell=1000,
      4                                           cmin=1, cmax=50)
      6 ddf['W'] = weights
      7 ddf.head()                                  

File /srv/conda/envs/notebook/lib/python3.10/site-packages/geostatspy/geostats.py:1607, in declus(df, xcol, ycol, vcol, iminmax, noff, ncell, cmin, cmax)
   1605     icell = icellx + (icelly - 1) * ncellx
   1606     index[i] = icell
-> 1607     cellwt[icell] = cellwt[icell] + 1.0
   1609 # The weight assigned to each datum is inversely proportional to the
   1610 # number of data in the cell. We first need to get the sum of
   1611 # weights so that we can normalize the weights to sum to one
   1612 sumw = 0.0

IndexError: index 3109994 is out of bounds for axis 0 with size 3109994```