Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve documentation #1116

Merged
merged 42 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5c21170
bump to v1.9.0
gboeing Jan 20, 2024
e997203
disable typehints in function signatures in documentation for now
gboeing Jan 20, 2024
23f7f96
pull documentation param/return types from function signature annotat…
gboeing Jan 23, 2024
3b80941
improve docstrings and remove redundant type info
gboeing Jan 23, 2024
c6c60a7
add sphinx_autodoc_typehints to requirements
gboeing Jan 23, 2024
83da83b
fix package name
gboeing Jan 23, 2024
3eea5c6
add sphinx-autodoc-typehints to rtd environment
gboeing Jan 23, 2024
6deb57b
update changelog
gboeing Jan 26, 2024
1bee3c7
add endpoint_attrs param to flexibly relax simplification strictness
gboeing Jan 26, 2024
8e3c61b
improve docstrings in elevation module
gboeing Jan 27, 2024
e468a08
improve docstrings in geocoder module
gboeing Jan 27, 2024
dbe60b0
code cleanup
gboeing Jan 27, 2024
690838a
fix docstring
gboeing Jan 27, 2024
2ed9270
increase test coverage
gboeing Jan 27, 2024
424d056
improve docstrings in features and graph modules
gboeing Jan 29, 2024
1682471
improve docstrings of _http and io modules
gboeing Jan 29, 2024
80c11dc
improve docstrings of _nominatim module
gboeing Jan 29, 2024
9a908ec
replace iteration counter with enumerate
gboeing Jan 29, 2024
b814772
update ruff version
gboeing Jan 29, 2024
b8715e1
improve docstrings of _osm_xml and _overpass modules
gboeing Jan 29, 2024
70b97ce
update ruff version
gboeing Jan 30, 2024
89fd2ff
Add Dependabot configuration for GitHub Actions updates
EwoutH Jan 30, 2024
2e39e19
Merge branch 'main' into simplify
gboeing Jan 30, 2024
fb6e328
Merge pull request #1119 from EwoutH/patch-5
gboeing Jan 30, 2024
9e1f3a7
Bump actions/checkout from 3 to 4
dependabot[bot] Jan 30, 2024
498b49a
Merge pull request #1120 from gboeing/dependabot/github_actions/actio…
gboeing Jan 30, 2024
ee0dccc
improve docstrings of projection module
gboeing Jan 30, 2024
d34a2c8
improve docstrings of plot module and improve handling of save/show/c…
gboeing Jan 30, 2024
e98d1a6
deprecate address, point, network_type, edge_color, and smooth_joints…
gboeing Jan 30, 2024
99c55e1
Merge pull request #1117 from gboeing/simplify
gboeing Jan 30, 2024
5c27133
Merge pull request #1121 from gboeing/plot
gboeing Jan 30, 2024
488297f
Merge branch 'main' into dep
gboeing Jan 30, 2024
c7c191a
fix tests and docstrings
gboeing Jan 30, 2024
b545bdb
code cleanup
gboeing Jan 30, 2024
9b24303
update changelog
gboeing Jan 30, 2024
335b141
Merge pull request #1122 from gboeing/dep
gboeing Jan 30, 2024
bb920db
improve docstrings of routing, settings, and simplification modules
gboeing Jan 30, 2024
96319f4
fix docstring
gboeing Jan 30, 2024
40be9b2
improve docstrings of speed, stats, and truncate modules
gboeing Jan 31, 2024
34d7d9d
improve docstrings of the utility modules
gboeing Jan 31, 2024
6eb380a
fix docstrings
gboeing Jan 31, 2024
a87f667
docstring cleanup
gboeing Jan 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
furo
sphinx == 7.* # same value as needs_sphinx in /docs/source/conf.py
sphinx-autodoc-typehints
9 changes: 8 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@
"sklearn",
]

