Skip to content

Commit

Permalink
Roll back addition of sample_size parameters in DL_calculation.py
Browse files Browse the repository at this point in the history
And linting.
  • Loading branch information
ioannis-vm committed May 27, 2024
1 parent bc50313 commit dc72f5a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pelicun/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def emit_warnings(self):
"""
for message in self.warning_stack:
if message not in self.emitted:
warnings.warn(message, PelicunWarning)
warnings.warn(message, PelicunWarning, stacklevel=2)
if self.warning_file is not None:
with open(self.warning_file, 'a', encoding='utf-8') as f:
f.write(
Expand Down
1 change: 0 additions & 1 deletion pelicun/model/damage_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def load_model_parameters(self, data_paths, cmp_set, warn_missing=False):

def calculate(
self,
sample_size=None,
dmg_process=None,
block_batch_size=1000,
scaling_specification=None,
Expand Down
9 changes: 7 additions & 2 deletions pelicun/model/loss_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def load_model_parameters(self, data_paths, decision_variables=None):
)
self._ensure_loss_parameter_availability()

def calculate(self, sample_size=None):
def calculate(self):
"""
Calculate the loss of each component block.
Expand Down Expand Up @@ -596,6 +596,11 @@ def save_sample(self, filepath=None, save_units=False):
Saves the sample of the `ds_model`.
Returns
-------
tuple
The output of {loss model}.ds_model.save_sample.
"""
self.log.warn(
'`{loss model}.save_sample` is deprecated and will raise '
Expand Down Expand Up @@ -1194,7 +1199,7 @@ def save_sample(self, filepath=None, save_units=False):
If no `filepath` is specified, returns:
* DataFrame containing the loss sample.
* Optionally, a Series containing the units for each
column if `save_units` is True.
column if `save_units` is True.
Raises
------
Expand Down
6 changes: 4 additions & 2 deletions pelicun/tests/basic/test_asset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,17 @@ def test_load_cmp_model_csv(self, asset_model):

def test_load_cmp_model_exceptions(self, asset_model):
cmp_marginals = pd.read_csv(
'pelicun/tests/basic/data/model/test_AssetModel/CMP_marginals_invalid_loc.csv',
'pelicun/tests/basic/data/model/test_AssetModel/'
'CMP_marginals_invalid_loc.csv',
index_col=0,
)
asset_model._asmnt.stories = 4
with pytest.raises(ValueError):
asset_model.load_cmp_model({'marginals': cmp_marginals})

cmp_marginals = pd.read_csv(
'pelicun/tests/basic/data/model/test_AssetModel/CMP_marginals_invalid_dir.csv',
'pelicun/tests/basic/data/model/test_AssetModel/'
'CMP_marginals_invalid_dir.csv',
index_col=0,
)
asset_model._asmnt.stories = 4
Expand Down
12 changes: 9 additions & 3 deletions pelicun/tests/basic/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,18 +856,24 @@ def test_parse_units():

# Test that an exception is raised if a unit is defined twice in
# the additional units file
duplicate_units_file = 'pelicun/tests/basic/data/base/test_parse_units/duplicate2.json'
duplicate_units_file = (
'pelicun/tests/basic/data/base/test_parse_units/duplicate2.json'
)
with pytest.raises(ValueError):
units = base.parse_units(duplicate_units_file)

# Test that an exception is raised if a unit conversion factor is not a float
invalid_units_file = 'pelicun/tests/basic/data/base/test_parse_units/not_float.json'
invalid_units_file = (
'pelicun/tests/basic/data/base/test_parse_units/not_float.json'
)
with pytest.raises(TypeError):
units = base.parse_units(invalid_units_file)

# Test that we get an error if some first-level key does not point
# to a dictionary
invalid_units_file = 'pelicun/tests/basic/data/base/test_parse_units/not_dict.json'
invalid_units_file = (
'pelicun/tests/basic/data/base/test_parse_units/not_dict.json'
)
with pytest.raises(ValueError):
units = base.parse_units(invalid_units_file)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_compatibility_DesignSafe_PRJ_3411_Example01():

P58_data_for_this_assessment = P58_data.loc[
loss_map['BldgRepair'].values[:-2], :
]
]

additional_consequences = pd.DataFrame(
columns=pd.MultiIndex.from_tuples(
Expand Down Expand Up @@ -189,7 +189,10 @@ def test_compatibility_DesignSafe_PRJ_3411_Example01():

with pytest.warns(PelicunWarning):
PAL.bldg_repair.load_model(
[additional_consequences, "PelicunDefault/bldg_repair_DB_FEMA_P58_2nd.csv"],
[
additional_consequences,
"PelicunDefault/bldg_repair_DB_FEMA_P58_2nd.csv",
],
loss_map,
)

Expand Down
4 changes: 2 additions & 2 deletions pelicun/tools/DL_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def run_pelicun(
)

# calculate damages
PAL.damage.calculate(sample_size, dmg_process=dmg_process)
PAL.damage.calculate(dmg_process=dmg_process)

# if requested, save results
if 'Damage' in config['DL']['Outputs']:
Expand Down Expand Up @@ -1622,7 +1622,7 @@ def run_pelicun(
decision_variables=DV_list,
)

PAL.repair.calculate(sample_size)
PAL.repair.calculate()

agg_repair = PAL.repair.aggregate_losses()

Expand Down

0 comments on commit dc72f5a

Please sign in to comment.