Skip to content

Commit

Permalink
fix: make previous OSM versions compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHofmann committed Jan 15, 2025
1 parent f13b905 commit d2fd82a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
1 change: 0 additions & 1 deletion matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
#
# SPDX-License-Identifier: CC0-1.0
font.family: sans-serif
font.sans-serif: Ubuntu, DejaVu Sans
image.cmap: viridis
figure.autolayout : True
48 changes: 18 additions & 30 deletions rules/retrieve.smk
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if config["enable"]["retrieve"]:
zip_ref.extract(filename, Path(output.shapes_level_3).parent)
extracted_file = Path(output.shapes_level_3).parent / filename
extracted_file.rename(
getattr(output, f"shapes_level_{level[-1]}")
getattr(output, f"shapes_level_{level[- 1]}")
)
os.remove(params.zip_file)

Expand Down Expand Up @@ -473,7 +473,7 @@ if config["enable"]["retrieve"]:
layer_path = (
f"/vsizip/{params.folder}/WDPA_{bYYYY}_Public_shp_{i}.zip"
)
print(f"Adding layer {i+1} of 3 to combined output file.")
print(f"Adding layer {i + 1} of 3 to combined output file.")
shell("ogr2ogr -f gpkg -update -append {output.gpkg} {layer_path}")

rule download_wdpa_marine:
Expand All @@ -496,7 +496,7 @@ if config["enable"]["retrieve"]:
for i in range(3):
# vsizip is special driver for directly working with zipped shapefiles in ogr2ogr
layer_path = f"/vsizip/{params.folder}/WDPA_WDOECM_{bYYYY}_Public_marine_shp_{i}.zip"
print(f"Adding layer {i+1} of 3 to combined output file.")
print(f"Adding layer {i + 1} of 3 to combined output file.")
shell("ogr2ogr -f gpkg -update -append {output.gpkg} {layer_path}")


Expand Down Expand Up @@ -539,8 +539,11 @@ if config["enable"]["retrieve"]:
if config["enable"]["retrieve"] and (
config["electricity"]["base_network"] == "osm-prebuilt"
):
# Dictionary of prebuilt versions, e.g. 0.3 : "13358976"
osm_prebuilt_version = {
OSM_VERSION = config["electricity"]["osm-prebuilt-version"]
OSM_COMPONENTS = ["buses", "converters", "lines", "links", "transformers"]
if OSM_VERSION >= 0.6:
OSM_COMPONENTS.append("map")
OSM_ZENODO_IDS = {
0.1: "12799202",
0.2: "13342577",
0.3: "13358976",
Expand All @@ -552,37 +555,22 @@ if config["enable"]["retrieve"] and (
# update rule to use the correct version
rule retrieve_osm_prebuilt:
input:
buses=storage(
f"https://zenodo.org/records/{osm_prebuilt_version[config['electricity']['osm-prebuilt-version']]}/files/buses.csv"
),
converters=storage(
f"https://zenodo.org/records/{osm_prebuilt_version[config['electricity']['osm-prebuilt-version']]}/files/converters.csv"
),
lines=storage(
f"https://zenodo.org/records/{osm_prebuilt_version[config['electricity']['osm-prebuilt-version']]}/files/lines.csv"
),
links=storage(
f"https://zenodo.org/records/{osm_prebuilt_version[config['electricity']['osm-prebuilt-version']]}/files/links.csv"
),
transformers=storage(
f"https://zenodo.org/records/{osm_prebuilt_version[config['electricity']['osm-prebuilt-version']]}/files/transformers.csv"
),
map=storage(
f"https://zenodo.org/records/{osm_prebuilt_version[config['electricity']['osm-prebuilt-version']]}/files/map.html"
),
[
storage(
f"https://zenodo.org/records/{OSM_ZENODO_IDS[OSM_VERSION]}/files/{component}.csv"
)
for component in OSM_COMPONENTS
],
output:
buses=f"data/osm-prebuilt/{config['electricity']['osm-prebuilt-version']}/buses.csv",
converters=f"data/osm-prebuilt/{config['electricity']['osm-prebuilt-version']}/converters.csv",
lines=f"data/osm-prebuilt/{config['electricity']['osm-prebuilt-version']}/lines.csv",
links=f"data/osm-prebuilt/{config['electricity']['osm-prebuilt-version']}/links.csv",
transformers=f"data/osm-prebuilt/{config['electricity']['osm-prebuilt-version']}/transformers.csv",
map=f"data/osm-prebuilt/{config['electricity']['osm-prebuilt-version']}/map.html",
[
f"data/osm-prebuilt/{OSM_VERSION}/{component}.csv"
for component in OSM_COMPONENTS
],
log:
"logs/retrieve_osm_prebuilt.log",
threads: 1
resources:
mem_mb=500,
retries: 2
run:
for key in input.keys():
move(input[key], output[key])
Expand Down

0 comments on commit d2fd82a

Please sign in to comment.