Config Modules
Functions and tools for working with configuration files.
merge_mappings(map1: MutableMappingType, map2: MutableMappingType) -> MutableMappingType
Merge two mappings (dictionaries), with priority given to the second mapping.
Note: Using a Mapping should make this robust to any mapping type, not just dictionaries. MutableMapping was needed as Mapping is not a mutable type, and this function needs to be able to change the dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map1
|
MutableMapping
|
First mapping to merge, with secondary priority. |
required |
map2
|
MutableMapping
|
Second mapping to merge, with primary priority. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Merged dictionary. |
Source code in topostats\config.py
reconcile_config_args(args: Namespace | None, default_config: dict[str, Any]) -> dict
Reconcile command line arguments with the default configuration.
Command line arguments take precedence over the default configuration. If a partial configuration file is specified (with '-c' or '--config-file') the defaults are over-ridden by these values (internally the configuration dictionary is updated with these values). Any other command line arguments take precedence over both the default and those supplied in a configuration file (again the dictionary is updated).
The final configuration is validated before processing begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Command line arguments passed into TopoStats. |
required |
default_config
|
dict[str, Any]
|
Dictionary containing the default configuration for the package. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The configuration dictionary. |
Source code in topostats\config.py
update_config(config: dict, args: dict | Namespace) -> dict
Update the configuration with any arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Dictionary of configuration (typically read from YAML file specified with '-c/--config |
required |
args
|
Namespace
|
Command line arguments. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary updated with command arguments. |
Source code in topostats\config.py
update_module(args: Namespace, topostats_modules: tuple = ('bruker-rename', 'create-config', 'curvature', 'disordered_tracing', 'filter', 'grains', 'grainstats', 'nodestats', 'ordered_tracing', 'process', 'splining')) -> None
Update the args.module argument if processing TopoStats objects.
This function allows the sub-parser command to map to the pipeline we wish to use. For now TopoStats has sub-parsers but it is the intention to introduce sub-sub-parsers for other modules such that eventually we invoke ``topostats``` with a module argument followed by the step of processing.
topostats topostats filter topostats topostats process topostats afmslicer slice topostats afmslicer process topostats perovstats process
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Default arguments that need parsing and updating. |
required |
topostats_modules
|
tuple
|
List of module names that are unique to TopoStats. |
('bruker-rename', 'create-config', 'curvature', 'disordered_tracing', 'filter', 'grains', 'grainstats', 'nodestats', 'ordered_tracing', 'process', 'splining')
|
Source code in topostats\config.py
update_plotting_config(plotting_config: dict) -> dict
Update the plotting config for each of the plots in plot_dict.
Ensures that each entry has all the plotting configuration values that are needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotting_config
|
dict
|
Plotting configuration to be updated. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Updated plotting configuration. |
Source code in topostats\config.py
write_config_with_comments(args: Namespace = None, valid_config: tuple[str] = ('default', 'simple', 'mplstyle', 'var_to_label'), valid_module: tuple[str] = 'topostats') -> None
Write a sample configuration with in-line comments.
This function is not designed to be used interactively but can be, just call it without any arguments and it will write a configuration to './config.yaml'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
A Namespace object parsed from argparse with values for 'filename'. |
None
|
valid_config
|
tuple[str]
|
Tuple of valid configuration options. |
('default', 'simple', 'mplstyle', 'var_to_label')
|
valid_module
|
tuple[str]
|
Tuple of valid modules, currently 'topostats'. |
'topostats'
|
Source code in topostats\config.py
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |