def fit(frequencies, stats, center_freq, width=None, obs_length=None, baseline=0): estimated_amp = stats[np.argmin(np.abs(frequencies - center_freq))] if obs_length is not None: s = fit_sinc(frequencies, stats - baseline, obs_length=obs_length, amp=estimated_amp, mean=center_freq) else: df = frequencies[1] - frequencies[0] if width is None: width = 2 * df s = fit_gaussian(frequencies, stats - baseline, stddev=width, amplitude=estimated_amp, mean=center_freq) return s
def test_sinc_fixed(): x = np.linspace(-5., 5., 200) y = 2 * (np.sin(x)/x)**2 y += np.random.normal(0., 0.1, x.shape) sf = fit_sinc(x, y, mean=1., fixed={"mean": True, "amplitude": False}) assert sf.mean.fixed assert not sf.amplitude.fixed
def test_sinc_function(): x = np.linspace(-5., 5., 200) y = 2 * (np.sin(x)/x)**2 y += np.random.normal(0., 0.1, x.shape) s = fit_sinc(x, y) assert np.abs(s.mean) < 0.1 assert np.abs(s.amplitude - 2) < 0.1 assert np.abs(s.width - 1) < 0.1
def test_sinc_obs(): obs_length = 0.32 x = np.linspace(-5., 5., 200) w = 1 / (np.pi*obs_length) y = 2 * (np.sin(x / w) / (x / w))**2 y += np.random.normal(0., 0.1, x.shape) s = fit_sinc(x, y, obs_length=obs_length) assert np.abs(1 / (np.pi*obs_length) - s.width) < 0.1 assert s.width.fixed