Skip to content

Commit 7c24e21

Browse files
committed
use absolute imports
1 parent c3cdff9 commit 7c24e21

File tree

115 files changed

+407
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+407
-475
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ To generate a PDF of the dependency graph of all steps `build/dag.pdf` run:
9090

9191
## License
9292

93-
The code in this repo is MIT licensed, see `./LICENSE.md`.
93+
The code in this repo is MIT licensed, see `./LICENSE.md`.

rules/common.smk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ from functools import partial, lru_cache
77

88
import os, sys, glob
99

10-
path = workflow.source_path("../scripts/_helpers.py")
11-
sys.path.insert(0, os.path.dirname(path))
10+
sys.path.insert(0, os.path.abspath("../scripts"))
1211

13-
from _helpers import validate_checksum, update_config_from_wildcards
12+
from scripts._helpers import validate_checksum, update_config_from_wildcards
1413
from snakemake.utils import update_config
1514

1615

scripts/_benchmark.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
33
#
44
# SPDX-License-Identifier: MIT
5-
"""
6-
7-
"""
5+
""" """
86

97
from __future__ import absolute_import, print_function
108

scripts/add_brownfield.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import pandas as pd
1313
import pypsa
1414
import xarray as xr
15-
from _helpers import (
15+
from add_existing_baseyear import add_build_year_to_new_assets
16+
from pypsa.clustering.spatial import normed_or_uniform
17+
18+
from scripts._helpers import (
1619
configure_logging,
1720
get_snapshots,
1821
set_scenario_config,
1922
update_config_from_wildcards,
2023
)
21-
from add_existing_baseyear import add_build_year_to_new_assets
22-
from pypsa.clustering.spatial import normed_or_uniform
2324

2425
logger = logging.getLogger(__name__)
2526
idx = pd.IndexSlice
@@ -258,7 +259,7 @@ def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int)
258259

259260
if __name__ == "__main__":
260261
if "snakemake" not in globals():
261-
from _helpers import mock_snakemake
262+
from scripts._helpers import mock_snakemake
262263

