Skip to content

Commit 4b4d9aa

Browse files
committed
use data from geodatasets in examples
1 parent 52e063f commit 4b4d9aa

File tree

4 files changed

+58483
-5515
lines changed

4 files changed

+58483
-5515
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PySGN can be installed using pip:
1515
pip install pysgn
1616
```
1717

18-
If you plan to run the Getting Started notebook `docs/getting_started.ipynb` (or build the documentation) locally, install the optional `docs` extras to get the other dependencies such as Jupyter and Sphinx:
18+
If you plan to run the code snippets below or the Getting Started notebook `docs/getting_started.ipynb` locally, install the optional `docs` extras to get the other dependencies such as geodatasets, Jupyter and Sphinx:
1919

2020
```bash
2121
pip install "pysgn[docs]"
@@ -34,11 +34,17 @@ pip install -e ".[docs]"
3434
Here's a simple example of how to use the `geo_erdos_renyi_network` function to create a geospatial Erdős-Rényi network. It generates a network where each pair of nodes is connected with probability `p`, which depends on the spatial distance between the nodes. The parameter `a` controls the rate of decay of the connection probability with distance.
3535

3636
```python
37+
import geodatasets
3738
import geopandas as gpd
3839
from pysgn import geo_erdos_renyi_network
3940

40-
# Load your geospatial data into a GeoDataFrame
41-
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
41+
# Load the sample grocery-store points from geodatasets
42+
gdf = (
43+
gpd.read_file(geodatasets.get_path("geoda.groceries"))
44+
.explode(index_parts=False)
45+
.reset_index(drop=True)
46+
.to_crs("EPSG:26971")
47+
)
4248

4349
# Create a geospatial Erdős-Rényi network
4450
graph = geo_erdos_renyi_network(gdf, a=3)
@@ -53,11 +59,16 @@ print(f"Number of edges: {graph.number_of_edges()}")
5359
Similarly you can use the `geo_watts_strogatz_network` function to create a geospatial Watts-Strogatz network. It first creates a network where each node is connected to its `k` nearest neighbors. Then, it rewires each edge with probability `p`. If an edge is chosen to be rewired, it is replaced with a new edge to a random node, where the probability of connecting to this new node is inversely proportional to the spatial distance.
5460

5561
```python
62+
import geodatasets
5663
import geopandas as gpd
5764
from pysgn import geo_watts_strogatz_network
5865

59-
# Load your geospatial data into a GeoDataFrame
60-
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
66+
gdf = (
67+
gpd.read_file(geodatasets.get_path("geoda.groceries"))
68+
.explode(index_parts=False)
69+
.reset_index(drop=True)
70+
.to_crs("EPSG:26971")
71+
)
6172

6273
# Create a geospatial Watts-Strogatz network
6374
graph = geo_watts_strogatz_network(
@@ -77,12 +88,17 @@ print(f"Number of edges: {graph.number_of_edges()}")
7788
You can also use the `geo_barabasi_albert_network` function to create a geospatial Barabási-Albert network. It creates a network using geospatial preferential attachment, where the probability of connecting to existing nodes depends on both their degrees and the spatial distances.
7889

7990
```python
91+
import geodatasets
8092
import geopandas as gpd
8193
from pysgn import geo_barabasi_albert_network
8294
from pysgn.ordering import density_order
8395

84-
# Load your geospatial data into a GeoDataFrame
85-
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
96+
gdf = (
97+
gpd.read_file(geodatasets.get_path("geoda.groceries"))
98+
.explode(index_parts=False)
99+
.reset_index(drop=True)
100+
.to_crs("EPSG:26971")
101+
)
86102

87103
# Create a geospatial Barabási-Albert network
88104
graph = geo_barabasi_albert_network(

docs/getting_started.ipynb

Lines changed: 58436 additions & 5501 deletions
Large diffs are not rendered by default.

docs/index.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PySGN can be installed using pip:
1515
pip install pysgn
1616
```
1717

18-
If you plan to run the Getting Started notebook `docs/getting_started.ipynb` (or build the documentation) locally, install the optional `docs` extras to get the other dependencies such as Jupyter and Sphinx:
18+
If you plan to run the code snippets below or the Getting Started notebook `docs/getting_started.ipynb` locally, install the optional `docs` extras to get the other dependencies such as geodatasets, Jupyter and Sphinx:
1919

2020
```bash
2121
pip install "pysgn[docs]"
@@ -34,11 +34,17 @@ pip install -e ".[docs]"
3434
Here's a simple example of how to use the `geo_erdos_renyi_network` function to create a geospatial Erdős-Rényi network. It generates a network where each pair of nodes is connected with probability `p`, which depends on the spatial distance between the nodes. The parameter `a` controls the rate of decay of the connection probability with distance.
3535

3636
```python
37+
import geodatasets
3738
import geopandas as gpd
3839
from pysgn import geo_erdos_renyi_network
3940

40-
# Load your geospatial data into a GeoDataFrame
41-
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
41+
# Load the sample grocery-store points from geodatasets
42+
gdf = (
43+
gpd.read_file(geodatasets.get_path("geoda.groceries"))
44+
.explode(index_parts=False)
45+
.reset_index(drop=True)
46+
.to_crs("EPSG:26971")
47+
)
4248

4349
# Create a geospatial Erdős-Rényi network
4450
graph = geo_erdos_renyi_network(gdf, a=3)
@@ -53,11 +59,16 @@ print(f"Number of edges: {graph.number_of_edges()}")
5359
Similarly you can use the `geo_watts_strogatz_network` function to create a geospatial Watts-Strogatz network. It first creates a network where each node is connected to its `k` nearest neighbors. Then, it rewires each edge with probability `p`. If an edge is chosen to be rewired, it is replaced with a new edge to a random node, where the probability of connecting to this new node is inversely proportional to the spatial distance.
5460

5561
```python
62+
import geodatasets
5663
import geopandas as gpd
5764
from pysgn import geo_watts_strogatz_network
5865

59-
# Load your geospatial data into a GeoDataFrame
60-
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
66+
gdf = (
67+
gpd.read_file(geodatasets.get_path("geoda.groceries"))
68+
.explode(index_parts=False)
69+
.reset_index(drop=True)
70+
.to_crs("EPSG:26971")
71+
)
6172

6273
# Create a geospatial Watts-Strogatz network
6374
graph = geo_watts_strogatz_network(
@@ -77,12 +88,17 @@ print(f"Number of edges: {graph.number_of_edges()}")
7788
You can also use the `geo_barabasi_albert_network` function to create a geospatial Barabási-Albert network. It creates a network using geospatial preferential attachment, where the probability of connecting to existing nodes depends on both their degrees and the spatial distances.
7889

7990
```python
91+
import geodatasets
8092
import geopandas as gpd
8193
from pysgn import geo_barabasi_albert_network
8294
from pysgn.ordering import density_order
8395

84-
# Load your geospatial data into a GeoDataFrame
85-
gdf = gpd.read_file('path/to/your/geospatial_data.shp')
96+
gdf = (
97+
gpd.read_file(geodatasets.get_path("geoda.groceries"))
98+
.explode(index_parts=False)
99+
.reset_index(drop=True)
100+
.to_crs("EPSG:26971")
101+
)
86102

87103
# Create a geospatial Barabási-Albert network
88104
graph = geo_barabasi_albert_network(

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ docs = [
5151
"jupyterlab-lsp",
5252
"python-lsp-server",
5353
"isort",
54+
"geodatasets",
5455
]
5556

5657
[project.urls]

0 commit comments

Comments
 (0)