geoh5py.ui_json¶
geoh5py.ui_json.constants¶
geoh5py.ui_json.input_file¶
- class geoh5py.ui_json.input_file.InputFile(data: dict[str, Any] | None = None, ui_json: dict[str, Any] | None = None, validate: bool = True, validations: dict | None = None, validation_options: dict | None = None, promotion: bool = True)[source]¶
Bases:
object
Handles loading ui.json input files.
- Attributes:
data
Input file content parsed to flat dictionary of key:value.Dictionary representing the input data for the ui.json file.
- ui_json: User interface serializable as ui.json format
- workspace: Target :obj:`geoh5py.workspace.Workspace`
- validations: Dictionary of validations for parameters in the input file
Methods
write_ui_json()
Writes a ui.json formatted file from ‘data’ attribute contents.
read_ui_json()
Reads a ui.json formatted file into ‘data’ attribute dictionary. Optionally filters ui.json fields other than ‘value’.
- association_validator = <geoh5py.shared.validators.AssociationValidator object>¶
- property data: dict[str, Any] | None¶
Dictionary representing the input data for the ui.json file.
- classmethod demote(var: dict[str, Any]) dict[str, Any] [source]¶
Converts promoted parameter values to their string representations.
Other parameters are left unchanged.
- property geoh5¶
Geoh5 workspace.
- property name: str | None¶
Name of ui.json file.
- classmethod numify(ui_json: dict[str, Any]) dict[str, Any] [source]¶
Convert inf, none and list strings to numerical types within a dictionary
- Parameters:
- ui_json
dictionary containing ui.json keys, values, fields
- Returns:
- Dictionary with inf, none and list string representations converted numerical types.
- property path: str | None¶
Directory for the input/output ui.json file.
- property path_name: str | None¶
- static read_ui_json(json_file: str | Path, **kwargs)[source]¶
Read and create an InputFile from ui.json
- set_data_value(key: str, value)[source]¶
Set the data and json form values from a dictionary.
- Parameters:
key – Parameter name to update.
value – Value to update with.
- static stringify(var: dict[str, Any]) dict[str, Any] [source]¶
Convert inf, none, and list types to strings within a dictionary
- Parameters:
var – Dictionary containing ui.json keys, values, fields
- Returns:
Dictionary with inf and none types converted to string representations in json format.
- property ui_json: dict | None¶
Dictionary representing the ui.json file with promoted values.
- update_ui_values(data: dict)[source]¶
Update the ui.json values and enabled status from input data.
- Parameters:
data – Key and value pairs expected by the ui_json.
- Raises:
AttributeError – If attempting to set None value to non-optional parameter.
- property validate¶
Option to run validations.
- property validation_options¶
Pass validation options to the validators.
The following options are supported:
- update_enabled: bool
If True, the enabled status of the ui_json will be updated based on the value provided. Default is True.
- ignore_list: tuple
List of keys to ignore when validating the ui_json. Default is empty tuple.
- property validations: dict | None¶
Dictionary of validations for the ui_json.
- property validators¶
geoh5py.ui_json.templates¶
- geoh5py.ui_json.templates.bool_parameter(main: bool = True, label: str = 'Logical data', value: bool = False) dict [source]¶
Checkbox for true/false choice.
- Parameters:
main – Show ui in main.
label – Label identifier.
value – Input value.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.choice_string_parameter(choice_list: tuple = ('Option A', 'Option B'), label: str = 'String data', main: bool = True, multi_select: bool = False, optional: str | None = None, value: str = 'Option A') dict [source]¶
Dropdown menu of string choices.
- Parameters:
main – Show form in main.
choice_list – List of options.
label – Label identifier.
multi_select – Option to select multiple choices.
value – Input value.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.data_parameter(main: bool = True, label: str = 'Data channel', association: str = 'Vertex', data_type: str = 'Float', data_group_type: str | None = None, parent: str = '', value: str = '', optional: str | None = None) dict [source]¶
Dropdown menu of data from parental object.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
association – Data association type from ‘Vertex’ or ‘Cell’.
data_type – Type of data selectable from ‘Float’, ‘Integer’ or ‘Reference’.
data_group_type – [Optional] Select from property_groups of type. ‘3D vector’, ‘Dip direction & dip’, ‘Strike & dip’, or ‘Multi-element’.
multi_select – Option to select multiple choices.
parent – Parameter name corresponding to the parent object.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.data_value_parameter(main: bool = True, label: str = 'Data channel', association: str = 'Vertex', data_type: str = 'Float', parent: str = '', value: float = 0.0, is_value: bool = True, prop: UUID | Entity | None = None, optional: str | None = None) dict [source]¶
Dropdown of data or input box.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
association – Data association type from ‘Vertex’ or ‘Cell’.
data_type – Type of data selectable from ‘Float’, ‘Integer’ or ‘Reference’.
data_group_type – [Optional] Select from property_groups of type. ‘3D vector’, ‘Dip direction & dip’, ‘Strike & dip’, or ‘Multi-element’.
parent – Parameter name corresponding to the parent object.
is_value – Display the input box or dropdown menu.
prop – Data entity selected in the dropdown menu if ‘is_value=False’.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.drillhole_group_data(value: list[str] | None = None, main: bool = True, label: str = 'Data channel', group_type: UUID = UUID('825424fb-c2c6-4fea-9f2b-6cd00023d393'), group_value: UUID | None = None, multiselect: bool = True, optional: str | None = None, enabled: bool = True, tooltip: str = 'Select the data channel to use for the calculation.') dict [source]¶
Dropdown of data or input box.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
group_type – The group type to select, must be drillhole group.
group_value – The selected group UUID.
multiselect – Allow multiple data selection.
value – The name of the Data channel to extract.
optional – Make optional if not None. Initial state provided by not None
enabled – Enable or disable the form.
tooltip – The tooltip to display when hovering over the form.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.file_parameter(main: bool = True, label: str = 'File choices', file_description: tuple = (), file_type: tuple = (), value: str = '', optional: str | None = None) dict [source]¶
File loader for specific extensions.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
file_description – Title used to describe each type.
file_type – Extension of files to display.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.float_parameter(main: bool = True, label: str = 'Float data', value: float = 1.0, vmin: float | None = None, vmax: float | None = None, precision: int = 2, line_edit: bool = True, optional: str | None = None) dict [source]¶
Input box for float value.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
vmin – Minimum value allowed.
vmax – Maximum value allowed.
line_edit – Allow line edit or spin box
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.group_parameter(main: bool = True, label: str = 'Object', group_type: tuple = (UUID('812f3b2a-fdae-4752-8391-3b657953a983'), UUID('3d0e8578-7764-48cf-8db8-6c83d6411762'), UUID('61fbb4e8-a480-11e3-8d5a-2776bdf4f982'), UUID('79769142-2009-4450-a9f3-88b6b9a35841'), UUID('825424fb-c2c6-4fea-9f2b-6cd00023d393'), UUID('adee3b2a-3829-11e4-a70e-fcddabfddab1'), UUID('72f29283-a4f6-4fc0-a1a8-1417ce5fcbec'), UUID('ed00094f-3da1-485f-8c4e-b52f6f171ea4'), UUID('151778d9-6cc0-4e72-ba08-2a80a4fb967f'), UUID('585b3218-c24b-41fe-ad1f-24d5e6e8348a'), UUID('47d6f059-b56a-46c7-8fc7-a0ded87360c3'), UUID('952829b6-76a2-4d0b-b908-7f8d2482dc0d'), UUID('61449477-3833-11e4-a7fb-fcddabfddab1'), UUID('56f6f03e-3833-11e4-a7fb-fcddabfddab1'), UUID('dd99b610-be92-48c0-873c-5b5946ea2840'), UUID('f65e521c-a763-427b-97bf-d0b4e5689e0d'), UUID('85756113-592a-4088-b374-f32c8fac37a2'), UUID('cbeb3920-a1a9-46f8-ab2b-7dfdf79c8a00'), UUID('dd99b610-be92-48c0-873c-5b5946ea2840'), UUID('1cde9996-cda7-40f0-8c20-faeb4e926748'), UUID('55ed3daf-c192-4d4b-a439-60fa987fe2b8')), value: str | None = None, optional: str | None = None) dict [source]¶
Dropdown menu of groups of specific types.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
group_type – Type of selectable groups.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.integer_parameter(main: bool = True, label: str = 'Integer data', value: int = 1, vmin: int | None = None, vmax: int | None = None, optional: str | None = None) dict [source]¶
Input box for integer value.
- Parameters:
main – Show ui in main.
label – Label identifier.
value – Input value.
vmin – Minimum value allowed.
vmax – Maximum value allowed.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.object_parameter(main: bool = True, label: str = 'Object', mesh_type: tuple = (UUID('b3a47539-0301-4b27-922e-1dde9d882c60'), UUID('a006cf3e-e24a-4c02-b904-2e57b9b5916d'), UUID('4b99204c-d133-4579-a916-a9c8b98cfccb'), UUID('19730589-fd28-4649-9de0-ad47249d9aba'), UUID('58c4849f-41e2-4e09-b69b-01cf4286cded'), UUID('b020a277-90e2-4cd7-84d6-612ee3f25051'), UUID('9b08bb5a-300c-48fe-9007-d206f971ea92'), UUID('6a057fdc-b355-11e3-95be-fd84a7ffcb88'), UUID('c94968ea-cf7d-11eb-b8bc-0242ac130003'), UUID('7caebf0e-d16e-11e3-bc69-e4632694aa37'), UUID('77ac043c-fe8d-4d14-8167-75e300fb835a'), UUID('48f5054a-1c5c-4ca4-9048-80f36dc60a06'), UUID('6832acf3-78aa-44d3-8506-9574a3510c44'), UUID('e79f449d-74e3-4598-9c9c-351a28b8b69e'), UUID('30928322-cf2c-4230-b393-4dc629259b64'), UUID('fe1a240a-9189-49ff-aa7e-6067405b6e0a'), UUID('deebe11a-b57b-4a03-99d6-8f27b25eb2a8'), UUID('17dbbfbb-3ee4-461c-9f1d-1755144aac90'), UUID('b99bd6e5-4fe1-45a5-bd2f-75fc31f91b38'), UUID('a81c6b0a-f290-4bc8-b72d-60e59964bfe8'), UUID('f59d5a1c-5e63-4297-b5bc-43898cb4f5f8'), UUID('41018a45-01a0-4c61-a7cb-9f32d8159df4'), UUID('98a96d44-6144-4adb-afbe-0d5e757c9dfc'), UUID('88087fb8-76ae-445b-9cdf-68dbce530404'), UUID('849d2f3e-a46e-11e3-b401-2776bdf4f982'), UUID('4ea87376-3ece-438b-bf12-3479733ded46'), UUID('202c5db1-a56d-4004-9cad-baafd8899406'), UUID('275ecee9-9c24-4378-bf94-65f3c5fbe163'), UUID('f26feba3-aded-494b-b9e9-b2bbcbe298e1'), UUID('f495cd13-f09b-4a97-9212-2ea392aeb375'), UUID('0b639533-f35b-44d8-92a8-f70ecff3fd26')), multi_select: bool = False, value: str | None = None, optional: str | None = None) dict [source]¶
Dropdown menu of objects of specific types.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input value.
multi_select – Option to select multiple choices.
mesh_type – Type of selectable objects.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
- geoh5py.ui_json.templates.optional_parameter(state: str) dict[str, bool] [source]¶
Returns dictionary to make existing ui optional via .update() method.
- Parameters:
state – Initial state of optional parameter. Can be ‘enabled’ or ‘disabled’.
- geoh5py.ui_json.templates.range_label_template(main: bool = True, label: str = 'Range', allow_complement: bool = False, is_complement: bool = False, parent: str = '', property_: str | UUID = '', association: str = 'Vertex', data_type: list[str] | str = 'Float', value: list[float | int] | None = None, range_label: str = 'Values', enabled: bool = True, optional: str | None = None) dict [source]¶
Template for range label.
Or it is a multiselect data on a property group if referenced data. Or they are 2 values, an upper and lower bound as float values. In the second scenario, is_complement allows to invert the range.
- Parameters:
main – Show form in main.
label – The label identifier.
allow_complement – If users can invert the range.
is_complement – If the range is inverted.
parent – The parent object.
property – The property uid associated with the range.
association – The association type.
data_type – The data type of the range.
value – The value of the range.
range_label – The label of the range.
enabled – The state of the form.
optional – Make optional if not None. Initial state provided by not None.
- Returns:
The form dictionary.
- geoh5py.ui_json.templates.string_parameter(main: bool = True, label: str = 'String data', value: str = 'data', optional: str | None = None) dict [source]¶
Input box for string value.
- Parameters:
main – Show form in main.
label – Label identifier.
value – Input string value.
optional – Make optional if not None. Initial state provided by not None value. Can be either ‘enabled’ or ‘disabled’.
- Returns:
Ui_json compliant dictionary.
geoh5py.ui_json.utils¶
- geoh5py.ui_json.utils.collect(ui_json: dict[str, dict], member: str, value: Any | None = None) dict[str, Any] [source]¶
Collects ui parameters with common field and optional value.
- geoh5py.ui_json.utils.dependency_requires_value(ui_json: dict[str, dict], parameter: str) bool [source]¶
Handles dependency and optional requirements.
If dependency doesn’t require a value then the function returns False. But 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
parameter – Name of parameter to check type.
- geoh5py.ui_json.utils.find_all(ui_json: dict[str, dict], member: str, value: Any | None = None) list[str] [source]¶
Returns names of all collected parameters.
- geoh5py.ui_json.utils.flatten(ui_json: dict[str, dict]) dict[str, Any] [source]¶
Flattens ui.json format to simple key/value pair.
- geoh5py.ui_json.utils.group_enabled(group: dict[str, dict]) bool [source]¶
Return true if groupOptional and enabled are both true.
- Parameters:
group – UI.json dictionary
- geoh5py.ui_json.utils.group_optional(ui_json: dict[str, dict], group_name: str) bool [source]¶
Returns groupOptional bool for group name.
- geoh5py.ui_json.utils.group_requires_value(ui_json: dict[str, dict], parameter: str) bool [source]¶
True is groupOptional and group is enabled else False
- Parameters:
ui_json – UI.json dictionary
parameter – Name of parameter to check type.
- geoh5py.ui_json.utils.is_form(var) bool [source]¶
Return true if dictionary ‘var’ contains both ‘label’ and ‘value’ members.
- geoh5py.ui_json.utils.is_uijson(ui_json: dict[str, dict])[source]¶
Returns True if dictionary contains all the required parameters.
- geoh5py.ui_json.utils.monitored_directory_copy(directory: str, entity: ObjectBase | Group, copy_children: bool = True) str [source]¶
Create a temporary geoh5 file in the monitoring folder and export entity for update.
- Parameters:
directory – Monitoring directory
entity – Entity to be updated
copy_children – Option to copy children entities.
- geoh5py.ui_json.utils.optional_requires_value(ui_json: dict[str, dict], parameter: str) bool [source]¶
True if enabled else False.
- Parameters:
ui_json – UI.json dictionary
parameter – Name of parameter to check type.
- geoh5py.ui_json.utils.requires_value(ui_json: dict[str, dict], parameter: str) bool [source]¶
Check if a ui.json parameter requires a value (is not optional).
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 on the bottom is the optional switch. When group optional is disabled all parameters in the group are not required, When the groupOptional is enabled the required status of a parameter depends first any dependencies and lastly on it’s optional status.
- Parameters:
ui_json – UI.json dictionary
parameter – Name of parameter to check type.
- geoh5py.ui_json.utils.set_enabled(ui_json: dict, parameter: str, value: bool)[source]¶
Set enabled status for an optional or groupOptional parameter.
- Parameters:
ui_json – UI.json dictionary
parameter – Parameter name.
value – Boolean value set to parameter’s enabled member.
geoh5py.ui_json.validation¶
- class geoh5py.ui_json.validation.InputValidation(validators: dict[str, BaseValidator] | None = None, validations: dict[str, Any] | None = None, ui_json: dict[str, Any] | None = None, validation_options: dict[str, Any] | None = None)[source]¶
Bases:
object
Validations on dictionary of parameters.
- Attributes:
- validationsValidations dictionary with matching set of input parameter keys.
- ignore_requirements (optional): Omit raising error on ‘required’ validator.
Methods
validate_data(data)
Validates data of params and contents/type/shape/keys/reqs of values.
- static infer_validations(ui_json: dict[str, Any] | None, validations: dict[str, dict] | None = None) dict [source]¶
Infer necessary validations from ui json structure.
- validate(name: str, value: Any, validations: dict[str, Any] | None = None)[source]¶
Run validations on a given key and value.
- Parameters:
name – Parameter identifier.
value – Input parameter value.
validations – [Optional] Validations provided on runtime
- validate_data(data: dict[str, Any]) None [source]¶
Calls validate method on ui.json data structure for cross-dependencies.
Individual key, value pairs are validated for expected type.
- Parameters:
data – Input data with known validations.
- property validations¶
- property validators¶