Skip to content

Commit d05e0eb

Browse files
authored
Merge pull request #1 from PhysicsOfMobility/black
code formatting
2 parents e2a4c38 + 175890d commit d05e0eb

File tree

13 files changed

+1366
-959
lines changed

13 files changed

+1366
-959
lines changed

examples/hh_algorithm.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ def run_city_static(city_params):
1313
place, save = city_params
1414

1515
params["dynamic routes"] = False
16-
run_simulation(place, f'{save}_static', params=params, paths=paths)
16+
run_simulation(place, f"{save}_static", params=params, paths=paths)
1717

1818
params["penalty weighting"] = False
19-
run_simulation(place, f'{save}_static_npw', params=params, paths=paths)
19+
run_simulation(place, f"{save}_static_npw", params=params, paths=paths)
2020

2121

22-
if __name__ == '__main__':
23-
city = 'Hamburg'
24-
base_save = 'hh'
22+
if __name__ == "__main__":
23+
city = "Hamburg"
24+
base_save = "hh"
2525
hom_sets = 10
2626

2727
# If you only want to run the algorithm for the empirical data, use this
2828
# command and remove the lines below.
2929
# run_simulation(city, base_save, params=params, paths=paths)
3030

31-
city_p = [(city, f'{base_save}_hom_{i + 1}') for i in range(hom_sets)]
31+
city_p = [(city, f"{base_save}_hom_{i + 1}") for i in range(hom_sets)]
3232
city_p.insert(0, (city, base_save))
3333

34-
p = Pool(processes=min(cpu_count()-1, len(city_p)))
34+
p = Pool(processes=min(cpu_count() - 1, len(city_p)))
3535
data = p.map(run_city, city_p)
3636
p.close()
3737

3838
# Small comparison with static approach
3939
# run_city_static((city, base_save))
4040

41-
print('Run complete!')
41+
print("Run complete!")

examples/hh_plot.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import warnings
22
from params import params
33
from paths import paths
4-
from BikePathNet.main.plot import plot_city, plot_city_hom_demand,\
5-
plot_dynamic_vs_static
4+
from BikePathNet.main.plot import (
5+
plot_city,
6+
plot_city_hom_demand,
7+
plot_dynamic_vs_static,
8+
)
69

7-
warnings.simplefilter(action='ignore', category=FutureWarning)
10+
warnings.simplefilter(action="ignore", category=FutureWarning)
811

9-
base_save = 'hh'
10-
city = 'Hamburg'
12+
base_save = "hh"
13+
city = "Hamburg"
1114

1215
params["legends"] = False
1316
params["titles"] = False
14-
params["plot_format"] = 'png'
17+
params["plot_format"] = "png"
1518

1619
params["figs_station_usage"] = (2.7, 2.6)
17-
params["stat_usage_norm"] = 1246/365 # norm station usage to year average
20+
params["stat_usage_norm"] = 1246 / 365 # norm station usage to year average
1821

1922
params["figs_bp_comp"] = (2.8, 2.6)
2023

2124
plot_city(city, base_save, paths=paths, params=params)
2225

2326
for i in range(1, 11):
24-
hom_save = f'{base_save}_hom_{i}'
27+
hom_save = f"{base_save}_hom_{i}"
2528
params["stat_usage_norm"] = 1
2629
plot_city(city, hom_save, paths=paths, params=params)
2730

28-
plot_city_hom_demand(city, base_save, paths, params, hom_pattern='hom',
29-
nbr_of_hom_sets=10)
31+
plot_city_hom_demand(
32+
city, base_save, paths, params, hom_pattern="hom", nbr_of_hom_sets=10
33+
)
3034

3135

3236
# Small comparison with static approach

examples/hh_prep.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
from paths import paths
44
from shutil import copyfile
55

6-
city_name = 'Hamburg'
7-
save_name = 'hh'
6+
city_name = "Hamburg"
7+
save_name = "hh"
88
hom_sets = 10
99

10-
input_csv = f'{save_name}.csv'
10+
input_csv = f"{save_name}.csv"
1111

