Skip to content

Commit

Permalink
Fix download_osm_data for countries with missing entities (#988)
Browse files Browse the repository at this point in the history
* Fix missing data for download_osm_data

* Revise naming
  • Loading branch information
davide-f authored Mar 11, 2024
1 parent a48eeb1 commit d27fb08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
5 changes: 1 addition & 4 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ E.g. if a new rule becomes available describe how to use it `snakemake -j1 run_t

* Minor bug-fixing for GADM_ID format naming. `PR #980 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/980>`__ and `PR #986 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/986>`__


* Keep data on the original voltage value when rebasing voltages to the standard values and adjust the transmission capacity accordingly. `PR #898 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/978>`__

* Minor bug-fixing for GADM_ID format naming. `PR #980 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/980>`__

* Fix download_osm_data compatibility for earth-osm v2.1. `PR #954 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/954>`__
* Fix download_osm_data compatibility for earth-osm v2.1. `PR #954 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/954>`__ and `PR #988 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/988>`__

PyPSA-Earth 0.3.0
=================
Expand Down
24 changes: 12 additions & 12 deletions scripts/download_osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,22 @@ def convert_iso_to_geofk(

out_path = Path.joinpath(store_path_resources, "out")
names = ["generator", "cable", "line", "substation"]
format = ["csv", "geojson"]
out_formats = ["csv", "geojson"]
new_files = os.listdir(out_path) # list downloaded osm files

# earth-osm (eo) only outputs files with content
# If the file is empty, it is not created
# This is a workaround to create empty files for the workflow

# Rename and move osm files to the resources folder output
for file in new_files:
for name in names:
for f in format:
ext = f"{name}.{f}"
if ext in file:
new_file_name = Path.joinpath(
store_path_resources, f"all_raw_{name}s.{f}"
)
old_file_name = Path.joinpath(out_path, file)
logger.info(f"Move {old_file_name} to {new_file_name}")
shutil.move(old_file_name, new_file_name)
for name in names:
for f in out_formats:
new_file_name = Path.joinpath(store_path_resources, f"all_raw_{name}s.{f}")
old_files = list(Path(out_path).glob(f"*{name}.{f}"))
# if file is missing, create empty file, otherwise rename it an move it
if not old_files:
with open(new_file_name, "w") as f:
pass
else:
logger.info(f"Move {old_files[0]} to {new_file_name}")
shutil.move(old_files[0], new_file_name)

0 comments on commit d27fb08

Please sign in to comment.