geoh5py.ui_json package#

Submodules#

geoh5py.ui_json.annotations module#

geoh5py.ui_json.constants module#

geoh5py.ui_json.forms module#

geoh5py.ui_json.input_file module#

geoh5py.ui_json.templates module#

geoh5py.ui_json.ui_json module#

geoh5py.ui_json.utils module#

geoh5py.ui_json.utils.collect(ui_json: dict[str, dict[str, Any]], member: str, value: Any = None) → dict[str, dict[str, Any]]#

Collect UI parameters with a common field and optional value.

Searches through the ui_json dictionary for parameters that contain a specific member field, optionally filtering by the value of that field.

Parameters:
  • ui_json – The UI JSON dictionary to search through.

  • member – The field name to search for in each parameter.

  • value – Optional value to match against the member field.

Returns:

Dictionary of parameters that match the criteria.

geoh5py.ui_json.utils.container_group2name(value: Any) → Any#

Convert a ContainerGroup object to its name string.

Deprecated: This function will be removed in future releases.

Parameters:

value – ContainerGroup object or other value to convert.

Returns:

Name string for ContainerGroup objects, original value otherwise.

geoh5py.ui_json.utils.dependency_requires_value(ui_json: dict[str, dict[str, Any]], parameter: str) → bool#

Check if a parameter requires a value based on its dependency constraints.

Handles dependency and optional requirements for parameters. If a dependency doesn’t require a value then the function returns False. If the dependency does require a value, the return value is either True, or will take on the enabled state if the dependent parameter is optional.

Parameters:
  • ui_json – UI JSON dictionary containing the parameters.

  • parameter – Name of the parameter to check.

Returns:

True if the parameter requires a value based on dependencies, False otherwise.

geoh5py.ui_json.utils.find_all(ui_json: dict[str, dict[str, Any]], member: str, value: Any = None) → list[str]#

Return names of all parameters matching the given criteria.

Convenience function that returns just the parameter names from the collect function results.

Parameters:
  • ui_json – The UI JSON dictionary to search through.

  • member – The field name to search for in each parameter.

  • value – Optional value to match against the member field.

Returns:

List of parameter names that match the criteria.

geoh5py.ui_json.utils.flatten(ui_json: dict[str, dict[str, Any]]) → dict[str, Any]#

Flatten ui.json format to simple key/value pairs.

Converts the nested ui.json structure to a flat dictionary where most fields have their values extracted from the ‘value’ member. For widgets storing multiple values, the values are passed as a dictionary.

Parameters:

ui_json – The form containing the UI data to flatten.

Returns:

A flattened dictionary with parameter names as keys and their values.

geoh5py.ui_json.utils.group_enabled(group: dict[str, dict[str, Any]]) → bool#

Check if a group is enabled based on groupOptional and enabled flags.

Returns True if both groupOptional and enabled are True for the group.

Parameters:

group – UI JSON group dictionary containing parameters.

Returns:

True if the group is enabled, False otherwise.

Raises:

ValueError – If the provided group does not contain a parameter with groupOptional member.

geoh5py.ui_json.utils.group_optional(ui_json: dict[str, dict[str, Any]], group_name: str) → bool#

Check if a group has the groupOptional flag enabled.

Searches for parameters belonging to the specified group and returns the groupOptional boolean value for that group.

Parameters:
  • ui_json – The UI JSON dictionary to search through.

  • group_name – Name of the group to check.

Returns:

True if the group is optional, False otherwise.

geoh5py.ui_json.utils.group_requires_value(ui_json: dict[str, dict[str, Any]], parameter: str) → bool#

Check if a parameter requires a value based on its group’s optional status.

Determines if a parameter requires a value by checking if its group is optional and if the group is enabled.

Parameters:
  • ui_json – UI JSON dictionary containing the parameters.

  • parameter – Name of the parameter to check.

Returns:

True if the group is optional and enabled, or if the group is not optional.

geoh5py.ui_json.utils.is_form(var: Any) → bool#

Check if a variable is a valid form dictionary.

Returns True if the dictionary variable contains both ‘label’ and ‘value’ members, which are required for a valid UI form element.

Parameters:

var – Variable to check for form structure.

Returns:

True if the variable is a valid form dictionary, False otherwise.

geoh5py.ui_json.utils.is_uijson(ui_json: dict[str, dict[str, Any]]) → bool#

Check if a dictionary contains all the required UI JSON parameters.

Validates that a dictionary has the structure and required fields of a valid UI JSON configuration.

Parameters:

ui_json – Dictionary to validate as UI JSON.

Returns:

True if the dictionary contains all required parameters, False otherwise.

