def test_rainflow_rebinning_nbin2(self): """ Test that values are correctly gathered to 2 bins """ self.assertEqual( self.cycles_n2, rainflow.rebin(rainflow.count_cycles(self.series), n=2))
def test_series_with_zero_derivatives(self): """ Duplicate values in series to create zero derivatives (platou). Test that these are ignored by the cycle counting. """ series = itertools.chain(*([x, x] for x in self.series)) self.assertEqual(self.cycles, rainflow.count_cycles(series))
def test_rainflow_rebinning_binwidth5(self): """ Test that values are correctly gathered to new bins of width 5 """ self.assertEqual( self.cycles_bw5, rainflow.rebin(rainflow.count_cycles(self.series), w=5.))
def test_rainflow_counting(self): """ Standard test """ # self.assertEqual(np.array(self.cycles), rainflow.count_cycles(self.series)) # np.testing module ensures that the list `self.cycles` may be compared to the array returned from count_cycles np.testing.assert_array_equal(self.cycles, rainflow.count_cycles(self.series))
def test_rainflow_counting_using_reversals(self): """ Test that cycle counting using reversals works if endpoints=True """ reversals = list(rainflow.reversals(self.series)) self.assertEqual(self.cycles, rainflow.count_cycles(reversals, endpoints=True))
def test_mesh(self): """ Multiple tests to ensure meshgrid returned from mesh() is correct. """ # no. of range and mean bins, respectively (should be different to avoid hiding errors caused by transposing) nr, nm = 100, 50 # raw cycles cycles = rainflow.count_cycles(self.irreg_series) # rebinned cycles - will be used to verify mesh cycles_rebinned_range = rainflow.rebin(cycles, binby='range', n=nr) cycles_rebinned_mean = rainflow.rebin(cycles, binby='mean', n=nm) # generate mesh rmesh, mmesh, cmesh = rainflow.mesh(cycles, nr=nr, nm=nm) # tests # (shape) np.testing.assert_equal(cmesh.shape, (nm, nr), err_msg=f"Shape of mesh is wrong, should be {(nm, nr)}") np.testing.assert_equal(cmesh.shape, rmesh.shape, err_msg="Shapes do not match: 'cmesh' and 'rmesh'") np.testing.assert_equal(cmesh.shape, mmesh.shape, err_msg="Shapes do not match: 'cmesh' and 'mmesh'") # (sum of counts; total and along each axis) np.testing.assert_equal(cycles[:, 2].sum(), cmesh.sum(), err_msg="Sum of counts and mesh not equal") np.testing.assert_array_equal(cycles_rebinned_range[:, 2], cmesh.sum(axis=0), err_msg=f"Sum of counts along mean axis (constant ranges) are wrong") np.testing.assert_array_equal(cycles_rebinned_mean[:, 2], cmesh.sum(axis=1), err_msg=f"Sum of counts along range axis (constant means) are wrong") # (bins along respective axes should match bins obtained by rebinning by 'range' and 'mean', respectively) np.testing.assert_array_equal(rmesh[0, :], cycles_rebinned_range[:, 0], err_msg="Range mesh error (transposed by 'accident'?)") np.testing.assert_array_equal(mmesh[:, 0], cycles_rebinned_mean[:, 1], err_msg="Mean mesh error (transposed by 'accident'?)")
def test_rebin_sum_of_counts(self): """ Test that rebinning does not alter total number of counts. """ cycles = rainflow.count_cycles(self.irreg_series) cycles_rebinned_range = rainflow.rebin(cycles, binby='range', n=50) self.assertEqual(cycles[:, 2].sum(), cycles_rebinned_range[:, 2].sum(), msg="Total cycle counts changed after rebinning.")
def test_rainflow_rebinning_binwidth2(self): """ Test that values are correctly gathered to new bins of width 2 """ # self.assertEqual(self.cycles_bw2, rainflow.rebin(rainflow.count_cycles(self.series), w=2.)) # np.testing.assert_array_equal(self.cycles_bw2, rainflow.rebin(rainflow.count_cycles(self.series), w=2.)) np.testing.assert_array_almost_equal(self.cycles_bw2, rainflow.rebin(rainflow.count_cycles(self.series), w=2.), decimal=6)
def test_rainflow_counting_with_endpoints(self): """ Test cycle counting when end points are included. """ self.assertEqual(self.cycles_endpoints, rainflow.count_cycles(self.series, endpoints=True))
def test_rainflow_counting(self): """ Standard test """ self.assertEqual(self.cycles, rainflow.count_cycles(self.series))