Skip to content

Commit

Permalink
Turn warning into an error.
Browse files Browse the repository at this point in the history
Also reorders the branches of the if statement to avoid excessive
indentation.
  • Loading branch information
ioannis-vm committed Dec 6, 2024
1 parent e3eb4d7 commit 457bdd3
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions pelicun/model/damage_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ def map_ds(values: np.ndarray, offset: int) -> np.ndarray:

def parse_scaling_specification(scaling_specification: dict) -> dict: # noqa: C901
"""
Parse and validate the scaling specification, used in the '_create_dmg_RVs' method.
Parse and validate the scaling specification.
Parameters
----------
Expand All @@ -1353,6 +1353,8 @@ def parse_scaling_specification(scaling_specification: dict) -> dict: # noqa: C
------
ValueError
If the scaling specification is invalid.
ValueError
If an unupported distribution is specified.
TypeError
If the type of an entry is invalid.
"""
Expand Down Expand Up @@ -1481,34 +1483,36 @@ def parse_scaling_specification(scaling_specification: dict) -> dict: # noqa: C
)

if capacity_adjustment_operation:
if family in {'normal', 'lognormal'}:
# Only scale the median value if ls_id is defined in capacity_adjustment_operation
# Otherwise, use the original value
new_theta_0 = None
if 'ALL' in capacity_adjustment_operation:
new_theta_0 = self._handle_operation_list(
theta[0],
capacity_adjustment_operation['ALL'],
)
elif f'LS{ls_id}' in capacity_adjustment_operation:
new_theta_0 = self._handle_operation_list(
theta[0],
capacity_adjustment_operation[f'LS{ls_id}'],
)
if new_theta_0 is not None:
if new_theta_0.size == 1:
theta[0] = new_theta_0[0]
else:
# Repeat the theta values new_theta_0.size times along axis 0
# and 1 time along axis 1
theta = np.tile(theta, (new_theta_0.size, 1))
theta[:, 0] = new_theta_0
else:
self.log.warning(
if family not in {'normal', 'lognormal'}:
msg = (
f'Capacity adjustment is only supported '
f'for `normal` or `lognormal` distributions. '
f'Ignoring: `{cmp_loc_dir}`, which is `{family}`'
)
raise ValueError(msg) # noqa: DOC501
# Only scale the median value if ls_id is
# defined in capacity_adjustment_operation
# Otherwise, use the original value
new_theta_0 = None
if 'ALL' in capacity_adjustment_operation:
new_theta_0 = self._handle_operation_list(
theta[0],
capacity_adjustment_operation['ALL'],
)
elif f'LS{ls_id}' in capacity_adjustment_operation:
new_theta_0 = self._handle_operation_list(
theta[0],
capacity_adjustment_operation[f'LS{ls_id}'],
)
if new_theta_0 is not None:
if new_theta_0.size == 1:
theta[0] = new_theta_0[0]
else:
# Repeat the theta values
# new_theta_0.size times along
# axis 0 and 1 time along axis 1
theta = np.tile(theta, (new_theta_0.size, 1))
theta[:, 0] = new_theta_0

tr_lims = np.array(
[
Expand Down

0 comments on commit 457bdd3

Please sign in to comment.