def test_remove_peak_unknown_value(self): """Test removing single peak with unknown peak name. It should throw ValueError exception.""" t = np.arange(0, 2, 0.001) peak_in = np.random.random(t.size) with self.assertRaises(ValueError) as context: Preprocessor._remove_peak(t, peak_in, ptype="unknown") self.assertTrue("Incorrect ptype value" in str(context.exception)) with self.assertRaises(ValueError) as context: Preprocessor._remove_peak(t, peak_in, ptype="other") self.assertTrue("Incorrect ptype value" in str(context.exception))
def test_remove_peak_lorentz(self): """Test removing single peak as a Lorentzian peak""" t = np.arange(0, 3, 0.001) param_in = np.array([0.8, 2.5, 0.2]) peak_in = self.peak_lorentz(t, param_in[0], param_in[1], param_in[2]) peak_out, param_out = Preprocessor._remove_peak(t, peak_in, ptype="lorentz") self.assertTrue(np.allclose(param_in, param_out), "Parameters should be the same") self.assertTrue(np.allclose(peak_in, peak_out), "Peaks should be the same")
def test_remove_peak_triangle(self): """Test removing single peak as a triangle peak""" t = np.arange(0, 2, 0.001) param_in = np.array([0.5, 1.5, 0.3]) peak_in = self.peak_triangle(t, param_in[0], param_in[1], param_in[2]) peak_out, param_out = Preprocessor._remove_peak(t, peak_in, ptype="triang") self.assertTrue(np.allclose(param_in, param_out), "Parameters should be the same") self.assertTrue(np.allclose(peak_in, peak_out), "Peaks should be the same")
def test_remove_peak_norm(self): """Test removing single peak as a Gaussian peak""" #If too small segment then it doesn't converge properly t = np.arange(0, 2, 0.001) param_in = np.array([1.2, 0.4, 0.1]) peak_in = self.peak_norm(t, param_in[0], param_in[1], param_in[2]) peak_out, param_out = Preprocessor._remove_peak(t, peak_in, ptype='norm') self.assertTrue(np.allclose(param_in, param_out), "Parameters should be the same") self.assertTrue(np.allclose(peak_in, peak_out), "Peaks should be the same")