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"])
: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()
#!/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