Skip to content

Commit 1843f84

Browse files
apply configure_logging more comprehensively (#1508)
* apply configure_logging more comprehensively * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * make module level imports at top * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2fec716 commit 1843f84

24 files changed

+139
-21
lines changed

scripts/build_ammonia_production.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
(July 2024) published by the US Geological Survey (USGS) and the National Minerals Information Center and extracts the annual ammonia production per country in ktonN/a. The data is converted to ktonNH3/a.
2222
"""
2323

24+
import logging
25+
2426
import country_converter as coco
2527
import pandas as pd
26-
from _helpers import set_scenario_config
28+
from _helpers import configure_logging, set_scenario_config
29+
30+
logger = logging.getLogger(__name__)
2731

2832
cc = coco.CountryConverter()
2933

@@ -34,6 +38,7 @@
3438

3539
snakemake = mock_snakemake("build_ammonia_production")
3640

41+
configure_logging(snakemake)
3742
set_scenario_config(snakemake)
3843

3944
ammonia = pd.read_excel(

scripts/build_biomass_transport_costs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
@author: bw0928
1717
"""
1818

19+
import logging
20+
1921
import pandas as pd
22+
from _helpers import configure_logging
23+
24+
logger = logging.getLogger(__name__)
2025

2126
ENERGY_CONTENT = 4.8 # unit MWh/t (wood pellets)
2227

@@ -117,5 +122,6 @@ def build_biomass_transport_costs():
117122
from _helpers import mock_snakemake
118123

119124
snakemake = mock_snakemake("build_biomass_transport_costs")
125+
configure_logging(snakemake)
120126

121127
build_biomass_transport_costs()

scripts/build_clustered_population_layouts.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
split by urban and rural population.
77
"""
88

9+
import logging
10+
911
import atlite
1012
import geopandas as gpd
1113
import pandas as pd
1214
import xarray as xr
13-
from _helpers import set_scenario_config
15+
from _helpers import configure_logging, set_scenario_config
16+
17+
logger = logging.getLogger(__name__)
1418

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

1923
snakemake = mock_snakemake("build_clustered_population_layouts", clusters=48)
2024

25+
configure_logging(snakemake)
2126
set_scenario_config(snakemake)
2227

2328
cutout = atlite.Cutout(snakemake.input.cutout)

scripts/build_daily_heat_demand.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@
4343
default_cutout``:
4444
"""
4545

46+
import logging
47+
4648
import atlite
4749
import geopandas as gpd
4850
import numpy as np
4951
import xarray as xr
50-
from _helpers import get_snapshots, set_scenario_config
52+
from _helpers import configure_logging, get_snapshots, set_scenario_config
5153
from dask.distributed import Client, LocalCluster
5254

55+
logger = logging.getLogger(__name__)
56+
5357
if __name__ == "__main__":
5458
if "snakemake" not in globals():
5559
from _helpers import mock_snakemake
@@ -59,6 +63,7 @@
5963
scope="total",
6064
clusters=48,
6165
)
66+
configure_logging(snakemake)
6267
set_scenario_config(snakemake)
6368

6469
nprocesses = int(snakemake.threads)

