diff --git a/ra2ce/analysis/losses/losses_base.py b/ra2ce/analysis/losses/losses_base.py index 23bc4d0a8..555792f5d 100644 --- a/ra2ce/analysis/losses/losses_base.py +++ b/ra2ce/analysis/losses/losses_base.py @@ -161,10 +161,10 @@ def _get_disrupted_criticality_analysis_results( ] # link_id from list to tuple if len(self.criticality_analysis_non_disrupted) > 0: - self.criticality_analysis_non_disrupted[self.link_id] = ( - self.criticality_analysis_non_disrupted[self.link_id].apply( - lambda x: tuple(x) if isinstance(x, list) else x - ) + self.criticality_analysis_non_disrupted[ + self.link_id + ] = self.criticality_analysis_non_disrupted[self.link_id].apply( + lambda x: tuple(x) if isinstance(x, list) else x ) self.criticality_analysis[self.link_id] = self.criticality_analysis[ self.link_id @@ -451,9 +451,9 @@ def _calculate_production_loss_per_capita( [vlh_row.name], f"vlh_{trip_type}_{hazard_col_name}" ] = vlh_trip_type_event vlh_total += vlh_trip_type_event - vehicle_loss_hours.loc[[vlh_row.name], f"vlh_{hazard_col_name}_total"] = ( - vlh_total - ) + vehicle_loss_hours.loc[ + [vlh_row.name], f"vlh_{hazard_col_name}_total" + ] = vlh_total def _populate_vehicle_loss_hour( self, @@ -503,9 +503,9 @@ def _populate_vehicle_loss_hour( [vlh_row.name], f"vlh_{trip_type}_{hazard_col_name}" ] = vlh_trip_type_event vlh_total += vlh_trip_type_event - vehicle_loss_hours.loc[[vlh_row.name], f"vlh_{hazard_col_name}_total"] = ( - vlh_total - ) + vehicle_loss_hours.loc[ + [vlh_row.name], f"vlh_{hazard_col_name}_total" + ] = vlh_total @abstractmethod def _get_criticality_analysis(self) -> AnalysisLossesProtocol: diff --git a/ra2ce/analysis/losses/risk_calculation/risk_calculation_base.py b/ra2ce/analysis/losses/risk_calculation/risk_calculation_base.py index bf4e8a0ed..814e505a3 100644 --- a/ra2ce/analysis/losses/risk_calculation/risk_calculation_base.py +++ b/ra2ce/analysis/losses/risk_calculation/risk_calculation_base.py @@ -1,8 +1,8 @@ +import re from abc import ABC, abstractmethod import geopandas as gpd import numpy as np -import re class RiskCalculationBase(ABC): @@ -80,5 +80,3 @@ def get_integration_of_df_trapezoidal(self) -> np.array: _risk_calculations = self._get_network_risk_calculations() frequencies = sorted(1 / rp for rp in _risk_calculations.columns) return np.trapz(_risk_calculations.values, frequencies, axis=1) - - diff --git a/ra2ce/analysis/losses/risk_calculation/risk_calculation_cut_from_year.py b/ra2ce/analysis/losses/risk_calculation/risk_calculation_cut_from_year.py index de6f89a34..cc12453c0 100644 --- a/ra2ce/analysis/losses/risk_calculation/risk_calculation_cut_from_year.py +++ b/ra2ce/analysis/losses/risk_calculation/risk_calculation_cut_from_year.py @@ -1,6 +1,6 @@ import logging -import geopandas as gpd +import geopandas as gpd import numpy as np from ra2ce.analysis.losses.risk_calculation.risk_calculation_base import ( diff --git a/ra2ce/analysis/losses/risk_calculation/risk_calculation_default.py b/ra2ce/analysis/losses/risk_calculation/risk_calculation_default.py index da65d98f0..a9649dc5d 100644 --- a/ra2ce/analysis/losses/risk_calculation/risk_calculation_default.py +++ b/ra2ce/analysis/losses/risk_calculation/risk_calculation_default.py @@ -1,4 +1,5 @@ import logging + import geopandas as gpd from ra2ce.analysis.losses.risk_calculation.risk_calculation_base import ( diff --git a/ra2ce/analysis/losses/risk_calculation/risk_calculation_factory.py b/ra2ce/analysis/losses/risk_calculation/risk_calculation_factory.py index a4983a899..b2054d673 100644 --- a/ra2ce/analysis/losses/risk_calculation/risk_calculation_factory.py +++ b/ra2ce/analysis/losses/risk_calculation/risk_calculation_factory.py @@ -1,4 +1,5 @@ import geopandas as gpd + from ra2ce.analysis.analysis_config_data.enums.risk_calculation_mode_enum import ( RiskCalculationModeEnum, ) diff --git a/ra2ce/analysis/losses/risk_calculation/risk_calculation_triangle_to_null_year.py b/ra2ce/analysis/losses/risk_calculation/risk_calculation_triangle_to_null_year.py index 5610acef4..dc8a9099e 100644 --- a/ra2ce/analysis/losses/risk_calculation/risk_calculation_triangle_to_null_year.py +++ b/ra2ce/analysis/losses/risk_calculation/risk_calculation_triangle_to_null_year.py @@ -1,4 +1,5 @@ import logging + import geopandas as gpd from ra2ce.analysis.losses.risk_calculation.risk_calculation_base import ( diff --git a/ra2ce/network/network_wrappers/vector_network_wrapper.py b/ra2ce/network/network_wrappers/vector_network_wrapper.py index 0ea83010b..6fdfa0d29 100644 --- a/ra2ce/network/network_wrappers/vector_network_wrapper.py +++ b/ra2ce/network/network_wrappers/vector_network_wrapper.py @@ -150,7 +150,9 @@ def get_network( graph_simple = nut.add_missing_geoms_graph(graph_simple, geom_name="geometry") # Update rfid_c after segmentation, which created more edges n teh complex graph - graph_simple = nut.add_complex_id_to_graph_simple(graph_simple, link_tables[0], "rfid") + graph_simple = nut.add_complex_id_to_graph_simple( + graph_simple, link_tables[0], "rfid" + ) logging.info("Finished converting the complex graph to a simple graph") diff --git a/ra2ce/network/networks_utils.py b/ra2ce/network/networks_utils.py index 622240e49..0e9a76f54 100644 --- a/ra2ce/network/networks_utils.py +++ b/ra2ce/network/networks_utils.py @@ -20,10 +20,10 @@ """ import itertools import logging -from copy import deepcopy import os import sys import warnings +from copy import deepcopy from pathlib import Path from statistics import mean from typing import Optional @@ -1481,9 +1481,7 @@ def add_simple_id_to_graph_complex( """ # {(u,v,k) : 'rfid_c'} - obtained_complex_ids = nx.get_edge_attributes( - complex_graph, "{}_c".format(new_id) - ) + obtained_complex_ids = nx.get_edge_attributes(complex_graph, "{}_c".format(new_id)) # start with a copy simple_ids_per_complex_id = deepcopy(obtained_complex_ids) @@ -1491,9 +1489,7 @@ def add_simple_id_to_graph_complex( for key, value in obtained_complex_ids.items(): try: # find simple id belonging to the complex id - new_value = complex_to_simple[ - value - ] + new_value = complex_to_simple[value] simple_ids_per_complex_id[key] = new_value except KeyError as e: logging.error( @@ -1585,6 +1581,7 @@ def buffer_geometry( ) return gdf + def add_complex_id_to_graph_simple( simple_graph: nx.classes.Graph, simple_to_complex, simple_id: str ) -> nx.classes.Graph: @@ -1601,19 +1598,15 @@ def add_complex_id_to_graph_simple( """ # {(u,v,k) : 'rfid'} - obtained_simple_ids = nx.get_edge_attributes( - simple_graph, f"{simple_id}" - ) + obtained_simple_ids = nx.get_edge_attributes(simple_graph, f"{simple_id}") # start with a copy complex_ids_per_simple_id = deepcopy(obtained_simple_ids) # {(u,v,k) : 'rfid'} - for key, value in obtained_simple_ids.items(): + for key, value in obtained_simple_ids.items(): try: # find simple id belonging to the complex id - new_value = simple_to_complex[ - value - ] + new_value = simple_to_complex[value] complex_ids_per_simple_id[key] = new_value except KeyError as e: logging.error( diff --git a/tests/analysis/losses/resilience_curves/test_resilience_curves.py b/tests/analysis/losses/resilience_curves/test_resilience_curves.py index f8c271791..04ee5e89e 100644 --- a/tests/analysis/losses/resilience_curves/test_resilience_curves.py +++ b/tests/analysis/losses/resilience_curves/test_resilience_curves.py @@ -72,7 +72,9 @@ def test_get_functionality_loss_ratio( "link_type, hazard_range, expected", [ pytest.param(RoadTypeEnum.MOTORWAY, (0.2, 0.5), 5.0, id="Motorway 0.2-0.5"), - pytest.param(RoadTypeEnum.MOTORWAY, (0.5, 1.2), 10.0, id="Motorway 0.5-1.2"), + pytest.param( + RoadTypeEnum.MOTORWAY, (0.5, 1.2), 10.0, id="Motorway 0.5-1.2" + ), ], ) def test_calculate_disruption( diff --git a/tests/analysis/losses/risk_calculation/conftest.py b/tests/analysis/losses/risk_calculation/conftest.py index 183571c39..7508314bd 100644 --- a/tests/analysis/losses/risk_calculation/conftest.py +++ b/tests/analysis/losses/risk_calculation/conftest.py @@ -109,7 +109,7 @@ def get_expected_factory_results_fixture() -> Iterator[dict]: name="risk_calculation_info_fixture", ) def _get_risk_calculation_info_fixture( - request: pytest.FixtureRequest, + request: pytest.FixtureRequest, ) -> Iterator[tuple[RiskCalculationModeEnum, int]]: _risk_calculation_info = request.param assert isinstance(_risk_calculation_info[0], RiskCalculationModeEnum) diff --git a/tests/analysis/losses/risk_calculation/test_risk_calculation.py b/tests/analysis/losses/risk_calculation/test_risk_calculation.py index d0a8fab98..acc6fd0bb 100644 --- a/tests/analysis/losses/risk_calculation/test_risk_calculation.py +++ b/tests/analysis/losses/risk_calculation/test_risk_calculation.py @@ -1,4 +1,5 @@ import pandas as pd + from ra2ce.analysis.analysis_config_data.enums.risk_calculation_mode_enum import ( RiskCalculationModeEnum, ) diff --git a/tests/conftest.py b/tests/conftest.py index ae6d689dd..213e10343 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,8 @@ from pathlib import Path from typing import Iterator + import pytest + from tests import acceptance_test_data