263264
snakemake = mock_snakemake(
264265
"add_brownfield",

scripts/add_electricity.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@
119119
import powerplantmatching as pm
120120
import pypsa
121121
import xarray as xr
122-
from _helpers import (
122+
from powerplantmatching.export import map_country_bus
123+
from pypsa.clustering.spatial import DEFAULT_ONE_PORT_STRATEGIES, normed_or_uniform
124+
125+
from scripts._helpers import (
123126
configure_logging,
124127
get_snapshots,
125128
set_scenario_config,
126129
update_p_nom_max,
127130
)
128-
from powerplantmatching.export import map_country_bus
129-
from pypsa.clustering.spatial import DEFAULT_ONE_PORT_STRATEGIES, normed_or_uniform
130131

131132
idx = pd.IndexSlice
132133

@@ -308,7 +309,6 @@ def load_and_aggregate_powerplants(
308309
aggregation_strategies: dict = None,
309310
exclude_carriers: list = None,
310311
) -> pd.DataFrame:
311-
312312
if not aggregation_strategies:
313313
aggregation_strategies = {}
314314

@@ -410,7 +410,6 @@ def attach_load(
410410
busmap_fn: str,
411411
scaling: float = 1.0,
412412
) -> None:
413-
414413
load = (
415414
xr.open_dataarray(load_fn).to_dataframe().squeeze(axis=1).unstack(level="time")
416415
)
@@ -431,7 +430,6 @@ def set_transmission_costs(
431430
line_length_factor: float = 1.0,
432431
link_length_factor: float = 1.0,
433432
) -> None:
434-
435433
n.lines["capital_cost"] = (
436434
n.lines["length"]
437435
* line_length_factor
@@ -1014,7 +1012,7 @@ def attach_stores(n, costs, extendable_carriers):
10141012

10151013
if __name__ == "__main__":
10161014
if "snakemake" not in globals():
1017-
from _helpers import mock_snakemake
1015+
from scripts._helpers import mock_snakemake
10181016

10191017
snakemake = mock_snakemake("add_electricity", clusters=100)
10201018
configure_logging(snakemake)

scripts/add_existing_baseyear.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
import powerplantmatching as pm
1919
import pypsa
2020
import xarray as xr
21-
from _helpers import (
21+
22+
from scripts._helpers import (
2223
configure_logging,
2324
set_scenario_config,
2425
update_config_from_wildcards,
2526
)
26-
from add_electricity import sanitize_carriers
27-
from definitions.heat_sector import HeatSector
28-
from definitions.heat_system import HeatSystem
29-
from definitions.heat_system_type import HeatSystemType
30-
from prepare_sector_network import cluster_heat_buses, define_spatial, prepare_costs
27+
from scripts.add_electricity import sanitize_carriers
28+
from scripts.definitions.heat_sector import HeatSector
29+
from scripts.definitions.heat_system import HeatSystem
30+
from scripts.definitions.heat_system_type import HeatSystemType
31+
from scripts.prepare_sector_network import (
32+
cluster_heat_buses,
33+
define_spatial,
34+
prepare_costs,
35+
)
3136

3237
logger = logging.getLogger(__name__)
3338
cc = coco.CountryConverter()
@@ -1063,7 +1068,7 @@ def set_defaults(n):
10631068
# %%
10641069
if __name__ == "__main__":
10651070
if "snakemake" not in globals():
1066-
from _helpers import mock_snakemake
1071+
from scripts._helpers import mock_snakemake
10671072

10681073
snakemake = mock_snakemake(
10691074
"add_existing_baseyear",

scripts/add_transmission_projects_and_dlr.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import pandas as pd
1414
import pypsa
1515
import xarray as xr
16-
from _helpers import configure_logging, set_scenario_config
16+
17+
from scripts._helpers import configure_logging, set_scenario_config
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -71,7 +72,7 @@ def attach_line_rating(
7172

7273
if __name__ == "__main__":
7374
if "snakemake" not in globals():
74-
from _helpers import mock_snakemake
75+
from scripts._helpers import mock_snakemake
7576

7677
snakemake = mock_snakemake("add_transmission_projects_and_dlr")
7778
configure_logging(snakemake)
@@ -82,11 +83,9 @@ def attach_line_rating(
8283
n = pypsa.Network(snakemake.input.network)
8384

8485
if params["transmission_projects"]["enable"]:
85-
8686
attach_transmission_projects(n, snakemake.input.transmission_projects)
8787

8888
if params["dlr"]["activate"]:
89-
9089
rating = xr.open_dataarray(snakemake.input.dlr).to_pandas().transpose()
9190

9291
s_max_pu = params["s_max_pu"]

scripts/base_network.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,19 @@
8686
import shapely.prepared
8787
import shapely.wkt
8888
import yaml
89-
from _helpers import REGION_COLS, configure_logging, get_snapshots, set_scenario_config
9089
from packaging.version import Version, parse
9190
from scipy.sparse import csgraph
9291
from scipy.spatial import KDTree
9392
from shapely.geometry import LineString, Point
9493

95-
PD_GE_2_2 = parse(pd.__version__) >= Version("2.2")
94+
from scripts._helpers import (
95+
REGION_COLS,
96+
configure_logging,
97+
get_snapshots,
98+
set_scenario_config,
99+
)
96100

101+
PD_GE_2_2 = parse(pd.__version__) >= Version("2.2")
97102
logger = logging.getLogger(__name__)
98103

99104

@@ -976,7 +981,7 @@ def append_bus_shapes(n, shapes, type):
976981

977982
if __name__ == "__main__":
978983
if "snakemake" not in globals():
979-
from _helpers import mock_snakemake
984+
from scripts._helpers import mock_snakemake
980985

981986
snakemake = mock_snakemake("base_network")
982987
configure_logging(snakemake)

scripts/build_ammonia_production.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
import country_converter as coco
2626
import numpy as np
2727
import pandas as pd
28-
from _helpers import set_scenario_config
28+
29+
from scripts._helpers import set_scenario_config
2930

3031
cc = coco.CountryConverter()
3132

3233

3334
if __name__ == "__main__":
3435
if "snakemake" not in globals():
35-
from _helpers import mock_snakemake
36+
from scripts._helpers import mock_snakemake
3637

3738
snakemake = mock_snakemake("build_ammonia_production")
3839

scripts/build_biomass_potentials.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import geopandas as gpd
1313
import numpy as np
1414
import pandas as pd
15-
from _helpers import configure_logging, set_scenario_config
16-
from build_energy_totals import build_eurostat
15+
16+
from scripts._helpers import configure_logging, set_scenario_config
17+
from scripts.build_energy_totals import build_eurostat
1718

1819
logger = logging.getLogger(__name__)
1920
AVAILABLE_BIOMASS_YEARS = [2010, 2020, 2030, 2040, 2050]
@@ -339,8 +340,7 @@ def add_unsustainable_potentials(df):
339340

340341
if __name__ == "__main__":
341342
if "snakemake" not in globals():
342-
343-
from _helpers import mock_snakemake
343+
from scripts._helpers import mock_snakemake
344344

345345
snakemake = mock_snakemake(
346346
"build_biomass_potentials",

0 commit comments

Comments
 (0)