Deltares / ra2ce

RA2CE helps to quantify resilience of critical infrastructure networks, prioritize interventions and adaptation measures and select the most appropriate action perspective to increase resilience considering future conditions.
https://deltares.github.io/ra2ce/
Other
10 stars 2 forks source link

avgspeed should not be 0 #433

Closed sahand-asgarpour closed 3 months ago

sahand-asgarpour commented 5 months ago

Ra2ce version checks

Reproducible example

OSM download, example_multi_link_losses, network.ini changed to include up to residential.

Exception has occurred: TypeError

unsupported operand type(s) for -: 'float' and 'NoneType'
  File "C:\python\ra2ce\ra2ce\analysis\indirect\multi_link_redundancy.py", line 161, in execute     alt_value  File "C:\python\ra2ce\ra2ce\analysis\indirect\losses.py", line 624, in execute     criticality_analysis = MultiLinkRedundancy(self.analysis_input).execute()  File "C:\python\ra2ce\ra2ce\runners\indirect_analysis_runner.py", line 60, in run     _result = analysis.execute()  File "C:\python\ra2ce\ra2ce\ra2ce_handler.py", line 175, in run_analysis     return _runner.run(self.input_config.analysis_config)  File "C:\Users\meije_le\AppData\Local\Temp\ipykernel_50384\285750240.py", line 4, in <module>     handler.run_analysis()TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

Current behaviour

OSM downloaded some links with avgspeed of 0. This results in NaN time calculation for each link. This crashes the multi_link_losses.

Desired behaviour

For links with avgspeed 0, convert this to the non-zero average of the speed of the links with the same road_type.

Additional context

Bellow time is calculated as np.nan if avgspeed is 0.

def _calculate_time(self) -> float:
        length = self.weighing_data.get("length", None)
        avgspeed = self.weighing_data.get("avgspeed", None)
        if length and avgspeed:
            _calculated_time = round(
                (length * 1e-3) / avgspeed,
                3,
            )  # in hours and avg speed in km/h
            self.weighing_data[WeighingEnum.TIME.config_value] = _calculated_time
            return round(_calculated_time, 3)
        else:
            return np.nan
ArdtK commented 3 months ago

This can be reproduced by adjusting example_single_link_redundancy:

from ra2ce.analysis.analysis_config_data.enums.weighing_enum import WeighingEnum

handler = Ra2ceHandler(network=network_ini, analysis=analyses_ini)
handler.input_config.analysis_config.config_data.analyses[0].weighing = WeighingEnum.TIME
handler.configure()
handler.run_analysis()
ArdtK commented 3 months ago

Discussed with @sahand-asgarpour: