Skip to content

Commit

Permalink
Fix pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-f committed Jun 30, 2023
1 parent 6340398 commit cc6e346
Show file tree
Hide file tree
Showing 30 changed files with 270 additions and 201 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ notebooks/old_notebooks/*.tif
doc/_build

# VS code related
.vscode
doc/.vscode/settings.json
.vscode/settings.json
*.vscode
doc/*.vscode/settings.json
*.vscode/settings.json
*.code-workspace

# Additional debugging folders
Expand Down
14 changes: 13 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Copied from https://github.com/PyPSA/pypsa-eur/pull/302/files

exclude: ^(LICENSES|README.md)
exclude: ^(LICENSES)


repos:
Expand Down Expand Up @@ -35,6 +35,18 @@ repos:
types_or: [python, rst, markdown]
files: ^(scripts|doc)/

# Make docstrings PEP 257 compliant
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.3
hooks:
- id: docformatter
args: ["--in-place", "--make-summary-multi-line", "--pre-summary-newline"]

- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc

# Formatting with "black" coding style
- repo: https://github.com/psf/black
rev: 23.3.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later

# PyPSA-Earth

<p align="left">
<p align="left">
by
<a href="https://pypsa-meets-earth.github.io">
<img src="https://github.com/pypsa-meets-earth/pypsa-meets-earth.github.io/raw/main/assets/img/logo.png" width="150">
Expand Down
4 changes: 2 additions & 2 deletions config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ monte_carlo:
# Key: add below the pypsa object for the monte_carlo sampling, "network" is only allowed for filtering!
# Value: currently supported format [l_bound, u_bound] or empty [], represent multiplication factors for the object
loads_t.p_set: [0.9, 1.1]
generators_t.p_max_pu.loc[:, n.generators.carrier == "wind"]: [0.9, 1.1]
generators_t.p_max_pu.loc[:, n.generators.carrier == "solar"]: [0.9, 1.1]
# generators_t.p_max_pu.loc[:, n.generators.carrier == "wind"]: [0.9, 1.1]
# generators_t.p_max_pu.loc[:, n.generators.carrier == "solar"]: [0.9, 1.1]


solving:
Expand Down
6 changes: 3 additions & 3 deletions config.tutorial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ costs:

monte_carlo:
options:
add_to_snakefile: false
add_to_snakefile: true
samples: 7 # number of optimizations
sampling_strategy: "chaospy" # "pydoe2", "chaospy", "scipy", packages that are supported
pypsa_standard:
Expand All @@ -337,8 +337,8 @@ monte_carlo:
# Key: add below the pypsa object for the monte_carlo sampling, "network" is only allowed for filtering!
# Value: currently supported format [l_bound, u_bound] or empty [], represent multiplication factors for the object
loads_t.p_set: [0.9, 1.1]
generators_t.p_max_pu.loc[:, n.generators.carrier == "wind"]: [0.9, 1.1]
generators_t.p_max_pu.loc[:, n.generators.carrier == "solar"]: [0.9, 1.1]
# generators_t.p_max_pu.loc[:, n.generators.carrier == "wind"]: [0.9, 1.1]
# generators_t.p_max_pu.loc[:, n.generators.carrier == "solar"]: [0.9, 1.1]


solving:
Expand Down
1 change: 1 addition & 0 deletions doc/short_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The solved networks can be analysed just like any other PyPSA network (e.g. in J
.. code:: python
import pypsa
network = pypsa.Network("results/networks/elec_s_6_ec_lcopt_Co2L-4H.nc")
The video below shows how to analyse solved PyPSA-Eur networks in Jupyter Notebooks.
Expand Down
1 change: 1 addition & 0 deletions doc/wildcards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ formats depends on the used backend. To query the supported file types on your s
.. code:: python
import matplotlib.pyplot as plt
plt.gcf().canvas.get_supported_filetypes()
29 changes: 16 additions & 13 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def sets_path_to_root(root_directory_name):
Name of the root directory.
n : int
Number of folders the function will check upwards/root directed.
"""
import os

Expand Down Expand Up @@ -294,7 +293,8 @@ def aggregate_costs(n, flatten=False, opts=None, existing_only=False):

def progress_retrieve(url, file, data=None, disable_progress=False, roundto=1.0):
"""
Function to download data from a url with a progress bar progress in retrieving data
Function to download data from a url with a progress bar progress in
retrieving data.
Parameters
----------
Expand Down Expand Up @@ -328,9 +328,10 @@ def dlProgress(count, blockSize, totalSize, roundto=roundto):

def get_aggregation_strategies(aggregation_strategies):
"""
default aggregation strategies that cannot be defined in .yaml format must be specified within
the function, otherwise (when defaults are passed in the function's definition) they get lost
when custom values are specified in the config.
Default aggregation strategies that cannot be defined in .yaml format must
be specified within the function, otherwise (when defaults are passed in
the function's definition) they get lost when custom values are specified
in the config.
"""
import numpy as np

Expand Down Expand Up @@ -429,7 +430,7 @@ def make_accessable(*ios):

def getContinent(code):
"""
Returns continent names that contains list of iso-code countries
Returns continent names that contains list of iso-code countries.
Parameters
----------
Expand Down Expand Up @@ -549,7 +550,7 @@ def two_digits_2_name_country(two_code_country, nocomma=False, remove_start_word

def country_name_2_two_digits(country_name):
"""
Convert full country name to 2-digit country code
Convert full country name to 2-digit country code.
Parameters
----------
Expand Down Expand Up @@ -614,9 +615,9 @@ def save_to_geojson(df, fn):

def read_geojson(fn, cols=[], dtype=None, crs="EPSG:4326"):
"""
Function to read a geojson file fn.
When the file is empty, then an empty GeoDataFrame is returned having columns cols,
the specified crs and the columns specified by the dtype dictionary it not none
Function to read a geojson file fn. When the file is empty, then an empty
GeoDataFrame is returned having columns cols, the specified crs and the
columns specified by the dtype dictionary it not none.
Parameters:
----------
Expand All @@ -643,7 +644,7 @@ def read_geojson(fn, cols=[], dtype=None, crs="EPSG:4326"):

def create_country_list(input, iso_coding=True):
"""
Create a country list for defined regions in config_osm_data.py
Create a country list for defined regions in config_osm_data.py.
Parameters
----------
Expand Down Expand Up @@ -672,8 +673,10 @@ def create_country_list(input, iso_coding=True):
def filter_codes(c_list, iso_coding=True):
"""
Filter list according to the specified coding.
When iso code are implemented (iso_coding=True), then remove the geofabrik-specific ones.
When geofabrik codes are selected(iso_coding=False), ignore iso-specific names.
When iso code are implemented (iso_coding=True), then remove the
geofabrik-specific ones. When geofabrik codes are
selected(iso_coding=False), ignore iso-specific names.
"""
if (
iso_coding
Expand Down
13 changes: 8 additions & 5 deletions scripts/add_electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

# -*- coding: utf-8 -*-
"""
Adds electrical generators, load and existing hydro storage units to a base network.
Adds electrical generators, load and existing hydro storage units to a base
network.
Relevant Settings
-----------------
Expand Down Expand Up @@ -109,7 +110,7 @@ def normed(s):
def calculate_annuity(n, r):
"""
Calculate the annuity factor for an asset with lifetime n years and
discount rate of r, e.g. annuity(20, 0.05) * 20 = 1.6
discount rate of r, e.g. annuity(20, 0.05) * 20 = 1.6.
"""
if isinstance(r, pd.Series):
return pd.Series(1 / n, index=r.index).where(
Expand Down Expand Up @@ -137,7 +138,7 @@ def _add_missing_carriers_from_costs(n, costs, carriers):

def load_costs(tech_costs, config, elec_config, Nyears=1):
"""
set all asset costs and other parameters
Set all asset costs and other parameters.
"""
costs = pd.read_csv(tech_costs, index_col=["technology", "parameter"]).sort_index()

Expand Down Expand Up @@ -232,7 +233,7 @@ def load_powerplants(ppl_fn):

def attach_load(n, demand_profiles):
"""
Add load profiles to network buses
Add load profiles to network buses.
Parameters
----------
Expand Down Expand Up @@ -374,7 +375,9 @@ def attach_conventional_generators(
conventional_config,
conventional_inputs,
):
carriers = set(conventional_carriers) | (set(extendable_carriers["Generator"]) - set(renewable_carriers))
carriers = set(conventional_carriers) | (
set(extendable_carriers["Generator"]) - set(renewable_carriers)
)
_add_missing_carriers_from_costs(n, costs, carriers)

ppl = (
Expand Down
2 changes: 0 additions & 2 deletions scripts/augmented_line_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
Description
-----------
"""
import logging
import os
Expand Down
5 changes: 2 additions & 3 deletions scripts/base_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# -*- coding: utf-8 -*-
"""
Creates the network topology from a OpenStreetMap
Creates the network topology from a OpenStreetMap.
Relevant Settings
-----------------
Expand Down Expand Up @@ -54,7 +54,6 @@
Description
-----------
"""
import logging
import os
Expand Down Expand Up @@ -411,7 +410,7 @@ def _set_countries_and_substations(inputs, config, n):

def _rebase_voltage_to_config(config, component):
"""
Rebase the voltage of components to the config.yaml input
Rebase the voltage of components to the config.yaml input.
Components such as line and buses have voltage levels between
110 kV up to around 850 kV. PyPSA-Africa uses 3 voltages as config input.
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

# -*- coding: utf-8 -*-
"""
Creates Voronoi shapes for each bus representing both onshore and offshore regions.
Creates Voronoi shapes for each bus representing both onshore and offshore
regions.
Relevant Settings
-----------------
Expand Down Expand Up @@ -40,7 +41,6 @@
Description
-----------
"""
import logging
import os
Expand Down
7 changes: 3 additions & 4 deletions scripts/build_demand_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# -*- coding: utf-8 -*-
"""
Creates electric demand profile csv
Creates electric demand profile csv.
Relevant Settings
-----------------
Expand Down Expand Up @@ -39,7 +39,6 @@
It creates the load paths for GEGIS outputs by combining the input parameters of the countries, weather year, prediction year, and SSP scenario.
Then with a function that takes in the PyPSA network "base.nc", region and gadm shape data, the countries of interest, a scale factor, and the snapshots,
it returns a csv file called "demand_profiles.csv", that allocates the load to the buses of the network according to GDP and population.
"""
import logging
import os
Expand All @@ -63,7 +62,7 @@ def normed(s):

def get_load_paths_gegis(ssp_parentfolder, config):
"""
Create load paths for GEGIS outputs
Create load paths for GEGIS outputs.
The paths are created automatically according to included country,
weather year, prediction year and ssp scenario
Expand Down Expand Up @@ -143,7 +142,7 @@ def build_demand_profiles(

def upsample(cntry, group):
"""
Distributes load in country according to population and gdp
Distributes load in country according to population and gdp.
"""
l = gegis_load.loc[gegis_load.region_code == cntry]["Electricity demand"]
if len(group) == 1:
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_natura_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ def get_transform_and_shape(bounds, res, out_logging):

def unify_protected_shape_areas(inputs, natura_crs, out_logging):
"""
Iterates through all snakemake rule inputs and unifies shapefiles (.shp) only.
Iterates through all snakemake rule inputs and unifies shapefiles (.shp)
only.
The input is given in the Snakefile and shapefiles are given by .shp
Returns
-------
unified_shape : GeoDataFrame with a unified "multishape"
"""
import pandas as pd
from shapely.ops import unary_union
Expand Down
Loading

0 comments on commit cc6e346

Please sign in to comment.