PySGN (Python for Synthetic Geospatial Networks) is a Python package for constructing synthetic geospatial networks. It is built on top of the NetworkX package, which provides a flexible and efficient data structure for representing complex networks and GeoPandas, which extends the datatypes used by pandas to allow spatial operations on geometric types. PySGN is designed to be easy to use and flexible, allowing users to generate networks with a wide range of characteristics.
PySGN can be installed using pip:
pip install pysgn
Here's a simple example of how to use the geo_erdos_renyi_network
function to create a geospatial Erdős-Rényi network:
import geopandas as gpd
from pysgn import geo_erdos_renyi_network
# Load your geospatial data into a GeoDataFrame
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
# Create a geospatial Erdős-Rényi network
graph = geo_erdos_renyi_network(gdf, a=3)
# Output the number of nodes and edges
print(f"Number of nodes: {graph.number_of_nodes()}")
print(f"Number of edges: {graph.number_of_edges()}")
Similarly you can use the geo_watts_strogatz_network
function to create a geospatial Watts-Strogatz network:
import geopandas as gpd
from pysgn import geo_watts_strogatz_network
# Load your geospatial data into a GeoDataFrame
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
# Create a geospatial Watts-Strogatz network
graph = geo_watts_strogatz_network(gdf, k=4, p=0.1)
# Output the number of nodes and edges
print(f"Number of nodes: {graph.number_of_nodes()}")
print(f"Number of edges: {graph.number_of_edges()}")
For more information on how to use PySGN, please refer to the documentation.
If you run into an issue, please file a ticket for us to discuss. If possible, follow up with a pull request.
If you would like to add a feature, please reach out via ticket or start a discussion. A feature is most likely to be added if you build it!
Don't forget to check out the Contributors guide.
PySGN is released under the MIT License.