def test_determine_params_ptype(self): t = np.arange(0, 5, 0.001) c1 = self._cos(t, 2, 2, 0) c2 = self._cos(t, 5, 1.1, 1.5) c3 = self._cos(t, 8, 6, np.pi) # Highest amplitude S = c1 + c2 + c3 preprocessor = Preprocessor() norm_params = preprocessor.determine_params(t, S, energy_ratio=0.20, ptype="norm") lorentz_params = preprocessor.determine_params(t, S, energy_ratio=0.20, ptype="lorentz") # Expecting similar freqs and amps self.assertEqual(norm_params.shape, lorentz_params.shape, "Expecting same number of oscillators") self.assertTrue( np.allclose(norm_params[:, 0], lorentz_params[:, 0], atol=1e-1), "Expecting similar frequencies,\n" + str(norm_params[:, 0] - lorentz_params[:, 0])) self.assertTrue( np.allclose(norm_params[:, 1], lorentz_params[:, 1], atol=1e-1), "Expecting similar amplitudes,\n" + str(norm_params[:, 1] - lorentz_params[:, 1]))
def test_determine_params_energy_ratio(self): t = np.arange(0, 5, 0.001) c1 = self._cos(t, 2, 2, 0) c2 = self._cos(t, 5, 1.1, 1.5) c3 = self._cos(t, 8, 6, np.pi) # Highest amplitude c4 = self._cos(t, 15, 3, 0) S = c1 + c2 + c3 + c4 preprocessor = Preprocessor() high_energy = 0.8 params = preprocessor.determine_params(t, S, energy_ratio=high_energy) self.assertEqual(len(params), 1, "Only one oscillator") self.assertTrue( abs(params[0, 0] - 8) < 0.01, "Highest amp for osc with 8 Hz") mid_energy = 0.5 params = preprocessor.determine_params(t, S, energy_ratio=mid_energy) self.assertEqual(len(params), 2, "Two oscillators identified") self.assertTrue(abs(params[0, 0] - 15) < 0.01, "First osc with 15 Hz") self.assertTrue(abs(params[1, 0] - 8) < 0.01, "Second osc with 8 Hz") low_energy = 0.1 params = preprocessor.determine_params(t, S, energy_ratio=low_energy) self.assertEqual(len(params), 4, "All oscillators identified") self.assertTrue(abs(params[0, 0] - 15) < 0.01, "First osc with 15 Hz") self.assertTrue(abs(params[1, 0] - 8) < 0.01, "Second osc with 8 Hz") self.assertTrue(abs(params[2, 0] - 5) < 0.01, "Third osc with 5 Hz") self.assertTrue(abs(params[3, 0] - 2) < 0.01, "Fourth osc with 2 Hz")
def test_determine_params_max_oscillators(self): t = np.arange(0, 5, 0.001) c1 = self._cos(t, 2, 2, 0) c2 = self._cos(t, 5, 1.1, 1.5) c3 = self._cos(t, 8, 6, np.pi) # Highest amplitude c4 = self._cos(t, 15, 3, 0) S = c1 + c2 + c3 + c4 preprocessor = Preprocessor() max_peaks_1 = 1 params = preprocessor.determine_params(t, S, max_peaks=max_peaks_1) self.assertEqual(len(params), max_peaks_1, "Only one oscillator identified") max_peaks_2 = 2 params = preprocessor.determine_params(t, S, max_peaks=max_peaks_2) self.assertEqual(len(params), max_peaks_2, "Two oscillators identified") max_peaks_3 = 3 params = preprocessor.determine_params(t, S, max_peaks=max_peaks_3) self.assertEqual(len(params), max_peaks_3, "Three oscillators identified")
def test_determine_params_default(self): t = np.arange(0, 5, 0.001) c1 = self._cos(t, 2, 2, 0) c2 = self._cos(t, 5, 1.1, 1) S = c1 + c2 preprocessor = Preprocessor() params = preprocessor.determine_params(t, S) # Testing for number self.assertEqual(params.shape, (2, 4), "Two oscillators with (W, A, s, ph)") # Testing for frequency self.assertTrue( abs(params[0, 0] - 5) < 0.001, "First oscillator is with 5 Hz") self.assertTrue( abs(params[1, 0] - 2) < 0.001, "Second oscillator is with 2 Hz") # Testing for phase self.assertTrue( abs(params[0, 3] - 1) < 0.001, "First oscillator has phase 1") self.assertTrue( abs(params[1, 3] - 0) < 0.001, "Second oscillator has phase 0")