Skip to content

Commit

Permalink
[Draft] Standardize doc-strings (#59)
Browse files Browse the repository at this point in the history
* osm_parser doc-strings

* calculate_od_raw doc-strings

* fetch_pois doc-strings

* style network_clean.py

* doc-strings conversion_utils.py

* doc-strings graphtool.py

* doc-strings optimization.py

* doc-strings fetch_od.py

* doc-strings load_osm.py

* doc-strings core.py
  • Loading branch information
elbeejay authored Feb 27, 2024
1 parent 403224f commit 72f1d3a
Show file tree
Hide file tree
Showing 10 changed files with 1,671 additions and 442 deletions.
88 changes: 68 additions & 20 deletions src/GOSTnets/calculate_od_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ def calculateOD_gdf(
):
"""Calculate Origin destination matrix from GeoDataframes
Args:
G (networkx graph): describes the road network. Often extracted using OSMNX
origins (geopandas dataframe): source locations for calculating access
destinations (geopandas dataframe): destination locations for calculating access
calculate_snap (boolean, optional): variable to add snapping distance to travel time, default is false
wgs84 (CRS dictionary, optional): CRS of road network to which the GDFs are projected
Returns:
numpy array: 2d OD matrix with columns as index of origins and rows as index of destinations
Parameters
----------
G : networkx graph
describes the road network. Often extracted using OSMNX
origins : geopandas dataframe
source locations for calculating access
destinations : geopandas dataframe
destination locations for calculating access
calculate_snap : boolean, optional
variable to add snapping distance to travel time, default is false
wgs84 : CRS dictionary, optional
CRS of road network to which the GDFs are projected
Returns
-------
numpy array
2d OD matrix with columns as index of origins and rows as index of
destinations
"""
# Get a list of originNodes and destinationNodes
if origins.crs != wgs84:
Expand Down Expand Up @@ -74,18 +84,36 @@ def calculateOD_csv(
"""
Calculate OD matrix from csv files of points
:param G: describes the road network. Often extracted using OSMNX
:param string origins: path to csv file with locations for calculating access
:param string destinations: path to csv with destination locations for calculating access
:param string oLat:
:param string oLon:
:param string dLat:
:param string dLon:
:param dict crs: crs of input origins and destinations, defaults to {'init':'epsg:4326'}
:param int fail-value: value to put in OD matrix if no route found, defaults to -1
:param string weight: variable in G used to define edge impedance, defaults to 'time'
:param bool calculate_snap: variable to add snapping distance to travel time, default is false
:returns: numpy array: 2d OD matrix with columns as index of origins and rows as index of destinations
Parameters
----------
G :
describes the road network. Often extracted using OSMNX
origins : str
path to csv file with locations for calculating access
destinations : str
path to csv with destination locations for calculating access
oLat : str
Origin latitude field
oLon : str
Origin longitude field
dLat : str
Destination latitude field
dLon : str
Destination longitude field
crs : dict
crs of input origins and destinations, defaults to {'init':'epsg:4326'}
fail-value : int
value to put in OD matrix if no route found, defaults to -1
weight : str
variable in G used to define edge impedance, defaults to 'time'
calculate_snap : bool
variable to add snapping distance to travel time, default is false
Returns
-------
numpy array
2d OD matrix with columns as index of origins and rows as index of
destinations
"""

originPts = pd.read_csv(originCSV)
Expand Down Expand Up @@ -121,6 +149,26 @@ def calculate_gravity(
0.00001,
],
):
"""
Calculate gravity model values for origin-destination (OD) matrix.
Parameters
----------
od : numpy.ndarray
Origin-destination matrix.
oWeight : list, optional
List of weights for each origin. Defaults to an empty list.
dWeight : list, optional
List of weights for each destination. Defaults to an empty list.
decayVals : list, optional
List of decay values for market access. Defaults to a predefined list.
Returns
-------
pandas.DataFrame
DataFrame containing gravity model values for each origin-destination
pair.
"""
if len(oWeight) != od.shape[0]:
oWeight = [1] * od.shape[0]
if len(dWeight) != od.shape[1]:
Expand Down
16 changes: 11 additions & 5 deletions src/GOSTnets/conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
def rasterize_od_results(inD, outFile, field, template=None):
"""Convert gridded point data frame to raster of commensurate size and resolution
INPUT
inD [ geopandas data frame ] - OD matrix as point data frame
outFile [ string ] - path to save output raster
field [ string ] - field to rasterize
Parameters
----------
inD : geopandas data frame
OD matrix as point data frame
outFile: string
path to save output raster
field : string
field to rasterize
RETURNS
Returns
-------
None
"""
if template:
raster_template = rasterio.open(template)
Expand Down
Loading

0 comments on commit 72f1d3a

Please sign in to comment.