12-
prep_city(city_name, save_name, input_csv, consolidate=False,
13-
cached_graph=True,
14-
cached_graph_folder=f'{paths["input_folder"]}{save_name}/',
15-
cached_graph_name=save_name,
16-
paths=paths, params=params)
12+
prep_city(
13+
city_name,
14+
save_name,
15+
input_csv,
16+
consolidate=False,
17+
cached_graph=True,
18+
cached_graph_folder=f'{paths["input_folder"]}{save_name}/',
19+
cached_graph_name=save_name,
20+
paths=paths,
21+
params=params,
22+
)
1723

1824
# If you want to use the newest version of the street network us the
1925
# following command and remove the one above. Be aware, the existing graph
@@ -22,15 +28,20 @@
2228
consolidate=True, tol=35, paths=paths, params=params)"""
2329

2430
for i in range(hom_sets):
25-
hom_save_name = f'{save_name}_hom_{i+1}'
26-
hom_input_csv = f'{hom_save_name}.csv'
27-
prep_city(city_name, hom_save_name, hom_input_csv,
28-
consolidate=False,
29-
cached_graph=True, # use same graph as emp. demand
30-
cached_graph_folder=f'{paths["input_folder"]}{save_name}/',
31-
cached_graph_name=save_name,
32-
paths=paths, params=params)
33-
31+
hom_save_name = f"{save_name}_hom_{i+1}"
32+
hom_input_csv = f"{hom_save_name}.csv"
33+
prep_city(
34+
city_name,
35+
hom_save_name,
36+
hom_input_csv,
37+
consolidate=False,
38+
cached_graph=True, # use same graph as emp. demand
39+
cached_graph_folder=f'{paths["input_folder"]}{save_name}/',
40+
cached_graph_name=save_name,
41+
paths=paths,
42+
params=params,
43+
)
44+
3445
# Small comparison with static approach
3546
"""static = f'{save_name}_static'
3647
prep_city(city_name, static, input_csv, consolidate=False,

examples/params.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
"""
44

55
params = {}
6-
params["penalties"] = {'primary': 7, 'secondary': 2.4, 'tertiary': 1.4,
7-
'residential': 1.1}
8-
params["street_cost"] = {'primary': 1, 'secondary': 1, 'tertiary': 1,
9-
'residential': 1}
10-
6+
params["penalties"] = {
7+
"primary": 7,
8+
"secondary": 2.4,
9+
"tertiary": 1.4,
10+
"residential": 1.1,
11+
}
12+
params["street_cost"] = {"primary": 1, "secondary": 1, "tertiary": 1, "residential": 1}
13+
1114
params["penalty weighting"] = True # Penalties for load weighting
1215
params["dynamic routes"] = True # Route recalculation after each step
13-
16+
1417
params["cut"] = True # If results should be normalised to first removal
1518
params["bike_paths"] = None # Additional ike Paths for current state
1619
params["correct_area"] = True # Correction of the area size
@@ -20,58 +23,62 @@
2023
params["dpi"] = 300 # dpi of plots
2124
params["titles"] = True # If figure title should be plotted
2225
params["legends"] = True # If legends should be plotted
23-
params["plot_format"] = 'png' # Format of the saved plot
26+
params["plot_format"] = "png" # Format of the saved plot
2427

2528
params["fs_title"] = 12 # Fontsize for title
2629
params["fs_axl"] = 7 # Fontsize for axis labels
2730
params["fs_ticks"] = 6 # Fontsize for axis tick numbers
2831
params["fs_legend"] = 6 # Fontsize for legends
2932

3033
params["figs_ba_cost"] = (2.8, 2.6) # Figsize ba-cost plot
31-
params["c_ba"] = '#0080c0' # Colour for ba in normal plot
34+
params["c_ba"] = "#0080c0" # Colour for ba in normal plot
3235
params["lw_ba"] = 0.75
33-
params["m_ba"] = 'o' # Marker for ba
36+
params["m_ba"] = "o" # Marker for ba
3437
params["ms_ba"] = 2 # Marker size for ba
35-
params["c_cost"] = '#4d4d4d' # Colour for cost in normal plot
38+
params["c_cost"] = "#4d4d4d" # Colour for cost in normal plot
3639
params["lw_cost"] = 0.75
37-
params["m_cost"] = 's'
40+
params["m_cost"] = "s"
3841
params["ms_cost"] = 2 # Marker size for cost
3942

40-
params["c_st"] = {'primary': '#4d4d4d', 'secondary': '#666666',
41-
'tertiary': '#808080', 'residential': '#999999',
42-
'bike paths': '#0080c0'}
43+
params["c_st"] = {
44+
"primary": "#4d4d4d",
45+
"secondary": "#666666",
46+
"tertiary": "#808080",
47+
"residential": "#999999",
48+
"bike paths": "#0080c0",
49+
}
4350
params["figs_comp_st"] = (0.8, 1.6) # Figsize for comp_st_driven plot
4451

4552
params["figs_snetwork"] = (7, 5)
4653
params["ns_snetwork"] = 4
47-
params["nc_snetwork"] = '#333333'
54+
params["nc_snetwork"] = "#333333"
4855
params["ew_snetwork"] = 1
49-
params["ec_snetwork"] = '#b3b3b3'
56+
params["ec_snetwork"] = "#b3b3b3"
5057

5158
params["figs_station_usage"] = (2.7, 2.6)
52-
params["figs_station_usage_hist"] = (2.9, 1) # (2.4, 0.8)
59+
params["figs_station_usage_hist"] = (2.9, 1) # (2.4, 0.8)
5360
params["stat_usage_norm"] = 1
54-
params["cmap_nodes"] = 'cool' # Cmap for nodes usage
61+
params["cmap_nodes"] = "cool" # Cmap for nodes usage
5562
params["ns_station_usage"] = 10
5663
params["edge_lw"] = 0.5
57-
params["ec_station_usage"] = '#b3b3b3'
64+
params["ec_station_usage"] = "#b3b3b3"
5865

5966
params["figs_bp_evo"] = (2.2, 2.2)
6067
params["lw_legend_bp_evo"] = 4
6168

6269
params["figs_bp_comp"] = (2.8, 2.6)
6370
params["ns_bp_comp"] = 5
64-
params["nc_pb_evo"] = '#d726ffff'
65-
params["color_algo"] = '#000075'
66-
params["color_cs"] = '#40e640'
67-
params["color_both"] = '#e6194B'
68-
params["color_unused"] = '#b3b3b3ff'
71+
params["nc_pb_evo"] = "#d726ffff"
72+
params["color_algo"] = "#000075"
73+
params["color_cs"] = "#40e640"
74+
params["color_both"] = "#e6194B"
75+
params["color_unused"] = "#b3b3b3ff"
6976

7077

7178
params["figs_hom_comp"] = (2.6, 2.4)
72-
params["c_ed"] = '#0080c0'
73-
params["c_hom"] = '#f58231'
79+
params["c_ed"] = "#0080c0"
80+
params["c_hom"] = "#f58231"
7481
params["lw_ed"] = 0.9
7582
params["lw_hom"] = 0.9
76-
params["c_hom_ed_area"] = '#999999'
83+
params["c_hom_ed_area"] = "#999999"
7784
params["a_hom_ed_area"] = 0.75

examples/paths.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"""
44

55
paths = {}
6-
paths["csv_folder"] = 'examples/data/csv/'
7-
paths["input_folder"] = 'examples/data/input/'
8-
paths["output_folder"] = 'examples/data/output/'
9-
paths["log_folder"] = 'examples/logs/'
10-
paths["polygon_folder"] = 'examples/data/polygons/'
6+
paths["csv_folder"] = "examples/data/csv/"
7+
paths["input_folder"] = "examples/data/input/"
8+
paths["output_folder"] = "examples/data/output/"
9+
paths["log_folder"] = "examples/logs/"
10+
paths["polygon_folder"] = "examples/data/polygons/"
1111

12-
paths["plot_folder"] = 'examples/plots/'
13-
paths["comp_folder"] = 'examples/data/plot/'
12+
paths["plot_folder"] = "examples/plots/"
13+
paths["comp_folder"] = "examples/data/plot/"

0 commit comments

Comments
 (0)