def test_filetype_keywords():
    kws = {'poissonize': True}
    format = DD.filetype_keywords(kws)
    assert format == 'singfel'
    kws = {'woo': True}
    format = DD.filetype_keywords(kws)
    assert format == 'UNKNOWN'
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_writeUnsupported():
    input_arr = np.random.rand(10, 10)
    data = DiffractionData(arrary=input_arr)
    with pytest.raises(UnknownFileTypeError) as excinfo:
        DD.write("filename", data, format='blabla')
        print(excinfo.value)
    assert "Unsupported format" in str(excinfo.value)
Exemplo n.º 4
0
    def saveH5(self, format='emc'):
        """Save noised diffraction data as a HDF5 file

        :param format: What format to save the data in.
        :type format: str
        """
        DD.write(self.output_path, self.data, format)
def test_filetype_content():
    h5_file = './testFiles/singfel.h5'
    format = DD.filetype_content(h5_file)
    assert format == 'singfel'

    md_file = './testFiles/README.md'
    format = DD.filetype_content(md_file)
    assert format == 'UNKNOWN'
def test_filetype():
    h5_file = './testFiles/singfel.h5'
    format = DD.filetype(h5_file)
    assert format == 'singfel'
    try:
        md_file = './testFiles/README.md'
        format = DD.filetype(md_file)
    except UnknownFileTypeError:
        assert True
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 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
def test_read():
    h5_file = './testFiles/singfel.h5'
    DiffrData = DD.read(h5_file)
    assert isinstance(DiffrData, DD.DiffractionData) is True
Exemplo n.º 11
0
def test_file_not_exists():
    h5_file = './testFiles/xx.h5'
    with pytest.raises(FileNotFoundError):
        DD.read(h5_file)
Exemplo n.º 12
0
def test_listFormats():
    DD.listFormats()
Exemplo n.º 13
0
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)
Exemplo n.º 14
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
Exemplo n.º 15
0
def test_addBeamStop():
    h5_file = './testFiles/singfel-multi.h5'
    data = DD.read(h5_file)
    data.addBeamStop(3)
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
def test_plotPattern():
    h5_file = './testFiles/singfel-multi.h5'
    data = DD.read(h5_file, poissonize=False)
    data.plotPattern(idx=0, logscale=True)
Exemplo n.º 18
0
def test_print_format_keys():
    DD.listFormats()
Exemplo n.º 19
0
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))
Exemplo n.º 20
0
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
Exemplo n.º 21
0
def test_readSingFEL():
    h5_file = './testFiles/singfel-multi.h5'
    data = DD.read(h5_file)
    assert len(data.array) == 13
Exemplo n.º 22
0
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
Exemplo n.º 23
0
def test_plotStatistics():
    h5_file = './testFiles/singfel-multi.h5'
    dd = DD.read(h5_file, poissonize=False)
    if __name__ == "__main__":
        dd.plotHistogram()
Exemplo n.º 24
0
def test_photon_statistics():
    h5_file = './testFiles/singfel-multi.h5'
    dd = DD.read(h5_file, poissonize=False)
    pprint(dd.photon_statistics)
Exemplo n.º 25
0
def test_pattern_total():
    h5_file = './testFiles/singfel-multi.h5'
    dd = DD.read(h5_file)
    assert dd.pattern_total == 13
Exemplo n.º 26
0
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)
Exemplo n.º 27
0
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)
Exemplo n.º 28
0
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))