Skip to content

Commit

Permalink
Merge pull request #402 from MiraGeoscience/GEOPY-564
Browse files Browse the repository at this point in the history
Geopy 564
  • Loading branch information
domfournier authored Sep 14, 2022
2 parents 2343607 + dd0ce29 commit a35d86b
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 136 deletions.
4 changes: 2 additions & 2 deletions geoapps/base/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def set_bounding_box(self, _):
self.window_center_y.min = lim_y[0] - height * 0.1

self.window_width.max = width * 1.2
self.window_width.value = self.window_width.max / 2.0
self.window_width.value = self.window_width.max
self.window_width.min = 0

self.window_height.max = height * 1.2
self.window_height.min = 0
self.window_height.value = self.window_height.max / 2.0
self.window_height.value = self.window_height.max
self.refresh.value = True
9 changes: 9 additions & 0 deletions geoapps/driver_base/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,21 @@ def update(self, params_dict: dict[str, Any], validate=True):
params_dict = self.input_file._promote( # pylint: disable=protected-access
params_dict
)

for key, value in params_dict.items():
if key not in self.ui_json or key == "geoh5":
continue # ignores keys not in default_ui_json

setattr(self, key, value)

# Set all parameters belonging to groupOptional disabled.
for key in utils.find_all(self.ui_json, "groupOptional"):
if key in params_dict and params_dict[key] is None:
for elem in utils.collect(
self.ui_json, "group", self.ui_json[key]["group"]
):
setattr(self, elem, None)

self.validate = original_validate_state

@property
Expand Down
5 changes: 5 additions & 0 deletions geoapps/inversion/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def __init__(

super().__init__(input_file=input_file, **kwargs)

if not self.forward_only:
for key in self.__dict__:
if "channel_bool" in key and getattr(self, key[:-5], None) is not None:
setattr(self, key, True)

def data_channel(self, component: str):
"""Return uuid of data channel."""
return getattr(self, "_".join([component, "channel"]), None)
Expand Down
46 changes: 28 additions & 18 deletions geoapps/inversion/potential_fields/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,17 +957,6 @@ def inversion_type_observer(self, _):
)
data_channel_options = {}
self.data_channel_choices.options = data_type_list
obj, _ = self.get_selected_entities()
if obj is not None:
children_list = {child.uid: child.name for child in obj.children}
ordered = OrderedDict(sorted(children_list.items(), key=lambda t: t[1]))
options = [
[name, uid]
for uid, name in ordered.items()
if "visual parameter" not in name.lower()
]
else:
options = []

def channel_setter(caller):
channel = caller["owner"]
Expand Down Expand Up @@ -1062,9 +1051,7 @@ def value_setter(self, key, value):
]
),
)

setattr(InversionApp, f"{key}_uncertainty", value_setter)

data_channel_options[key] = getattr(self, f"{key}_group")
data_channel_options[key].children[3].children[0].header = key
data_channel_options[key].children[3].children[1].header = key
Expand All @@ -1082,15 +1069,12 @@ def value_setter(self, key, value):
data_channel_options[key].children[3].children[1].observe(
uncert_setter, names="value"
)
data_channel_options[key].children[1].options = [["", None]] + options
data_channel_options[key].children[3].children[1].options = [
["", None]
] + options

self.data_channel_choices.value = inversion_defaults()["component"][
self.inversion_type.value
]
self.data_channel_choices.data_channel_options = data_channel_options
self.update_data_channel_options()
self.data_channel_panel.children = [
self.data_channel_choices,
data_channel_options[self.data_channel_choices.value],
Expand Down Expand Up @@ -1148,12 +1132,33 @@ def object_observer(self, _):
return

self.update_data_list(None)
self.update_data_channel_options()
self.sensor.update_data_list(None)
self.inversion_type_observer(None)
self.write.button_style = "warning"
self._run_params = None
self.trigger.button_style = "danger"

def update_data_channel_options(self):
if getattr(self.data_channel_choices, "data_channel_options", None) is None:
return

obj, _ = self.get_selected_entities()
if obj is not None:
children_list = {child.uid: child.name for child in obj.children}
ordered = OrderedDict(sorted(children_list.items(), key=lambda t: t[1]))
options = [
[name, uid]
for uid, name in ordered.items()
if "visual parameter" not in name.lower()
]
else:
options = []

for channel_option in self.data_channel_choices.data_channel_options.values():
channel_option.children[1].options = [["", None]] + options
channel_option.children[3].children[1].options = [["", None]] + options

def data_channel_choices_observer(self, _):
if hasattr(
self.data_channel_choices, "data_channel_options"
Expand Down Expand Up @@ -1363,8 +1368,13 @@ def file_browser_change(self, _):
InputFile.read_ui_json(self.file_browser.selected)
)
self.params.geoh5.open(mode="r")

params = self.params.to_dict(ui_json_format=False)
if params["resolution"] is None:
params["resolution"] = 0

self.refresh.value = False
self.__populate__(**self.params.to_dict(ui_json_format=False))
self.__populate__(**params)
self.refresh.value = True

elif extension == ".geoh5":
Expand Down
12 changes: 4 additions & 8 deletions geoapps/iso_surfaces/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,17 @@ def trigger_click(self, _) -> str:
with self.get_output_workspace(
self.export_directory.selected_path, temp_geoh5
) as new_workspace:
with self.workspace.open(mode="r"):
param_dict["objects"] = param_dict["objects"].copy(
parent=new_workspace, copy_children=False
)
param_dict["data"] = param_dict["data"].copy(
parent=param_dict["objects"]
)
param_dict["objects"] = param_dict["objects"].copy(
parent=new_workspace, copy_children=False
)
param_dict["data"] = param_dict["data"].copy(parent=param_dict["objects"])
param_dict["geoh5"] = new_workspace

if self.live_link.value:
param_dict["monitoring_directory"] = self.monitoring_directory

new_params = IsoSurfacesParams(**param_dict)
new_params.write_input_file(name=temp_geoh5.replace(".geoh5", ".ui.json"))

driver = IsoSurfacesDriver(new_params)
driver.run()

Expand Down
9 changes: 5 additions & 4 deletions geoapps/iso_surfaces/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ def run(self):
"""
Create iso surfaces from input values
"""

workspace = self.params.geoh5.open(mode="r+")
levels = input_string_2_float(self.params.contours)

if levels is None:
return

print("Starting the isosurface creation.")
surfaces = self.iso_surface(
self.params.objects,
Expand Down Expand Up @@ -66,7 +65,7 @@ def run(self):
):
monitored_directory_copy(self.params.monitoring_directory, container)
print("Isosurface completed. " f"-> {len(surfaces)} surface(s) created.")
workspace.close()

return result

@staticmethod
Expand Down Expand Up @@ -193,4 +192,6 @@ def iso_surface(
file = sys.argv[1]
params_class = IsoSurfacesParams(InputFile.read_ui_json(file))
driver = IsoSurfacesDriver(params_class)
driver.run()

with params_class.geoh5.open(mode="r+"):
driver.run()
Loading

0 comments on commit a35d86b

Please sign in to comment.