pointpats.SpaceTimeEvents

class pointpats.SpaceTimeEvents(path, time_col, infer_timestamp=False)[source]

Method for reformatting event data stored in a shapefile for use in calculating metrics of spatio-temporal interaction.

Parameters:
pathstring

the path to the appropriate shapefile, including the file name and extension

timestring

column header in the DBF file indicating the column containing the time stamp.

infer_timestampbool, optional

if the column containing the timestamp is formatted as calendar dates, try to coerce them into Python datetime objects (the default is False).

Examples

Read in the example shapefile data, ensuring to omit the file extension. In order to successfully create the event data the .dbf file associated with the shapefile should have a column of values that are a timestamp for the events. This timestamp may be a numerical value or a date. Date inference was added in version 1.6.

>>> import libpysal as lps
>>> path = lps.examples.get_path("burkitt.shp")
>>> from pointpats import SpaceTimeEvents

Create an instance of SpaceTimeEvents from a shapefile, where the temporal information is stored in a column named “T”.

>>> events = SpaceTimeEvents(path,'T')

See how many events are in the instance.

>>> events.n
188

Check the spatial coordinates of the first event.

>>> events.space[0]
array([300., 302.])

Check the time of the first event.

>>> events.t[0]
array([413.])

Calculate the time difference between the first two events.

>>> events.t[1] - events.t[0]
array([59.])

New, in 1.6, date support: Now, create an instance of SpaceTimeEvents from a shapefile, where the temporal information is stored in a column named “DATE”.

>>> events = SpaceTimeEvents(path,'DATE')

See how many events are in the instance.

>>> events.n
188

Check the spatial coordinates of the first event.

>>> events.space[0]
array([300., 302.])

Check the time of the first event. Note that this value is equivalent to 413 days after January 1, 1900.

>>> events.t[0][0]
datetime.date(1901, 2, 16)

Calculate the time difference between the first two events.

>>> (events.t[1][0] - events.t[0][0]).days
59
Attributes:
nint

number of events.

xarray

(n, 1), array of the x coordinates for the events.

yarray

(n, 1), array of the y coordinates for the events.

tarray

(n, 1), array of the temporal coordinates for the events.

spacearray

(n, 2), array of the spatial coordinates (x,y) for the events.

timearray

(n, 2), array of the temporal coordinates (t,1) for the events, the second column is a vector of ones.

__init__(path, time_col, infer_timestamp=False)[source]

Methods

__init__(path, time_col[, infer_timestamp])