2

I'm new to PySAL and trying to run Knox test to find space-time correlation in my dataset. My original dataset is in the form of csv including attributes such latitude, longitude, date and other related features. I converted the csv file into shapefile (point-type shapefile) using QGIS. I stored the .shp, .dbf and .shx in a folder in pysal/examples directory.

I'm trying to run these lines of code:

import numpy as np
import pysal
import pysal.spatial_dynamics.interaction as interaction
np.random.seed(100)
path = "...pysal/examples/Shapefile/trial.shp"
events = interaction.SpaceTimeEvents(path, 'Date', infer_timestamp = True)

(source: http://pysal.readthedocs.io/en/latest/users/tutorials/dynamics.html#space-time-interaction-tests)

I'm facing the following error even though the trial.dbf file is present in the same folder:

KeyError: 'trial.dbf not found in PySAL built-in examples.'

Can anyone guide me as to what I'm doing wrong here?

What is the solution for this error?

1

Summary: You can fix this by changing one line of code but I also will do a pull request for the pysal library to make sure no one else has the issue in the future.

Details: The problem is line 124 in line in the pysal source code for the SpaceTimeEvents class. As stated, I will submit a pull request to the Pysal project, but in the meantime you can use these instructions to get the module working locally for yourself.

Solution: You must change a line of code for your locally installed version of pysal. To find out where your local pysal install is, follow these directions. Open a python interpreter, and then:

# loading libraries
import pysal,os

# this line finds where your pysal is installed and prints it out
head,tail=os.path.split(pysal.__file__)

# this will print out the location of the file you need to change
print(os.path.join(head,"spatial_dynamics/interaction.py"))

If you run the code above, it should print the location of the pysal file you need to change. Now, navigate to that file.

Open that file in a text editor or a word pad. You will change line 124 from:

# this is the old pysal code causing the error
dbf = pysal.open(pysal.examples.get_path(dbf_tail)) 

to

# replace the code above with this code
dbf = pysal.open(os.path.join(head,dbf_tail))

Save the edited file. Re-import pysal (you may have to restart your python), and try using SpaceTimeEvents to load your local file. It should work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.