API reference

IO Module

Storing data

geosnap’s io module provides functions for collecting and storing a variety of datasets including U.S. Census data from 1990-2010, LEHD data from any vintage, and external longitudinal databases.

io.store_census()

Save census data to the local quilt package storage.

io.store_blocks_2000()

Save census 2000 census block data to the local quilt package storage.

io.store_blocks_2010()

Save census 2010 census block data to the local quilt package storage.

io.store_ltdb(sample, fullcount)

Read & store data from Brown’s Longitudinal Tract Database (LTDB).

io.store_ncdb(filepath)

Read & store data from Geolytics’s Neighborhood Change Database.

io.get_lehd([dataset, state, year])

Grab data from the LODES FTP server as a pandas DataFrame.

Accessing Stored Datasets

It also provides a storage container datasets that provides access to datasets that have been imported with the functions above

datasets

Storage for geosnap data.

datasets.blocks_2000([states, convert, fips])

Census blocks for 2000.

datasets.blocks_2010([states, convert, fips])

Census blocks for 2010.

datasets.codebook()

Codebook.

datasets.counties()

Nationwide counties as drawn in 2010.

datasets.ltdb()

Longitudinal Tract Database (LTDB).

datasets.msa_definitions()

2010 Metropolitan Statistical Area definitions.

datasets.msas([convert])

Metropolitan Statistical Areas as drawn in 2010.

datasets.ncdb()

Geolytics Neighborhood Change Database (NCDB).

datasets.states([convert])

States.

datasets.tracts_1990([states, convert])

Nationwide Census Tracts as drawn in 1990 (cartographic 500k).

datasets.tracts_2000([states, convert])

Nationwide Census Tracts as drawn in 2000 (cartographic 500k).

datasets.tracts_2010([states, convert])

Nationwide Census Tracts as drawn in 2010 (cartographic 500k).

The Community Class

The Community is the central construct in geonap used to hold spatiotemporal neighborhood data. The most common way to interact with geosnap is by instantiating a Community using a constructor method, then using analytical methods upon the community

Community([gdf, harmonized])

Spatial and tabular data for a collection of “neighborhoods” over time.

Community Constructors

Community.from_census([state_fips, …])

Create a new Community from original vintage US Census data.

Community.from_geodataframes([gdfs])

Create a new Community from a list of geodataframes.

Community.from_lodes([state_fips, …])

Create a new Community from Census LEHD/LODES data.

Community.from_ltdb([state_fips, …])

Create a new Community from LTDB data.

Community.from_ncdb([state_fips, …])

Create a new Community from NCDB data.

Community Analytics

Community.cluster([n_clusters, method, …])

Create a geodemographic typology by running a cluster analysis on the study area’s neighborhood attributes.

Community.cluster_spatial([n_clusters, …])

Create a spatial geodemographic typology by running a cluster analysis on the metro area’s neighborhood attributes and including a contiguity constraint.

Community.harmonize([target_year, …])

Standardize inconsistent boundaries into time-static ones.

Community.sequence(cluster_col[, …])

Pairwise sequence analysis to evaluate the distance/dissimilarity between every two neighborhood sequences.

Community.simulate([model_name, index_col, …])

Simulate community dynamics using spatial Markov transition rules.

Community.transition(cluster_col[, …])

(Spatial) Markov approach to transitional dynamics of neighborhoods.

Community Visualization

Community.animate_timeseries([column, …])

Create an animated gif from a Community timeseries.

Community.plot_boundary_silhouette([…])

Plot boundary_silhouettes of the Commiunity model.

Community.plot_next_best_label([model_name, …])

Plot the nearest_labels of the community model.

Community.plot_silhouette([model_name, year])

Make silhouette plot of the Community model.

Community.plot_silhouette_map([model_name, …])

Plot of the silhouette scores of a Community model.

Community.plot_path_silhouette([model_name, …])

Plot the path_silhouettes of Commmunity model.

Community.plot_timeseries(column[, title, …])

Plot an attribute from a Community arranged as a timeseries.

Community.plot_transition_matrix([…])

Plot global and spatially-conditioned transition matrices as heatmaps

Community.plot_transition_graphs([…])

Plot a network graph representation of global and spatially-conditioned transition matrices.

Analyze Module

analyze.ModelResults(X, columns, labels, …)

Stores data about cluster and cluster_spatial models.

Neighborhood Clustering Methods

Model neighborhood differentiation using multivariate clustering algorithms

analyze.cluster(gdf[, n_clusters, method, …])

Create a geodemographic typology by running a cluster analysis on the study area’s neighborhood attributes.

analyze.cluster_spatial(gdf[, n_clusters, …])

Create a spatial geodemographic typology by running a cluster analysis on the metro area’s neighborhood attributes and including a contiguity constraint.

Clustering algorithms

The following algorithms may be passed to geosnap.analyze.cluster or geosnap.analyze.cluster_spatial but they should not be called directly

Classic (aspatial) Clustering

affinity_propagation(X[, damping, …])

Clustering with Affinity Propagation.

gaussian_mixture(X[, n_clusters, …])

Clustering with Gaussian Mixture Model.

hdbscan(X[, min_cluster_size, gen_min_span_tree])

Clustering with Hierarchical DBSCAN.

kmeans(X, n_clusters[, init, n_init, …])

K-Means clustering.

spectral(X, n_clusters[, eigen_solver, …])

Spectral Clustering.

ward(X[, n_clusters])

Agglomerative clustering using Ward linkage.

Spatial Clustering

azp(X, w[, n_clusters])

AZP clustering algorithm.

max_p(X, w[, threshold_variable, threshold])

Max-p clustering algorithm [DAR12].

skater(X, w[, n_clusters, floor, trace, islands])

SKATER spatial clustering algorithm.

spenc(X, w[, n_clusters, gamma])

Spatially encouraged spectral clustering.

ward_spatial(X, w[, n_clusters])

Agglomerative clustering using Ward linkage with a spatial connectivity constraint.

Neighborhood Dynamics Methods

Model neighborhood change using optimal-matching algorithms or spatial discrete markov chains

analyze.linc(labels_sequence)

Local Indicator of Neighborhood Change

analyze.sequence(gdf, cluster_col[, …])

Pairwise sequence analysis and sequence clustering.

analyze.transition(gdf, cluster_col[, …])

(Spatial) Markov approach to transitional dynamics of neighborhoods.

Harmonize Module

harmonize.harmonize(raw_community[, …])

Use spatial interpolation to standardize neighborhood boundaries over time.

Visualize Module

visualize.indexplot_seq(df_traj, clustering)

Function for index plot of neighborhood sequences within each cluster.

visualize.explore([data])

Launch an interactive visualization portal.

Util Module

util.gif_from_path([path, figsize, fps, …])

Create an animated gif from a director of image files.

util.fetch_acs([state, level, year, …])

Collect the variables defined in geosnap.datasets.codebook from the Census API.

util.process_acs(df)

Calculate variables from the geosnap codebook