autodoc_typehints = "description"
napoleon_use_param = True
napoleon_use_rtype = False
typehints_document_rtype = True
typehints_use_rtype = False
typehints_fully_qualified = False

# general configuration and options for HTML output
# see https://www.sphinx-doc.org/en/master/usage/configuration.html
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_autodoc_typehints"]
html_static_path: list[str] = []
html_theme = "furo"
language = "en"
Expand Down
1 change: 1 addition & 0 deletions environments/docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ statsmodels
# docs
furo
sphinx
sphinx-autodoc-typehints

# packaging
conda-smithy
Expand Down
2 changes: 1 addition & 1 deletion osmnx/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class CacheOnlyInterruptError(InterruptedError):
"""Exception for settings.cache_only_mode=True interruption."""
"""Exception for `settings.cache_only_mode=True` interruption."""


class GraphSimplificationError(ValueError):
Expand Down
132 changes: 66 additions & 66 deletions osmnx/bearing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Calculate graph edge bearings."""
"""Calculate graph edge bearings and orientation entropy."""

from __future__ import annotations

from typing import overload
Expand Down Expand Up @@ -49,24 +50,24 @@ def calculate_bearing(

Vectorized function to calculate initial bearings between two points'
coordinates or between arrays of points' coordinates. Expects coordinates
in decimal degrees. Bearing represents the clockwise angle in degrees
between north and the geodesic line from (lat1, lon1) to (lat2, lon2).
in decimal degrees. The bearing represents the clockwise angle in degrees
between north and the geodesic line from `(lat1, lon1)` to `(lat2, lon2)`.

Parameters
----------
lat1 : float or numpy.array of float
first point's latitude coordinate
lon1 : float or numpy.array of float
first point's longitude coordinate
lat2 : float or numpy.array of float
second point's latitude coordinate
lon2 : float or numpy.array of float
second point's longitude coordinate
lat1
First point's latitude coordinate(s).
lon1
First point's longitude coordinate(s).
lat2
Second point's latitude coordinate(s).
lon2
Second point's longitude coordinate(s).

Returns
-------
bearing : float or numpy.array of float
the bearing(s) in decimal degrees
bearing
The bearing(s) in decimal degrees.
"""
# get the latitudes and the difference in longitudes, all in radians
lat1 = np.radians(lat1)
Expand All @@ -85,24 +86,24 @@ def calculate_bearing(

def add_edge_bearings(G: nx.MultiDiGraph) -> nx.MultiDiGraph:
"""
Add compass `bearing` attributes to all graph edges.
Calculate and add compass `bearing` attributes to all graph edges.

Vectorized function to calculate (initial) bearing from origin node to
destination node for each edge in a directed, unprojected graph then add
these bearings as new edge attributes. Bearing represents angle in degrees
(clockwise) between north and the geodesic line from the origin node to
the destination node. Ignores self-loop edges as their bearings are
undefined.
these bearings as new `bearing` edge attributes. Bearing represents angle
in degrees (clockwise) between north and the geodesic line from the origin
node to the destination node. Ignores self-loop edges as their bearings
are undefined.

Parameters
----------
G : networkx.MultiDiGraph
unprojected graph
G
Unprojected graph.

Returns
-------
G : networkx.MultiDiGraph
graph with edge bearing attributes
G
Graph with `bearing` attributes on the edges.
"""
if projection.is_projected(G.graph["crs"]): # pragma: no cover
msg = "graph must be unprojected to add edge bearings"
Expand All @@ -128,34 +129,33 @@ def orientation_entropy(
"""
Calculate undirected graph's orientation entropy.

Orientation entropy is the entropy of its edges' bidirectional bearings
across evenly spaced bins. Ignores self-loop edges as their bearings are
undefined.
Orientation entropy is the Shannon entropy of the graphs' edges'
bidirectional bearings across evenly spaced bins. Ignores self-loop edges
as their bearings are undefined.

For more info see: Boeing, G. 2019. "Urban Spatial Order: Street Network
Orientation, Configuration, and Entropy." Applied Network Science, 4 (1),
67. https://doi.org/10.1007/s41109-019-0189-1

Parameters
----------
Gu : networkx.MultiGraph
undirected, unprojected graph with `bearing` attributes on each edge
num_bins : int
number of bins; for example, if `num_bins=36` is provided, then each
bin will represent 10 degrees around the compass
min_length : float
ignore edges with `length` attributes less than `min_length`; useful
to ignore the noise of many very short edges
weight : string
if not None, weight edges' bearings by this (non-null) edge attribute.
for example, if "length" is provided, this will return 1 bearing
observation per meter per street, which could result in a very large
`bearings` array.
Gu
Undirected, unprojected graph with `bearing` attributes on each edge.
num_bins
Number of bins. For example, if `num_bins=36` is provided, then each
bin will represent 10 degrees around the compass.
min_length
Ignore edges with `length` attributes less than `min_length`. Useful
to ignore the noise of many very short edges.
weight
If not None, weight edges' bearings by this (non-null) edge attribute.
For example, if "length" is provided, this will return 1 bearing
observation per meter per street.

Returns
-------
entropy : float
the graph's orientation entropy
entropy
The orientation entropy of `Gu`.
"""
# check if we were able to import scipy
if scipy is None: # pragma: no cover
Expand All @@ -177,21 +177,21 @@ def _extract_edge_bearings(

Parameters
----------
Gu : networkx.MultiGraph
undirected, unprojected graph with `bearing` attributes on each edge
min_length : float
ignore edges with `length` attributes less than `min_length`; useful
to ignore the noise of many very short edges
weight : string
if not None, weight edges' bearings by this (non-null) edge attribute.
for example, if "length" is provided, this will return 1 bearing
observation per meter per street, which could result in a very large
`bearings` array.
Gu
Undirected, unprojected graph with `bearing` attributes on each edge.
min_length
Ignore edges with `length` attributes less than `min_length`. Useful
to ignore the noise of many very short edges.
weight
If not None, weight edges' bearings by this (non-null) edge attribute.
For example, if "length" is provided, this will return 1 bearing
observation per meter per street (which could result in a very large
`bearings` array).

Returns
-------
bearings : numpy.array of float
the graph's bidirectional edge bearings
bearings
The bidirectional edge bearings of `Gu`.
"""
if nx.is_directed(Gu) or projection.is_projected(Gu.graph["crs"]): # pragma: no cover
msg = "graph must be undirected and unprojected to analyze edge bearings"
Expand Down Expand Up @@ -228,23 +228,23 @@ def _bearings_distribution(

Parameters
----------
Gu : networkx.MultiGraph
undirected, unprojected graph with `bearing` attributes on each edge
num_bins : int
number of bins for the bearings histogram
min_length : float
ignore edges with `length` attributes less than `min_length`; useful
to ignore the noise of many very short edges
weight : string
if not None, weight edges' bearings by this (non-null) edge attribute.
for example, if "length" is provided, this will return 1 bearing
observation per meter per street, which could result in a very large
`bearings` array.
Gu
Undirected, unprojected graph with `bearing` attributes on each edge.
num_bins
Number of bins for the bearing histogram.
min_length
Ignore edges with `length` attributes less than `min_length`. Useful
to ignore the noise of many very short edges.
weight
If not None, weight edges' bearings by this (non-null) edge attribute.
For example, if "length" is provided, this will return 1 bearing
observation per meter per street (which could result in a very large
`bearings` array).

Returns
-------
bin_counts, bin_edges : tuple of numpy.array of float
counts of bearings per bin and the bins edges
bin_counts, bin_edges
Counts of bearings per bin and the bins edges.
"""
n = num_bins * 2
bins = np.arange(n + 1) * 360 / n
Expand Down
Loading
Loading