Skip to content

Commit 4966fd0

Browse files
Fix doctest
Signed-off-by: Johannes Mueller <[email protected]>
1 parent 9a57d55 commit 4966fd0

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

src/pylife/strength/fkm_load_distribution.py

+42-25
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,58 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
r'''Scale up a load sequence to incorporate safety factors for FKM
17+
"""Scale up a load sequence to incorporate safety factors for FKM
1818
nonlinear lifetime assessment.
1919
20-
Given a pandas Series of load values, return a scaled version where the safety has been incorporated.
21-
The series is scaled by a constant value :math:`\gamma_L`, which models the distribution of the load,
22-
the severity of the failure (modeled by :math:`P_A`) and the considered load probability of either
23-
:math:`P_L=2.5 \%` or :math:`P_L=50 \%`.
20+
Given a pandas Series of load values, return a scaled version where the safety
21+
has been incorporated. The series is scaled by a constant value
22+
:math:`\gamma_L`, which models the distribution of the load, the severity of
23+
the failure (modeled by :math:`P_A`) and the considered load probability of
24+
either :math:`P_L=2.5 \%` or :math:`P_L=50 \%`.
2425
25-
The FKM nonlinear guideline defines three possible methods to consider the statistical distribution of the load:
26+
The FKM nonlinear guideline defines three possible methods to consider the
27+
statistical distribution of the load:
2628
2729
* a normal distribution with given standard deviation, $s_L$
2830
* a logarithmic-normal distribution with given standard deviation $LSD_s$
29-
* an unknown distribution, use the constant factor :math:`\gamma_L=1.1` for $P_L = 2.5\%$
31+
* an unknown distribution, use the constant factor :math:`\gamma_L=1.1` for
32+
$P_L = 2.5\%$
3033
31-
For these three methods, there exist the three accessors `fkm_safety_normal_from_stddev`, `fkm_safety_lognormal_from_stddev`,
32-
and `fkm_safety_blanket`.
34+
For these three methods, there exist the three accessors
35+
`fkm_safety_normal_from_stddev`, `fkm_safety_lognormal_from_stddev`, and
36+
`fkm_safety_blanket`.
3337
34-
The resulting scaling factor can be retrieved with ``.gamma_L(input_parameters)``, the scaled load series can be obtained
35-
with ``.scaled_load_sequence(input_parameters)``.
38+
The resulting scaling factor can be retrieved with
39+
``.gamma_L(input_parameters)``, the scaled load series can be obtained with
40+
``.scaled_load_sequence(input_parameters)``.
3641
3742
Examples
3843
--------
39-
Assuming ``load_sequence`` is a pandas Series of load values and ``input_parameters`` is a series containing the required
40-
parameters, apply the three possible scaling methods as follows:
4144
45+
>>> input_parameters = pd.Series({"P_A": 1e-5, "P_L": 50, "s_L": 10, "LSD_s": 1e-2,})
46+
>>> load_sequence = pd.Series([100.0, 150.0, 200.0], name="load")
4247
>>> # uses input_parameters.s_L, input_parameters.P_L, input_parameters.P_A
43-
>>> scaled_load_sequence = load_sequence.fkm_safety_normal_from_stddev.scaled_load_sequence(input_parameters)
48+
>>> load_sequence.fkm_safety_normal_from_stddev.scaled_load_sequence(input_parameters)
49+
0 114.9450
50+
1 172.4175
51+
2 229.8900
52+
Name: load, dtype: float64
4453
4554
>>> # uses input_parameters.s_L, input_parameters.P_L, input_parameters.P_A
46-
>>> scaled_load_sequence = load_sequence.fkm_safety_lognormal_from_stddev.scaled_load_sequence(input_parameters)
55+
>>> load_sequence.fkm_safety_lognormal_from_stddev.scaled_load_sequence(input_parameters)
56+
0 107.124794
57+
1 160.687191
58+
2 214.249588
59+
Name: load, dtype: float64
4760
4861
>>> # uses input_parameters.P_L
49-
>>> scaled_load_sequence = load_sequence.fkm_safety_blanket.scaled_load_sequence(input_parameters)
62+
>>> load_sequence.fkm_safety_blanket.scaled_load_sequence(input_parameters)
63+
0 100.0
64+
1 150.0
65+
2 200.0
66+
Name: load, dtype: float64
5067
51-
'''
68+
"""
5269

5370
__author__ = "Benjamin Maier"
5471
__maintainer__ = __author__
@@ -60,7 +77,7 @@
6077
@pd.api.extensions.register_dataframe_accessor("fkm_load_sequence")
6178
@pd.api.extensions.register_series_accessor("fkm_load_sequence")
6279
class FKMLoadSequence(PylifeSignal):
63-
'''Base class used by the safety scaling method. It is used to compute the beta parameter
80+
"""Base class used by the safety scaling method. It is used to compute the beta parameter
6481
and to scale the load sequence by a constant gamma_L.
6582
6683
This class can be used from user code to scale a load sequence, potentially on a mesh with other fields set for every node.
@@ -86,7 +103,7 @@ class FKMLoadSequence(PylifeSignal):
86103
87104
# scale the load sequence by the factor 2, note that col2 is not scaled
88105
mesh.fkm_load_sequence.scaled_by_constant(2)
89-
'''
106+
"""
90107

91108
def scaled_by_constant(self, gamma_L):
92109
"""
@@ -226,7 +243,7 @@ def _get_beta(self, input_parameters):
226243
@pd.api.extensions.register_dataframe_accessor("fkm_safety_normal_from_stddev")
227244
@pd.api.extensions.register_series_accessor("fkm_safety_normal_from_stddev")
228245
class FKMLoadDistributionNormal(FKMLoadSequence):
229-
r'''Series accessor to get a scaled up load series, i.e., a list of load values with included load safety,
246+
r"""Series accessor to get a scaled up load series, i.e., a list of load values with included load safety,
230247
as used in FKM nonlinear lifetime assessments.
231248
232249
The loads are assumed to follow a **normal distribution** with standard deviation :math:`s_L`.
@@ -239,7 +256,7 @@ class FKMLoadDistributionNormal(FKMLoadSequence):
239256
See also
240257
--------
241258
:class:`AbstractFKMLoadDistribution`: accesses meshes with connectivity information
242-
'''
259+
"""
243260

