Convenience function to edit and save a config file from a dictionary. Parameters ---------- configname : string String containing the full path of the config file in the project. edits : dict Key–value pairs to edit in config output_name : string, optional (defa
(configname, edits, output_name="")
| 260 | |
| 261 | |
| 262 | def edit_config(configname, edits, output_name=""): |
| 263 | """Convenience function to edit and save a config file from a dictionary. |
| 264 | |
| 265 | Parameters |
| 266 | ---------- |
| 267 | configname : string |
| 268 | String containing the full path of the config file in the project. |
| 269 | edits : dict |
| 270 | Key–value pairs to edit in config |
| 271 | output_name : string, optional (default='') |
| 272 | Overwrite the original config.yaml by default. |
| 273 | If passed in though, new filename of the edited config. |
| 274 | |
| 275 | Examples |
| 276 | -------- |
| 277 | config_path = 'my_stellar_lab/dlc/config.yaml' |
| 278 | |
| 279 | edits = {'numframes2pick': 5, |
| 280 | 'trainingFraction': [0.5, 0.8], |
| 281 | 'skeleton': [['a', 'b'], ['b', 'c']]} |
| 282 | |
| 283 | deeplabcut.auxiliaryfunctions.edit_config(config_path, edits) |
| 284 | """ |
| 285 | cfg = read_plainconfig(configname) |
| 286 | for key, value in edits.items(): |
| 287 | cfg[key] = value |
| 288 | if not output_name: |
| 289 | output_name = configname |
| 290 | try: |
| 291 | write_plainconfig(output_name, cfg) |
| 292 | except ruamel.yaml.representer.RepresenterError: |
| 293 | warnings.warn("Some edits could not be written. The configuration file will be left unchanged.", stacklevel=2) |
| 294 | for key in edits: |
| 295 | cfg.pop(key) |
| 296 | write_plainconfig(output_name, cfg) |
| 297 | return cfg |
| 298 | |
| 299 | |
| 300 | def get_bodyparts(cfg: dict) -> list[str]: |
no test coverage detected