Exemplo n.º 1
0
def test_converter_more_files(_sdds_file, _test_file):
    rep = 2
    converter_entrypoint(files=[_sdds_file],
                         outputdir=_test_file.parent,
                         realizations=rep)
    origin = tbt.read_tbt(_sdds_file)
    for i in range(rep):
        new = tbt.read_tbt(f"{_test_file}_r{i}.sdds")
        _compare_tbt(origin, new, False)
Exemplo n.º 2
0
def test_converter_one_file_with_noise(_sdds_file, _test_file):
    np.random.seed(2019)
    noiselevel = 0.0005
    converter_entrypoint(files=[_sdds_file],
                         outputdir=_test_file.parent,
                         noise_levels=[noiselevel])
    origin = tbt.read_tbt(_sdds_file)
    new = tbt.read_tbt(f"{_test_file}_n{noiselevel}.sdds")
    _compare_tbt(origin, new, True, noiselevel * 10)
Exemplo n.º 3
0
def test_converter_more_files_with_noise(_sdds_file, _test_file):
    np.random.seed(2019)
    rep = 2
    noiselevel = 0.0005
    converter_entrypoint(files=[_sdds_file],
                         outputdir=_test_file.parent,
                         realizations=rep,
                         noise_levels=[noiselevel])
    origin = tbt.read_tbt(_sdds_file)
    for i in range(rep):
        new = tbt.read_tbt(f"{_test_file}_n{noiselevel}_r{i}.sdds")
        _compare_tbt(origin, new, True, noiselevel * 10)
Exemplo n.º 4
0
def test_converter_drop_elements(_sdds_file, _test_file, dropped_elements):
    converter_entrypoint(
        files=[_sdds_file],
        outputdir=_test_file.parent,
        drop_elements=dropped_elements,
    )
    new = tbt.read_tbt(f"{_test_file}.sdds")
    for transverse_data in new.matrices:
        for dataframe in (transverse_data.X, transverse_data.Y):
            for element in dropped_elements:
                assert element not in dataframe.index
Exemplo n.º 5
0
def _run_harpy(harpy_options):
    iotools.create_dirs(harpy_options.outputdir)
    with timeit(
            lambda spanned: LOGGER.info(f"Total time for Harpy: {spanned}")):
        lins = []
        all_options = _replicate_harpy_options_per_file(harpy_options)
        tbt_datas = [(tbt.read_tbt(option.files,
                                   datatype=option.tbt_datatype), option)
                     for option in all_options]
        for tbt_data, option in tbt_datas:
            lins.extend([
                handler.run_per_bunch(bunch_data, bunch_options)
                for bunch_data, bunch_options in _multibunch(tbt_data, option)
            ])
    return lins
Exemplo n.º 6
0
def _read_and_write_files(opt):
    for input_file in opt.files:
        tbt_data = tbt.read_tbt(input_file, datatype=opt.tbt_datatype)
        if opt.drop_elements:
            tbt_data = _drop_elements(tbt_data, opt.drop_elements)
        if opt.use_average:
            tbt_data = tbt.utils.generate_average_tbtdata(tbt_data)
        for i in range(opt.realizations):
            suffix = f"_r{i}" if opt.realizations > 1 else ""
            if opt.noise_levels is None:
                tbt.write(
                    Path(opt.outputdir) /
                    f"{_file_name_without_sdds(input_file)}{suffix}",
                    tbt_data=tbt_data,
                )
            else:
                for noise_level in opt.noise_levels:
                    tbt.write(
                        Path(opt.outputdir) /
                        f"{_file_name_without_sdds(input_file)}_n{noise_level}{suffix}",
                        tbt_data=tbt_data,
                        noise=float(noise_level),
                    )
Exemplo n.º 7
0
def test_converter_one_file(_sdds_file, _test_file):
    converter_entrypoint(files=[_sdds_file], outputdir=_test_file.parent)
    origin = tbt.read_tbt(_sdds_file)
    new = tbt.read_tbt(f"{_test_file}.sdds")
    _compare_tbt(origin, new, False)