Skip to content

Commit

Permalink
Fix logger calls and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatef committed Oct 29, 2023
1 parent b75b1eb commit 64388a3
Show file tree
Hide file tree
Showing 25 changed files with 21 additions and 100 deletions.
1 change: 1 addition & 0 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def create_logger(logger_name, level=logging.INFO):
logger.setLevel(level)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
sys.excepthook = handle_exception


def read_osm_config(*args):
Expand Down
10 changes: 1 addition & 9 deletions scripts/add_electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,19 @@

import logging
import os
import sys

import geopandas as gpd
import numpy as np
import pandas as pd
import powerplantmatching as pm
import pypsa
import xarray as xr
from _helpers import (
configure_logging,
create_logger,
handle_exception,
read_csv_nafix,
update_p_nom_max,
)
from _helpers import configure_logging, create_logger, read_csv_nafix, update_p_nom_max
from powerplantmatching.export import map_country_bus

idx = pd.IndexSlice

create_logger(__name__)
sys.excepthook = handle_exception


def normed(s):
Expand Down
4 changes: 1 addition & 3 deletions scripts/add_extra_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@
"""
import logging
import os
import sys

import numpy as np
import pandas as pd
import pypsa
from _helpers import configure_logging, create_logger, handle_exception
from _helpers import configure_logging, create_logger
from add_electricity import (
_add_missing_carriers_from_costs,
add_nice_carrier_names,
Expand All @@ -69,7 +68,6 @@
idx = pd.IndexSlice

create_logger(__name__)
sys.excepthook = handle_exception


def attach_storageunits(n, costs, config):
Expand Down
4 changes: 1 addition & 3 deletions scripts/augmented_line_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@
"""
import logging
import os
import sys

import networkx as nx
import numpy as np
import pandas as pd
import pypsa
from _helpers import configure_logging, create_logger, handle_exception
from _helpers import configure_logging, create_logger
from add_electricity import load_costs
from base_network import _set_dc_underwater_fraction
from networkx.algorithms import complement
from networkx.algorithms.connectivity.edge_augmentation import k_edge_augmentation
from pypsa.geo import haversine_pts

create_logger(__name__)
sys.excepthook = handle_exception


# Functions
Expand Down
4 changes: 1 addition & 3 deletions scripts/base_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"""
import logging
import os
import sys

import geopandas as gpd
import networkx as nx
Expand All @@ -68,13 +67,12 @@
import shapely.prepared
import shapely.wkt
import yaml
from _helpers import configure_logging, create_logger, handle_exception, read_csv_nafix
from _helpers import configure_logging, create_logger, read_csv_nafix
from scipy.sparse import csgraph
from shapely.geometry import LineString, Point
from shapely.ops import unary_union

create_logger(__name__)
sys.excepthook = handle_exception


def _get_oid(df):
Expand Down
4 changes: 1 addition & 3 deletions scripts/build_bus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@
"""
import logging
import os
import sys

import geopandas as gpd
import pandas as pd
import pypsa
from _helpers import REGION_COLS, configure_logging, create_logger, handle_exception
from _helpers import REGION_COLS, configure_logging, create_logger
from shapely.geometry import Point

# from scripts.build_shapes import gadm

create_logger(__name__)
sys.excepthook = handle_exception


def custom_voronoi_partition_pts(points, outline, add_bounds_shape=True, multiplier=5):
Expand Down
5 changes: 2 additions & 3 deletions scripts/build_cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@
"""
import logging
import os
import sys

import atlite
import geopandas as gpd
import pandas as pd
from _helpers import configure_logging, create_logger, handle_exception
from _helpers import configure_logging, create_logger

create_logger(__name__)
sys.excepthook = handle_exception


if __name__ == "__main__":
if "snakemake" not in globals():
Expand Down
10 changes: 1 addition & 9 deletions scripts/build_demand_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"""
import logging
import os
import sys
from itertools import product

import geopandas as gpd
Expand All @@ -52,18 +51,11 @@
import pypsa
import scipy.sparse as sparse
import xarray as xr
from _helpers import (
configure_logging,
create_logger,
getContinent,
handle_exception,
update_p_nom_max,
)
from _helpers import configure_logging, create_logger, getContinent, update_p_nom_max
from shapely.prepared import prep
from shapely.validation import make_valid

create_logger(__name__)
sys.excepthook = handle_exception


