Beispiel #1
0
 def setUp(self) -> None:
     self.command_line_args = {
         "data_dir": str(here),
         "scan": 999999999,
         "root_folder": str(here),
     }
     self.parser = ConfigParser(CONFIG, self.command_line_args)
Beispiel #2
0
 def test_load_arguments_cl_params_flip_no_bool(self):
     self.parser = ConfigParser(
         CONFIG,
         {
             "data_dir": str(here),
             "flip_reconstruction": "weirdstring",
             "root_folder": str(here),
         },
     )
     with self.assertRaises(TypeError):
         self.parser.load_arguments()
Beispiel #3
0
class TestConfigParser(unittest.TestCase):
    """
    Tests on the class ConfigParser.

    def __init__(self, file_path : str, script_type : str = "preprocessing") -> None :
    """
    def setUp(self) -> None:
        self.command_line_args = {"scan": 999999999, "root_folder": str(here)}
        self.parser = ConfigParser(CONFIG, self.command_line_args)

    def test_init_file_path(self):
        self.assertTrue(self.parser.file_path == CONFIG)

    def test_init_file_path_2(self):
        self.assertTrue(self.parser.arguments is None)

    def test_init_file_path_wrong_type(self):
        with self.assertRaises(TypeError):
            ConfigParser(1234, self.command_line_args)

    def test_init_file_path_wrong_file_extension(self):
        with self.assertRaises(ValueError):
            ConfigParser("C:/test.txt", self.command_line_args)

    def test_init_file_path_not_existing(self):
        with self.assertRaises(ValueError):
            ConfigParser("C:/test.yml", self.command_line_args)

    def test_init_command_line_args(self):
        self.assertTrue(
            self.parser.command_line_args == self.command_line_args)

    def test_init_command_line_args_none(self):
        parser = ConfigParser(CONFIG, None)
        self.assertTrue(parser.command_line_args is None)

    def test_init_raw_config(self):
        self.assertIsInstance(self.parser.raw_config, bytes)

    def test_filter_dict(self):
        dic = {"scan": "9999", "sdd": None}
        output = self.parser.filter_dict(dic)
        self.assertTrue(output == {"scan": "9999"})

    def test_filter_dict_filter_value(self):
        dic = {"scan": "9999", "sdd": None, "test": True}
        output = self.parser.filter_dict(dic, filter_value=True)
        self.assertTrue(output == {"scan": "9999", "sdd": None})

    def test_load_arguments(self):
        args = self.parser.load_arguments()
        # "scan" is also key in CONFIG, which means that the overriding by the optional
        # --scan argument from the command line works as expected
        self.assertTrue(args.get("scan") == self.command_line_args["scan"])
Beispiel #4
0
 def test_load_arguments_cl_params_flip(self):
     self.parser = ConfigParser(
         CONFIG,
         {
             "data_dir": str(here),
             "flip_reconstruction": "False",
             "root_folder": str(here),
         },
     )
     # "flip_reconstruction" is also key in CONFIG, which means that the overriding
     # by the optional --flip_reconstruction argument from the command line works as
     # expected
     args = self.parser.load_arguments()
     self.assertTrue(args.get("flip_reconstruction") is False)
Beispiel #5
0
    :param apodization_alpha: e.g. [1.0, 1.0, 1.0]
     shape parameter of the tukey window

    Parameters related to saving:

    :param save_rawdata: e.g. False
     True to save the amp-phase.vti before orthogonalization
    :param save_support: e.g. False
     True to save the non-orthogonal support for later phase retrieval
    :param save: e.g. True
     True to save amp.npz, phase.npz, strain.npz and vtk files

"""

if __name__ == "__main__":
    # construct the argument parser and parse the command-line arguments
    ap = argparse.ArgumentParser()
    ap = add_cli_parameters(ap)
    cli_args = vars(ap.parse_args())

    # load the config file
    file = cli_args.get("config_file") or CONFIG_FILE
    parser = ConfigParser(file, cli_args)
    args = parser.load_arguments()
    args["time"] = f"{datetime.now()}"
    run(prm=args)

    print("\nEnd of script")
    plt.ioff()
    plt.show()
Beispiel #6
0
 def test_init_command_line_args_none(self):
     parser = ConfigParser(CONFIG, None)
     self.assertTrue(parser.command_line_args is None)
Beispiel #7
0
 def test_init_file_path_not_existing(self):
     with self.assertRaises(ValueError):
         ConfigParser("C:/test.yml", self.command_line_args)
Beispiel #8
0
 def test_init_file_path_wrong_file_extension(self):
     with self.assertRaises(ValueError):
         ConfigParser("C:/test.txt", self.command_line_args)
Beispiel #9
0
 def test_init_file_path_wrong_type(self):
     with self.assertRaises(TypeError):
         ConfigParser(1234, self.command_line_args)
Beispiel #10
0
 def test_instantiate_configparser_no_cla(self):
     self.parser = ConfigParser(CONFIG)
     self.assertIsNone(self.parser.arguments)
Beispiel #11
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# BCDI: tools for pre(post)-processing Bragg coherent X-ray diffraction imaging data
#   (c) 07/2017-06/2019 : CNRS UMR 7344 IM2NP
#   (c) 07/2019-present : DESY PHOTON SCIENCE
#       authors:
#         Clément Atlan, [email protected]

from bcdi.utils.parser import ConfigParser

if __name__ == "__main__":
    config_file = "../../conf/config_preprocessing.yml"
    arg_handler = ConfigParser(config_file)

    args = arg_handler.load_arguments()  # this can also be accessed by
    # arg_handler.arguments once load_arguments() has been computed

    print(f"The current configuration file is:\n{config_file}\n")
    print("attribute arg_handler.arguments:")
    print(arg_handler.arguments)  # or args