def test_write_emc_h5_multi(tmp_path): h5_file = './testFiles/singfel-multi.h5' out_path = tmp_path / "h5_multi.emc" DiffrData = DD.read(h5_file, poissonize=False) DiffrData.multiply(1e9) assert isinstance(DiffrData, DiffractionData) is True DD.write(out_path, DiffrData, 'emc')
def test_multiply(): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file, poissonize=False) orig = dd.array val_orig = np.max(orig[0]) dd.multiply(0) multi = dd.array assert np.max(orig[0]) == val_orig assert np.max(multi[0]) == 0 assert np.max(multi[2]) == 0
def test_addGaussianNoise(tmp_path): h5_file = './testFiles/singfel-multi.h5' data = DD.read(h5_file) xcs = np.array([-1.845, 56.825, 114.623]) fwhms = np.array([20.687, 26.771, 29.232]) hist_params = DD.histogramParams(xcs, fwhms) data.addGaussianNoise(hist_params.mu, hist_params.sigs_popt) out_path = tmp_path / "fitting.png" fn = str(out_path) hist_params.plotFitting(fn) assert out_path.is_file() is True
def backengine(self): """ Method to do the actual calculation.""" diffr_data = DD.read(self.input_path, self.parameters.index, **self.parameters.read_args) diffr_data.addGaussianNoise(self.parameters.mu, self.parameters.sigs_popt) diffr_data.multiply(1 / self.parameters.mu) for i in tqdm(range(len(diffr_data.array))): diffr_data.array[i] = np.round(diffr_data.array[i]) diffr_data.array[diffr_data.array < 0] = 0 diffr_data.setArrayDataType('i4') self._set_data(diffr_data) return 0
def test_read_emc_h5_multi(): h5_file = './testFiles/h5_multi.emc' DiffrData = DD.read(h5_file, pattern_shape=[81, 81]) DiffrData.plotPattern(1) assert len(DiffrData.array) == 13
def test_read_emc_h5_single(): h5_file = './testFiles/h5.emc' DiffrData = DD.read(h5_file, pattern_shape=[81, 81]) DiffrData.plotPattern(0) with pytest.raises(IndexError): DiffrData.plotPattern(1)
def test_write_EMC_ini(tmp_path): h5_file = './testFiles/singfel-multi.h5' out_path = tmp_path / "config.ini" # out_path = 'config.ini' dd = DD.read(h5_file) dd.writeEmcIni(str(out_path))
def test_file_not_exists(): h5_file = './testFiles/xx.h5' with pytest.raises(FileNotFoundError): DD.read(h5_file)
def test_saveHistogram(tmp_path): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file, poissonize=False) out_path = tmp_path / "test.png" dd.plotHistogram(fn_png=str(out_path)) assert out_path.is_file() is True
def test_plotStatistics(): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file, poissonize=False) if __name__ == "__main__": dd.plotHistogram()
def test_photon_statistics(): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file, poissonize=False) pprint(dd.photon_statistics)
def test_savePattern(tmp_path): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file, poissonize=False) out_path = tmp_path / "test.png" dd.plotPattern(idx=0, logscale=True, fn_png=str(out_path)) assert out_path.is_file() is True
def test_plotPattern(): h5_file = './testFiles/singfel-multi.h5' data = DD.read(h5_file, poissonize=False) data.plotPattern(idx=0, logscale=True)
def test_addBeamStop(): h5_file = './testFiles/singfel-multi.h5' data = DD.read(h5_file) data.addBeamStop(3)
def test_unexpected_read_argument(tmp_path): diffr_path = './testFiles/singfel-multi.h5' with pytest.raises(TypeError) as excinfo: DD.read(diffr_path, pattern_shape=[81, 81]) assert "got an unexpected keyword argument" in str(excinfo.value)
def test_read(): h5_file = './testFiles/singfel.h5' DiffrData = DD.read(h5_file) assert isinstance(DiffrData, DD.DiffractionData) is True
def test_pattern_total(): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file) assert dd.pattern_total == 13
def test_readSingFEL(): h5_file = './testFiles/singfel-multi.h5' data = DD.read(h5_file) assert len(data.array) == 13
def test_data_simplebeam(): h5_file = './testFiles/singfel-multi.h5' dd = DD.read(h5_file) assert pytest.approx(dd.beam.attrs['wavelength'], 0.1) == 2.5 assert pytest.approx(dd.beam.wavelength, 0.1) == 2.5 print(dd.beam)
def test_write_multi(tmp_path): diffr_path = './testFiles/singfel-multi.h5' out_path = tmp_path / "t.emc" diffr = DD.read(diffr_path) EMC.write(str(out_path), diffr)
def test_readAutoRewriteSingFEL(tmp_path): h5_file = './testFiles/singfel-multi.h5' data = DD.read(h5_file) ofn = tmp_path / 'rewrite_singfel.h5' DD.write(str(ofn), data, 'singfel') DD.read(str(ofn))