def test_get_data(): ex_f = np.array([1, 2, 3, 4, 5]) ex_PSD = np.array([[1.1, 1.2, 1.2, 1.3], [2.4, 2.7, 2.4, 2.7], [3.95, 3.9, 4, 3.8], [5, 5.4, 5.7, 4.7], [5, 6, 6, 4]]) # Create the test HDF5 file with h5py.File('test.h5', 'w', driver='core', backing_store=False) as fh: fh['x'] = ex_f fh['y'] = ex_PSD.mean(axis=1) fh['y'].attrs['n_avg'] = ex_PSD.shape[1] # Need ddof=1 to get sample standard deviation, rather than population. fh['y_std'] = ex_PSD.std(axis=1, ddof=1) ex_mean = np.array([1.2, 2.55, 3.9125, 5.2, 5.25]) ex_ci = np.array([0.080016664930917122, 0.16974097914175013, 0.083683431255336824, 0.43090292797024871, 0.93827856560121137]) f, psd_mean, psd_ci = get_data(fh) assert np.allclose(ex_f, f) assert np.allclose(ex_mean, psd_mean) assert np.allclose(ex_ci, psd_ci)
def test_convert_data(self): convert_data(self.testv1, self.converted) f, psd_mean, psd_ci = get_data(self.converted) ex_mean = np.array([1.2, 2.55, 3.9125, 5.2, 5.25]) ex_ci = np.array([0.080016664930917122, 0.16974097914175013, 0.083683431255336824, 0.43090292797024871, 0.93827856560121137]) assert np.allclose(self.ex_f, f) assert np.allclose(ex_mean, psd_mean) assert np.allclose(ex_ci, psd_ci)
def calck(filename, f_min, f_max, quality_factor, spring_constant, resonance_frequency, temperature): """Base function for the command line interface. TODO: Add numpy style param strings.""" est_cant = Cantilever(f_c=resonance_frequency*u.Hz, k_c=spring_constant*u.N/u.m, Q=quality_factor*u.dimensionless) data = get_data(filename) bmf = BrownianMotionFitter(*data, T=temperature, est_cant=est_cant) bmf.calc_fit(f_min, f_max) return bmf