def normed(s):
Expand Down
5 changes: 2 additions & 3 deletions scripts/build_natura_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@
"""
import logging
import os
import sys

import atlite
import geopandas as gpd
import numpy as np
import rasterio as rio
from _helpers import configure_logging, create_logger, handle_exception
from _helpers import configure_logging, create_logger
from rasterio.features import geometry_mask
from rasterio.warp import transform_bounds

create_logger(__name__)
sys.excepthook = handle_exception


CUTOUT_CRS = "EPSG:4326"

Expand Down
3 changes: 0 additions & 3 deletions scripts/build_osm_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

import logging
import os
import sys

import geopandas as gpd
import numpy as np
import pandas as pd
from _helpers import (
configure_logging,
create_logger,
handle_exception,
read_geojson,
read_osm_config,
sets_path_to_root,
Expand All @@ -26,7 +24,6 @@
from tqdm import tqdm

create_logger(__name__)
sys.excepthook = handle_exception


def line_endings_to_bus_conversion(lines):
Expand Down
3 changes: 0 additions & 3 deletions scripts/build_powerplants.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"""
import logging
import os
import sys

import geopandas as gpd
import numpy as np
Expand All @@ -105,7 +104,6 @@
from _helpers import (
configure_logging,
create_logger,
handle_exception,
read_csv_nafix,
to_csv_nafix,
two_digits_2_name_country,
Expand All @@ -116,7 +114,6 @@
from shapely.geometry import Point

create_logger(__name__)
sys.excepthook = handle_exception


def convert_osm_to_pm(filepath_ppl_osm, filepath_ppl_pm):
Expand Down
11 changes: 2 additions & 9 deletions scripts/build_renewable_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
import functools
import logging
import os
import sys
import time
from math import isnan

Expand All @@ -204,13 +203,7 @@
import pandas as pd
import progressbar as pgb
import xarray as xr
from _helpers import (
configure_logging,
create_logger,
handle_exception,
read_csv_nafix,
sets_path_to_root,
)
from _helpers import configure_logging, create_logger, read_csv_nafix, sets_path_to_root
from add_electricity import load_powerplants
from dask.distributed import Client, LocalCluster
from pypsa.geo import haversine
Expand All @@ -219,7 +212,7 @@
cc = coco.CountryConverter()

create_logger(__name__)
sys.excepthook = handle_exception


COPERNICUS_CRS = "EPSG:4326"
GEBCO_CRS = "EPSG:4326"
Expand Down
3 changes: 0 additions & 3 deletions scripts/build_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import multiprocessing as mp
import os
import shutil
import sys
import zipfile
from itertools import takewhile
from math import ceil
Expand All @@ -26,7 +25,6 @@
from _helpers import (
configure_logging,
create_logger,
handle_exception,
sets_path_to_root,
three_2_two_digits_country,
two_2_three_digits_country,
Expand All @@ -42,7 +40,6 @@
sets_path_to_root("pypsa-earth")

create_logger(__name__)
sys.excepthook = handle_exception


def get_GADM_filename(country_code):
Expand Down
3 changes: 0 additions & 3 deletions scripts/clean_osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import logging
import os
import sys

import geopandas as gpd
import numpy as np
Expand All @@ -17,13 +16,11 @@
REGION_COLS,
configure_logging,
create_logger,
handle_exception,
save_to_geojson,
to_csv_nafix,
)

create_logger(__name__)
sys.excepthook = handle_exception


def prepare_substation_df(df_all_substations):
Expand Down
3 changes: 0 additions & 3 deletions scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
"""
import logging
import os
import sys
from functools import reduce

import geopandas as gpd
Expand All @@ -138,7 +137,6 @@
configure_logging,
create_logger,
get_aggregation_strategies,
handle_exception,
sets_path_to_root,
update_p_nom_max,
)
Expand All @@ -155,7 +153,6 @@
idx = pd.IndexSlice

create_logger(__name__)
sys.excepthook = handle_exception


def normed(x):
Expand Down
4 changes: 1 addition & 3 deletions scripts/download_osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
import logging
import os
import shutil
import sys
from pathlib import Path

from _helpers import configure_logging, create_logger, handle_exception, read_osm_config
from _helpers import configure_logging, create_logger, read_osm_config
from earth_osm import eo

create_logger(__name__)
sys.excepthook = handle_exception


def country_list_to_geofk(country_list):
Expand Down
10 changes: 1 addition & 9 deletions scripts/make_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"""
import os
import shutil
import sys
from datetime import datetime
from pathlib import Path

Expand All @@ -33,19 +32,12 @@
import pandas as pd
import pypsa
import xarray as xr
from _helpers import (
create_logger,
handle_exception,
mock_snakemake,
sets_path_to_root,
to_csv_nafix,
)
from _helpers import create_logger, mock_snakemake, sets_path_to_root, to_csv_nafix
from build_test_configs import create_test_config
from ruamel.yaml import YAML
from shapely.validation import make_valid

create_logger(__name__)
sys.excepthook = handle_exception


def _multi_index_scen(rulename, keys):
Expand Down
Loading

0 comments on commit 64388a3

Please sign in to comment.