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

Refactoring changes and Pytest Integration #1083

Draft
wants to merge 69 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
3f9a5b7
_helpers.py os to pathlib
finozzifa Jun 4, 2024
a3b8022
os to pathlib for add_electricity, add_extra_components, augmented_li…
finozzifa Jun 5, 2024
8c11895
re-formatting
finozzifa Jun 5, 2024
04378db
os to pathlib build_shapes.py, build_test_configs.py, clean_osm_data.…
finozzifa Jun 5, 2024
16e6c46
os to pathlib make_summary.py, monte_carlo.py, non_workflow/zip_folde…
finozzifa Jun 5, 2024
56911ff
add unit test setup
finozzifa Jun 5, 2024
75d27a5
reformatting
finozzifa Jun 5, 2024
0c9dd21
change to _helpers.py methods
finozzifa Jun 5, 2024
c64be54
add new unit test for build_directory
finozzifa Jun 5, 2024
924a917
remove .github/workflows/main.yml
finozzifa Jun 5, 2024
d6f7d99
modify unit test build_directory
finozzifa Jun 6, 2024
2fdd90e
comment out test_prepare_network
finozzifa Jun 6, 2024
1498ce4
add ci-unit-test.yaml
finozzifa Jun 6, 2024
b5158f8
modify ci-unit-test.yaml
finozzifa Jun 6, 2024
a3bf6cc
remove match statement from monte_carlo.py
finozzifa Jun 6, 2024
8254876
Merge pull request #1 from open-energy-transition/update_workflows
pz-max Jun 6, 2024
6590496
Merge branch 'main' of https://github.com/open-energy-transition/pyps…
finozzifa Jun 6, 2024
3971b02
add unit tests at the end of current workflows
finozzifa Jun 6, 2024
c059a3a
add os.sep in test_helpers.py
finozzifa Jun 6, 2024
52b4d4c
from scripts
finozzifa Jun 7, 2024
d8430b0
move load_network_for_plots to plot_network
finozzifa Jun 7, 2024
72c09a2
Merge branch 'pypsa-meets-earth:main' into oet_main
finozzifa Jun 7, 2024
547eae0
Merge branch 'main' of https://github.com/open-energy-transition/pyps…
finozzifa Jun 7, 2024
451f569
main to oet_main in workflow files
finozzifa Jun 7, 2024
7a71537
modify Snakefile
finozzifa Jun 7, 2024
b522879
remove .scripts/
finozzifa Jun 7, 2024
e2abe30
remove some abstractions
finozzifa Jun 7, 2024
480fd1e
Merge pull request #2 from open-energy-transition/os_to_pathlib
finozzifa Jun 7, 2024
84c599c
Merge branch 'pypsa-meets-earth:main' into oet_main
finozzifa Jun 15, 2024
825efe2
merge from upstream main
finozzifa Jul 1, 2024
de1ad66
Unify gadm download and layer (#3)
finozzifa Jul 5, 2024
3136f62
Merge branch 'main' of https://github.com/open-energy-transition/pyps…
finozzifa Jul 11, 2024
6a79e1a
Merge branch 'oet_main' of https://github.com/open-energy-transition/…
finozzifa Jul 11, 2024
d4697ac
modify workflow files
finozzifa Jul 11, 2024
c9938de
Merge pull request #4 from open-energy-transition/oet_main
finozzifa Jul 11, 2024
da684c5
Merge remote-tracking branch 'upstream/main'
finozzifa Jul 12, 2024
544503b
Merge remote-tracking branch 'upstream/main'
finozzifa Jul 19, 2024
448fae6
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Jul 31, 2024
feb3b63
Unit test base network (#5)
finozzifa Aug 1, 2024
2d7ef6d
normed in _helpers.py with dedicated unit test
finozzifa Aug 1, 2024
9c4268d
initial addition of unit tests for build_demand_profile.py
finozzifa Aug 1, 2024
6ca2cba
add test_build_demand_profiles.py
finozzifa Aug 3, 2024
067110d
add documentation
finozzifa Aug 3, 2024
1deda27
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Aug 7, 2024
f17fd8b
Merge branch 'main' of https://github.com/open-energy-transition/pyps…
finozzifa Aug 7, 2024
1473be6
add unit tests for add_extra_components
finozzifa Aug 8, 2024
2852bc6
add unit tests for add_extra_components - 2
finozzifa Aug 8, 2024
372a53d
Merge pull request #7 from open-energy-transition/unit_test_add_extra…
FabianHofmann Aug 9, 2024
928d435
Merge pull request #6 from open-energy-transition/unit_test_build_dem…
FabianHofmann Aug 9, 2024
4e51132
configs from yaml file (#9)
finozzifa Aug 28, 2024
3298a6a
apply index=False (#11)
finozzifa Sep 4, 2024
3b6ab96
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 9, 2024
ba82543
Unit test build shapes (#12)
finozzifa Sep 11, 2024
2b91e91
Unit test ad add_power_plants in build_powerplants.py (#10)
finozzifa Sep 11, 2024
c78cf82
Unit test prepare network (#8)
finozzifa Sep 11, 2024
5468643
code:merge from upstream
finozzifa Sep 17, 2024
43b5940
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 19, 2024
8bd4b86
config: restricting fiona version to <=1.9.6 (#13)
finozzifa Sep 19, 2024
4b44f8a
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 19, 2024
73ca8d2
Merge the merge (#14)
finozzifa Sep 24, 2024
dbb3c31
code: merge from upstream
finozzifa Sep 24, 2024
2178212
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 27, 2024
250efe8
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 27, 2024
ff8e4e9
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 28, 2024
c185c0b
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Sep 30, 2024
5c6ef0e
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Oct 4, 2024
82de61f
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Oct 7, 2024
1d44b6f
Merge branch 'main' of https://github.com/pypsa-meets-earth/pypsa-earth
finozzifa Oct 16, 2024
c2b2551
code: merge from upstream main
finozzifa Oct 22, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3


- name: Setup micromamba
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
run: micromamba list

- name: Run Test
run: make test
run: make checks

# - name: Test plotting and summaries
# run: |
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
on:
push:
branches:
- main

# push:
# branches:
# - main
#
jobs:
contrib-readme-job:
runs-on: ubuntu-latest
name: A job to automate contrib in readme
steps:
- name: Contribute List
uses: akhilmhdh/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# contrib-readme-job:
# runs-on: ubuntu-latest
# name: A job to automate contrib in readme
# steps:
# - name: Contribute List
# uses: akhilmhdh/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

.PHONY: test setup clean
.PHONY: checks tests setup clean

test:
tests:
set -e
snakemake solve_all_networks -call --configfile config.tutorial.yaml # this runs the tutorial config
snakemake solve_all_networks -call --configfile config.tutorial.yaml test/config.custom.yaml # add custom config to tutorial config
Expand All @@ -14,6 +14,9 @@ test:
snakemake -c4 solve_sector_networks --configfile config.tutorial.yaml test/config.test1.yaml
echo "All tests completed successfully."

checks: tests
pytest test

setup:
# Add setup commands here
echo "Setup complete."
Expand Down
7 changes: 6 additions & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ SPDX-FileCopyrightText = "The PyPSA-Earth and PyPSA-Eur Authors"
SPDX-License-Identifier = "CC-BY-4.0"

[[annotations]]
path = "data/**"
path = "test/test_data/**"
precedence = "aggregate"
SPDX-FileCopyrightText = "The PyPSA-Earth and PyPSA-Eur Authors"
SPDX-License-Identifier = "CC-BY-4.0"

[[annotations]]
path = "data/**"
precedence = "aggregate"
SPDX-FileCopyrightText = "The PyPSA-Earth and PyPSA-Eur Authors"
SPDX-License-Identifier = "CC-BY-4.0"

[[annotations]]
path = ".github/**"
Expand Down
31 changes: 21 additions & 10 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

import sys
import pathlib

sys.path.append("./scripts")

from os.path import normpath, exists, isdir
from os.path import normpath
from shutil import copyfile, move

from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider
Expand All @@ -19,7 +20,6 @@ from _helpers import (
)
from build_demand_profiles import get_load_paths_gegis
from retrieve_databundle_light import datafiles_retrivedatabundle
from pathlib import Path


HTTP = HTTPRemoteProvider()
Expand Down Expand Up @@ -295,7 +295,7 @@ rule build_bus_regions:
base_network="networks/" + RDIR + "base.nc",
#gadm_shapes="resources/" + RDIR + "shapes/MAR2.geojson",
#using this line instead of the following will test updated gadm shapes for MA.
#To use: downlaod file from the google drive and place it in resources/" + RDIR + "shapes/
#To use: download file from the google drive and place it in resources/" + RDIR + "shapes/
#Link: https://drive.google.com/drive/u/1/folders/1dkW1wKBWvSY4i-XEuQFFBj242p0VdUlM
gadm_shapes="resources/" + RDIR + "shapes/gadm_shapes.geojson",
output:
Expand Down Expand Up @@ -323,7 +323,7 @@ def terminate_if_cutout_exists(config=config):

for ct in set(config_cutouts):
cutout_fl = "cutouts/" + CDIR + ct + ".nc"
if os.path.exists(cutout_fl):
if pathlib.Path(cutout_fl).exists():
raise Exception(
"An option `build_cutout` is enabled, while a cutout file '"
+ cutout_fl
Expand Down Expand Up @@ -491,15 +491,12 @@ rule build_powerplants:
gadm_layer_id=config["build_shape_options"]["gadm_layer_id"],
alternative_clustering=config["cluster_options"]["alternative_clustering"],
powerplants_filter=config["electricity"]["powerplants_filter"],
custom_powerplants=config["electricity"]["custom_powerplants"],
input:
base_network="networks/" + RDIR + "base.nc",
pm_config="configs/powerplantmatching_config.yaml",
custom_powerplants="data/custom_powerplants.csv",
custom_powerplants_file="data/custom_powerplants.csv",
osm_powerplants="resources/" + RDIR + "osm/clean/all_clean_generators.csv",
#gadm_shapes="resources/" + RDIR + "shapes/MAR2.geojson",
#using this line instead of the following will test updated gadm shapes for MA.
#To use: downlaod file from the google drive and place it in resources/" + RDIR + "shapes/
#Link: https://drive.google.com/drive/u/1/folders/1dkW1wKBWvSY4i-XEuQFFBj242p0VdUlM
gadm_shapes="resources/" + RDIR + "shapes/gadm_shapes.geojson",
output:
powerplants="resources/" + RDIR + "powerplants.csv",
Expand Down Expand Up @@ -1042,6 +1039,8 @@ if not config["custom_data"]["gas_network"]:
year=config["build_shape_options"]["year"],
nprocesses=config["build_shape_options"]["nprocesses"],
contended_flag=config["build_shape_options"]["contended_flag"],
gadm_file_prefix=config["build_shape_options"]["gadm_file_prefix"],
gadm_url_prefix=config["build_shape_options"]["gadm_url_prefix"],
geo_crs=config["crs"]["geo_crs"],
custom_gas_network=config["custom_data"]["gas_network"],
input:
Expand All @@ -1060,6 +1059,10 @@ if not config["custom_data"]["gas_network"]:
rule prepare_sector_network:
params:
costs=config["costs"],
contended_flag=config["build_shape_options"]["contended_flag"],
gadm_file_prefix=config["build_shape_options"]["gadm_file_prefix"],
gadm_url_prefix=config["build_shape_options"]["gadm_url_prefix"],
geo_crs=config["crs"]["geo_crs"],
input:
network=RESDIR
+ "prenetworks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_{sopts}_{planning_horizons}_{discountrate}_{demand}_presec.nc",
Expand Down Expand Up @@ -1124,6 +1127,10 @@ rule add_export:
export_profile=config["export"]["export_profile"],
snapshots=config["snapshots"],
costs=config["costs"],
contended_flag=config["build_shape_options"]["contended_flag"],
gadm_file_prefix=config["build_shape_options"]["gadm_file_prefix"],
gadm_url_prefix=config["build_shape_options"]["gadm_url_prefix"],
geo_crs=config["crs"]["geo_crs"],
input:
overrides="data/override_component_attrs",
export_ports="data/export_ports.csv",
Expand Down Expand Up @@ -1646,6 +1653,10 @@ rule build_industrial_distribution_key: #default data
gadm_level=config["sector"]["gadm_level"],
alternative_clustering=config["cluster_options"]["alternative_clustering"],
industry_database=config["custom_data"]["industry_database"],
contended_flag=config["build_shape_options"]["contended_flag"],
gadm_file_prefix=config["build_shape_options"]["gadm_file_prefix"],
gadm_url_prefix=config["build_shape_options"]["gadm_url_prefix"],
geo_crs=config["crs"]["geo_crs"],
input:
regions_onshore="resources/"
+ RDIR
Expand Down Expand Up @@ -1943,6 +1954,6 @@ rule run_all_scenarios:
"results/{scenario_name}/scenario.done",
scenario_name=[
c.stem.replace("config.", "")
for c in Path("configs/scenarios").glob("config.*.yaml")
for c in pathlib.Path("configs/scenarios").glob("config.*.yaml")
],
),
2 changes: 2 additions & 0 deletions config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ build_shape_options:
# false (not "false") no pop addition to shape which is useful when generating only cutout
gdp_method: "standard" # "standard" pulls from web 1x1km raster, false (not "false") no gdp addition to shape which useful when generating only cutout
contended_flag: "set_by_country" # "set_by_country" assigns the contended areas to the countries according to the GADM database, "drop" drops these contended areas from the model
gadm_file_prefix: "gadm41_"
gadm_url_prefix: "https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg/"

clean_osm_data_options: # osm = OpenStreetMap
names_by_shapes: true # Set the country name based on the extended country shapes
Expand Down
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# documentation root, use pathlib.Path.absolute to make it absolute, like shown here.
#
import datetime
import os
import pathlib
import shutil
import sys

from git import Repo

sys.path.insert(0, os.path.abspath("../scripts"))
sys.path.insert(0, str(pathlib.Path("../scripts").absolute()))
for p in sys.path:
print(p)

Expand Down
Loading
Loading