Exemple #1
0
    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'?)")
Exemple #2
0
 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))
Exemple #3
0
 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.))
Exemple #4
0
 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.")
Exemple #5
0
    def test_rainflow_rebin_exceptions(self):
        """
        Test that rebinning raises errors as it should do
        """
        try:
            _ = rainflow.rebin(self.cycles, binby='nothing')
        except ValueError:
            pass
        else:
            self.fail("Did not raise ValueError when binby was not equal to neither 'mean' nor 'range'.")

        try:
            _ = rainflow.rebin(self.cycles)
        except ValueError:
            pass
        else:
            self.fail("Did not raise ValueError when neither `n` nor `w` were specified.")
Exemple #6
0
 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)