From bff99fcb4bd6262f507346ec074e882ebf1d78d3 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Mon, 30 Dec 2024 17:04:43 -0800 Subject: [PATCH 01/18] Added Power to latest Pelicun I intentionally deleted my fork of PELICUN which was forked from Adam's forked. So, all me contribution there is gone. I reforked the repor from NHERI-SimCenter/pelicun tried to figure out which changes translates to my forked version. These chanegs are not yet tested. Also needs the pull request for DBDL repo to be accepted --- pelicun/assessment.py | 1 + pelicun/resources/auto/Hazus_Earthquake_IM.py | 115 ++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/pelicun/assessment.py b/pelicun/assessment.py index 2c4977da..68e587fc 100644 --- a/pelicun/assessment.py +++ b/pelicun/assessment.py @@ -63,6 +63,7 @@ 'Hazus Earthquake - Stories': 'damage_DB_Hazus_EQ_story.csv', 'Hazus Earthquake - Transportation': 'damage_DB_Hazus_EQ_trnsp.csv', 'Hazus Earthquake - Water': 'damage_DB_Hazus_EQ_water.csv', + 'Hazus Earthquake - Power': 'damage_DB_Hazus_EQ_power.csv', 'Hazus Hurricane': 'damage_DB_SimCenter_Hazus_HU_bldg.csv', }, 'repair': { diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index f67c52fd..875ee76a 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -829,6 +829,121 @@ def auto_populate(aim): # noqa: C901 dl_ap = None comp = None + elif asset_type == 'PowerNetwork': + # initialize the auto-populated GI + power_asset_type = gi_ap.get("type", "MISSING") + asset_name = gi_ap.get("AIM_id", None) + + if power_asset_type == "Substation": + + ep_s_size = "" + substation_voltage = gi_ap.get("Voltage", None) + if not substation_voltage: + print("Substation feature \"Voltage\" is missing. " + f" substation \"{asset_name}\" assuemd to be " + "\" Low Voltage\".") + substation_voltage = "low" + + if isinstance(substation_voltage, str): + if substation_voltage.lower() == "low": + ep_s_size = "L" + elif substation_voltage.lower() == "medium": + ep_s_size = "M" + elif substation_voltage.lower() == "high": + ep_s_size = "H" + else: + raise ValueError("substation Voltage value is = " + f"{substation_voltage}. " + "The value must be either \"low\" " + ", \" medium\", or \" high\".") + elif isinstance(substation_voltage, (float, int)): + + # Substation Voltage unit is kV. ANy number smaller than + # 34 kv is not supported by HAZUS methodlogy. Furthermore, + # values significantly larger may refer to a voltage value in + # different unit. The upper bound value is set ro 1200 kV. + + + if substation_voltage < 34: + raise ValueError(f"The subtation Viltage for asset \"{asset_name}\" " + f"is too low({substation_voltage}). The current " + "methodology support voltage ebtween 34 kV and 1200 " + " kV. Please make sure that the units are in kV.") + + elif substation_voltage > 1200: + raise ValueError(f"The subtation Viltage for asset \"{asset_name}\" " + f"is too high({substation_voltage}). The current " + "methodology support voltage ebtween 34 kV and 1200 " + " kV. Please make sure that the units are in kV.") + + if substation_voltage <= 150: + ep_s_size = "L" + elif substation_voltage <= 230: + ep_s_size = "M" + elif substation_voltage >= 500: + ep_s_size = "H" + else: + raise RuntimeError("This should never have happed. Please " + "report this to the devloper(SimCenter)" + ". (Value = {substation_voltage}).") + else: + raise ValueError("substation Voltage value is = " + f"{substation_voltage}. It should be " + "string or a numebr. For more information, " + "refer to the documentation please.") + + + substation_anchored = gi_ap.get("Anchored", None) + + if not substation_anchored: + print("Substation feature \"Anchored\" is missing. " + f" substation \"{asset_name}\" assuemd to be " + "\" Unanchored\".") + + substation_anchored = False + + if isinstance(substation_anchored, str): + if substation_anchored.lower() in ["a", "anchored", "yes", "true", + "possitive", "1"]: + ep_s_anchored = "A" + elif substation_anchored.lower() in ["u", "unanchored", "no", + "false", "negative", "0"]: + ep_s_anchored = "U" + elif isinstance(substation_anchored, (bool, int, float)): + if abs(substation_anchored - True) < 0.001: + ep_s_anchored = "A" + elif abs(substation_anchored) < 0.001: + ep_s_anchored = "U" + else: + raise RuntimeError("This should never have happed. Please " + "report this to the devloper(SimCenter)" + ". (Value = {substation_anchored}).") + else: + raise ValueError("substation anchored value is = " + f"{substation_anchored}. It should be " + "string, boolean, or a number representing " + "True or False. For more information, " + "refer to the documentation please.") + + + # Define performance model + # fmt: off + comp = pd.DataFrame( # noqa + {f'EP.S.{ep_s_size}.{ep_s_anchored}': ['ea', 1, 1, 1, 'N/A']}, # noqa + index = ['Units','Location','Direction','Theta_0','Family'] # noqa + ).T # noqa + + # Define the auto-populated config + dl_ap = { + "Asset": { + "ComponentAssignmentFile": "CMP_QNT.csv", + "ComponentDatabase": "Hazus Earthquake - Power", + "Substation Voltage": ep_s_size, + "Substation Anchored": ep_s_anchored, + }, + "Damage": {"DamageProcess": "Hazus Earthquake"}, + "Demands": {}, + } else: print( f'AssetType: {asset_type} is not supported ' From b2277b2f973f44bb434f00c20306fce8c41fefc5 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Fri, 3 Jan 2025 14:29:05 -0800 Subject: [PATCH 02/18] added empty loss to power substation. It has no difference, just a reminder that it is considered empty. --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index 875ee76a..9fce1e76 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -943,6 +943,7 @@ def auto_populate(aim): # noqa: C901 }, "Damage": {"DamageProcess": "Hazus Earthquake"}, "Demands": {}, + "Losses": {}, } else: print( From c6f684c03b053a847a979b9521b41e2d14158115 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Fri, 3 Jan 2025 14:30:12 -0800 Subject: [PATCH 03/18] Add the power fragility location to the dlml path file --- pelicun/resources/dlml_resource_paths.json | 1 + 1 file changed, 1 insertion(+) diff --git a/pelicun/resources/dlml_resource_paths.json b/pelicun/resources/dlml_resource_paths.json index 66a6692b..1c4f00a7 100644 --- a/pelicun/resources/dlml_resource_paths.json +++ b/pelicun/resources/dlml_resource_paths.json @@ -8,6 +8,7 @@ "damage_DB_Hazus_EQ_trnsp.csv": "seismic/transportation_network/portfolio/Hazus v5.1/fragility.csv", "damage_DB_Hazus_EQ_trnsp.json": "seismic/transportation_network/portfolio/Hazus v5.1/fragility.json", "damage_DB_Hazus_EQ_water.csv": "seismic/water_network/portfolio/fragility.csv", + "damage_DB_Hazus_EQ_power.csv": "seismic/power_network/portfolio/Hazus v5.1/fragility.csv", "damage_DB_SimCenter_HU.csv": "hurricane/building/component/fragility.csv", "damage_DB_SimCenter_HU.json": "hurricane/building/component/fragility.json", "damage_DB_SimCenter_Hazus_HU_bldg.csv": "hurricane/building/portfolio/Hazus v4.2/fragility_fitted.csv", From 559f68d6985c951fc4ba723cbd8dd0db67ecf430 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Mon, 6 Jan 2025 13:00:23 -0800 Subject: [PATCH 04/18] Added Circuit and Generation Power subassets to the autopop Not yet test with latest changes --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 183 +++++++++++++++++- 1 file changed, 182 insertions(+), 1 deletion(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index 9fce1e76..f6d78c91 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -919,7 +919,7 @@ def auto_populate(aim): # noqa: C901 "report this to the devloper(SimCenter)" ". (Value = {substation_anchored}).") else: - raise ValueError("substation anchored value is = " + raise ValueError("Substation anchored value is = " f"{substation_anchored}. It should be " "string, boolean, or a number representing " "True or False. For more information, " @@ -945,6 +945,187 @@ def auto_populate(aim): # noqa: C901 "Demands": {}, "Losses": {}, } + + elif power_asset_type == "Circuit": + + circuit_anchored = gi_ap.get("Anchored", None) + + if not circuit_anchored: + print("Circuit feature \"Anchored\" is missing. " + f" Circuit \"{asset_name}\" assuemd to be " + "\" Unanchored\".") + + circuit_anchored = False + + if isinstance(circuit_anchored, str): + if circuit_anchored.lower() in ["a", "anchored", "yes", "true", + "possitive", "1"]: + ep_c_anchored = "A" + elif circuit_anchored.lower() in ["u", "unanchored", "no", + "false", "negative", "0"]: + ep_c_anchored = "U" + elif isinstance(circuit_anchored, (bool, int, float)): + if abs(circuit_anchored - True) < 0.001: + ep_c_anchored = "A" + elif abs(circuit_anchored) < 0.001: + ep_c_anchored = "U" + else: + raise RuntimeError("This should never have happed. Please " + "report this to the devloper(SimCenter)" + ". (Value = {circuit_anchored}).") + else: + raise ValueError("Circuit anchored value is = " + f"{circuit_anchored}. It should be " + "string, boolean, or a number representing " + "True or False. For more information, " + "refer to the documentation please.") + + + # Define performance model + # fmt: off + comp = pd.DataFrame( # noqa + {f'EP.C.{ep_s_size}.{ep_c_anchored}': ['ea', 1, 1, 1, 'N/A']}, # noqa + index = ['Units','Location','Direction','Theta_0','Family'] # noqa + ).T # noqa + + # Define the auto-populated config + dl_ap = { + "Asset": { + "ComponentAssignmentFile": "CMP_QNT.csv", + "ComponentDatabase": "Hazus Earthquake - Power", + "Circuit Anchored": ep_c_anchored, + }, + "Damage": {"DamageProcess": "Hazus Earthquake"}, + "Demands": {}, + "Losses": {}, + } + + elif power_asset_type == "Generation": + + ep_g_size = "" + generation_output = gi_ap.get("Output", None) + if not generation_output: + print("Generation feature \"Output\" is missing. " + f" Generation \"{asset_name}\" assuemd to be " + "\"Small\".") + ep_g_size = "small" + + if isinstance(generation_output, str): + + generation_output = generation_output.lower() + generation_output = generation_output.strip() + acceptable_power_unit = ("w", "kw", "gw") + + if_unit_exists = [st in generation_output for st in acceptable_power_unit] + + power_unit = None + + if True in if_unit_exists: + power_unit = acceptable_power_unit[ + if_unit_exists.index(True)] + + if generation_output.endswith(power_unit): + generation_output = generation_output.strip(power_unit) + generation_output = generation_output.strip() + else: + print("Generation feature doesn't have a unit for \"Output\" value. " + f" The ybit for Generation \"{asset_name}\" " + "is assumed to be \"Mw\".") + power_unit = "mw" + + + try: + generation_output = float(generation_output) + + + if power_unit == "w": + generation_output = generation_output / 1000 + elif power_unit == "gw": + generation_output = generation_output * 1000 + + if generation_output < 200: + ep_g_size = "small" + elif (generation_output > 200 and + generation_output < 500): + ep_g_size = "medium" + else: + ep_g_size = "large" + + + except: + print("Generation feature has an unrconizable \"Output\" value. " + f" Generation \"{asset_name}\" = {generation_output}, " + "instead of a numerical value." + "so the sizze of the Generation is assumed to be \"Small\".") + + ep_g_size = "small" + + if ep_g_size == "small": + ep_g_size = "s" + elif (ep_g_size == "medium" or + ep_g_size == "large"): + # because medium and large size generation plants are in + # categorized in the same category. + ep_g_size = "ML" + else: + raise ValueError("This should never have happed. Please " + "report this to the devloper(SimCenter)" + ". (Value = {ep_g_size}).") + + generation_anchored = gi_ap.get("Anchored", None) + + if not generation_anchored: + print("Generation feature \"Anchored\" is missing. " + f" Circuit \"{asset_name}\" assuemd to be " + "\" Unanchored\".") + + generation_anchored = False + ep_g_anchored = None + + if isinstance(generation_anchored, str): + if generation_anchored.lower() in ["a", "anchored", "yes", "true", + "possitive", "1"]: + ep_g_anchored = "A" + elif generation_anchored.lower() in ["u", "unanchored", "no", + "false", "negative", "0"]: + ep_g_anchored = "U" + elif isinstance(generation_anchored, (bool, int, float)): + if abs(generation_anchored - True) < 0.001: + ep_g_anchored = "A" + elif abs(generation_anchored) < 0.001: + ep_g_anchored = "U" + else: + raise RuntimeError("This should never have happed. Please " + "report this to the devloper(SimCenter)" + ". (Value = {generation_anchored}).") + else: + raise ValueError("Circuit anchored value is = " + f"{circuit_anchored}. It should be " + "string, boolean, or a number representing " + "True or False. For more information, " + "refer to the documentation please.") + + + # Define performance model + # fmt: off + comp = pd.DataFrame( # noqa + {f'EP.C.{ep_g_size}.{ep_g_anchored}': ['ea', 1, 1, 1, 'N/A']}, # noqa + index = ['Units','Location','Direction','Theta_0','Family'] # noqa + ).T # noqa + + # Define the auto-populated config + dl_ap = { + "Asset": { + "ComponentAssignmentFile": "CMP_QNT.csv", + "ComponentDatabase": "Hazus Earthquake - Power", + "Generation Size": ep_g_size, + "Generation Anchored": ep_g_anchored, + }, + "Damage": {"DamageProcess": "Hazus Earthquake"}, + "Demands": {}, + "Losses": {}, + } + else: print( f'AssetType: {asset_type} is not supported ' From 178114298c03015f500c4a5fcbbbcd1aa85a5362 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Mon, 6 Jan 2025 16:04:16 -0800 Subject: [PATCH 05/18] Linted and other things --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 236 ++++++++++-------- 1 file changed, 129 insertions(+), 107 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index f6d78c91..aff814cc 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -570,7 +570,8 @@ def auto_populate(aim): # noqa: C901 raise ValueError(msg) pipe_length = gi_ap.get('Len', None) - # length value is a fundamental part of hydraulic performance assessment + # length value is a fundamental part of + # hydraulic performance assessment if pipe_diameter is None: msg = f'pipe length in asset type {asset_type}, \ asset id "{asset_name}" has no diameter \ @@ -600,8 +601,8 @@ def auto_populate(aim): # noqa: C901 if pipe_material is None: if pipe_diameter > 20 * 0.0254: # 20 inches in meter print( - f'Asset {asset_name} is missing material. Material is\ - assumed to be Cast Iron' + f'Asset {asset_name} is missing material. ' + 'Material is assumed to be Cast Iron' ) pipe_material = 'CI' else: @@ -615,16 +616,17 @@ def auto_populate(aim): # noqa: C901 if (pipe_construction_year is not None) and ( pipe_construction_year >= 1935 ): - print( - f'Asset {asset_name} has material of "ST" is assumed to be\ - Ductile Steel' - ) + msg = (f'Asset {asset_name} has material of "ST" ' + 'is assumed to be Ductile Steel.') + + print(msg) pipe_material = 'DS' + else: - print( - f'Asset {asset_name} has material of "ST" is assumed to be ' - f'Brittle Steel' - ) + msg = (f'Asset {asset_name} has material of "ST" ' + 'is assumed to be Brittle Steel.') + + print(msg) pipe_material = 'BS' pipe_flexibility = pipe_material_map.get(pipe_material, 'missing') @@ -643,25 +645,29 @@ def auto_populate(aim): # noqa: C901 # Determine number of segments pipe_length_unit = gi_ap['units']['length'] - pipe_length_feet = pelicun.base.convert_units( - pipe_length, unit=pipe_length_unit, to_unit='ft', category='length' - ) + pipe_length_ft = pelicun.base.convert_units(pipe_length, + unit=pipe_length_unit, + to_unit='ft', + category='length' + ) reference_length = 20.00 # 20 ft - if pipe_length_feet % reference_length < 1e-2: + if pipe_length_ft % reference_length < 1e-2: # If the lengths are equal, then that's one segment, not two. - num_segments = int(pipe_length_feet / reference_length) + num_segments = int(pipe_length_ft / reference_length) else: # In all other cases, round up. - num_segments = int(pipe_length_feet / reference_length) + 1 + num_segments = int(pipe_length_ft / reference_length) + 1 location_string = f'1--{num_segments}' if num_segments > 1 else '1' # Define performance model # fmt: off + + pipe_fl = f'PWP.{pipe_flexibility}' comp = pd.DataFrame( - {f'PWP.{pipe_flexibility}.GS': ['ea', location_string, '0', 1, 'N/A'], - f'PWP.{pipe_flexibility}.GF': ['ea', location_string, '0', 1, 'N/A'], - 'aggregate': ['ea', location_string, '0', 1, 'N/A']}, - index = ['Units','Location','Direction','Theta_0','Family'] # noqa: E231, E251 + {pipe_fl+'.GS': ['ea', location_string, '0', 1, 'N/A'], + pipe_fl+'.GF': ['ea', location_string, '0', 1, 'N/A'], + 'aggregate': ['ea', location_string, '0', 1, 'N/A']}, + index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] ).T # fmt: on @@ -723,7 +729,8 @@ def auto_populate(aim): # noqa: C901 ('OG', 'S', 0): {'PST.G.S.U.GS': ['ea', 1, 1, 1, 'N/A']}, # Anchored status and Wood is not defined for On Ground tanks ('OG', 'W', 0): {'PST.G.W.GS': ['ea', 1, 1, 1, 'N/A']}, - # Anchored status and Steel is not defined for Above Ground tanks + # Anchored status and Steel is not defined for + # Above Ground tanks ('AG', 'S', 0): {'PST.A.S.GS': ['ea', 1, 1, 1, 'N/A']}, # Anchored status and Concrete is not defined for Buried tanks. ('B', 'C', 0): {'PST.B.C.GF': ['ea', 1, 1, 1, 'N/A']}, @@ -761,36 +768,39 @@ def auto_populate(aim): # noqa: C901 raise ValueError(msg) if tank_location == 'AG' and tank_material == 'C': - print( - f'The tank {asset_name} is Above Ground (i.e., AG), but \ - the material type is Concrete ("C"). Tank type "C" is not \ - defined for AG tanks. The tank is assumed to be Steel ("S")' - ) + msg = (f'The tank {asset_name} is Above Ground (i.e., AG), ' + 'but the material type is Concrete ("C"). ' + 'Tank type "C" is not defined for AG tanks. ' + 'The tank is assumed to be Steel ("S").') + + print(msg) tank_material = 'S' if tank_location == 'AG' and tank_material == 'W': - print( - f'The tank {asset_name} is Above Ground (i.e., AG), but \ - the material type is Wood ("W"). Tank type "W" is not \ - defined for AG tanks. The tank is assumed to be Steel ("S")' - ) + msg = (f'The tank {asset_name} is Above Ground (i.e., AG), but' + ' the material type is Wood ("W"). ' + 'Tank type "W" is not defined for AG tanks. ' + 'The tank is assumed to be Steel ("S").') + + print(msg) tank_material = 'S' if tank_location == 'B' and tank_material == 'S': - print( - f'The tank {asset_name} is buried (i.e., B), but the\ - material type is Steel ("S"). \ - Tank type "S" is not defined for\ - B tanks. The tank is assumed to be Concrete ("C")' - ) + msg = (f'The tank {asset_name} is buried (i.e., B), but the ' + 'material type is Steel ("S"). Tank type "S" is ' + 'not defined for "B" tanks. ' + 'The tank is assumed to be Concrete ("C").') + + print(msg) tank_material = 'C' if tank_location == 'B' and tank_material == 'W': - print( - f'The tank {asset_name} is buried (i.e., B), but the\ - material type is Wood ("W"). Tank type "W" is not defined \ - for B tanks. The tank is assumed to be Concrete ("C")' - ) + msg = (f'The tank {asset_name} is buried (i.e., B), but the' + 'material type is Wood ("W"). Tank type "W" is ' + 'not defined for B tanks. The tank is assumed ' + 'to be Concrete ("C")') + + print(msg) tank_material = 'C' if tank_anchored == 1: @@ -815,7 +825,8 @@ def auto_populate(aim): # noqa: C901 'Location': tank_location, 'Anchored': tank_anchored, 'PlanArea': '1', # Sina: does not make sense for water. - # Kept it here since itw as also kept here for Transportation + # Kept it here since itw as also kept here for + # Transportation }, 'Damage': {'DamageProcess': 'Hazus Earthquake'}, 'Demands': {}, @@ -837,11 +848,13 @@ def auto_populate(aim): # noqa: C901 if power_asset_type == "Substation": ep_s_size = "" + ep_s_anchored = "" substation_voltage = gi_ap.get("Voltage", None) if not substation_voltage: - print("Substation feature \"Voltage\" is missing. " - f" substation \"{asset_name}\" assuemd to be " - "\" Low Voltage\".") + msg = ("Substation feature \"Voltage\" is missing. " + f" substation \"{asset_name}\" assuemd to be " + "\" Low Voltage\".") + print(msg) substation_voltage = "low" if isinstance(substation_voltage, str): @@ -856,25 +869,27 @@ def auto_populate(aim): # noqa: C901 f"{substation_voltage}. " "The value must be either \"low\" " ", \" medium\", or \" high\".") - elif isinstance(substation_voltage, (float, int)): + elif isinstance(substation_voltage, (float, int)): # Substation Voltage unit is kV. ANy number smaller than # 34 kv is not supported by HAZUS methodlogy. Furthermore, # values significantly larger may refer to a voltage value in # different unit. The upper bound value is set ro 1200 kV. - if substation_voltage < 34: - raise ValueError(f"The subtation Viltage for asset \"{asset_name}\" " - f"is too low({substation_voltage}). The current " - "methodology support voltage ebtween 34 kV and 1200 " - " kV. Please make sure that the units are in kV.") + msg = (f"The subtation Viltage for asset \"{asset_name}\" " + f"is too low({substation_voltage}). The current " + "methodology support voltage ebtween 34 kV and 1200" + " kV. Please make sure that the units are in kV.") + raise ValueError(msg) + + if substation_voltage > 1200: + msg = (f"The subtation Viltage for asset \"{asset_name}\"" + f"is too high({substation_voltage}). The current " + "methodology support voltage ebtween 34 kV and 1200" + " kV. Please make sure that the units are in kV.") - elif substation_voltage > 1200: - raise ValueError(f"The subtation Viltage for asset \"{asset_name}\" " - f"is too high({substation_voltage}). The current " - "methodology support voltage ebtween 34 kV and 1200 " - " kV. Please make sure that the units are in kV.") + raise ValueError(msg) if substation_voltage <= 150: ep_s_size = "L" @@ -892,19 +907,18 @@ def auto_populate(aim): # noqa: C901 "string or a numebr. For more information, " "refer to the documentation please.") - substation_anchored = gi_ap.get("Anchored", None) if not substation_anchored: print("Substation feature \"Anchored\" is missing. " - f" substation \"{asset_name}\" assuemd to be " - "\" Unanchored\".") + f" substation \"{asset_name}\" assuemd to be " + "\" Unanchored\".") substation_anchored = False if isinstance(substation_anchored, str): - if substation_anchored.lower() in ["a", "anchored", "yes", "true", - "possitive", "1"]: + if substation_anchored.lower() in ["a", "anchored", "yes", + "true", "possitive", "1"]: ep_s_anchored = "A" elif substation_anchored.lower() in ["u", "unanchored", "no", "false", "negative", "0"]: @@ -925,13 +939,13 @@ def auto_populate(aim): # noqa: C901 "True or False. For more information, " "refer to the documentation please.") - # Define performance model # fmt: off - comp = pd.DataFrame( # noqa - {f'EP.S.{ep_s_size}.{ep_s_anchored}': ['ea', 1, 1, 1, 'N/A']}, # noqa - index = ['Units','Location','Direction','Theta_0','Family'] # noqa - ).T # noqa + substation_type = f'EP.S.{ep_s_size}.{ep_s_anchored}' + comp = pd.DataFrame( + {substation_type: ['ea', 1, 1, 1, 'N/A']}, + index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] + ).T # Define the auto-populated config dl_ap = { @@ -950,19 +964,20 @@ def auto_populate(aim): # noqa: C901 circuit_anchored = gi_ap.get("Anchored", None) + ep_c_anchored = None if not circuit_anchored: print("Circuit feature \"Anchored\" is missing. " - f" Circuit \"{asset_name}\" assuemd to be " - "\" Unanchored\".") + f" Circuit \"{asset_name}\" assuemd to be " + "\" Unanchored\".") circuit_anchored = False if isinstance(circuit_anchored, str): if circuit_anchored.lower() in ["a", "anchored", "yes", "true", - "possitive", "1"]: + "possitive", "1"]: ep_c_anchored = "A" elif circuit_anchored.lower() in ["u", "unanchored", "no", - "false", "negative", "0"]: + "false", "negative", "0"]: ep_c_anchored = "U" elif isinstance(circuit_anchored, (bool, int, float)): if abs(circuit_anchored - True) < 0.001: @@ -980,13 +995,13 @@ def auto_populate(aim): # noqa: C901 "True or False. For more information, " "refer to the documentation please.") - # Define performance model # fmt: off - comp = pd.DataFrame( # noqa - {f'EP.C.{ep_s_size}.{ep_c_anchored}': ['ea', 1, 1, 1, 'N/A']}, # noqa - index = ['Units','Location','Direction','Theta_0','Family'] # noqa - ).T # noqa + circuit_type = f'EP.C.{ep_s_size}.{ep_c_anchored}' + comp = pd.DataFrame( + {circuit_type: ['ea', 1, 1, 1, 'N/A']}, # noqa + index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] + ).T # Define the auto-populated config dl_ap = { @@ -1006,8 +1021,10 @@ def auto_populate(aim): # noqa: C901 generation_output = gi_ap.get("Output", None) if not generation_output: print("Generation feature \"Output\" is missing. " - f" Generation \"{asset_name}\" assuemd to be " - "\"Small\".") + f" Generation \"{asset_name}\" assuemd to be " + "\"Small\".") + # if the power feature is missing, teh generation is assuemd + # to be small ep_g_size = "small" if isinstance(generation_output, str): @@ -1016,28 +1033,28 @@ def auto_populate(aim): # noqa: C901 generation_output = generation_output.strip() acceptable_power_unit = ("w", "kw", "gw") - if_unit_exists = [st in generation_output for st in acceptable_power_unit] + units_exist = [unit in generation_output + for unit in acceptable_power_unit] power_unit = None - if True in if_unit_exists: + if True in units_exist: power_unit = acceptable_power_unit[ - if_unit_exists.index(True)] + units_exist.index(True)] if generation_output.endswith(power_unit): generation_output = generation_output.strip(power_unit) generation_output = generation_output.strip() else: - print("Generation feature doesn't have a unit for \"Output\" value. " - f" The ybit for Generation \"{asset_name}\" " - "is assumed to be \"Mw\".") - power_unit = "mw" + print("Generation feature doesn't have a unit for " + "\"Output\" value. The ybit for Generation " + f"\"{asset_name}\" is assumed to be \"Mw\".") + power_unit = "mw" try: generation_output = float(generation_output) - if power_unit == "w": generation_output = generation_output / 1000 elif power_unit == "gw": @@ -1045,45 +1062,50 @@ def auto_populate(aim): # noqa: C901 if generation_output < 200: ep_g_size = "small" - elif (generation_output > 200 and - generation_output < 500): + elif 200 < generation_output < 500: ep_g_size = "medium" else: ep_g_size = "large" + except ValueError as e: - except: - print("Generation feature has an unrconizable \"Output\" value. " - f" Generation \"{asset_name}\" = {generation_output}, " - "instead of a numerical value." - "so the sizze of the Generation is assumed to be \"Small\".") + # check if the exception is for value not being a float + not_float_str = "could not convert string to float:" + if not str(e).startswith(not_float_str): + raise e + # otherwise + print("Generation feature has an unrconizable \"Output\"" + f" value. Generation \"{asset_name}\" = " + f"{generation_output}, instead of a numerical value." + "so the sizze of the Generation is assumed to be " + "\"Small\".") ep_g_size = "small" if ep_g_size == "small": ep_g_size = "s" - elif (ep_g_size == "medium" or - ep_g_size == "large"): + elif ep_g_size in ("medium", "large"): # because medium and large size generation plants are in # categorized in the same category. ep_g_size = "ML" else: raise ValueError("This should never have happed. Please " - "report this to the devloper(SimCenter)" - ". (Value = {ep_g_size}).") + "report this to the devloper(SimCenter)" + ". (Value = {ep_g_size}).") generation_anchored = gi_ap.get("Anchored", None) if not generation_anchored: print("Generation feature \"Anchored\" is missing. " - f" Circuit \"{asset_name}\" assuemd to be " - "\" Unanchored\".") + f" Circuit \"{asset_name}\" assuemd to be " + "\" Unanchored\".") generation_anchored = False - ep_g_anchored = None + ep_g_anchored = None if isinstance(generation_anchored, str): - if generation_anchored.lower() in ["a", "anchored", "yes", "true", + if generation_anchored.lower() in ["a", "anchored", "yes", + "true", "possitive", "1"]: ep_g_anchored = "A" elif generation_anchored.lower() in ["u", "unanchored", "no", @@ -1105,13 +1127,13 @@ def auto_populate(aim): # noqa: C901 "True or False. For more information, " "refer to the documentation please.") - # Define performance model # fmt: off - comp = pd.DataFrame( # noqa - {f'EP.C.{ep_g_size}.{ep_g_anchored}': ['ea', 1, 1, 1, 'N/A']}, # noqa - index = ['Units','Location','Direction','Theta_0','Family'] # noqa - ).T # noqa + generation_type = f'EP.C.{ep_g_size}.{ep_g_anchored}' + comp = pd.DataFrame( + {generation_type: ['ea', 1, 1, 1, 'N/A']}, + index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] + ).T # Define the auto-populated config dl_ap = { From 20754b0cb52376189e7f27f4de3bab87241cf693 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Mon, 6 Jan 2025 16:41:55 -0800 Subject: [PATCH 06/18] Exclude TRY003 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index cb9c3fba..78a5e6c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ exclude = [ [tool.ruff.lint] # Enable all known categories select = ["ALL"] -ignore = ["ANN101", "D211", "D212", "Q000", "Q003", "COM812", "D203", "ISC001", "E501", "ERA001", "PGH003", "FIX002", "TD003", "S101", "N801", "S311", "G004", "SIM102", "SIM108", "NPY002", "F401"] +ignore = ["ANN101", "D211", "D212", "Q000", "Q003", "COM812", "D203", "ISC001", "E501", "ERA001", "PGH003", "FIX002", "TD003", "S101", "N801", "S311", "G004", "SIM102", "SIM108", "NPY002", "F401", "TRY003"] preview = true [tool.ruff.lint.pydocstyle] From d6a67e949bcd9b63f4c425233e4142d4a02b4ca9 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Mon, 6 Jan 2025 17:07:30 -0800 Subject: [PATCH 07/18] Ruff check and Ruff formatted Warning: Right now ruff ignores 79 character per line rule (E501) as specified in pyproject.toml. Thus, ruff format will reformat files resulting in lines with more than 79 characters --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 447 +++++++++++------- 1 file changed, 270 insertions(+), 177 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index aff814cc..0c91159d 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -215,9 +215,9 @@ def convertBridgeToHAZUSclass(aim): # noqa: C901 def convertTunnelToHAZUSclass(aim) -> str: - if ('Bored' in aim['ConstructType']) or ('Drilled' in aim['ConstructType']): + if 'Bored' in aim['ConstructType'] or 'Drilled' in aim['ConstructType']: return 'HTU1' - elif ('Cut' in aim['ConstructType']) or ('Cover' in aim['ConstructType']): + elif 'Cut' in aim['ConstructType'] or 'Cover' in aim['ConstructType']: return 'HTU2' else: # Select HTU2 for unclassified tunnels because it is more conservative. @@ -319,7 +319,8 @@ def auto_populate(aim): # noqa: C901 gi_ap = gi.copy() asset_type = aim['assetType'] - ground_failure = aim['Applications']['DL']['ApplicationData']['ground_failure'] + dl_app_data = aim['Applications']['DL']['ApplicationData'] + ground_failure = ['ground_failure'] if asset_type == 'Buildings': # get the building parameters @@ -329,8 +330,8 @@ def auto_populate(aim): # noqa: C901 dl = gi.get('DesignLevel', None) if dl is None: - # If there is no DesignLevel provided, we assume that the YearBuilt is - # available + # If there is no DesignLevel provided, + # we assume that the YearBuilt is available year_built = gi['YearBuilt'] design_l = ap_design_level_w1 if 'W1' in bt else ap_design_level @@ -601,8 +602,8 @@ def auto_populate(aim): # noqa: C901 if pipe_material is None: if pipe_diameter > 20 * 0.0254: # 20 inches in meter print( - f'Asset {asset_name} is missing material. ' - 'Material is assumed to be Cast Iron' + f'Asset {asset_name} is missing material. ' + 'Material is assumed to be Cast Iron' ) pipe_material = 'CI' else: @@ -616,15 +617,19 @@ def auto_populate(aim): # noqa: C901 if (pipe_construction_year is not None) and ( pipe_construction_year >= 1935 ): - msg = (f'Asset {asset_name} has material of "ST" ' - 'is assumed to be Ductile Steel.') + msg = ( + f'Asset {asset_name} has material of "ST" ' + 'is assumed to be Ductile Steel.' + ) print(msg) pipe_material = 'DS' else: - msg = (f'Asset {asset_name} has material of "ST" ' - 'is assumed to be Brittle Steel.') + msg = ( + f'Asset {asset_name} has material of "ST" ' + 'is assumed to be Brittle Steel.' + ) print(msg) pipe_material = 'BS' @@ -645,11 +650,9 @@ def auto_populate(aim): # noqa: C901 # Determine number of segments pipe_length_unit = gi_ap['units']['length'] - pipe_length_ft = pelicun.base.convert_units(pipe_length, - unit=pipe_length_unit, - to_unit='ft', - category='length' - ) + pipe_length_ft = pelicun.base.convert_units( + pipe_length, unit=pipe_length_unit, to_unit='ft', category='length' + ) reference_length = 20.00 # 20 ft if pipe_length_ft % reference_length < 1e-2: # If the lengths are equal, then that's one segment, not two. @@ -664,8 +667,8 @@ def auto_populate(aim): # noqa: C901 pipe_fl = f'PWP.{pipe_flexibility}' comp = pd.DataFrame( - {pipe_fl+'.GS': ['ea', location_string, '0', 1, 'N/A'], - pipe_fl+'.GF': ['ea', location_string, '0', 1, 'N/A'], + {pipe_fl + '.GS': ['ea', location_string, '0', 1, 'N/A'], + pipe_fl + '.GF': ['ea', location_string, '0', 1, 'N/A'], 'aggregate': ['ea', location_string, '0', 1, 'N/A']}, index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] ).T @@ -768,37 +771,45 @@ def auto_populate(aim): # noqa: C901 raise ValueError(msg) if tank_location == 'AG' and tank_material == 'C': - msg = (f'The tank {asset_name} is Above Ground (i.e., AG), ' - 'but the material type is Concrete ("C"). ' - 'Tank type "C" is not defined for AG tanks. ' - 'The tank is assumed to be Steel ("S").') + msg = ( + f'The tank {asset_name} is Above Ground (i.e., AG), ' + 'but the material type is Concrete ("C"). ' + 'Tank type "C" is not defined for AG tanks. ' + 'The tank is assumed to be Steel ("S").' + ) print(msg) tank_material = 'S' if tank_location == 'AG' and tank_material == 'W': - msg = (f'The tank {asset_name} is Above Ground (i.e., AG), but' - ' the material type is Wood ("W"). ' - 'Tank type "W" is not defined for AG tanks. ' - 'The tank is assumed to be Steel ("S").') + msg = ( + f'The tank {asset_name} is Above Ground (i.e., AG), but' + ' the material type is Wood ("W"). ' + 'Tank type "W" is not defined for AG tanks. ' + 'The tank is assumed to be Steel ("S").' + ) print(msg) tank_material = 'S' if tank_location == 'B' and tank_material == 'S': - msg = (f'The tank {asset_name} is buried (i.e., B), but the ' - 'material type is Steel ("S"). Tank type "S" is ' - 'not defined for "B" tanks. ' - 'The tank is assumed to be Concrete ("C").') + msg = ( + f'The tank {asset_name} is buried (i.e., B), but the ' + 'material type is Steel ("S"). Tank type "S" is ' + 'not defined for "B" tanks. ' + 'The tank is assumed to be Concrete ("C").' + ) print(msg) tank_material = 'C' if tank_location == 'B' and tank_material == 'W': - msg = (f'The tank {asset_name} is buried (i.e., B), but the' - 'material type is Wood ("W"). Tank type "W" is ' - 'not defined for B tanks. The tank is assumed ' - 'to be Concrete ("C")') + msg = ( + f'The tank {asset_name} is buried (i.e., B), but the' + 'material type is Wood ("W"). Tank type "W" is ' + 'not defined for B tanks. The tank is assumed ' + 'to be Concrete ("C")' + ) print(msg) tank_material = 'C' @@ -842,33 +853,37 @@ def auto_populate(aim): # noqa: C901 elif asset_type == 'PowerNetwork': # initialize the auto-populated GI - power_asset_type = gi_ap.get("type", "MISSING") - asset_name = gi_ap.get("AIM_id", None) - - if power_asset_type == "Substation": + power_asset_type = gi_ap.get('type', 'MISSING') + asset_name = gi_ap.get('AIM_id', None) - ep_s_size = "" - ep_s_anchored = "" - substation_voltage = gi_ap.get("Voltage", None) + if power_asset_type == 'Substation': + ep_s_size = '' + ep_s_anchored = '' + substation_voltage = gi_ap.get('Voltage', None) if not substation_voltage: - msg = ("Substation feature \"Voltage\" is missing. " - f" substation \"{asset_name}\" assuemd to be " - "\" Low Voltage\".") + msg = ( + 'Substation feature "Voltage" is missing. ' + f' substation "{asset_name}" assuemd to be ' + '" Low Voltage".' + ) print(msg) - substation_voltage = "low" + substation_voltage = 'low' if isinstance(substation_voltage, str): - if substation_voltage.lower() == "low": - ep_s_size = "L" - elif substation_voltage.lower() == "medium": - ep_s_size = "M" - elif substation_voltage.lower() == "high": - ep_s_size = "H" + if substation_voltage.lower() == 'low': + ep_s_size = 'L' + elif substation_voltage.lower() == 'medium': + ep_s_size = 'M' + elif substation_voltage.lower() == 'high': + ep_s_size = 'H' else: - raise ValueError("substation Voltage value is = " - f"{substation_voltage}. " - "The value must be either \"low\" " - ", \" medium\", or \" high\".") + msg = ( + 'substation Voltage value is = ' + f'{substation_voltage}. ' + 'The value must be either "low" ' + ', " medium", or " high".' + ) + raise ValueError(msg) elif isinstance(substation_voltage, (float, int)): # Substation Voltage unit is kV. ANy number smaller than @@ -877,67 +892,97 @@ def auto_populate(aim): # noqa: C901 # different unit. The upper bound value is set ro 1200 kV. if substation_voltage < 34: - msg = (f"The subtation Viltage for asset \"{asset_name}\" " - f"is too low({substation_voltage}). The current " - "methodology support voltage ebtween 34 kV and 1200" - " kV. Please make sure that the units are in kV.") + msg = ( + f'The subtation Viltage for asset "{asset_name}" ' + f'is too low({substation_voltage}). The current ' + 'methodology support voltage ebtween 34 kV and 1200' + ' kV. Please make sure that the units are in kV.' + ) raise ValueError(msg) if substation_voltage > 1200: - msg = (f"The subtation Viltage for asset \"{asset_name}\"" - f"is too high({substation_voltage}). The current " - "methodology support voltage ebtween 34 kV and 1200" - " kV. Please make sure that the units are in kV.") - + msg = ( + f'The subtation Viltage for asset "{asset_name}"' + f'is too high({substation_voltage}). The current ' + 'methodology support voltage ebtween 34 kV and 1200' + ' kV. Please make sure that the units are in kV.' + ) raise ValueError(msg) if substation_voltage <= 150: - ep_s_size = "L" + ep_s_size = 'L' elif substation_voltage <= 230: - ep_s_size = "M" + ep_s_size = 'M' elif substation_voltage >= 500: - ep_s_size = "H" + ep_s_size = 'H' else: - raise RuntimeError("This should never have happed. Please " - "report this to the devloper(SimCenter)" - ". (Value = {substation_voltage}).") + msg = ( + 'This should never have happed. Please ' + 'report this to the devloper(SimCenter)' + f'. (Value = {substation_voltage}).' + ) + raise RuntimeError(msg) else: - raise ValueError("substation Voltage value is = " - f"{substation_voltage}. It should be " - "string or a numebr. For more information, " - "refer to the documentation please.") + msg = ( + 'substation Voltage value is = ' + f'{substation_voltage}. It should be ' + 'string or a numebr. For more information, ' + 'refer to the documentation please.' + ) + raise ValueError(msg) - substation_anchored = gi_ap.get("Anchored", None) + substation_anchored = gi_ap.get('Anchored', None) if not substation_anchored: - print("Substation feature \"Anchored\" is missing. " - f" substation \"{asset_name}\" assuemd to be " - "\" Unanchored\".") + print( + 'Substation feature "Anchored" is missing. ' + f' substation "{asset_name}" assuemd to be ' + '" Unanchored".' + ) substation_anchored = False if isinstance(substation_anchored, str): - if substation_anchored.lower() in ["a", "anchored", "yes", - "true", "possitive", "1"]: - ep_s_anchored = "A" - elif substation_anchored.lower() in ["u", "unanchored", "no", - "false", "negative", "0"]: - ep_s_anchored = "U" + if substation_anchored.lower() in [ + 'a', + 'anchored', + 'yes', + 'true', + 'possitive', + '1', + ]: + ep_s_anchored = 'A' + elif substation_anchored.lower() in [ + 'u', + 'unanchored', + 'no', + 'false', + 'negative', + '0', + ]: + ep_s_anchored = 'U' elif isinstance(substation_anchored, (bool, int, float)): if abs(substation_anchored - True) < 0.001: - ep_s_anchored = "A" + ep_s_anchored = 'A' elif abs(substation_anchored) < 0.001: - ep_s_anchored = "U" + ep_s_anchored = 'U' else: - raise RuntimeError("This should never have happed. Please " - "report this to the devloper(SimCenter)" - ". (Value = {substation_anchored}).") + msg = ( + 'This should never have happed. Please ' + 'report this to the devloper(SimCenter)' + f'. (Value = {substation_anchored}).' + ) + raise RuntimeError(msg) + else: - raise ValueError("Substation anchored value is = " - f"{substation_anchored}. It should be " - "string, boolean, or a number representing " - "True or False. For more information, " - "refer to the documentation please.") + msg = ( + 'Substation anchored value is = ' + f'{substation_anchored}. It should be ' + 'string, boolean, or a number representing ' + 'True or False. For more information, ' + 'refer to the documentation please.' + ) + raise ValueError(msg) # Define performance model # fmt: off @@ -960,46 +1005,65 @@ def auto_populate(aim): # noqa: C901 "Losses": {}, } - elif power_asset_type == "Circuit": - - circuit_anchored = gi_ap.get("Anchored", None) + elif power_asset_type == 'Circuit': + circuit_anchored = gi_ap.get('Anchored', None) ep_c_anchored = None if not circuit_anchored: - print("Circuit feature \"Anchored\" is missing. " - f" Circuit \"{asset_name}\" assuemd to be " - "\" Unanchored\".") + print( + 'Circuit feature "Anchored" is missing. ' + f' Circuit "{asset_name}" assuemd to be ' + '" Unanchored".' + ) circuit_anchored = False if isinstance(circuit_anchored, str): - if circuit_anchored.lower() in ["a", "anchored", "yes", "true", - "possitive", "1"]: - ep_c_anchored = "A" - elif circuit_anchored.lower() in ["u", "unanchored", "no", - "false", "negative", "0"]: - ep_c_anchored = "U" + if circuit_anchored.lower() in [ + 'a', + 'anchored', + 'yes', + 'true', + 'possitive', + '1', + ]: + ep_c_anchored = 'A' + elif circuit_anchored.lower() in [ + 'u', + 'unanchored', + 'no', + 'false', + 'negative', + '0', + ]: + ep_c_anchored = 'U' elif isinstance(circuit_anchored, (bool, int, float)): if abs(circuit_anchored - True) < 0.001: - ep_c_anchored = "A" + ep_c_anchored = 'A' elif abs(circuit_anchored) < 0.001: - ep_c_anchored = "U" + ep_c_anchored = 'U' else: - raise RuntimeError("This should never have happed. Please " - "report this to the devloper(SimCenter)" - ". (Value = {circuit_anchored}).") + msg = ( + 'This should never have happed. Please ' + 'report this to the devloper(SimCenter)' + f'. (Value = {circuit_anchored}).' + ) + raise RuntimeError(msg) else: - raise ValueError("Circuit anchored value is = " - f"{circuit_anchored}. It should be " - "string, boolean, or a number representing " - "True or False. For more information, " - "refer to the documentation please.") + msg = ( + 'Circuit anchored value is = ' + f'{circuit_anchored}. It should be ' + 'string, boolean, or a number representing ' + 'True or False. For more information, ' + 'refer to the documentation please.' + ) + raise ValueError(msg) # Define performance model # fmt: off circuit_type = f'EP.C.{ep_s_size}.{ep_c_anchored}' comp = pd.DataFrame( - {circuit_type: ['ea', 1, 1, 1, 'N/A']}, # noqa + {circuit_type: ['ea', 1, 1, 1, 'N/A']}, index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] ).T @@ -1015,117 +1079,146 @@ def auto_populate(aim): # noqa: C901 "Losses": {}, } - elif power_asset_type == "Generation": - - ep_g_size = "" - generation_output = gi_ap.get("Output", None) + elif power_asset_type == 'Generation': + ep_g_size = '' + generation_output = gi_ap.get('Output', None) if not generation_output: - print("Generation feature \"Output\" is missing. " - f" Generation \"{asset_name}\" assuemd to be " - "\"Small\".") + msg = ( + 'Generation feature "Output" is missing. ' + f' Generation "{asset_name}" assuemd to be ' + '"Small".' + ) + print(msg) # if the power feature is missing, teh generation is assuemd # to be small - ep_g_size = "small" + ep_g_size = 'small' if isinstance(generation_output, str): - generation_output = generation_output.lower() generation_output = generation_output.strip() - acceptable_power_unit = ("w", "kw", "gw") + acceptable_power_unit = ('w', 'kw', 'gw') - units_exist = [unit in generation_output - for unit in acceptable_power_unit] + units_exist = [ + unit in generation_output for unit in acceptable_power_unit + ] power_unit = None if True in units_exist: - power_unit = acceptable_power_unit[ - units_exist.index(True)] + power_unit = acceptable_power_unit[units_exist.index(True)] if generation_output.endswith(power_unit): generation_output = generation_output.strip(power_unit) generation_output = generation_output.strip() else: - print("Generation feature doesn't have a unit for " - "\"Output\" value. The ybit for Generation " - f"\"{asset_name}\" is assumed to be \"Mw\".") + msg = ( + "Generation feature doesn't have a unit for " + '"Output" value. The ybit for Generation ' + f'"{asset_name}" is assumed to be "Mw".' + ) + print(msg) - power_unit = "mw" + power_unit = 'mw' try: generation_output = float(generation_output) - if power_unit == "w": + if power_unit == 'w': generation_output = generation_output / 1000 - elif power_unit == "gw": + elif power_unit == 'gw': generation_output = generation_output * 1000 if generation_output < 200: - ep_g_size = "small" + ep_g_size = 'small' elif 200 < generation_output < 500: - ep_g_size = "medium" + ep_g_size = 'medium' else: - ep_g_size = "large" + ep_g_size = 'large' except ValueError as e: - # check if the exception is for value not being a float - not_float_str = "could not convert string to float:" + not_float_str = 'could not convert string to float:' if not str(e).startswith(not_float_str): - raise e + raise # otherwise - print("Generation feature has an unrconizable \"Output\"" - f" value. Generation \"{asset_name}\" = " - f"{generation_output}, instead of a numerical value." - "so the sizze of the Generation is assumed to be " - "\"Small\".") + msg = ( + 'Generation feature has an unrconizable "Output"' + f' value. Generation "{asset_name}" = ' + f'{generation_output}, instead of a numerical ' + 'value. So the sizze of the Generation is assumed ' + 'to be "Small".' + ) + print(msg) - ep_g_size = "small" + ep_g_size = 'small' - if ep_g_size == "small": - ep_g_size = "s" - elif ep_g_size in ("medium", "large"): + if ep_g_size == 'small': + ep_g_size = 's' + elif ep_g_size in ('medium', 'large'): # because medium and large size generation plants are in # categorized in the same category. - ep_g_size = "ML" + ep_g_size = 'ML' else: - raise ValueError("This should never have happed. Please " - "report this to the devloper(SimCenter)" - ". (Value = {ep_g_size}).") + msg = ( + 'This should never have happed. Please ' + 'report this to the devloper(SimCenter)' + f'. (Value = {ep_g_size}).' + ) + raise ValueError(msg) - generation_anchored = gi_ap.get("Anchored", None) + generation_anchored = gi_ap.get('Anchored', None) if not generation_anchored: - print("Generation feature \"Anchored\" is missing. " - f" Circuit \"{asset_name}\" assuemd to be " - "\" Unanchored\".") + msg = ( + 'Generation feature "Anchored" is missing. ' + f' Circuit "{asset_name}" assuemd to be ' + '" Unanchored".' + ) + print(msg) generation_anchored = False ep_g_anchored = None if isinstance(generation_anchored, str): - if generation_anchored.lower() in ["a", "anchored", "yes", - "true", - "possitive", "1"]: - ep_g_anchored = "A" - elif generation_anchored.lower() in ["u", "unanchored", "no", - "false", "negative", "0"]: - ep_g_anchored = "U" + if generation_anchored.lower() in [ + 'a', + 'anchored', + 'yes', + 'true', + 'possitive', + '1', + ]: + ep_g_anchored = 'A' + elif generation_anchored.lower() in [ + 'u', + 'unanchored', + 'no', + 'false', + 'negative', + '0', + ]: + ep_g_anchored = 'U' elif isinstance(generation_anchored, (bool, int, float)): if abs(generation_anchored - True) < 0.001: - ep_g_anchored = "A" + ep_g_anchored = 'A' elif abs(generation_anchored) < 0.001: - ep_g_anchored = "U" + ep_g_anchored = 'U' else: - raise RuntimeError("This should never have happed. Please " - "report this to the devloper(SimCenter)" - ". (Value = {generation_anchored}).") + msg = ( + 'This should never have happed. Please ' + 'report this to the devloper(SimCenter)' + f'. (Value = {generation_anchored}).' + ) + raise RuntimeError(msg) else: - raise ValueError("Circuit anchored value is = " - f"{circuit_anchored}. It should be " - "string, boolean, or a number representing " - "True or False. For more information, " - "refer to the documentation please.") + msg = ( + 'Circuit anchored value is = ' + f'{circuit_anchored}. It should be ' + 'string, boolean, or a number representing ' + 'True or False. For more information, ' + 'refer to the documentation please.' + ) + raise ValueError(msg) # Define performance model # fmt: off From ab14e83a95a31b70dc94068732d0c52dabf63936 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Mon, 6 Jan 2025 17:10:23 -0800 Subject: [PATCH 08/18] Fixed a small issue --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index 0c91159d..a06f8dd4 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -320,7 +320,7 @@ def auto_populate(aim): # noqa: C901 asset_type = aim['assetType'] dl_app_data = aim['Applications']['DL']['ApplicationData'] - ground_failure = ['ground_failure'] + ground_failure = dl_app_data['ground_failure'] if asset_type == 'Buildings': # get the building parameters From ec0fd9002bb8675ecc94bc0357a504b9afb92db1 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Tue, 7 Jan 2025 12:31:17 -0800 Subject: [PATCH 09/18] Spell Check Done for Hazus_Earthquake_IM --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index a06f8dd4..b9656d7f 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -918,7 +918,7 @@ def auto_populate(aim): # noqa: C901 else: msg = ( 'This should never have happed. Please ' - 'report this to the devloper(SimCenter)' + 'report this to the developer(SimCenter)' f'. (Value = {substation_voltage}).' ) raise RuntimeError(msg) @@ -926,7 +926,7 @@ def auto_populate(aim): # noqa: C901 msg = ( 'substation Voltage value is = ' f'{substation_voltage}. It should be ' - 'string or a numebr. For more information, ' + 'string or a number. For more information, ' 'refer to the documentation please.' ) raise ValueError(msg) @@ -969,7 +969,7 @@ def auto_populate(aim): # noqa: C901 else: msg = ( 'This should never have happed. Please ' - 'report this to the devloper(SimCenter)' + 'report this to the developer(SimCenter)' f'. (Value = {substation_anchored}).' ) raise RuntimeError(msg) @@ -1045,7 +1045,7 @@ def auto_populate(aim): # noqa: C901 else: msg = ( 'This should never have happed. Please ' - 'report this to the devloper(SimCenter)' + 'report this to the developer(SimCenter)' f'. (Value = {circuit_anchored}).' ) raise RuntimeError(msg) @@ -1089,7 +1089,7 @@ def auto_populate(aim): # noqa: C901 '"Small".' ) print(msg) - # if the power feature is missing, teh generation is assuemd + # if the power feature is missing, the generation is assuemd # to be small ep_g_size = 'small' @@ -1161,7 +1161,7 @@ def auto_populate(aim): # noqa: C901 else: msg = ( 'This should never have happed. Please ' - 'report this to the devloper(SimCenter)' + 'report this to the developer(SimCenter)' f'. (Value = {ep_g_size}).' ) raise ValueError(msg) @@ -1206,7 +1206,7 @@ def auto_populate(aim): # noqa: C901 else: msg = ( 'This should never have happed. Please ' - 'report this to the devloper(SimCenter)' + 'report this to the developer(SimCenter)' f'. (Value = {generation_anchored}).' ) raise RuntimeError(msg) From e0c2a5d1d2268cdde717537063c01ea6181153c1 Mon Sep 17 00:00:00 2001 From: Sina Naeimi Date: Tue, 7 Jan 2025 17:17:09 -0800 Subject: [PATCH 10/18] bug fix --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index 1e389f79..e414fdcd 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1266,7 +1266,7 @@ def auto_populate(aim): # noqa: C901 # Define performance model # fmt: off - circuit_type = f'EP.C.{ep_s_size}.{ep_c_anchored}' + circuit_type = f'EP.C.{ep_c_anchored}' comp = pd.DataFrame( {circuit_type: ['ea', 1, 1, 1, 'N/A']}, index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] From db3302793e347d2b909eaef2f7da0bf871f886d1 Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 13:54:23 -0800 Subject: [PATCH 11/18] fixed typos in the file --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index e414fdcd..ecd707b4 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -919,7 +919,7 @@ def auto_populate(aim): # noqa: C901 'ComponentDatabase': 'Hazus Earthquake - Water', 'Material Flexibility': pipe_flexibility, 'PlanArea': '1', # Sina: does not make sense for water. - # Kept it here since itw as also + # Kept it here since it was also # kept here for Transportation }, 'Damage': { @@ -1041,7 +1041,7 @@ def auto_populate(aim): # noqa: C901 'Location': tank_location, 'Anchored': tank_anchored, 'PlanArea': '1', # Sina: does not make sense for water. - # Kept it here since itw as also kept here for + # Kept it here since it was also kept here for # Transportation }, 'Damage': {'DamageProcess': 'Hazus Earthquake'}, @@ -1068,7 +1068,7 @@ def auto_populate(aim): # noqa: C901 if not substation_voltage: msg = ( 'Substation feature "Voltage" is missing. ' - f' substation "{asset_name}" assuemd to be ' + f' substation "{asset_name}" assumed to be ' '" Low Voltage".' ) print(msg) @@ -1091,25 +1091,25 @@ def auto_populate(aim): # noqa: C901 raise ValueError(msg) elif isinstance(substation_voltage, (float, int)): - # Substation Voltage unit is kV. ANy number smaller than - # 34 kv is not supported by HAZUS methodlogy. Furthermore, + # Substation Voltage unit is kV. Any number smaller than + # 34 kV is not supported by HAZUS methodlogy. Furthermore, # values significantly larger may refer to a voltage value in # different unit. The upper bound value is set ro 1200 kV. if substation_voltage < 34: msg = ( - f'The subtation Viltage for asset "{asset_name}" ' + f'The subtation Voltage for asset "{asset_name}" ' f'is too low({substation_voltage}). The current ' - 'methodology support voltage ebtween 34 kV and 1200' + 'methodology support voltage between 34 kV and 1200' ' kV. Please make sure that the units are in kV.' ) raise ValueError(msg) if substation_voltage > 1200: msg = ( - f'The subtation Viltage for asset "{asset_name}"' + f'The subtation Voltage for asset "{asset_name}"' f'is too high({substation_voltage}). The current ' - 'methodology support voltage ebtween 34 kV and 1200' + 'methodology support voltage between 34 kV and 1200' ' kV. Please make sure that the units are in kV.' ) raise ValueError(msg) @@ -1141,7 +1141,7 @@ def auto_populate(aim): # noqa: C901 if not substation_anchored: print( 'Substation feature "Anchored" is missing. ' - f' substation "{asset_name}" assuemd to be ' + f' substation "{asset_name}" assumed to be ' '" Unanchored".' ) @@ -1153,7 +1153,7 @@ def auto_populate(aim): # noqa: C901 'anchored', 'yes', 'true', - 'possitive', + 'positive', '1', ]: ep_s_anchored = 'A' @@ -1217,7 +1217,7 @@ def auto_populate(aim): # noqa: C901 if not circuit_anchored: print( 'Circuit feature "Anchored" is missing. ' - f' Circuit "{asset_name}" assuemd to be ' + f' Circuit "{asset_name}" assumed to be ' '" Unanchored".' ) @@ -1229,7 +1229,7 @@ def auto_populate(aim): # noqa: C901 'anchored', 'yes', 'true', - 'possitive', + 'positive', '1', ]: ep_c_anchored = 'A' @@ -1290,11 +1290,11 @@ def auto_populate(aim): # noqa: C901 if not generation_output: msg = ( 'Generation feature "Output" is missing. ' - f' Generation "{asset_name}" assuemd to be ' + f' Generation "{asset_name}" assumed to be ' '"Small".' ) print(msg) - # if the power feature is missing, the generation is assuemd + # if the power feature is missing, the generation is assumed # to be small ep_g_size = 'small' @@ -1318,8 +1318,8 @@ def auto_populate(aim): # noqa: C901 else: msg = ( "Generation feature doesn't have a unit for " - '"Output" value. The ybit for Generation ' - f'"{asset_name}" is assumed to be "Mw".' + '"Output" value. The unit for Generation ' + f'"{asset_name}" is assumed to be "MW".' ) print(msg) @@ -1347,10 +1347,10 @@ def auto_populate(aim): # noqa: C901 raise # otherwise msg = ( - 'Generation feature has an unrconizable "Output"' + 'Generation feature has an unrecognizable "Output"' f' value. Generation "{asset_name}" = ' f'{generation_output}, instead of a numerical ' - 'value. So the sizze of the Generation is assumed ' + 'value. So the size of the Generation is assumed ' 'to be "Small".' ) print(msg) @@ -1360,7 +1360,7 @@ def auto_populate(aim): # noqa: C901 if ep_g_size == 'small': ep_g_size = 's' elif ep_g_size in ('medium', 'large'): - # because medium and large size generation plants are in + # because medium and large size generation plants are # categorized in the same category. ep_g_size = 'ML' else: @@ -1376,7 +1376,7 @@ def auto_populate(aim): # noqa: C901 if not generation_anchored: msg = ( 'Generation feature "Anchored" is missing. ' - f' Circuit "{asset_name}" assuemd to be ' + f' Circuit "{asset_name}" assumed to be ' '" Unanchored".' ) print(msg) @@ -1390,7 +1390,7 @@ def auto_populate(aim): # noqa: C901 'anchored', 'yes', 'true', - 'possitive', + 'positive', '1', ]: ep_g_anchored = 'A' From e41718dc80811b61642d4f3a8193b988cdbcd36f Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:11:23 -0800 Subject: [PATCH 12/18] added kW and MW as options and fixed the conversion --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index ecd707b4..b342a9d8 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1329,7 +1329,13 @@ def auto_populate(aim): # noqa: C901 generation_output = float(generation_output) if power_unit == 'w': - generation_output = generation_output / 1000 + generation_output = generation_output / 10^6 + elif power_unit == 'kw': + generation_output = generation_output / 10^3 + elif power_unit == 'mw': + # just for the sake of completeness, we don't + # need to convert here, since MW is our base unit + pass elif power_unit == 'gw': generation_output = generation_output * 1000 From f5dcf60adc0a0c9ce997840d4f36c17918b5da74 Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:14:13 -0800 Subject: [PATCH 13/18] Confirmed that the archetype ID uses capital S and fixed this typo. Also noticed a typo in the base ID string, it was EP.C instead of EP.G - fixed that too. --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index b342a9d8..ccbb4aba 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1364,7 +1364,7 @@ def auto_populate(aim): # noqa: C901 ep_g_size = 'small' if ep_g_size == 'small': - ep_g_size = 's' + ep_g_size = 'S' elif ep_g_size in ('medium', 'large'): # because medium and large size generation plants are # categorized in the same category. @@ -1433,7 +1433,7 @@ def auto_populate(aim): # noqa: C901 # Define performance model # fmt: off - generation_type = f'EP.C.{ep_g_size}.{ep_g_anchored}' + generation_type = f'EP.G.{ep_g_size}.{ep_g_anchored}' comp = pd.DataFrame( {generation_type: ['ea', 1, 1, 1, 'N/A']}, index=['Units', 'Location', 'Direction', 'Theta_0', 'Family'] From 5632f66d19d575c19e57be315e6ace4255fcc3c6 Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:15:47 -0800 Subject: [PATCH 14/18] Added 'mw' to the list of acceptable power units --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index ccbb4aba..d5e23904 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1301,7 +1301,7 @@ def auto_populate(aim): # noqa: C901 if isinstance(generation_output, str): generation_output = generation_output.lower() generation_output = generation_output.strip() - acceptable_power_unit = ('w', 'kw', 'gw') + acceptable_power_unit = ('w', 'kw', 'mw', 'gw') units_exist = [ unit in generation_output for unit in acceptable_power_unit From 32051d11ed4cd814fde14ff24a1c1f454967ba71 Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:23:22 -0800 Subject: [PATCH 15/18] Edited anchor property parser to make sure we throw errors in all cases when invalid inputs are provided. --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index d5e23904..d7fcdf00 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1179,7 +1179,7 @@ def auto_populate(aim): # noqa: C901 ) raise RuntimeError(msg) - else: + if ep_s_anchored is None: msg = ( 'Substation anchored value is = ' f'{substation_anchored}. It should be ' @@ -1254,7 +1254,8 @@ def auto_populate(aim): # noqa: C901 f'. (Value = {circuit_anchored}).' ) raise RuntimeError(msg) - else: + + if ep_c_anchored is None: msg = ( 'Circuit anchored value is = ' f'{circuit_anchored}. It should be ' @@ -1421,7 +1422,8 @@ def auto_populate(aim): # noqa: C901 f'. (Value = {generation_anchored}).' ) raise RuntimeError(msg) - else: + + if ep_g_anchored is None: msg = ( 'Circuit anchored value is = ' f'{circuit_anchored}. It should be ' From 95121a40a0d3a6d95abe7dd310298585931ae763 Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:26:10 -0800 Subject: [PATCH 16/18] replaced checking for falsy values with explicit checks for `None` --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index d7fcdf00..eb292b5a 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1065,7 +1065,7 @@ def auto_populate(aim): # noqa: C901 ep_s_size = '' ep_s_anchored = '' substation_voltage = gi_ap.get('Voltage', None) - if not substation_voltage: + if substation_voltage is None: msg = ( 'Substation feature "Voltage" is missing. ' f' substation "{asset_name}" assumed to be ' @@ -1138,7 +1138,7 @@ def auto_populate(aim): # noqa: C901 substation_anchored = gi_ap.get('Anchored', None) - if not substation_anchored: + if substation_anchored is None: print( 'Substation feature "Anchored" is missing. ' f' substation "{asset_name}" assumed to be ' @@ -1214,7 +1214,7 @@ def auto_populate(aim): # noqa: C901 circuit_anchored = gi_ap.get('Anchored', None) ep_c_anchored = None - if not circuit_anchored: + if circuit_anchored is None: print( 'Circuit feature "Anchored" is missing. ' f' Circuit "{asset_name}" assumed to be ' @@ -1288,7 +1288,7 @@ def auto_populate(aim): # noqa: C901 elif power_asset_type == 'Generation': ep_g_size = '' generation_output = gi_ap.get('Output', None) - if not generation_output: + if generation_output is None: msg = ( 'Generation feature "Output" is missing. ' f' Generation "{asset_name}" assumed to be ' @@ -1380,7 +1380,7 @@ def auto_populate(aim): # noqa: C901 generation_anchored = gi_ap.get('Anchored', None) - if not generation_anchored: + if generation_anchored is None: msg = ( 'Generation feature "Anchored" is missing. ' f' Circuit "{asset_name}" assumed to be ' From f13c10697542befb3feede331f6e67748f089fcd Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:32:25 -0800 Subject: [PATCH 17/18] bugfix: use correct exponentiation operator --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index eb292b5a..e5b081d5 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1330,9 +1330,9 @@ def auto_populate(aim): # noqa: C901 generation_output = float(generation_output) if power_unit == 'w': - generation_output = generation_output / 10^6 + generation_output = generation_output / 10**6 elif power_unit == 'kw': - generation_output = generation_output / 10^3 + generation_output = generation_output / 10**3 elif power_unit == 'mw': # just for the sake of completeness, we don't # need to convert here, since MW is our base unit From 15d2ff0db15ef0e5c2c70ff395c544419c02fcba Mon Sep 17 00:00:00 2001 From: Adam Zsarnoczay <33822153+zsarnoczay@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:36:40 -0800 Subject: [PATCH 18/18] ruff fix: remove whitespaces --- pelicun/resources/auto/Hazus_Earthquake_IM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelicun/resources/auto/Hazus_Earthquake_IM.py b/pelicun/resources/auto/Hazus_Earthquake_IM.py index e5b081d5..7d90da62 100644 --- a/pelicun/resources/auto/Hazus_Earthquake_IM.py +++ b/pelicun/resources/auto/Hazus_Earthquake_IM.py @@ -1336,7 +1336,7 @@ def auto_populate(aim): # noqa: C901 elif power_unit == 'mw': # just for the sake of completeness, we don't # need to convert here, since MW is our base unit - pass + pass elif power_unit == 'gw': generation_output = generation_output * 1000 @@ -1422,7 +1422,7 @@ def auto_populate(aim): # noqa: C901 f'. (Value = {generation_anchored}).' ) raise RuntimeError(msg) - + if ep_g_anchored is None: msg = ( 'Circuit anchored value is = '