Skip to content

Commit

Permalink
removes pypsa-eur as a submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
ktehranchi committed Apr 22, 2024
1 parent 18e4a69 commit 85cd23f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 58 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@

[submodule "workflow/scripts/subworkflows/pypsa-eur"]
path = workflow/scripts/subworkflows/pypsa-eur
url = [email protected]:PyPSA/pypsa-eur.git
17 changes: 5 additions & 12 deletions docs/source/about-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

## Step 1. Clone GitHub Repository

Users can clone the repository using HTTPS, SSH, or GitHub CLI. Ensure you retrieve the submodules in the repository when cloning, using the `--recurse-submodules` flag. See [GitHub docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) for information on the different cloning methods. If you run into issues, follow GitHub troubleshooting suggestions [here](https://docs.github.com/en/repositories/creating-and-managing-repositories/troubleshooting-cloning-errors#https-cloning-errors).
Users can clone the repository using HTTPS, SSH, or GitHub CLI. See [GitHub docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) for information on the different cloning methods. If you run into issues, follow GitHub troubleshooting suggestions [here](https://docs.github.com/en/repositories/creating-and-managing-repositories/troubleshooting-cloning-errors#https-cloning-errors).

```{note}
If the repository is cloned without the `--recurse-submodules` flag, run the following commands.
### Using HTTPS

$ git submodule init
$ git submodule update
```bash
$ git clone https://github.com/PyPSA/pypsa-usa.git
```

### Using SSH-Key

If it your first time cloning a **repository through ssh**, you will need to set up your git with an ssh-key by following these [directions](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).

```bash
$ git clone --recurse-submodules [email protected]:PyPSA/pypsa-usa.git
```

### Using HTTPS

```bash
$ git clone --recurse-submodules https://github.com/PyPSA/pypsa-usa.git
$ git clone [email protected]:PyPSA/pypsa-usa.git
```

## Step 2. Initialize Configuration files
Expand Down
30 changes: 2 additions & 28 deletions workflow/rules/build_electricity.smk
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,6 @@ if config["enable"].get("build_cutout", False):
"../scripts/build_cutout.py"


rule build_ship_raster:
input:
ship_density=DATA + "shipdensity_global.zip",
cutouts=expand(
"cutouts/" + CDIR + "western_{cutout}.nc",
cutout=[
config["renewable"][carrier]["cutout"]
for carrier in config["electricity"]["renewable_carriers"]
],
),
output:
RESOURCES + "{interconnect}/shipdensity_raster.tif",
log:
LOGS + "{interconnect}/build_ship_raster.log",
resources:
mem_mb=5000,
benchmark:
BENCHMARKS + "{interconnect}/build_ship_raster"
script:
"../subworkflows/pypsa-eur/scripts/build_ship_raster.py"


rule build_hydro_profiles:
params:
hydro=config["renewable"]["hydro"],
Expand Down Expand Up @@ -192,11 +170,7 @@ rule build_renewable_profiles:
else []
)
),
ship_density=lambda w: (
RESOURCES + "{interconnect}/shipdensity_raster.tif"
if "ship_threshold" in config["renewable"][w.technology].keys()
else []
),
ship_density=[],
country_shapes=RESOURCES + "{interconnect}/country_shapes.geojson",
offshore_shapes=RESOURCES + "{interconnect}/offshore_shapes.geojson",
cec_onwind="repo_data/CEC_Wind_BaseScreen_epsg3310.tif",
Expand Down Expand Up @@ -462,4 +436,4 @@ rule prepare_network:
log:
"logs/prepare_network",
script:
"../scripts/subworkflows/pypsa-eur/scripts/prepare_network.py"
"../scripts/prepare_network.py"
2 changes: 1 addition & 1 deletion workflow/rules/postprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rule copy_config:
conda:
"../envs/environment.yaml"
script:
"../scripts/subworkflows/pypsa-eur/scripts/copy_config.py"
"../scripts/copy_config.py"


rule plot_network_maps:
Expand Down
16 changes: 16 additions & 0 deletions workflow/scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
REGION_COLS = ["geometry", "name", "x", "y", "country"]


def set_scenario_config(snakemake):
scenario = snakemake.config["run"].get("scenarios", {})
if scenario.get("enable") and "run" in snakemake.wildcards.keys():
try:
with open(scenario["file"], "r") as f:
scenario_config = yaml.safe_load(f)
except FileNotFoundError:
# fallback for mock_snakemake
script_dir = Path(__file__).parent.resolve()
root_dir = script_dir.parent
with open(root_dir / scenario["file"], "r") as f:
scenario_config = yaml.safe_load(f)
update_config(snakemake.config, scenario_config[snakemake.wildcards.run])



def configure_logging(snakemake, skip_handlers=False):
"""
Configure the basic behaviour for the logging module.
Expand Down
28 changes: 28 additions & 0 deletions workflow/scripts/copy_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Copy used configuration files and important scripts for archiving.
"""


import yaml
from _helpers import set_scenario_config

if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake

snakemake = mock_snakemake("copy_config")

set_scenario_config(snakemake)

with open(snakemake.output[0], "w") as yaml_file:
yaml.dump(
snakemake.config,
yaml_file,
default_flow_style=False,
allow_unicode=True,
sort_keys=False,
)
19 changes: 6 additions & 13 deletions workflow/scripts/prepare_network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -221,7 +222,7 @@ def apply_time_segmentation(n, segments, solver_name="cbc"):
import tsam.timeseriesaggregation as tsam
except ImportError:
raise ModuleNotFoundError(
"Optional dependency 'tsam' not found." "Install via 'pip install tsam'",
"Optional dependency 'tsam' not found." "Install via 'pip install tsam'"
)

p_max_pu_norm = n.generators_t.p_max_pu.max()
Expand Down Expand Up @@ -252,10 +253,7 @@ def apply_time_segmentation(n, segments, solver_name="cbc"):

n.set_snapshots(pd.DatetimeIndex(snapshots, name="name"))
n.snapshot_weightings = pd.Series(
weightings,
index=snapshots,
name="weightings",
dtype="float64",
weightings, index=snapshots, name="weightings", dtype="float64"
)

segmented.index = snapshots
Expand Down Expand Up @@ -306,11 +304,7 @@ def set_line_nom_max(
from _helpers import mock_snakemake

snakemake = mock_snakemake(
"prepare_network",
simpl="",
clusters="37",
ll="v1.0",
opts="Co2L-4H",
"prepare_network", simpl="", clusters="37", ll="v1.0", opts="Co2L-4H"
)
configure_logging(snakemake)
set_scenario_config(snakemake)
Expand Down Expand Up @@ -350,13 +344,12 @@ def set_line_nom_max(
emission_prices = snakemake.params.costs["emission_prices"]
if emission_prices["co2_monthly_prices"]:
logger.info(
"Setting time dependent emission prices according spot market price",
"Setting time dependent emission prices according spot market price"
)
add_dynamic_emission_prices(n)
elif emission_prices["enable"]:
add_emission_prices(
n,
dict(co2=snakemake.params.costs["emission_prices"]["co2"]),
n, dict(co2=snakemake.params.costs["emission_prices"]["co2"])
)

ll_type, factor = snakemake.wildcards.ll[0], snakemake.wildcards.ll[1:]
Expand Down

0 comments on commit 85cd23f

Please sign in to comment.