Skip to content

Commit d6c6d5c

Browse files
author
Garrett Barter
committed
robust selection of number of bins
1 parent 7a2801e commit d6c6d5c

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

pCrunch/aeroelastic_output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,14 @@ def kurtosis(self):
446446

447447
@dataproperty
448448
def integrated(self):
449-
return np.trapz(self.data, self.time, axis=0)
449+
return np.trapezoid(self.data, self.time, axis=0)
450450

451451
def compute_energy(self, pwrchan):
452-
return np.trapz(self[pwrchan], self.time)
452+
return np.trapezoid(self[pwrchan], self.time)
453453

454454
def total_travel(self, chanstr):
455455
dchan = np.gradient(self[chanstr], self.time)
456-
return np.trapz(np.abs(dchan), self.time)
456+
return np.trapezoid(np.abs(dchan), self.time)
457457

458458
def histogram(self, chanstr, bins=15):
459459
return np.histogram(self[chanstr], bins=bins, density=False)

pCrunch/fatigue.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,17 @@ def get_rainflow_counts(self, chan, bins, S_ult=None, goodman=False):
298298
Default: False
299299
S_ult: float (optional)
300300
Ultimate stress/load for the material
301+
302+
Returns
303+
-------
304+
N, S : 1darray
305+
The count and the characteristic value for the ranges.
301306
"""
302307

303308
try:
304-
S, Mrf = fatpack.find_rainflow_ranges(chan, k=256, return_means=True)
309+
ranges, Mrf = fatpack.find_rainflow_ranges(chan, k=256, return_means=True)
305310
except Exception:
306-
S = Mrf = np.zeros(1)
311+
ranges = Mrf = np.zeros(1)
307312

308313
if goodman:
309314
if S_ult is None:
@@ -312,9 +317,23 @@ def get_rainflow_counts(self, chan, bins, S_ult=None, goodman=False):
312317
if S_ult == 0.0:
313318
raise ValueError('Must specify an ultimate_stress to use Goodman correction')
314319

315-
S = fatpack.find_goodman_equivalent_stress(S, Mrf, S_ult)
316-
317-
return fatpack.find_range_count(S, bins)
320+
ranges = fatpack.find_goodman_equivalent_stress(ranges, Mrf, S_ult)
321+
322+
success = False
323+
while not success:
324+
try:
325+
N, S = fatpack.find_range_count(ranges, bins)
326+
success = True
327+
except ValueError:
328+
bins *= 0.5
329+
if bins < 1:
330+
print(ranges)
331+
print(bins)
332+
raise Exception("Failed to find bins for ranges")
333+
else:
334+
bins = int(bins)
335+
336+
return N, S
318337

319338

320339
def compute_del(self, chan, elapsed_time, **kwargs):

0 commit comments

Comments
 (0)