SpacetimePointDistribution
The SpacetimePointDistribution class is used for quantifying the distribution of points in a dataset. Unlike the PointDistribution class, the SpacetimePointDistribution analyses the distribution of points across both space and time. When analysing the distribution of data, we are interested in the shape, centre, and spread of the subject variable. In the context of points distributed over space and time, this involves calculating statistics concerning the spatial and temporal displacement of points in relation to each other or to some other point, such as their spatio-temporal midpoint.
Importing the Class
The SpacetimePointDistribution class is located in GeoJikuu's descriptives.spacetime_distribution module:
from geojikuu.descriptives.spacetime_distribution import SpacetimePointDistribution
Creating a SpacetimePointDistribution Object
A SpacetimePointDistribution object is created by passing in a list of (lat, lon, date) coordinates, along with the date's format:
data = {
"lat": [34.6870676, 34.696109, 34.6525807, 35.7146509, 35.6653623, 35.6856905],
"lon": [135.5237618, 135.5121774, 135.5059984, 139.7963897, 139.7254906, 139.7514867],
"date": ["19/03/1990", "19/03/1991", "19/03/1992", "19/03/1993", "19/03/1994", "19/03/1995"],
}
df = pd.DataFrame.from_dict(data)
stpd_analysis = SpacetimePointDistribution(list(zip(df["lat"], df["lon"], df["date"])),
date_format="%d/%m/%Y")
Computing the Geographical-Temporal Midpoint
Given a set of points on the surface of the Earth, their geographical-temporal midpoint is defined as the point which reflects their most central time and location. Computing the geographical-temporal midpoint of the SpacetimePointDistribution object can be done by calling the geo_temporal_midpoint() function:
stpd_analysis.geo_temporal_midpoint()
(35.20208795638931, 137.6226886288883, '17/09/1992')
Computing Pairwise Displacement Statistics
Displacement statistics are used to quantify the spatio-temporal distribution of a set of points. Such statistics can be computed by first calculating the spatial and temporal displacement between each pair of points and then calculating the following statistics related to those measurements: mean, standard deviation, variance, and quartiles. For example:
mean_displacement = stpd_analysis.mean_displacement()
displacement_std = stpd_analysis.displacement_std()
displacement_variance = stpd_analysis.displacement_variance()
displacement_quartiles = stpd_analysis.displacement_quartiles()
print("Displacement Statistics")
print("-----------------------")
print(f"{'Mean'}: {mean_displacement}")
print(f"{'Standard Deviation'}: {displacement_std}")
print(f"{'Variance'}: {displacement_variance}")
print("Quartiles:")
print(f" MIN: {displacement_quartiles['MIN']}")
print(f" Q1: {displacement_quartiles['Q1']}")
print(f" MEDIAN: {displacement_quartiles['MEDIAN']}")
print(f" Q3: {displacement_quartiles['Q3']}")
print(f" MAX: {displacement_quartiles['MAX']}")
print(f" IQR: {displacement_quartiles['IQR']}")
print(f" RANGE: {displacement_quartiles['RANGE']}")
Output:
Displacement Statistics
-----------------------
Mean: {'MEAN SPATIAL DISPLACEMENT': 242.82341922845717, 'MEAN TEMPORAL DISPLACEMENT': 852.2}
Standard Deviation: {'SPATIAL DISPLACEMENT STD': 201.3914252565384, 'TEMPORAL DISPLACEMENT STD': 471.50824867803584}
Variance: {'SPATIAL DISPLACEMENT VARIANCE': 40558.5061668599, 'TEMPORAL DISPLACEMENT VARIANCE': 222320.0285714285}
Quartiles:
MIN: {'DIS': 1.4603107237518165, 'TEMP': 365}
Q1: {'DIS': 5.0254511373009425, 'TEMP': 365.5}
MEDIAN: {'DIS': 397.76196647412286, 'TEMP': 731.0}
Q3: {'DIS': 401.6004309540522, 'TEMP': 1096.0}
MAX: {'DIS': 407.36364342227023, 'TEMP': 1826}
IQR: {'DIS': 396.57497981675124, 'TEMP': 730.5}
RANGE: {'DIS': 405.9033326985184, 'TEMP': 1461}
From the results above, we can make the following observations (among others):
- The mean displacement between any two points is ~243 kilometres and ~852 days, with a standard deviation of ~201 kilometres and ~472 days.
- No two points are less than ~1.5 kilometres and 365 days apart, and no two points are more than ~407 kilometres and 1826 days apart.
- 25% of the point pairs are within ~5 kilometres and ~366 days of each other, 50% are within ~398 kilometres and 731 days of each other, and 75% are within ~402 kilometres and 1096 days of each other.
Computing Reference Point Displacement Statistics
Rather than calculating statistics concerning the spatio-temporal displacement of each point in relation to every other point, we can also use a reference point instead. In this case, displacement statistics are calculated concerning each point in relation to the reference point.
This can be achieved by passing the desired spatio-temporal reference point into the same SpacetimePointDistribution functions used in the previous step.
Any arbitrary reference point can be given, but the example below uses the geo-temporal midpoint:
geo_temporal_midpoint = stpd_analysis.geo_temporal_midpoint()
mean_displacement = stpd_analysis.mean_displacement(reference_point=geo_temporal_midpoint)
displacement_std = stpd_analysis.displacement_std(reference_point=geo_temporal_midpoint)
displacement_variance = stpd_analysis.displacement_variance(reference_point=geo_temporal_midpoint)
displacement_quartiles = stpd_analysis.displacement_quartiles(reference_point=geo_temporal_midpoint)
print("Displacement Statistics")
print("-----------------------")
print(f"{'Mean'}: {mean_displacement}")
print(f"{'Standard Deviation'}: {displacement_std}")
print(f"{'Variance'}: {displacement_variance}")
print("Quartiles:")
print(f" MIN: {displacement_quartiles['MIN']}")
print(f" Q1: {displacement_quartiles['Q1']}")
print(f" MEDIAN: {displacement_quartiles['MEDIAN']}")
print(f" Q3: {displacement_quartiles['Q3']}")
print(f" MAX: {displacement_quartiles['MAX']}")
print(f" IQR: {displacement_quartiles['IQR']}")
print(f" RANGE: {displacement_quartiles['RANGE']}")
Output:
Displacement Statistics
-----------------------
Mean: {'MEAN SPATIAL DISPLACEMENT': 200.83619768738552, 'MEAN TEMPORAL DISPLACEMENT': 547.8333333333334}
Standard Deviation: {'SPATIAL DISPLACEMENT STD': 2.587762542918773, 'TEMPORAL DISPLACEMENT STD': 326.6897100716009}
Variance: {'SPATIAL DISPLACEMENT VARIANCE': 6.696514978533435, 'TEMPORAL DISPLACEMENT VARIANCE': 106726.16666666667}
Quartiles:
MIN: {'DIS': 197.35107354395333, 'TEMP': 182}
Q1: {'DIS': 199.81969582141406, 'TEMP': 274.25}
MEDIAN: {'DIS': 200.3040150988218, 'TEMP': 548.0}
Q3: {'DIS': 201.90911063541782, 'TEMP': 821.75}
MAX: {'DIS': 204.95568383948827, 'TEMP': 913}
IQR: {'DIS': 2.08941481400376, 'TEMP': 547.5}
RANGE: {'DIS': 7.60461029553494, 'TEMP': 731}
From the results above, we can make the following observations (among others):
- The mean displacement between any point and the midpoint is ~201 kilometres and ~548 days, with a standard deviation of ~2.6 kilometres and 327 days.
- No point is closer to the midpoint than ~197 kilometres and 182 days, and no point is further away than ~205 kilometres and 913 days.
- The quartiles, mean, and median are all approximately 200 kilometres in value. This indicates that the points are consistently centred at approximately 200 kilometres from the midpoint. However, we see a noticeable variance in temporal displacement from the midpoint.