histogram¶
Overview
Bin stress ranges and means and export rainflow counts.
py_fatigue.cycle_count.histogram ¶
The following code is based on the histogram function from the numpy
package [4]_.
.. _[4]: https://numpy.org/doc/stable/reference/generated/numpy.histogram2d
Classes¶
Functions:¶
binned_rainflow ¶
binned_rainflow(
data,
time=None,
range_bin_lower_bound=0.2,
range_bin_width=0.05,
range_bin_upper_bound=None,
mean_bin_lower_bound=None,
mean_bin_width=10.0,
mean_bin_upper_bound=None,
damage_tolerance_for_binning=0.001,
max_consetutive_zeros=10,
damage_exponent=5.0,
round_decimals=4,
debug_mode=False,
rainflow_method="astm",
)
Returns the cycle-count of the input data calculated through the rainflow method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
time series or residuals sequence |
required |
time
|
Optional[Union[ndarray, list]]
|
sampled times, by default None |
None
|
range_bin_lower_bound
|
float
|
lower bound of the range bin, by default 0.2 |
0.2
|
range_bin_width
|
float
|
width of the range bin, by default 0.05 |
0.05
|
range_bin_upper_bound
|
Optional[float]
|
upper bound of the range bin, by default None |
None
|
mean_bin_lower_bound
|
Optional[float]
|
lower bound of the mean bin, by default None |
None
|
mean_bin_width
|
float
|
width of the mean bin, by default 10 |
10.0
|
mean_bin_upper_bound
|
Optional[float]
|
upper bound of the mean bin, by default None |
None
|
damage_tolerance_for_binning
|
float
|
tolerance for the damage when binning large cycles separately, by default 1e-3 |
0.001
|
damage_exponent
|
float
|
exponent for the damage when binning large cycles separately, by default 5.0 |
5.0
|
round_decimals
|
int
|
number of decimals to round the output, by default 4 |
4
|
debug_mode
|
bool
|
if True, print debug messages, by default False |
False
|
rainflow_method
|
str
|
Rainflow counting algorithm passed to
|
'astm'
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, tuple]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
data shall be numpy.ndarray or list |
See also
calc_rainflow rainflow_binner
Source code in py_fatigue/cycle_count/histogram.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
initialise_binned_rainflow_dict ¶
initialise_binned_rainflow_dict(
ranges, means, nr_small_cycles, no_mean_stress=False
)
Initialises the binned rainflow dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
StressRange
|
The stress range object. |
required |
means
|
MeanStress
|
The mean stress object. |
required |
nr_small_cycles
|
int
|
The number of small cycles. |
required |
no_mean_stress
|
bool
|
Whether to ignore mean stress. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
The initialised binned rainflow dictionary. |
Source code in py_fatigue/cycle_count/histogram.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
make_axes ¶
make_axes(fig=None, ax=None)
Check if a figure and axes are provided, and if not, create them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Optional[Figure]
|
The figure instance, by default None |
None
|
ax
|
Optional[Axes]
|
The axes instance, by default None |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
The figure and axes instances |
Raises:
| Type | Description |
|---|---|
TypeError
|
If fig is not a matplotlib.figure.Figure instance |
Source code in py_fatigue/utils.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
make_histogram ¶
make_histogram(
mean_stress,
stress_range,
bins=10,
bin_range=None,
normed=False,
weights=None,
)
Make a scattered-histogram plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean_stress
|
(array_like, shape(n))
|
Input data |
required |
stress_range
|
(array_like, shape(n))
|
Input data |
required |
bins
|
int or array_like or [int, int] or [array, array]
|
The bin specification: * If int, the number of bins for the two dimensions (nx=ny=bins). * If array_like, the bin edges for the two dimensions (stress_range_edges=mean_stress_edges=bins). * If [int, int], the number of bins in each dimension (n_stress_range, n_mean_stress = bins). * If [array, array], the bin edges in each dimension (stress_range_edges, mean_stress_edges = bins). * A combination [int, array] or [array, int], where int is the number of bins and array is the bin edges. |
10
|
bin_range
|
(array_like, shape(2, 2))
|
The leftmost and rightmost edges of the bins along each dimension
(if not specified explicitly in the |
None
|
normed
|
bool
|
If False, returns the number of samples in each bin. If True,
returns the bin density |
False
|
weights
|
(array_like, shape(N))
|
An array of values |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
hist |
`np.ndarray`, shape(m,m)
|
Histogram matrix. |
hist_edges |
(ArrayArray, (shape(m + 1), shape(m + 1)))
|
Histogram bin edges. |
Source code in py_fatigue/cycle_count/histogram.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
map_hist ¶
map_hist(x, y, h, hist_bin_edges)
Maps the histogram to the original data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x-axis of the original data |
required |
y
|
ndarray
|
y-axis of the original data |
required |
h
|
ndarray
|
histogram |
required |
hist_bin_edges
|
tuple
|
histogram bin edges |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
mapped histogram |
Source code in py_fatigue/cycle_count/histogram.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
rainflow_binner ¶
rainflow_binner(
ranges,
_means,
damage_tolerance_for_binning=0.001,
damage_exponent=5.0,
max_consecutive_zeros=12,
round_decimals=4,
debug_mode=True,
)
Binning the rainflow cycles into mean-range bins up to a certain stress range which is based on the damage tolerance index. All the cycles beyond such stress range are saved separately for accuracy reasons as "large cycles".
By default, large cycles are calculated from all the cycles accounting for more than 0.1% of the total damage and that have a discrepancy of more than 0.1% with respect to the damage that would be obtained from the bin center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
StressRange
|
The stress range object. |
required |
_means
|
Optional[MeanStress]
|
The mean stress object. If not provided, the mean stress is set to zero. |
required |
damage_tolerance_for_binning
|
float
|
tolerance for the damage when binning large cycles separately, by default 1e-3 |
0.001
|
damage_exponent
|
float
|
exponent for the damage when binning large cycles separately, by default 5.0 |
5.0
|
max_consecutive_zeros
|
int
|
maximum number of consecutive zeros before saving a cycle to large cycles array. This quantity is introduced to save storage space, by default 8 |
12
|
round_decimals
|
int
|
number of decimals to round the output, by default 4 |
4
|
debug_mode
|
bool
|
if True, print debug messages, by default False |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
out_dct |
dict
|
A dictionary with the following keys: - "nr_small_cycles": number of small cycles - "range_bin_lower_bound": lower bound of the range bin - "range_bin_width": width of the range bins - "mean_bin_lower_bound": lower bound of the mean bin - "mean_bin_width": width of the mean bins - "hist": histogram of the rainflow cycles - "lg_c": large cycles - "res": residuals - "res_sig": residuals sequence |
See Also
make_histogram
Source code in py_fatigue/cycle_count/histogram.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
rainflow_threshold ¶
rainflow_threshold(ranges, means)
Removes the rainflow cycles below threshold for a given stress range and mean stress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
StressRange
|
The stress range object. |
required |
means
|
MeanStress
|
The mean stress object. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
The ranges and means above threshold, as well as small cycles. |
Source code in py_fatigue/cycle_count/histogram.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
xy_hist2d ¶
xy_hist2d(
x,
y,
mode="mountain",
bins=10,
bin_range=None,
normed=False,
weights=None,
fig=None,
ax=None,
dens_func=None,
**kwargs
)
Make a scattered-histogram plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(n))
|
Input data |
required |
y
|
(array_like, shape(n))
|
Input data |
required |
marker_size
|
int
|
Size of the markers |
required |
mode
|
str
|
Possible values are: - None : The points are plotted as one scatter object, in the order in-which they are specified at input. - 'mountain' : The points are sorted/plotted in the order of the number of points in their 'bin'. This means that points in the highest density will be plotted on-top of others. This cleans-up the edges a bit, the points near the edges will overlap. - 'valley' : The reverse order of 'mountain'. The low density bins are plotted on top of the high ones. |
'mountain'
|
bins
|
int or array_like or [int, int] or [array, array]
|
The bin specification: - If int, the number of bins for the two dimensions (nx=ny=bins). - If array_like, the bin edges for the two dimensions (x_edges = y_edges = bins). - If [int, int], the number of bins in each dimension (n_x, n_y = bins). - If [array, array], the bin edges in each dimension (x_edges, y_edges = bins). - A combination [int, array] or [array, int], where int is the number of bins and array is the bin edges. |
10
|
bin_range
|
(array_like, shape(2, 2))
|
The leftmost and rightmost edges of the bins along each dimension
(if not specified explicitly in the |
None
|
normed
|
bool
|
If False, returns the number of samples in each bin. If True,
returns the bin density |
False
|
weights
|
(array_like, shape(N))
|
An array of values |
None
|
fig
|
a figure instance to add.
|
|
None
|
ax
|
an axes instance to plot into.
|
|
None
|
dens_func
|
function or callable (default: None)
|
A function that modifies (inputs and returns) the dens values (e.g., np.log10). The default is to not modify the values. |
None
|
x_label
|
str
|
Label for the x-axis |
required |
y_label
|
str
|
Label for the y-axis |
required |
cbar_label
|
str
|
Label for the colorbar |
required |
kwargs
|
these are all passed on to scatter.
|
|
{}
|
Returns:
| Type | Description |
|---|---|
figure, paths : (
|
|
)
|
The figure with scatter instance. |
Source code in py_fatigue/cycle_count/histogram.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |