diff --git a/.gitignore b/.gitignore index 74cf7ab..f4b59e7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ data/ plots/ cache/ +results/ # Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,python,macos,windows # Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,python,macos,windows diff --git a/cities/test_cities.csv b/cities/test_cities.csv new file mode 100644 index 0000000..837a89d --- /dev/null +++ b/cities/test_cities.csv @@ -0,0 +1,2 @@ +name_en;country_en;nominatim_query +Copenhagen;Denmark; \ No newline at end of file diff --git a/scripts/growbikenet/batchexport_allcities.py b/scripts/growbikenet/batchexport_allcities.py new file mode 100644 index 0000000..75d867f --- /dev/null +++ b/scripts/growbikenet/batchexport_allcities.py @@ -0,0 +1,17 @@ +""" +Script for exporting some growbikenet data for multiple cities. +""" + +import pandas as pd +import os +from slugify import slugify + +df = pd.read_csv('./cities/european_capitals.csv', + sep = ';',) + +for nominatimstring, city_name in zip(list(df.nominatim_query), list(df.name_en)): + if type(nominatimstring) is str: + os.system("python ./scripts/growbikenet/batchexport_onecity.py '"+nominatimstring+"' '"+city_name+"'") + else: # No entry is a nan in a df. Here we need to use a shape file. It must be in the folder cities/ + os.system("python ./scripts/growbikenet/batchexport_onecity.py '"+city_name+"' '"+city_name+"'"+" geojson "+"'./cities/"+slugify(city_name)+".shp'") + diff --git a/scripts/growbikenet/exportsomedata_onecity.py b/scripts/growbikenet/batchexport_onecity.py similarity index 80% rename from scripts/growbikenet/exportsomedata_onecity.py rename to scripts/growbikenet/batchexport_onecity.py index 7bbe279..40a1b64 100644 --- a/scripts/growbikenet/exportsomedata_onecity.py +++ b/scripts/growbikenet/batchexport_onecity.py @@ -1,5 +1,5 @@ """ -Example for exporting some growbikenet data for one city. +Script for exporting some growbikenet data for one city. Parameters ---------- @@ -24,13 +24,13 @@ Examples -------- ->>> python exportsomedata_onecity.py Barcelona Barcelona gpkg +>>> python batchexport_onecity.py Barcelona Barcelona gpkg """ # WHICH DATA TO EXPORT? -export_seed_point_type = ["grid", "rail"] -export_ranking = ["betweenness_centrality"] -export_existing_network_spacing = [None] +export_seed_point_type = ["grid", "rail"] # Full array: ["grid", "rail"] +export_ranking = ["betweenness_centrality", "closeness_centrality"] # Full array: ["betweenness_centrality", "closeness_centrality", "random""] +export_existing_network_spacing = [None, 500] # Full array: [None, 500] # Main import growbikenet as gbn @@ -50,17 +50,12 @@ export_file_format = sys.argv[3] if len(sys.argv) >= 5: city_boundary_file = sys.argv[4] - -print("Exporting " + export_file_format + " data for " + city_name) export_data_slug = slugify(export_data_slug) for seed_point_type in export_seed_point_type: for ranking in export_ranking: for existing_network_spacing in export_existing_network_spacing: - if existing_network_spacing: existing_network_spacing_string = ", with existing bike network" - else: existing_network_spacing_string = "" - print("\n" + "Exporting " + seed_point_type + ", " + ranking + existing_network_spacing_string) gbn.growbikenet( city_name=city_name, ranking=ranking, diff --git a/scripts/growbikenet/exportalldata_allcities.py b/scripts/growbikenet/exportalldata_allcities.py deleted file mode 100644 index d6dfa36..0000000 --- a/scripts/growbikenet/exportalldata_allcities.py +++ /dev/null @@ -1,9 +0,0 @@ -import pandas as pd -import os - -df = pd.read_csv('./cities/european_capitals.csv', - sep = ';',) - -for nominatimstring, city_name in zip(list(df.nominatim_query), list(df.name_en)): - if type(nominatimstring) is str: - os.system("python ./scripts/growbikenet/exportalldata_onecity.py '"+nominatimstring+"' "+city_name) diff --git a/scripts/growbikenet/exportalldata_onecity.py b/scripts/growbikenet/exportalldata_onecity.py deleted file mode 100644 index 642540d..0000000 --- a/scripts/growbikenet/exportalldata_onecity.py +++ /dev/null @@ -1,69 +0,0 @@ -""" -Example for exporting all growbikenet data for one city. - -Parameters ----------- -city_name : str - Name of the city that the analysis should be performed on. This is the query string used to fetch the data from nominatim. Overruled (for data fetching) if city_boundary_file is set. -export_data_slug : str, optional, default None - If not set to None, the city_name will be slugified and used as the slug in the filename of the data export -export_file_format : str, optional, default "geojson" - File format for the data export. Default "geojson", also possible "gpkg". If exporting as geojson, generates extra files for seed points and city boundary. If exporting as gkpg, these are added all in one file as extra layers. -city_boundary_file : (str | None), default None - If not set to None, the study area will be selected from the (Multi)Polygon provided in the city_boundary_file shape file, ideally in unprojected latitude-longitude degrees (EPSG:4326), but EPSG:3857 also works. For example, "./tests/test_data/copenhagen.shp". - -Notes -------- -Exports data into four files: -[slug]-betweenness_centrality-grid.gpkg -[slug]-betweenness_centrality-rail.gpkg -[slug]-closeness_centrality-grid.gpkg -[slug]-closeness_centrality-rail.gpkg - Data is saved into the current working directory. - slug is a string id created out of city_name. - -Examples --------- ->>> python exportalldata_onecity.py Barcelona Barcelona gpkg -""" - -import growbikenet as gbn -import sys -from slugify import slugify - -city_name = "Barcelona" -export_data_slug = "Barcelona" -export_file_format = "geojson" -city_boundary_file = None - -if len(sys.argv) >= 2: - city_name = sys.argv[1] -if len(sys.argv) >= 3: - export_data_slug = sys.argv[2] -if len(sys.argv) >= 4: - export_file_format = sys.argv[3] -if len(sys.argv) >= 5: - city_boundary_file = sys.argv[4] - -print("Exporting " + export_file_format + " data for " + city_name) - -export_data_slug = slugify(export_data_slug) - -for seed_point_type in ["grid", "rail"]: - for ranking in ["betweenness_centrality", "closeness_centrality", "random"]: - for existing_network_spacing in [None, 500]: - if existing_network_spacing: existing_network_spacing_string = ", with existing bike network" - else: existing_network_spacing_string = "" - print("\n" + "Exporting " + seed_point_type + ", " + ranking + existing_network_spacing_string) - gbn.growbikenet( - city_name=city_name, - ranking=ranking, - seed_point_type=seed_point_type, - export_data=True, - export_plots=False, - export_video=False, - export_file_format=export_file_format, - existing_network_spacing=existing_network_spacing, - export_data_slug=export_data_slug, - city_boundary_file=city_boundary_file, - ) diff --git a/scripts/growbikenet/exportsomedata_allcities.py b/scripts/growbikenet/exportsomedata_allcities.py deleted file mode 100644 index 296f070..0000000 --- a/scripts/growbikenet/exportsomedata_allcities.py +++ /dev/null @@ -1,9 +0,0 @@ -import pandas as pd -import os - -df = pd.read_csv('./cities/european_capitals.csv', - sep = ';',) - -for nominatimstring, city_name in zip(list(df.nominatim_query), list(df.name_en)): - if type(nominatimstring) is str: - os.system("python ./scripts/growbikenet/exportsomedata_onecity.py '"+nominatimstring+"' "+city_name)