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_config_answers

Apply flat wizard answers to a copy of the JSON template.

ask_airi_family_questions

Ask AIRI-family algorithm questions.

ask_choice

Ask for a value from a fixed set of choices.

ask_compute_questions

Ask compute-resource questions.

ask_config_questions

Ask the interactive wizard questions and return configuration updates.

ask_constrained_questions

Ask constrained algorithm questions.

ask_data_questions

Ask data, image-grid, and channel questions.

ask_float

Ask for a floating-point value.

ask_general_questions

Ask output, run-metadata, and common flag questions.

ask_hyperairi_questions

Ask HyperAIRI-specific questions.

ask_int

Ask for an integer value.

ask_measurement_operator_questions

Ask optional measurement-operator questions.

ask_optional_float

Ask for an optional floating-point value.

ask_optional_int_list

Ask for an optional space-separated integer list.

ask_sara_family_questions

Ask SARA-family algorithm questions.

ask_str

Ask for a string value while preserving empty-list defaults.

ask_unconstrained_questions

Ask unconstrained algorithm questions.

ask_until_valid

Prompt until parser accepts the user input.

ask_weighting_questions

Ask imaging-weighting questions.

config_sections

Return a flat mapping from section name to section dictionary.

create_config

Create a HYRI imaging configuration file.

format_default

Format configuration defaults for display.

format_prompt

Format a prompt with a readable default value.

is_empty_value

Return whether a configuration value should be treated as unset.

load_default_config

Load the JSON template used by the config creator.

parse_bool

Parse a yes/no or true/false answer.

parse_choice

Parse a fixed-choice answer.

parse_float

Parse a float with an optional lower bound.

parse_int

Parse an integer with an optional lower bound.

parse_non_empty_str

Parse a string that cannot be empty.

parse_optional_float

Parse an optional float.

parse_optional_int

Parse an optional integer.

parse_optional_int_list

Parse an optional list of integers.

parse_spec_idx_init

Parse a spectral-index initialisation mode or FITS path.

parse_str

Parse a string prompt.

parsing_config_arguments

Parse arguments for the hyri-config command.

prepare_output_path

Create the output parent directory and protect existing files.

print_config_created

Print the generated config path and next imaging command.

prune_unselected_algorithms

Remove unused algorithm sections from the final configuration.

write_config

Write a HYRI JSON configuration file.

hyri.interface.create_config.create_config(argv: list[str] | None = None) → None#

Create a HYRI imaging configuration file.

--default copies 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. When None, argparse reads from sys.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-config command.

Parameters:

argv (list[str] | None, optional) – Command-line arguments to parse. Default: None. When None, argparse reads from sys.argv.

Returns:

Parsed command-line arguments.

Return type:

argparse.Namespace

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.

Returns:

Parsed default configuration template.

Return type:

list[dict[str, Any]]

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_path exists and overwrite is False.

hyri.interface.create_config.write_config(config: list[dict[str, Any]], output_path: str) → None#

Write a HYRI JSON configuration file.

Parameters:
  • config (list[dict[str, Any]]) – Configuration data to serialise.

  • output_path (str) – JSON file path to write.

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.

Return type:

dict[str, Any]

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.json and hyri.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:
  • config (list[dict[str, Any]]) – Configuration template to update.

  • answers (dict[str, Any]) – Wizard answers containing an "updates" list of (section, key, value) tuples.

Returns:

Updated configuration with unselected algorithm sections removed when an algorithm answer is present.

Return type:

list[dict[str, Any]]

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>.

Parameters:
  • output_path (str) – Path of the generated JSON configuration file.

  • config (list[dict[str, Any]]) – Generated configuration data used to decide whether the run command needs --data_file.

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:
  • config (list[dict[str, Any]]) – Configuration template used for default answers.

  • algorithm (str) – Selected SARA-family algorithm section to configure.

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:
  • config (list[dict[str, Any]]) – Configuration template used for default answers.

  • algorithm (str) – Selected AIRI-family algorithm section to configure.

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:
  • config (list[dict[str, Any]]) – Configuration template used for default answers.

  • algorithm (str) – Selected constrained algorithm section to configure.

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:
  • config (list[dict[str, Any]]) – Configuration template used for default answers.

  • algorithm (str) – Selected unconstrained algorithm section to configure.

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:
  • label (str) – Prompt label shown to the user.

  • default (Any, optional) – Value returned when the user submits an empty response. Default: None.

  • description (str | None, optional) – Extra prompt detail. Default: None.

