Custom User Interface (ui.json)#

This section provides training on how to create custom user interface within Geoscience ANALYST using the ui.json standard. In this section we are going to demonstrate how to:

  • Create a basic user-interface programmatically

  • Read and write a ui.json from file

  • Demonstrate how to set up ANALYST to run a custom program

Creating a ui.json#

The ui.json format is based on the json standard - a format widely used in programming. Python comes by default with a json module to read and write to file. All we need is a way to create the structure that ANALYST understands. We can make use of the geoh5py.ui_json module to get started.

from geoh5py.ui_json import constants, templates
from training import assets_path

First, we need the base components must contain a few base parameters, such as a title and a run_command. A constants.default_ui_json is available to quickly get starget:

my_ui = constants.default_ui_json.copy()
my_ui["title"] = "Hello World!"
my_ui
{'title': 'Hello World!',
 'geoh5': None,
 'run_command': None,
 'run_command_boolean': {'value': False,
  'label': 'Run python module ',
  'tooltip': 'Warning: launches process to run python model on save',
  'main': True},
 'monitoring_directory': None,
 'conda_environment': None,
 'conda_environment_boolean': False,
 'workspace': None}

Note that the run_command is currently set to None, and therefore nothing will be executed by ANALYST. We will get to that part later.

You could write this dictionary directly to file using the built-in json module with

import json

with open(assets_path() / "myUI.ui.json", "w", encoding="utf-8") as file:
    json.dump(my_ui, file, indent=4)

which writes it out as text file under the assets directory. From here you can drag & drop the file to the Viewport of ANALYST, which would render as:

base_ui

This user-interface doesn’t do much at the moment so we can add a few additional forms. More parameters can be added by a simple update of the base dictionary. You can use any of the 8 forms currently supported:

Bool value#

Checkbox to set an option as true or false.

my_ui.update({
    "value_bool": templates.bool_parameter(label="True/false")
})

bool_ui

Integer value#

Value field for integers. It is possible to set min/max values to bound the output.

my_ui.update({
    "value_int": templates.integer_parameter(label="Some value:")
})

int_ui

Float value#

Value field for floats. Bounds on value also available.

my_ui.update({
    "value_float": templates.float_parameter(label="Some value:")
})

float_ui

String value#

String field for text value.

my_ui.update({
    "value_string": templates.string_parameter(label="Some value:")
})

string_ui

Multi-choice string#

Dropdown list of string values to chose from.

my_ui.update({
    "choice": templates.choice_string_parameter(label="Select:")
})

choice_string_ui

File choice#

Button to browse for a file on disk.

my_ui.update({
    "file": templates.file_parameter(label="Select file:", fileType=["geoh5"], fileDescription=["project"])
})

file_ui

Geoh5 Object selection#

Dropdown selection for objects listed under an active ANALYST session. The mesh_type attribute lets filter specific object types by their uuid types

my_ui.update({
    "object": templates.object_parameter(label="Object", mesh_type="")
})

object_ui

Geoh5 Data selection#

Dropdown selection of data listed under the parent object.

my_ui.update({
    "object": templates.object_parameter(label="Object", mesh_type=""),
    "data": templates.data_parameter(label="Data", parent="object")
})

data_ui

You are invited to click on the link provided for each form to read about the different options available to further control your UI.

Once you are done adding forms:

  • Write this file out to disk

  • Drag & drop the ui.json to the viewport of ANALYST

  • Do some selections

  • Click Apply or Ok to write back out the ui.json.

run_ui

Copyright (c) 2022 Mira Geoscience Ltd.