Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify copy commit processing rule #237

Merged
merged 13 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from os.path import exists
from shutil import copyfile, move
from scripts.helpers import get_last_commit_message

from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider

Expand All @@ -19,6 +20,9 @@ SDIR = config["summary_dir"] + config["run"]
RDIR = config["results_dir"] + config["run"]
CDIR = config["costs_dir"]

config.update({"git_commit": get_last_commit_message(".")})
config.update({"submodule_commit": get_last_commit_message(PYPSAEARTH_FOLDER)})

CUTOUTS_PATH = (
"cutouts/cutout-2013-era5-tutorial.nc"
if config["tutorial"]
Expand Down Expand Up @@ -414,15 +418,6 @@ rule copy_config:
"scripts/copy_config.py"


rule copy_commit:
output:
SDIR + "/commit_info.txt",
shell:
"""
git log -n 1 --pretty=format:"Commit: %H%nAuthor: %an <%ae>%nDate: %ad%nMessage: %s" > {output}
"""


rule solve_network:
input:
overrides="data/override_component_attrs",
Expand All @@ -432,7 +427,6 @@ rule solve_network:
+ "/prenetworks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_{sopts}_{planning_horizons}_{discountrate}_{demand}_{h2export}export.nc",
costs=CDIR + "costs_{planning_horizons}.csv",
configs=SDIR + "/configs/config.yaml", # included to trigger copy_config rule
commit=SDIR + "/commit_info.txt",
output:
RDIR
+ "/postnetworks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_{sopts}_{planning_horizons}_{discountrate}_{demand}_{h2export}export.nc",
Expand Down
2 changes: 1 addition & 1 deletion pypsa-earth
Submodule pypsa-earth updated 43 files
+1 −0 .gitignore
+7 −7 .pre-commit-config.yaml
+0 −1 .readthedocs.yaml
+58 −36 README.md
+157 −5 Snakefile
+9 −1 config.default.yaml
+9 −1 config.tutorial.yaml
+31 −0 configs/bundle_config.yaml
+378 −0 configs/osm_config.yaml
+1 −1 doc/conf.py
+1 −0 doc/configtables/clean_osm_data_options.csv
+2 −0 doc/configtables/electricity.csv
+2 −2 doc/configtables/opts.csv
+1 −1 doc/how_to_docs.rst
+28 −0 doc/release_notes.rst
+9 −0 doc/wildcards.rst
+138 −131 envs/environment.fixed.yaml
+127 −9 scripts/_helpers.py
+42 −34 scripts/add_electricity.py
+2 −2 scripts/add_extra_components.py
+8 −8 scripts/augmented_line_connections.py
+87 −48 scripts/base_network.py
+7 −7 scripts/build_bus_regions.py
+5 −4 scripts/build_cutout.py
+6 −6 scripts/build_demand_profiles.py
+4 −3 scripts/build_natura_raster.py
+31 −16 scripts/build_osm_network.py
+7 −6 scripts/build_powerplants.py
+12 −11 scripts/build_renewable_profiles.py
+28 −16 scripts/build_shapes.py
+61 −12 scripts/clean_osm_data.py
+47 −32 scripts/cluster_network.py
+0 −672 scripts/config_osm_data.py
+6 −5 scripts/download_osm_data.py
+39 −22 scripts/make_statistics.py
+10 −8 scripts/make_summary.py
+5 −5 scripts/monte_carlo.py
+7 −3 scripts/plot_network.py
+2 −2 scripts/plot_summary.py
+98 −14 scripts/prepare_network.py
+25 −19 scripts/retrieve_databundle_light.py
+133 −46 scripts/simplify_network.py
+25 −11 scripts/solve_network.py
28 changes: 28 additions & 0 deletions scripts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import shutil
import subprocess
import zipfile
from pathlib import Path

Expand Down Expand Up @@ -693,3 +694,30 @@ def aggregate_fuels(sector):
heat = ["Heat", "Direct use of geothermal heat", "Direct use of solar thermal heat"]

return gas_fuels, oil_fuels, biomass_fuels, coal_fuels, heat, electricity


def get_last_commit_message(path):
"""
Function to get the last PyPSA-Earth Git commit message
Returns
-------
result : string
"""
_logger = logging.getLogger(__name__)
last_commit_message = None
backup_cwd = os.getcwd()
try:
os.chdir(path)
last_commit_message = (
subprocess.check_output(
["git", "log", "-n", "1", "--pretty=format:%H %s"],
stderr=subprocess.STDOUT,
)
.decode()
.strip()
)
except subprocess.CalledProcessError as e:
_logger.warning(f"Error executing Git: {e}")

os.chdir(backup_cwd)
return last_commit_message
5 changes: 3 additions & 2 deletions scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,11 @@ def add_existing(n):
snakemake = mock_snakemake(
"solve_network",
simpl="",
clusters="12",
clusters="4",
ll="c1.0",
opts="Co2L",
planning_horizons="2030",
sopts="24H",
sopts="144H",
discountrate=0.071,
demand="DF",
h2export="120",
Expand Down Expand Up @@ -539,6 +539,7 @@ def add_existing(n):
solver_logfile=snakemake.log.solver,
)

n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
n.export_to_netcdf(snakemake.output[0])

logger.info("Maximum memory usage: {}".format(mem.mem_usage))
Loading