scripts/build_direct_heat_source_utilisation_profiles.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
- `resources/<run_name>/direct_heat_source_utilisation_profiles_base_s_{clusters}_{planning_horizons}.nc`: Direct heat source utilisation profiles
2525
"""
2626

27+
import logging
28+
2729
import xarray as xr
28-
from _helpers import set_scenario_config
30+
from _helpers import configure_logging, set_scenario_config
31+
32+
logger = logging.getLogger(__name__)
2933

3034

3135
def get_source_temperature(heat_source_key: str):
@@ -89,7 +93,7 @@ def get_profile(
8993
"build_cop_profiles",
9094
clusters=48,
9195
)
92-
96+
configure_logging(snakemake)
9397
set_scenario_config(snakemake)
9498

9599
direct_utilisation_heat_sources: list[str] = (

scripts/build_egs_potentials.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import numpy as np
2323
import pandas as pd
2424
import xarray as xr
25+
from _helpers import configure_logging, set_scenario_config
2526
from shapely.geometry import Polygon
2627

2728
logger = logging.getLogger(__name__)
@@ -199,6 +200,9 @@ def get_capacity_factors(network_regions_file, air_temperatures_file):
199200
clusters=37,
200201
)
201202

203+
configure_logging(snakemake)
204+
set_scenario_config(snakemake)
205+
202206
egs_config = snakemake.params["sector"]["enhanced_geothermal"]
203207
costs_config = snakemake.params["costs"]
204208

scripts/build_existing_heating_distribution.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
- "Mapping and analyses of the current and future (2020 - 2030) heating/cooling fuel deployment (fossil/renewables)" (https://energy.ec.europa.eu/publications/mapping-and-analyses-current-and-future-2020-2030-heatingcooling-fuel-deployment-fossilrenewables-1_en)
3939
"""
4040

41+
import logging
42+
4143
import country_converter as coco
4244
import numpy as np
4345
import pandas as pd
44-
from _helpers import set_scenario_config
46+
from _helpers import configure_logging, set_scenario_config
47+
48+
logger = logging.getLogger(__name__)
4549

4650
cc = coco.CountryConverter()
4751

@@ -171,6 +175,7 @@ def build_existing_heating():
171175
clusters=48,
172176
planning_horizons=2050,
173177
)
178+
configure_logging(snakemake)
174179
set_scenario_config(snakemake)
175180

176181
build_existing_heating()

scripts/build_hac_features.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import atlite
1111
import geopandas as gpd
12-
from _helpers import get_snapshots, set_scenario_config
12+
from _helpers import configure_logging, get_snapshots, set_scenario_config
1313
from atlite.aggregate import aggregate_matrix
1414
from dask.distributed import Client
1515

@@ -20,6 +20,7 @@
2020
from _helpers import mock_snakemake
2121

2222
snakemake = mock_snakemake("build_hac_features")
23+
configure_logging(snakemake)
2324
set_scenario_config(snakemake)
2425

2526
params = snakemake.params

scripts/build_heat_totals.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
- `resources/<run_name>/heat_totals.csv`: Approximated annual heat demand for each country.
1717
"""
1818

19+
import logging
1920
from itertools import product
2021

2122
import pandas as pd
23+
from _helpers import configure_logging
2224
from numpy.polynomial import Polynomial
2325

26+
logger = logging.getLogger(__name__)
27+
2428
idx = pd.IndexSlice
2529

2630

@@ -104,6 +108,8 @@ def approximate_heat_demand(energy_totals: pd.DataFrame, hdd: pd.DataFrame):
104108

105109
snakemake = mock_snakemake("build_heat_totals")
106110

111+
configure_logging(snakemake)
112+
107113
hdd = pd.read_csv(snakemake.input.hdd, index_col=0).T
108114
hdd.index = hdd.index.astype(int)
109115

scripts/build_hourly_heat_demand.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@
2929
- ``resources/hourly_heat_demand_total_base_s<simpl>_<clusters>.nc``:
3030
"""
3131

32+
import logging
3233
from itertools import product
3334

3435
import pandas as pd
3536
import xarray as xr
36-
from _helpers import generate_periodic_profiles, get_snapshots, set_scenario_config
37+
from _helpers import (
38+
configure_logging,
39+
generate_periodic_profiles,
40+
get_snapshots,
41+
set_scenario_config,
42+
)
43+
44+
logger = logging.getLogger(__name__)
3745

3846
if __name__ == "__main__":
3947
if "snakemake" not in globals():
@@ -44,6 +52,7 @@
4452
scope="total",
4553
clusters=5,
4654
)
55+
configure_logging(snakemake)
4756
set_scenario_config(snakemake)
4857

4958
snapshots = get_snapshots(

0 commit comments

Comments
 (0)