def load_scans(start,stop): """ Creates a dictionary of scans for use in other test functions """ scansin=collections.OrderedDict() try: for idx in range(start,stop+1): scansin[idx]=npyio.load_data(os.path.join(os.path.dirname(__file__),'filetypes/HB1A/HB1A_exp0718_scan0%d.dat'%idx)) return scansin except: pytest.failed('scan load failed in scan collection test')
def load_scans(start,stop): """ Creates a dictionary of scans for use in other test functions """ scansin={} try: for idx in range(start,stop+1): scansin[idx]=npyio.load_data(os.path.join(os.path.dirname(__file__),'filetypes/HB1A/HB1A_exp0718_scan0%d.dat'%idx)) return scansin except: pytest.failed('scan load failed in scan collection test')
def test_fit_plot(mock_show): """Test that plot method works """ t_scan=npyio.load_data(os.path.join(os.path.dirname(__file__),'filetypes/HB1A/HB1A_exp0718_scan0222.dat')) x=t_scan.data['l'] y=t_scan.data['detector'] err=np.sqrt(y) params_in=[0.,0.,18.,0.0,0.01,400,0.22,0.01,8,0.25,0.01] fitobj=Fitter(residuals=residuals2, data=(functions.gaussian,x,y,err)) fitobj.fit(params0=params_in) fitobj.plot(functions.gaussian) fitobj.plot(functions.gaussian,plot_residuals=False) fitobj.plot(functions.gaussian,function_str="$p_0+p_1x+2\sqrt{\frac{\ln{2}}{\pi}}\sum_{i=0}^{1} \frac{p_{3i+2}}{p_{3i+4}}e^{-\frac{\ln{2}(x-p_{3i+3})^2}{\pi p_{3i+4}^2}}$")
def test_fit_plot(mock_show): """Test that plot method works """ t_scan = npyio.load_data( os.path.join(os.path.dirname(__file__), 'filetypes/HB1A/HB1A_exp0718_scan0222.dat')) x = t_scan.data['l'] y = t_scan.data['detector'] err = np.sqrt(y) params_in = [0., 0., 18., 0.0, 0.01, 400, 0.22, 0.01, 8, 0.25, 0.01] fitobj = Fitter(residuals=residuals2, data=(functions.gaussian, x, y, err)) fitobj.fit(params0=params_in) fitobj.plot(functions.gaussian) fitobj.plot(functions.gaussian, plot_residuals=False) fitobj.plot( functions.gaussian, function_str= "$p_0+p_1x+2\sqrt{\frac{\ln{2}}{\pi}}\sum_{i=0}^{1} \frac{p_{3i+2}}{p_{3i+4}}e^{-\frac{\ln{2}(x-p_{3i+3})^2}{\pi p_{3i+4}^2}}$" )
def test_load_data_files(mock_stdout): """Tests file loading """ try: load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0001.dat'), os.path.join(os.path.dirname(__file__), 'filetypes/scan0002.dat')), load_instrument=True) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0003.ng5'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0004.bt7'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0005'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0007.bt7'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/000000.nxs'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/000001.dat'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.iexy'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.spe'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.xyie'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.npy'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.h5'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_save_load_spice.npy')), load_instrument=True) load_data(os.path.join(os.path.dirname(__file__), u'filetypes/scan0001º£.dat')) except: pytest.fail('Data loading failed') with pytest.raises(KeyError): load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0006.test')), filetype='blah') try: a = load_data(os.path.join(os.path.dirname(__file__), 'filetypes/scan0001a.dat')) h, k, l, e = a.h, a.k, a.l, a.e except: pytest.fail('Data loading failed (missing column problem)') with pytest.raises(KeyError): a = load_data(os.path.join(os.path.dirname(__file__), 'filetypes/scan0001a.dat')) temp = a.temp
def test_load_data_files(mock_stdout): """Tests file loading """ try: load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0001.dat'), os.path.join(os.path.dirname(__file__), 'filetypes/scan0002.dat')), load_instrument=True) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0003.ng5'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0004.bt7'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0005'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0007.bt7'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/000000.nxs'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/000001.dat'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.iexy'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.spe'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.xyie'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.npy'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_filetypes.h5'))) load_data((os.path.join(os.path.dirname(__file__), 'filetypes/test_save_load_spice.npy')), load_instrument=True) except: pytest.fail('Data loading failed') with pytest.raises(KeyError): load_data((os.path.join(os.path.dirname(__file__), 'filetypes/scan0006.test')), filetype='blah')