PhD candidate at UCSB Dept of Geography. I specialize in spatio-temporal visualizations that help exploratory spatial data analysis and data-driven knowledge discovery. In my day-to-day tasks I prefer using FOSS (free and open source) tools (e.g. Python, QGIS, GeoDa, R, PostGIS) that help make research more reproducible. |
Wk | Date | Topics | Readings |
---|---|---|---|
1 | 09/26 | Introduction/Review of Spatial Analysis | GIA Ch1 |
1 | 09/28 | Review of Basic Statistics | TBD |
2 | 10/3 | Geographic Data | SD |
2 | 10/5 | Distance, adjacency and MAUP | GIA Ch1 |
3 | 10/10 | Geovisualization | GIA Ch3 |
3 | 10/12 | Point Pattern Analysis | GIA Ch5,6 |
3 | 10/16 | Data Report Due | ⚠️ |
4 | 10/17 | Correlation and Covariance | |
4 | 10/19 | ANOVA | |
5 | 10/24 | Spatial Autocorrelation 1 | GIA Ch7 |
5 | 10/26 | Spatial Autocorrelation 2 |
Wk | Date | Topics | Readings |
---|---|---|---|
6 | 10/31 | LISA and Local Moran's $I$ | GIA Ch8 |
6 | 11/2 | Other Local Statistics | |
6 | 11/6 | Interim Data Report Due | ⚠️ |
7 | 11/7 | Spatial Regression 1 | SR |
7 | 11/9 | Spatial Regression 2 | |
8 | 11/14 | Spatial Clustering/Regionalization 1 | CR |
8 | 11/16 | Spatial Clustering/Regionalization 2 | |
9 | 11/21 | Spatial Interpolation | GIA Ch9 |
9 | 11/23 | Geostatistics | GIA Ch10 |
9 | 11/27 | Presentation slides due | ⚠️ |
10 | 11/28 | Presentations 1 | |
10 | 11/30 | Presentations 2 | |
11 | 12/7 | Final Report Due | ⚠️ |
import geopandas as gpd
import osmnx as ox
import matplotlib.pyplot as plt
import contextily as cx
from IPython.display import Image
from pointpats import centrography
from matplotlib.patches import Ellipse
import numpy as np
ox.settings.use_cache = True
goleta = ox.geocode_to_gdf("Goleta, CA, USA") # get Goleta
go_graph = ox.graph_from_place('Goleta, CA, USA')
go_nodes, go_streets = ox.graph_to_gdfs(go_graph)
tags = {'amenity': ['pub', 'bar', 'cafe', 'restaurant']} # used for parsing OSM data
dist = 5000 # set search radius (in meters)
# download POIs
pois = ox.geometries.geometries_from_point(center_point = (goleta.lat[0],goleta.lon[0]), tags=tags, dist=dist)
go_proj = ox.project_gdf(goleta, to_crs='EPSG:3857') # re-project layers
go_streets_proj = ox.project_gdf(go_streets, to_crs='EPSG:3857')
pois_proj = ox.project_gdf(pois, to_crs='EPSG:3857')
# print to the output
print(f'There are {pois.shape} cafes/restaurants/bars/pubs in SB!')
pois.head(3)
There are (85, 58) cafes/restaurants/bars/pubs in SB!
amenity | brand | brand:wikidata | brand:wikipedia | cuisine | name | official_name | takeaway | geometry | source | ... | disused:building | capacity | height | roof:colour | roof:shape | contact:facebook | addr:housename | designation | ways | type | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element_type | osmid | |||||||||||||||||||||
node | 448863565 | cafe | Starbucks | Q37158 | en:Starbucks | coffee_shop | Starbucks | Starbucks Coffee | yes | POINT (-119.84817 34.41147) | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
1341709739 | restaurant | NaN | NaN | NaN | american | IHOP | NaN | NaN | POINT (-119.78818 34.44325) | Local Knowledge | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | |
1348747781 | restaurant | NaN | NaN | NaN | indian | Masala Spice Indian Cuisine | NaN | NaN | POINT (-119.82570 34.44172) | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
3 rows × 58 columns
go_streets_proj.highway.value_counts()[:15]
service 15890 footway 12784 residential 7977 path 1446 tertiary 772 secondary 644 unclassified 249 cycleway 150 track 84 [footway, service] 60 [footway, residential] 60 motorway_link 44 [footway, path] 30 motorway 27 living_street 14 Name: highway, dtype: int64
fig, ax = plt.subplots(figsize=(15,15))
major_str = go_streets_proj.loc[(go_streets_proj.highway=='secondary')|(go_streets_proj.highway=='primary')|(go_streets_proj.highway=='motorway')]
go_proj.plot(fc="blue", ec="blue", linewidth=3, alpha=.25, ax=ax, zorder=1, label='Goleta')
major_str.plot(color='k', ax=ax, zorder=2)
go_proj.centroid.plot(color='orange', markersize=200, marker='*', ax=ax, zorder=3)
go_proj.centroid.buffer(5000).plot(fc='none', ec='orange', linewidth=2, ax=ax, linestyle='dashed', zorder=4)
pois_proj.plot(column='amenity', markersize=20, ax=ax, categorical=True, legend=True, zorder=5)
cx.add_basemap(ax=ax)
ax.set_title('Cafes, restaraunts and bars\n within 5000m of Goleta,CA')
_ = ax.axis("off")
fig.savefig('goleta_cafe.png', bbox_inches='tight')
plt.close()
Image(filename='goleta_cafe.png')
# create x and y for calculation with projected coords (meters)
pois = pois.to_crs('EPSG:3857')
pois['x'] = pois.geometry.centroid.x
pois['y'] = pois.geometry.centroid.y
mean_center = centrography.mean_center(pois[["x", "y"]])
med_center = centrography.euclidean_median(pois[["x", "y"]])
std_dist = centrography.std_distance(pois[["x", "y"]])
major, minor, rotation = centrography.ellipse(pois[["x", "y"]])
print(mean_center)
print(med_center)
print(std_dist)
[-13341454.75696344 4086141.85634311] [-13342101.87019569 4085474.32197616] 2964.6474778578227
C:\Users\barguzin\anaconda3\envs\geo_env\lib\site-packages\pointpats\geometry.py:22: DeprecationWarning: Please use `ConvexHull` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated. spatial.qhull.ConvexHull, C:\Users\barguzin\anaconda3\envs\geo_env\lib\site-packages\pointpats\geometry.py:42: DeprecationWarning: Please use `ConvexHull` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated. def _(shape: spatial.qhull.ConvexHull): C:\Users\barguzin\anaconda3\envs\geo_env\lib\site-packages\pointpats\geometry.py:85: DeprecationWarning: Please use `ConvexHull` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated. def _(shape: spatial.qhull.ConvexHull): C:\Users\barguzin\anaconda3\envs\geo_env\lib\site-packages\pointpats\geometry.py:132: DeprecationWarning: Please use `ConvexHull` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated. def _(shape: spatial.qhull.ConvexHull, x: float, y: float): C:\Users\barguzin\anaconda3\envs\geo_env\lib\site-packages\pointpats\geometry.py:174: DeprecationWarning: Please use `ConvexHull` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated. def _(shape: spatial.qhull.ConvexHull):
# Set up figure and axis
fig, ax = plt.subplots(1, figsize=(9, 9))
# Plot photograph points
ax.scatter(pois["x"], pois["y"], s=2)
ax.scatter(*mean_center, color="red", marker="x", label="Mean Center")
ax.scatter(
*med_center, color="limegreen", marker="o", label="Median Center"
)
# Construct the standard ellipse using matplotlib
ellipse = Ellipse(
xy=mean_center, # center the ellipse on our mean center
width=major * 2, # centrography.ellipse only gives half the axis
height=minor * 2,
angle=np.rad2deg(
rotation
), # Angles for this are in degrees, not radians
facecolor="none",
edgecolor="red",
linestyle="--",
label="Std. Ellipse",
)
ax.add_patch(ellipse)
ax.legend()
# Display
# Add basemap
cx.add_basemap(
ax, source=cx.providers.Stamen.TonerLite
#ax, source=cx.providers.OpenStreetMap.Mapnik
)
fig.savefig('centro.png', bbox_inches='tight')
plt.close()
Image(filename='centro.png')