Skip to content

Commit

Permalink
Merge pull request #954 from GbotemiB/earth-osm-fix
Browse files Browse the repository at this point in the history
Fix for earth-osm V0.2.0
  • Loading branch information
davide-f authored Mar 8, 2024
2 parents 071c34e + bf0ed64 commit a48eeb1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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>`__

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

PyPSA-Earth 0.3.0
=================

Expand Down
2 changes: 1 addition & 1 deletion envs/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
# - atlite>=0.2.4 # until https://github.com/PyPSA/atlite/issues/244 is not merged
- dask
- powerplantmatching>=0.5.7
- earth-osm>=0.1.0, <0.2.0
- earth-osm>=2.1
- atlite

# Dependencies of the workflow itself
Expand Down
3 changes: 3 additions & 0 deletions scripts/clean_osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def prepare_substation_df(df_all_substations):
}
)

# Convert polygons to points
df_all_substations["geometry"] = df_all_substations["geometry"].centroid

# Add longitude (lon) and latitude (lat) coordinates in the dataset
df_all_substations["lon"] = df_all_substations["geometry"].x
df_all_substations["lat"] = df_all_substations["geometry"].y
Expand Down
36 changes: 18 additions & 18 deletions scripts/download_osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,36 @@ def convert_iso_to_geofk(
store_path_data = Path.joinpath(Path().cwd(), "data", "osm")
country_list = country_list_to_geofk(snakemake.params.countries)

eo.get_osm_data(
eo.save_osm_data(
primary_name="power",
region_list=country_list,
feature_list=["substation", "line", "cable", "generator"],
update=False,
mp=True,
data_dir=store_path_data,
out_dir=store_path_resources,
out_format=["csv", "geojson"],
out_aggregate=True,
)

out_path = Path.joinpath(store_path_data, "out")
names = ["generators", "cables", "lines", "substations"]
out_path = Path.joinpath(store_path_resources, "out")
names = ["generator", "cable", "line", "substation"]
format = ["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
for name in names:
for f in format:
filename = Path.joinpath(out_path, f"all_{name}.{f}")
# Create file if not exist
if not Path.exists(filename):
logger.info(f"{filename} does not exist, create empty file")
open(filename, "w").close()
# Move and rename
old_path = Path.joinpath(out_path, f"all_{name}.{f}")
new_path = Path.joinpath(store_path_resources, f"all_raw_{name}.{f}")
# Create directory if not exist (required for shutil)
if not os.path.exists(store_path_resources):
os.makedirs(store_path_resources)
logger.info(f"Create {old_path} and move to {new_path}")
shutil.move(old_path, new_path)

# 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)

0 comments on commit a48eeb1

Please sign in to comment.