244261
def gamma_L(self, input_parameters):
245262
r"""Compute the scaling factor :math:`\gamma_L=(L_\text{max} + \alpha_L) / L_\text{max}`.
@@ -324,7 +341,7 @@ def scaled_load_sequence(self, input_parameters):
324341
@pd.api.extensions.register_dataframe_accessor("fkm_safety_lognormal_from_stddev")
325342
@pd.api.extensions.register_series_accessor("fkm_safety_lognormal_from_stddev")
326343
class FKMLoadDistributionLognormal(FKMLoadSequence):
327-
r'''Series accessor to get a scaled up load series, i.e., a list of load values with included load safety,
344+
r"""Series accessor to get a scaled up load series, i.e., a list of load values with included load safety,
328345
as used in FKM nonlinear lifetime assessments.
329346
330347
The loads are assumed to follow a **lognormal distribution** with standard deviation :math:`LSD_s`.
@@ -337,7 +354,7 @@ class FKMLoadDistributionLognormal(FKMLoadSequence):
337354
See also
338355
--------
339356
:class:`AbstractFKMLoadDistribution`: accesses meshes with connectivity information
340-
'''
357+
"""
341358

342359
def gamma_L(self, input_parameters):
343360
r"""Compute the scaling factor :math:`\gamma_L`.
@@ -413,7 +430,7 @@ def scaled_load_sequence(self, input_parameters):
413430
@pd.api.extensions.register_dataframe_accessor("fkm_safety_blanket")
414431
@pd.api.extensions.register_series_accessor("fkm_safety_blanket")
415432
class FKMLoadDistributionBlanket(FKMLoadSequence):
416-
r'''Series accessor to get a scaled up load series, i.e., a list of load values with included load safety,
433+
r"""Series accessor to get a scaled up load series, i.e., a list of load values with included load safety,
417434
as used in FKM nonlinear lifetime assessments.
418435
419436
The distribution of loads is unknown, therefore a scaling factor of :math:`\gamma_L` = 1.1 is assumed.
@@ -426,7 +443,7 @@ class FKMLoadDistributionBlanket(FKMLoadSequence):
426443
See also
427444
--------
428445
:class:`AbstractFKMLoadDistribution`: accesses meshes with connectivity information
429-
'''
446+
"""
430447

431448
def gamma_L(self, input_parameters):
432449
r"""Compute the scaling factor :math:`\gamma_L`.

tests/strength/test_fkm_load_distribution.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def test_load_distribution_normal_1(P_A, resulting_gamma_L, result):
3636
# test with a plain series
3737
load_sequence = pd.Series([100, -200, 100, -250, 200, 0, 200, -200]) # [N]
3838

39-
assessment_parameters = pd.Series({
40-
"P_A": P_A,
41-
"P_L": 50,
42-
"s_L": 10,
43-
})
39+
assessment_parameters = pd.Series({"P_A": P_A, "P_L": 50, "s_L": 10})
4440

4541
# FKMLoadDistributionNormal, uses assessment_parameters.s_L, assessment_parameters.P_L, assessment_parameters.P_A
46-
scaled_load_sequence = load_sequence.fkm_safety_normal_from_stddev.scaled_load_sequence(assessment_parameters)
42+
scaled_load_sequence = (
43+
load_sequence.fkm_safety_normal_from_stddev.scaled_load_sequence(
44+
assessment_parameters
45+
)
46+
)
4747
gamma_L = load_sequence.fkm_safety_normal_from_stddev.gamma_L(assessment_parameters)
4848

4949
assert np.isclose(gamma_L, resulting_gamma_L)
@@ -164,11 +164,7 @@ def test_load_distribution_lognormal(P_L, resulting_gamma_L, result):
164164
load_sequence = pd.Series([100, -200, 100, -250, 200, 0, 200, -200]) # [N]
165165

166166
# FKMLoadDistributionLognormal, uses assessment_parameters.LSD_s, assessment_parameters.P_L, assessment_parameters.P_A
167-
assessment_parameters = pd.Series({
168-
"P_A": 7.2e-5,
169-
"P_L": P_L,
170-
"LSD_s": 1e-2,
171-
})
167+
assessment_parameters = pd.Series({"P_A": 7.2e-5, "P_L": P_L, "LSD_s": 1e-2})
172168

173169
scaled_load_sequence = load_sequence.fkm_safety_lognormal_from_stddev.scaled_load_sequence(assessment_parameters)
174170
gamma_L = load_sequence.fkm_safety_lognormal_from_stddev.gamma_L(assessment_parameters)

0 commit comments

Comments
 (0)