hyri.interface.create_config#
Create HYRI imaging configuration files.
The hyri-config command starts an interactive wizard by default. Users can
also pass --default to copy the default JSON template without prompts.
Functions
Apply flat wizard answers to a copy of the JSON template. |
|
Ask AIRI-family algorithm questions. |
|
Ask for a value from a fixed set of choices. |
|
Ask compute-resource questions. |
|
Ask the interactive wizard questions and return configuration updates. |
|
Ask constrained algorithm questions. |
|
Ask data, image-grid, and channel questions. |
|
Ask for a floating-point value. |
|
Ask output, run-metadata, and common flag questions. |
|
Ask HyperAIRI-specific questions. |
|
Ask for an integer value. |
|
Ask optional measurement-operator questions. |
|
Ask for an optional floating-point value. |
|
Ask for an optional space-separated integer list. |
|
Ask SARA-family algorithm questions. |
|
Ask for a string value while preserving empty-list defaults. |
|
Ask unconstrained algorithm questions. |
|
Prompt until |
|
Ask imaging-weighting questions. |
|
Return a flat mapping from section name to section dictionary. |
|
Create a HYRI imaging configuration file. |
|
Format configuration defaults for display. |
|
Format a prompt with a readable default value. |
|
Return whether a configuration value should be treated as unset. |
|
Load the JSON template used by the config creator. |
|
Parse a yes/no or true/false answer. |
|
Parse a fixed-choice answer. |
|
Parse a float with an optional lower bound. |
|
Parse an integer with an optional lower bound. |
|
Parse a string that cannot be empty. |
|
Parse an optional float. |
|
Parse an optional integer. |
|
Parse an optional list of integers. |
|
Parse a spectral-index initialisation mode or FITS path. |
|
Parse a string prompt. |
|
Parse arguments for the |
|
Create the output parent directory and protect existing files. |
|
Print the generated config path and next imaging command. |
|
Remove unused algorithm sections from the final configuration. |
|
Write a HYRI JSON configuration file. |
- hyri.interface.create_config.create_config(argv: list[str] | None = None) None#
Create a HYRI imaging configuration file.
--defaultcopies the default template. Without--default, this function starts an interactive wizard and reprompts until values are valid.- Parameters:
argv (list[str] | None, optional) – Command-line arguments to parse. Default:
None. WhenNone,argparsereads fromsys.argv.- Raises:
RuntimeError – If interactive input ends before the wizard is complete.
SystemExit – If the output file already exists and overwrite is disabled.
Note
Invalid interactive inputs should be handled by asking the same question again. The wizard should not collect all answers and then fail with a validation error.
Output overwrite safety is checked before the default copy or long interactive question flow starts.
Examples
>>> create_config(["--default", "--output", "hyri_config.json"])
- hyri.interface.create_config.parsing_config_arguments(argv: list[str] | None = None) Namespace#
Parse arguments for the
hyri-configcommand.
- hyri.interface.create_config.load_default_config() list[dict[str, Any]]#
Load the JSON template used by the config creator.
The template is bundled as package data at
hyri/config/default.json.
- hyri.interface.create_config.prepare_output_path(output_path: str, *, overwrite: bool = False) None#
Create the output parent directory and protect existing files.
- Parameters:
output_path (str) – JSON configuration path to prepare.
- Keyword Arguments:
overwrite (bool, optional) – Whether an existing file may be replaced. Default:
False.- Raises:
SystemExit – If
output_pathexists andoverwriteisFalse.
- hyri.interface.create_config.write_config(config: list[dict[str, Any]], output_path: str) None#
Write a HYRI JSON configuration file.
- hyri.interface.create_config.ask_config_questions(config: list[dict[str, Any]]) dict[str, Any]#
Ask the interactive wizard questions and return configuration updates.
- Parameters:
config (list[dict[str, Any]]) – Default configuration template used for current values and section names.
- Returns:
- Wizard answers with an
"updates"list containing (section, key, value)tuples.
- Wizard answers with an
- Return type:
- Raises:
RuntimeError – If interactive input ends before the wizard is complete.
- hyri.interface.create_config.ask_data_questions(config: list[dict[str, Any]]) list[tuple[str, str, Any]]#
Ask data, image-grid, and channel questions.
- Parameters:
config (list[dict[str, Any]]) – Configuration template used for default answers.
- Returns:
Updates for data, image, and channel settings.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_weighting_questions(config: list[dict[str, Any]]) list[tuple[str, str, Any]]#
Ask imaging-weighting questions.
- Parameters:
config (list[dict[str, Any]]) – Configuration template used for default answers.
- Returns:
- Updates for data-weighting flags and imaging-weight
settings.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_general_questions(config: list[dict[str, Any]]) list[tuple[str, str, Any]]#
Ask output, run-metadata, and common flag questions.
- Parameters:
config (list[dict[str, Any]]) – Configuration template used for default answers.
- Returns:
- Updates for result path, source metadata, run ID,
and common flags.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_measurement_operator_questions(config: list[dict[str, Any]]) list[tuple[str, str, Any]]#
Ask optional measurement-operator questions.
- Parameters:
config (list[dict[str, Any]]) – Configuration template used for default answers.
- Returns:
- Updates for the NUFFT package and, when using
TorchKbNUFFT, the NUFFT mode.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_compute_questions(config: list[dict[str, Any]]) list[tuple[str, str, Any]]#
Ask compute-resource questions.
- Parameters:
config (list[dict[str, Any]]) – Configuration template used for default answers.
- Returns:
- Updates for devices, dtypes, and distributed
initialisation settings.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.apply_config_answers(config: list[dict[str, Any]], answers: dict[str, Any]) list[dict[str, Any]]#
Apply flat wizard answers to a copy of the JSON template.
The implementation should update the existing nested config sections rather than constructing a new schema from scratch. That keeps this command aligned with
config/default.jsonandhyri.interface.io.parsing_parameters().Since invalid values should be handled during prompting, this function should be a straightforward mapping step rather than another validation layer.
- Parameters:
- Returns:
Updated configuration with unselected algorithm sections removed when an algorithm answer is present.
- Return type:
- hyri.interface.create_config.print_config_created(output_path: str, config: list[dict[str, Any]]) None#
Print the generated config path and next imaging command.
A detailed config summary is not necessary. The user can inspect the JSON file directly if needed. Keep the completion message focused:
created output path;
hyri-imaging --config <output_path>.
- hyri.interface.create_config.ask_sara_family_questions(config: list[dict[str, Any]], algorithm: str) list[tuple[str, str, Any]]#
Ask SARA-family algorithm questions.
- Parameters:
- Returns:
- Updates for SARA regularisation scale and
reweighting options.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_airi_family_questions(config: list[dict[str, Any]], algorithm: str) list[tuple[str, str, Any]]#
Ask AIRI-family algorithm questions.
- Parameters:
- Returns:
- Updates for denoiser shelf, noise scale, image peak,
and adaptive denoising options.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_constrained_questions(config: list[dict[str, Any]], algorithm: str) list[tuple[str, str, Any]]#
Ask constrained algorithm questions.
- Parameters:
- Returns:
- Updates for constrained preconditioning when the
selected section supports it.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_hyperairi_questions(config: list[dict[str, Any]]) list[tuple[str, str, Any]]#
Ask HyperAIRI-specific questions.
- Parameters:
config (list[dict[str, Any]]) – Configuration template used for default answers.
- Returns:
Updates for spectral-index map behaviour.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_unconstrained_questions(config: list[dict[str, Any]], algorithm: str) list[tuple[str, str, Any]]#
Ask unconstrained algorithm questions.
- Parameters:
- Returns:
- Updates for the approximate measurement operator
when the selected section supports it.
- Return type:
list[ConfigUpdate]
- Raises:
RuntimeError – If interactive input ends before these questions finish.
- hyri.interface.create_config.ask_str(label: str, default: Any = None, description: str | None = None) Any#
Ask for a string value while preserving empty-list defaults.
- Parameters:
- Returns:
Parsed string input, or a copy of
defaultfor an empty response.- Return type:
Any
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.ask_int(label: str, default: Any = None, description: str | None = None, *, minimum: int | None = None) int#
Ask for an integer value.
- Parameters:
- Keyword Arguments:
minimum (int | None, optional) – Inclusive lower bound for accepted values. Default:
None.- Returns:
Parsed integer input, or a copy of
defaultfor an empty response.- Return type:
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.ask_optional_int_list(label: str, default: Any = None, description: str | None = None, *, minimum: int | None = None) list[int] | list[Any]#
Ask for an optional space-separated integer list.
- Parameters:
- Keyword Arguments:
minimum (int | None, optional) – Inclusive lower bound for each accepted integer. Default:
None.- Returns:
- Parsed integer list, an empty-list sentinel, or a
copy of
defaultfor an empty response.
- Return type:
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.ask_float(label: str, default: Any = None, description: str | None = None, *, minimum: float | None = None) float#
Ask for a floating-point value.
- Parameters:
- Keyword Arguments:
minimum (float | None, optional) – Inclusive lower bound for accepted values. Default:
None.- Returns:
Parsed float input, or a copy of
defaultfor an empty response.- Return type:
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.ask_optional_float(label: str, default: Any = None, description: str | None = None, *, minimum: float | None = None) float | list[Any]#
Ask for an optional floating-point value.
- Parameters:
- Keyword Arguments:
minimum (float | None, optional) – Inclusive lower bound for accepted values. Default:
None.- Returns:
- Parsed float, an empty-list sentinel, or a copy of
defaultfor an empty response.
- Return type:
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.ask_choice(label: str, choices: list[str], default: Any = None, description: str | None = None) str#
Ask for a value from a fixed set of choices.
- Parameters:
- Returns:
Selected choice.
- Return type:
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.ask_until_valid(label: str, default: Any, parser: Callable[[str], Any], description: str | None = None) Any#
Prompt until
parseraccepts the user input.- Parameters:
- Returns:
Parsed value, or a copy of
defaultfor an empty response.- Return type:
Any
- Raises:
RuntimeError – If interactive input ends before a valid value is read.
- hyri.interface.create_config.format_prompt(label: str, default: Any, description: str | None = None) str#
Format a prompt with a readable default value.
- hyri.interface.create_config.format_default(value: Any) str#
Format configuration defaults for display.
- Parameters:
value (Any) – Default value from the configuration template.
- Returns:
Empty string for unset values, otherwise
str(value).- Return type:
- hyri.interface.create_config.is_empty_value(value: Any) bool#
Return whether a configuration value should be treated as unset.
- Parameters:
value (Any) – Configuration value to inspect.
- Returns:
Truewhenvalueis the empty-list sentinel,None, oran empty string.
- Return type:
- hyri.interface.create_config.parse_non_empty_str(text: str) str#
Parse a string that cannot be empty.
- Parameters:
text (str) – Prompt text to parse.
- Returns:
Unmodified prompt text.
- Return type:
- Raises:
ValueError – If
textis empty.
- hyri.interface.create_config.parse_int(text: str, *, minimum: int | None = None) int#
Parse an integer with an optional lower bound.
- Parameters:
text (str) – Prompt text to parse.
- Keyword Arguments:
minimum (int | None, optional) – Inclusive lower bound for the parsed value. Default:
None.- Returns:
Parsed integer value.
- Return type:
- Raises:
ValueError – If
textis not an integer or is less thanminimum.
- hyri.interface.create_config.parse_optional_int(text: str, *, minimum: int | None = None) int | list[Any]#
Parse an optional integer.
Users can type
noneor[]to store the empty-list sentinel used by the existing JSON files.- Parameters:
text (str) – Prompt text to parse.
- Keyword Arguments:
minimum (int | None, optional) – Inclusive lower bound for the parsed integer. Default:
None.- Returns:
Parsed integer value, or
[]for empty sentinels.- Return type:
- Raises:
ValueError – If
textis not an accepted sentinel or integer, or if the integer is less thanminimum.
- hyri.interface.create_config.parse_optional_int_list(text: str, *, minimum: int | None = None) list[int] | list[Any]#
Parse an optional list of integers.
- Parameters:
text (str) – Prompt text to parse. Commas and spaces may separate list entries.
- Keyword Arguments:
minimum (int | None, optional) – Inclusive lower bound for each parsed integer. Default:
None.- Returns:
- Parsed integer list, or
[]for empty sentinels and empty input.
- Parsed integer list, or
- Return type:
- Raises:
ValueError – If any list entry is not an integer or is less than
minimum.
- hyri.interface.create_config.parse_float(text: str, *, minimum: float | None = None) float#
Parse a float with an optional lower bound.
- Parameters:
text (str) – Prompt text to parse.
- Keyword Arguments:
minimum (float | None, optional) – Inclusive lower bound for the parsed value. Default:
None.- Returns:
Parsed floating-point value.
- Return type:
- Raises:
ValueError – If
textis not numeric or is less thanminimum.
- hyri.interface.create_config.parse_optional_float(text: str, *, minimum: float | None = None) float | list[Any]#
Parse an optional float.
- Parameters:
text (str) – Prompt text to parse.
- Keyword Arguments:
minimum (float | None, optional) – Inclusive lower bound for the parsed value. Default:
None.- Returns:
Parsed floating-point value, or
[]for empty sentinels.- Return type:
- Raises:
ValueError – If
textis not an accepted sentinel or numeric value, or if the value is less thanminimum.
- hyri.interface.create_config.parse_bool(text: str) bool#
Parse a yes/no or true/false answer.
- Parameters:
text (str) – Prompt text to parse.
- Returns:
Parsed boolean value.
- Return type:
- Raises:
ValueError – If
textis not a recognised boolean answer.
- hyri.interface.create_config.parse_choice(text: str, choices: list[str]) str#
Parse a fixed-choice answer.
- Parameters:
- Returns:
Parsed choice.
- Return type:
- Raises:
ValueError – If
textis not inchoices.
- hyri.interface.create_config.parse_spec_idx_init(text: str) str#
Parse a spectral-index initialisation mode or FITS path.
- Parameters:
text (str) – Prompt text to parse.
- Returns:
Spectral-index initialisation mode or FITS file path.
- Return type:
- Raises:
ValueError – If
textis neither a supported mode nor a.fitspath.
- hyri.interface.create_config.config_sections(config: list[dict[str, Any]]) dict[str, dict[str, Any]]#
Return a flat mapping from section name to section dictionary.
The template is stored as a list of dictionaries with optional
"__comment"entries. This helper should hide that layout from the rest of the implementation.