Skip to content

multi_scan

plantimager.cli.multi_scan Link

Multiple imaging with varying parameters to assess/test acquisition or reconstruction pipelines.

load_config_from_directory Link

load_config_from_directory(path)

Load TOML & JSON configuration files from path.

Parameters:

Name Type Description Default
path str

Path to where the configuration file(s) should be.

required

Returns:

Type Description
dict

The configuration dictionary, if loaded from the files.

Notes

We exclude the backup files SCAN_TOML & PIPE_TOML from the list of loadable files.

Source code in plantimager/cli/multi_scan.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def load_config_from_directory(path):
    """Load TOML & JSON configuration files from path.

    Parameters
    ----------
    path : str
        Path to where the configuration file(s) should be.

    Returns
    -------
    dict
        The configuration dictionary, if loaded from the files.

    Notes
    -----
    We exclude the backup files ``SCAN_TOML`` & ``PIPE_TOML`` from the list of loadable files.

    """
    # List TOML config files:
    toml_list = glob.glob(os.path.join(path, "*.toml"))
    toml_list = [cfg for cfg in toml_list if cfg.split("/")[-1] not in (SCAN_TOML, PIPE_TOML)]
    # List JSON config files:
    json_list = glob.glob(os.path.join(path, "*.json"))

    if len(toml_list) == 0 and len(json_list) == 0:
        logger.critical(f"Could not find any TOML or JSON configuration file in '{path}'!")
        sys.exit("Configuration file missing!")

    config = {}
    # Read TOML configs
    for f in toml_list:
        try:
            c = toml.load(open(f))
            config = {**config, **c}
        except:
            logger.warning(f"Could not process TOML config file: {f}")
        else:
            logger.info(f"Loaded configuration file: {f}")
    # Read JSON configs:
    for f in json_list:
        try:
            c = json.load(open(f))
            config = {**config, **c}
        except:
            logger.warning(f"Could not process JSON config file: {f}")
        else:
            logger.info(f"Loaded configuration file: {f}")

    return config

load_config_from_file Link

load_config_from_file(path)

Load TOML or JSON configuration file from path.

Parameters:

Name Type Description Default
path str

Path to the configuration file to load.

required

Returns:

Type Description
dict

The configuration dictionary.

Source code in plantimager/cli/multi_scan.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def load_config_from_file(path):
    """Load TOML or JSON configuration file from path.

    Parameters
    ----------
    path : str
        Path to the configuration file to load.

    Returns
    -------
    dict
        The configuration dictionary.

    """
    config = None
    if path.endswith("toml"):
        try:
            config = toml.load(open(path))
        except:
            logger.critical(f"Could not load TOML configuration file '{path}'!")
    elif path.endswith("json"):
        try:
            config = json.load(open(path))
        except:
            logger.critical(f"Could not load JSON configuration file '{path}'!")
    else:
        logger.critical(f"Unsupported configuration file format, should be TOML or JSON!")

    if config is None:
        sys.exit(f"Error while loading configuration file!")

    return config