Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 3, 2024
1 parent 461fb59 commit c37af73
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 219 deletions.
2 changes: 1 addition & 1 deletion Tutorials/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Tutorial
# Tutorial
These notebooks are designed to introduce the methodology of GOSTNets to novice python users; in order to properly implement these, users should have a basic knowledge of
- Python
- Jupyter notebooks
Expand Down
2 changes: 1 addition & 1 deletion Tutorials/tutorial_data/rek2.cpg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UTF-8
UTF-8
2 changes: 1 addition & 1 deletion Tutorials/tutorial_data/rek2.prj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PROJCS["ISN93_Lambert_1993",GEOGCS["GCS_ISN93",DATUM["D_Islands_Network_1993",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",64.25],PARAMETER["standard_parallel_2",65.75],PARAMETER["latitude_of_origin",65],PARAMETER["central_meridian",-19],PARAMETER["false_easting",500000],PARAMETER["false_northing",500000],UNIT["Meter",1]]
PROJCS["ISN93_Lambert_1993",GEOGCS["GCS_ISN93",DATUM["D_Islands_Network_1993",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",64.25],PARAMETER["standard_parallel_2",65.75],PARAMETER["latitude_of_origin",65],PARAMETER["central_meridian",-19],PARAMETER["false_easting",500000],PARAMETER["false_northing",500000],UNIT["Meter",1]]
2 changes: 1 addition & 1 deletion Tutorials/tutorial_data/rek_grid.cpg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UTF-8
UTF-8
2 changes: 1 addition & 1 deletion Tutorials/tutorial_data/rek_grid.prj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PROJCS["ISN93_Lambert_1993",GEOGCS["GCS_ISN93",DATUM["D_Islands_Network_1993",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["false_easting",500000.0],PARAMETER["false_northing",500000.0],PARAMETER["central_meridian",-19.0],PARAMETER["standard_parallel_1",64.25],PARAMETER["standard_parallel_2",65.75],PARAMETER["latitude_of_origin",65.0],UNIT["Meter",1.0]]
PROJCS["ISN93_Lambert_1993",GEOGCS["GCS_ISN93",DATUM["D_Islands_Network_1993",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["false_easting",500000.0],PARAMETER["false_northing",500000.0],PARAMETER["central_meridian",-19.0],PARAMETER["standard_parallel_1",64.25],PARAMETER["standard_parallel_2",65.75],PARAMETER["latitude_of_origin",65.0],UNIT["Meter",1.0]]
2 changes: 1 addition & 1 deletion Tutorials/tutorial_data/rek_grid_pop.cpg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ISO-8859-1
ISO-8859-1
2 changes: 1 addition & 1 deletion Tutorials/tutorial_data/rek_grid_pop.prj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
2 changes: 1 addition & 1 deletion Tutorials/tutorial_outputs/placeholder.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
outputs will go here!
outputs will go here!
2 changes: 1 addition & 1 deletion src/GOSTnets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
__version__ = version("GOSTnets")
except PackageNotFoundError:
# package is not installed
pass
pass
32 changes: 16 additions & 16 deletions src/GOSTnets/calculate_od_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def calculateOD_gdf(G, origins, destinations, fail_value=-1, weight="time", calculate_snap=False, wgs84 = {'init':'epsg:4326'}):
''' 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
Expand Down Expand Up @@ -44,8 +44,8 @@ def calculateOD_gdf(G, origins, destinations, fail_value=-1, weight="time", calc
for idx, row in originsUTM.iterrows():
outputMatrix[idx,:] = outputMatrix[idx,:] + row['tTime_sec']
outputMatrix = outputMatrix
return(outputMatrix)
return(outputMatrix)

def calculateOD_csv(G, originCSV, destinationCSV='', oLat="Lat", oLon="Lon", dLat="Lat", dLon="Lon", crs={'init':'epsg:4326'}, fail_value=-1, weight='time', calculate_snap=False):
"""
Calculate OD matrix from csv files of points
Expand Down Expand Up @@ -88,27 +88,27 @@ def calculate_gravity(od, oWeight=[], dWeight=[], decayVals=[0.01,
0.0000962704, # Market access halves every 120 mins
0.0000385082, # Market access halves every 300 mins
0.00001]):


if len(oWeight) != od.shape[0]:
oWeight = [1] * od.shape[0]
if len(dWeight) != od.shape[1]:
dWeight = [1] * od.shape[1]
allRes = []

od_df = pd.DataFrame(od)


for dist_decay in decayVals:
decayFunction = lambda x: np.exp(-1 * dist_decay * x)

summedVals = np.sum(decayFunction(od_df) * dWeight, axis=1) * oWeight

allRes.append(summedVals)

res = pd.DataFrame(allRes).transpose()
res.columns = columns=['d_%s' % d for d in decayVals]

return(res)


Expand All @@ -122,10 +122,10 @@ def calculate_gravity(od, oWeight=[], dWeight=[], decayVals=[0.01,
# 0.0000385082, # Market access halves every 300 mins
# 0.00001]):
# ''' Calculate the gravity weight between origins and destinations.

# Args:
# od (ndarray): matrix of travel time
# oWeight/dWeight (array, optional) - array of weights for calculating weight; reverts to 1 for if not defined
# od (ndarray): matrix of travel time
# oWeight/dWeight (array, optional) - array of weights for calculating weight; reverts to 1 for if not defined
# decayVals (array, optional): decayVals to calculate for gravity. Each value will be returned as a column of results
# Returns:
# geopandas: columns of decayvals
Expand All @@ -148,5 +148,5 @@ def calculate_gravity(od, oWeight=[], dWeight=[], decayVals=[0.01,
# res = pd.DataFrame(allRes).transpose()
# res.columns = columns=['d_%s' % d for d in decayVals]
# return(res)


16 changes: 8 additions & 8 deletions src/GOSTnets/conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

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
RETURNS
None
'''
Expand All @@ -45,7 +45,7 @@ def rasterize_od_results(inD, outFile, field, template = None):
new_dataset.write_band(1, burned)

new_dataset.close()

else:
#create grid from input shapefile
# get xs, ys, and values from origin points
Expand All @@ -64,7 +64,7 @@ def rasterize_od_results(inD, outFile, field, template = None):
xRes = (xx.max() - xx.min()) / len(unique_xs)
yRes = (yy.max() - yy.min()) / len(unique_ys)
# get the right transformation for raster file
trans = rasterio.transform.from_bounds(xx.min() - (xRes/2), yy.min() - (yRes/2),
trans = rasterio.transform.from_bounds(xx.min() - (xRes/2), yy.min() - (yRes/2),
xx.max() - (xRes/2), yy.max() - (yRes/2),
x_pixels - 1, y_pixels - 1)
new_dataset = rasterio.open(
Expand All @@ -74,10 +74,10 @@ def rasterize_od_results(inD, outFile, field, template = None):
crs=inD.crs,
transform=trans
)

shapes = ((row.geometry,row[field]) for idx, row in inD.iterrows())
burned = features.rasterize(shapes=shapes, fill=0, out_shape=grid_array.shape, transform=new_dataset.transform)
burned = burned.astype(grid_array.dtype)
burned = burned.astype(grid_array.dtype)
new_dataset.write_band(1, burned)
new_dataset.close()

new_dataset.close()
Loading

0 comments on commit c37af73

Please sign in to comment.