Skip to content

Commit

Permalink
Merge pull request #123 from boschresearch/backport-fix-woehler-warnings
Browse files Browse the repository at this point in the history
Backport fix woehler warnings
  • Loading branch information
johannes-mueller authored Oct 30, 2024
2 parents 50e6b7f + 7cc690c commit d819724
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 27 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ In this file noteworthy changes of new releases of pyLife are documented since

* Massive performance improvement when reading element connectivity by
`odbclient.` Note that also `odbserver` needs to be updated in its
environment.
environment. (#121)

* Fix some warnings on import


## pylife-2.1.2
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ addopts =
--cov src/pylife --cov-append -m "not slow_acceptance and not demos"
--doctest-modules
--ignore=src/pylife/materialdata/woehler/bayesian.py
--ignore=src/pylife/strength/helpers.py
--ignore=src/pylife/strength/sn_curve.py

norecursedirs =
dist
Expand Down
2 changes: 1 addition & 1 deletion src/pylife/materialdata/woehler/elementary.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def analyze(self, **kwargs):
Parameters
----------
\*\*kwargs : kwargs arguments
**kwargs : kwargs arguments
Arguments to be passed to the derived class
"""
if len(self._fd.load.unique()) < 2:
Expand Down
43 changes: 20 additions & 23 deletions src/pylife/materialdata/woehler/maxlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,42 +125,39 @@ def warn_and_fix_if_less_than_two_mixed_levels():
warn_and_fix_if_no_runouts()
warn_and_fix_if_less_than_two_mixed_levels()

p_opt = initial_wcurve.to_dict()
prms_to_optimize = initial_wcurve.to_dict()
for k in fixed_prms:
p_opt.pop(k)
prms_to_optimize.pop(k)

if not p_opt:
if not prms_to_optimize:
raise AttributeError('You need to leave at least one parameter empty!')
var_opt = optimize.fmin(
self.__likelihood_wrapper, [*p_opt.values()],
args=([*p_opt], fixed_prms),
optimized_prms = optimize.fmin(
self.__likelihood_wrapper, [*prms_to_optimize.values()],
args=([*prms_to_optimize], fixed_prms),
full_output=True,
disp=False,
maxiter=1e4,
maxfun=1e4,
)
res = {}
res.update(fixed_prms)
res.update(zip([*p_opt], var_opt[0]))
)[0]

return self.__make_parameters(res)
# TODO: Change to following line when python 3.8 is dropped
#r esult = fixed_prms | dict(zip(prms_to_optimize, optimized_prms))

result = {}
result.update(fixed_prms)
result.update(zip(prms_to_optimize, optimized_prms))

return self.__make_parameters(result)

def __make_parameters(self, params):
params['SD'] = np.abs(params['SD'])
params['TS'] = np.abs(params['TS'])
params['k_1'] = np.abs(params['k_1'])
params['ND'] = np.abs(params['ND'])
params['TN'] = np.abs(params['TN'])
return params
return {k: np.abs(v) for k, v in params.items()}

def __likelihood_wrapper(self, var_args, var_keys, fix_args):
''' 1) Finds the start values to be optimized. The rest of the paramters are fixed by the user.
2) Calls function mali_sum_lolli to calculate the maximum likelihood of the current
variable states.
'''
# TODO: Change to following line when python 3.8 is dropped
# args = self.__make_parameters(fix_args | dict(zip(var_keys, var_args)))

args = {}
args.update(fix_args)
args.update(zip(var_keys, var_args))
args = self.__make_parameters(args)

return -self._lh.likelihood_total(args['SD'], args['TS'], args['k_1'], args['ND'], args['TN'])
return -self._lh.likelihood_total(**args)
7 changes: 6 additions & 1 deletion src/pylife/strength/meanstress.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ def sum_intervals(iv, ranges, obj):

range_itv_idx, means_itg_idx = resulting_intervals()

# TODO: remove once we drop python 3.8 support
future_stack = {} if pd.__version__ < "2.1" else {'future_stack': True}

if len(self._remaining_names) > 0:
remaining_idx = self._obj.index.to_frame(index=False).groupby(self._remaining_names).first().index
result = (
Expand All @@ -466,7 +469,9 @@ def sum_intervals(iv, ranges, obj):
)
result.index = remaining_idx
result.columns = pd.MultiIndex.from_arrays([result.columns, means_itg_idx])
result = result.stack(['range', 'mean']).reorder_levels(['range', 'mean'] + self._remaining_names)
result = result.stack(['range', 'mean'], **future_stack).reorder_levels(
['range', 'mean'] + self._remaining_names
)
else:
result = range_itv_idx.to_series().apply(lambda iv: sum_intervals(iv, ranges, self._obj))
result.index = pd.MultiIndex.from_arrays([result.index, means_itg_idx])
Expand Down
2 changes: 1 addition & 1 deletion src/pylife/stress/rainflow/fourpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class FourPointDetector(AbstractDetector):
"""Implements four point rainflow counting algorithm.
r"""Implements four point rainflow counting algorithm.
.. jupyter-execute::
Expand Down
1 change: 1 addition & 0 deletions tests/materialdata/woehler/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ def test_woehler_max_likelihood_full_without_fixed_params():
np.testing.assert_almost_equal(we.bayesian_information_criterion(), bic, decimal=2)


@pytest.mark.filterwarnings("ignore:invalid value encountered in subtract")
def test_woehler_max_likelihood_full_without_fixed_params_no_runouts():
expected = pd.Series({
'SD': 0,
Expand Down

0 comments on commit d819724

Please sign in to comment.