Returns:

Parsed string input, or a copy of default for 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:
  • label (str) – Prompt label shown to the user.

  • default (Any, optional) – Value returned when the user submits an empty response. Default: None.

  • description (str | None, optional) – Extra prompt detail. Default: None.

Keyword Arguments:

minimum (int | None, optional) – Inclusive lower bound for accepted values. Default: None.

Returns:

Parsed integer input, or a copy of default for an empty response.

Return type:

int

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:
  • label (str) – Prompt label shown to the user.

  • default (Any, optional) – Value returned when the user submits an empty response. Default: None.

  • description (str | None, optional) – Extra prompt detail. Default: None.

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 default for an empty response.

Return type:

list[int] | list[Any]

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:
  • label (str) – Prompt label shown to the user.

  • default (Any, optional) – Value returned when the user submits an empty response. Default: None.

  • description (str | None, optional) – Extra prompt detail. Default: None.

Keyword Arguments:

minimum (float | None, optional) – Inclusive lower bound for accepted values. Default: None.

Returns:

Parsed float input, or a copy of default for an empty response.

Return type:

float

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:
  • label (str) – Prompt label shown to the user.

  • default (Any, optional) – Value returned when the user submits an empty response. Default: None.

  • description (str | None, optional) – Extra prompt detail. Default: None.

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

default for an empty response.

Return type:

float | list[Any]

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:
  • label (str) – Prompt label shown to the user.

  • choices (list[str]) – Accepted string values.

  • default (Any, optional) – Preferred default value. Default: None. If this is not in choices, the first choice is used.

  • description (str | None, optional) – Extra prompt detail. Default: None.

Returns:

Selected choice.

Return type:

str

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 parser accepts the user input.

Parameters:
  • label (str) – Prompt label shown to the user.

  • default (Any) – Value returned when the user submits an empty response.

  • parser (Callable[[str], Any]) – Function that converts non-empty input text to a configuration value.

  • description (str | None, optional) – Extra prompt detail. Default: None.

Returns:

Parsed value, or a copy of default for 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.

Parameters:
  • label (str) – Prompt label shown to the user.

  • default (Any) – Default value displayed in square brackets.

  • description (str | None, optional) – Extra prompt detail. Default: None.

Returns:

Complete prompt text ending with ": ".

Return type:

str

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:

str

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:

True when value is the empty-list sentinel, None, or

an empty string.

Return type:

bool

hyri.interface.create_config.parse_str(text: str) → str#

Parse a string prompt.

Parameters:

text (str) – Prompt text to parse.

Returns:

Unmodified prompt text.

Return type:

str

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:

str

Raises:

ValueError – If text is 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:

int

Raises:

ValueError – If text is not an integer or is less than minimum.

hyri.interface.create_config.parse_optional_int(text: str, *, minimum: int | None = None) → int | list[Any]#

Parse an optional integer.

Users can type none or [] 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:

int | list[Any]

Raises:

ValueError – If text is not an accepted sentinel or integer, or if the integer is less than minimum.

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.

Return type:

list[int] | list[Any]

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:

float

Raises:

ValueError – If text is not numeric or is less than minimum.

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:

float | list[Any]

Raises:

ValueError – If text is not an accepted sentinel or numeric value, or if the value is less than minimum.

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:

bool

Raises:

ValueError – If text is not a recognised boolean answer.

hyri.interface.create_config.parse_choice(text: str, choices: list[str]) → str#

Parse a fixed-choice answer.

Parameters:
  • text (str) – Prompt text to parse.

  • choices (list[str]) – Accepted string values.

Returns:

Parsed choice.

Return type:

str

Raises:

ValueError – If text is not in choices.

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:

str

Raises:

ValueError – If text is neither a supported mode nor a .fits path.

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.

Parameters:

config (list[dict[str, Any]]) – Configuration template or generated configuration data.

Returns:

Mapping from section name to section

dictionary.

Return type:

dict[str, dict[str, Any]]

hyri.interface.create_config.prune_unselected_algorithms(config: list[dict[str, Any]], algorithm: str) → None#

Remove unused algorithm sections from the final configuration.

Parameters:
  • config (list[dict[str, Any]]) – Configuration data to mutate in place.

  • algorithm (str) – Selected algorithm whose sections should be kept.