geoh5py.ui_json.utils.monitored_directory_copy(directory: str, entities: EntityContainer | list[EntityContainer], copy_children: bool = True) → str#

Create a temporary geoh5 file in the monitoring folder and export entities for update.

Creates a temporary workspace in the specified monitoring directory and copies the given entities to it. This is useful for monitoring and updating entities in a separate workspace environment.

Parameters:
  • directory – Path to the monitoring directory where the temporary file will be created.

  • entities – Entity (ObjectBase or Group) to be copied for monitoring.

  • copy_children – Whether to copy children entities along with the main entities.

Returns:

Full path to the created temporary geoh5 file.

geoh5py.ui_json.utils.optional_requires_value(ui_json: dict[str, dict[str, Any]], parameter: str) → bool#

Check if an optional parameter requires a value based on its enabled state.

For optional parameters, this function checks the ‘enabled’ field to determine if the parameter requires a value.

Parameters:
  • ui_json – UI JSON dictionary containing the parameters.

  • parameter – Name of the parameter to check.

Returns:

True if the parameter is enabled, False otherwise.

geoh5py.ui_json.utils.optional_uuid_mapper(value: Any)#

Take values and convert them into UUID or None (or list of).

Parameters:

value – Either a string of entity, or list of.

Returns:

UUID, Nont or list of.

geoh5py.ui_json.utils.path2workspace(value: Any) → Any#

Convert a file path string to a Workspace object if it represents a valid geoh5 file.

Creates a Workspace object from a path string if the file exists and has a .geoh5 extension.

Parameters:

value – File path string, Path object, or other value to convert.

Returns:

Workspace object if the value represents a valid geoh5 file, original value otherwise.

geoh5py.ui_json.utils.requires_value(ui_json: dict[str, dict[str, Any]], parameter: str) → bool#

Check if a UI JSON parameter requires a value based on hierarchy of switches.

The required status of a parameter depends on a hierarchy of UI switches. At the top is the groupOptional switch, below that is the dependency switch, and at the bottom is the optional switch. When groupOptional is disabled, all parameters in the group are not required. When the groupOptional is enabled, the required status of a parameter depends first on any dependencies and lastly on its optional status.

Parameters:
  • ui_json – UI JSON dictionary containing the parameters.

  • parameter – Name of the parameter to check.

Returns:

True if the parameter requires a value, False otherwise.

geoh5py.ui_json.utils.set_enabled(ui_json: dict[str, Any], parameter: str, value: bool, validate: bool = True) → None#

Set the enabled status for an optional or groupOptional parameter.

Updates the ‘enabled’ field for parameters that support it, including optional parameters, parameters with dependencies, and group optional parameters.

Parameters:
  • ui_json – UI JSON dictionary containing the parameters.

  • parameter – Name of the parameter to modify.

  • value – Boolean value to set for the parameter’s enabled member.

  • validate – Whether to perform validation checks on the operation.

Raises:

Warning – If attempting to disable a non-optional parameter.

geoh5py.ui_json.utils.str2inf(value: Any) → Any#

Convert string representations of infinity to float infinity values.

Converts “inf” and “-inf” strings to their corresponding float values.

Parameters:

value – Value to convert, typically a string.

Returns:

Float infinity value if input is “inf” or “-inf”, original value otherwise.

geoh5py.ui_json.utils.str2list(value: Any) → Any#

Convert string representation of numbers to list of floats.

Maps string values like “[1,2,3]” or “1,2,3” to [1.0, 2.0, 3.0]. Handles special cases like “inf”, “-inf”, and empty strings.

Parameters:

value – Value to convert, typically a string or already converted type.

Returns:

List of floats if conversion successful, original value otherwise.

geoh5py.ui_json.utils.truth(ui_json: dict[str, dict[str, Any]], name: str, member: str) → bool#

Get a parameter’s member value with default fallback for non-existent members.

Returns the value of a specific member field for a parameter, or a default value if the member doesn’t exist.

Parameters:
  • ui_json – UI JSON dictionary containing the parameters.

  • name – Name of the parameter to check.

  • member – Name of the member field to retrieve.

Returns:

The member’s value or its default value.

Raises:

ValueError – If the field was not provided and does not have a default state.

geoh5py.ui_json.utils.workspace2path(value: Any) → str#

Convert a Workspace object to its file path string.

Deprecated: This function has been migrated to geoh5py.shared.utils.workspace2path and will be removed in future versions.

Parameters:

value – Workspace object or other value to convert.

Returns:

File path string for Workspace objects, “[in-memory]” for in-memory workspaces, or the original value for non-Workspace inputs.

geoh5py.ui_json.validation module#

Module contents#