Skip to content

Commit b95dab0

Browse files
authored
Merge pull request #211 from MiraGeoscience/GEOPY-2143
GEOPY-2143: ensure backward compatibility of saved ui.json from Analyst 4.5 to 4.6
2 parents 7baad45 + 62eaa23 commit b95dab0

60 files changed

Lines changed: 13405 additions & 212 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ repos:
8686
- id: mixed-line-ending
8787
exclude: ^\.idea/.*\.xml$
8888
- id: name-tests-test
89+
exclude: testing_utils.py
8990
- id: pretty-format-json
9091
args:
9192
- --autofix

simpeg_drivers/driver.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -612,30 +612,38 @@ def configure_dask(self):
612612
dconf.set(scheduler="threads", pool=ThreadPool(n_cpu))
613613

614614
@classmethod
615-
def start(cls, filepath: str | Path | InputFile):
615+
def start(
616+
cls, filepath: str | Path | InputFile, driver_class=None, **kwargs
617+
) -> InversionDriver:
618+
"""
619+
Start the inversion driver.
620+
621+
:param filepath: Path to the input file or InputFile object.
622+
:param driver_class: Optional driver class to use instead of the default.
623+
:param kwargs: Additional keyword arguments for InputFile read_ui_json.
624+
625+
:return: InversionDriver instance with the specified parameters.
626+
"""
616627
if isinstance(filepath, InputFile):
617628
ifile = filepath
618629
else:
619-
ifile = InputFile.read_ui_json(filepath)
630+
ifile = InputFile.read_ui_json(filepath, **kwargs)
620631

621-
forward_only = ifile.data["forward_only"]
622-
inversion_type = ifile.ui_json.get("inversion_type", None)
623-
624-
driver_class = cls.driver_class_from_name(
625-
inversion_type, forward_only=forward_only
626-
)
627-
628-
with ifile.data["geoh5"].open(mode="r+"):
629-
params = driver_class._options_class.build(ifile)
630-
driver = driver_class(params)
632+
if driver_class is None:
633+
driver = cls.from_input_file(ifile)
634+
else:
635+
with ifile.data["geoh5"].open(mode="r+"):
636+
params = driver_class._options_class.build(ifile)
637+
driver = driver_class(params)
631638

632639
driver.run()
640+
633641
return driver
634642

635643
@staticmethod
636644
def driver_class_from_name(
637645
name: str, forward_only: bool = False
638-
) -> InversionDriver:
646+
) -> type[InversionDriver]:
639647
if name not in DRIVER_MAP:
640648
msg = f"Inversion type {name} is not supported."
641649
msg += f" Valid inversions are: {(*list(DRIVER_MAP),)}."
@@ -649,6 +657,26 @@ def driver_class_from_name(
649657
module = __import__(mod_name, fromlist=[class_name])
650658
return getattr(module, class_name)
651659

660+
@classmethod
661+
def from_input_file(cls, ifile: InputFile) -> InversionDriver:
662+
forward_only = ifile.data["forward_only"]
663+
inversion_type = ifile.ui_json.get("inversion_type", None)
664+
if inversion_type is None:
665+
raise GeoAppsError(
666+
"Key/value 'inversion_type' not found in the input file. "
667+
"Please specify the inversion type in the UI JSON."
668+
)
669+
670+
driver_class = cls.driver_class_from_name(
671+
inversion_type, forward_only=forward_only
672+
)
673+
674+
with ifile.data["geoh5"].open(mode="r+"):
675+
params = driver_class._options_class.build(ifile)
676+
driver = driver_class(params)
677+
678+
return driver
679+
652680

653681
class InversionLogger:
654682
def __init__(self, logfile, driver):

tests/data_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from simpeg_drivers.potential_fields.magnetic_vector.options import (
3030
MVIInversionOptions,
3131
)
32-
from simpeg_drivers.utils.testing import Geoh5Tester, setup_inversion_workspace
32+
from tests.testing_utils import Geoh5Tester, setup_inversion_workspace
3333

3434

3535
def get_mvi_params(tmp_path: Path, **kwargs) -> MVIInversionOptions:

tests/driver_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from simpeg_drivers.options import ActiveCellsOptions
1616
from simpeg_drivers.potential_fields import GravityInversionOptions
1717
from simpeg_drivers.potential_fields.gravity.driver import GravityInversionDriver
18-
from simpeg_drivers.utils.testing import setup_inversion_workspace
18+
from tests.testing_utils import setup_inversion_workspace
1919

2020

2121
def test_smallness_terms(tmp_path: Path):
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
{
2+
"version": "0.2.0-alpha.1",
3+
"title": "Direct Current (DC) 2D Forward",
4+
"icon": "PotentialElectrode",
5+
"documentation": "https://mirageoscience-simpeg-drivers.readthedocs-hosted.com/en/stable/intro.html",
6+
"conda_environment": "simpeg_drivers",
7+
"run_command": "simpeg_drivers.driver",
8+
"geoh5": "",
9+
"monitoring_directory": "",
10+
"workspace_geoh5": "",
11+
"inversion_type": "direct current 2d",
12+
"forward_only": true,
13+
"data_object": {
14+
"main": true,
15+
"group": "Survey",
16+
"label": "Object",
17+
"meshType": "{275ecee9-9c24-4378-bf94-65f3c5fbe163}",
18+
"value": ""
19+
},
20+
"z_from_topo": {
21+
"group": "Survey",
22+
"main": true,
23+
"label": "Surface survey",
24+
"tooltip": "Uncheck if borehole data is present",
25+
"value": true
26+
},
27+
"line_object": {
28+
"association": "Cell",
29+
"dataType": "Referenced",
30+
"group": "Survey",
31+
"main": true,
32+
"label": "Line ID",
33+
"parent": "data_object",
34+
"value": "",
35+
"tooltip": "Selects the data representing the different lines in the survey."
36+
},
37+
"line_id": {
38+
"group": "Survey",
39+
"main": true,
40+
"min": 1,
41+
"label": "Line number",
42+
"value": 1,
43+
"tooltip": "Selects the line of data to be processed."
44+
},
45+
"receivers_radar_drape": {
46+
"association": [
47+
"Cell",
48+
"Vertex"
49+
],
50+
"dataType": "Float",
51+
"group": "Data pre-processing",
52+
"label": "Z radar offset",
53+
"tooltip": "Apply a non-homogeneous offset to survey object from radar channel.",
54+
"optional": true,
55+
"parent": "data_object",
56+
"value": "",
57+
"enabled": false,
58+
"visible": false
59+
},
60+
"receivers_offset_z": {
61+
"group": "Data pre-processing",
62+
"label": "Z static offset",
63+
"optional": true,
64+
"enabled": false,
65+
"value": 0.0,
66+
"visible": false
67+
},
68+
"gps_receivers_offset": "",
69+
"potential_channel_bool": true,
70+
"mesh": {
71+
"group": "Mesh and models",
72+
"main": true,
73+
"optional": true,
74+
"enabled": false,
75+
"label": "Mesh",
76+
"meshType": "{c94968ea-cf7d-11eb-b8bc-0242ac130003}",
77+
"value": ""
78+
},
79+
"u_cell_size": {
80+
"min": 0.0,
81+
"group": "Mesh and models",
82+
"dependency": "mesh",
83+
"dependencyType": "disabled",
84+
"main": true,
85+
"enabled": true,
86+
"label": "Easting core cell size (m)",
87+
"value": 25.0
88+
},
89+
"v_cell_size": {
90+
"min": 0.0,
91+
"group": "Mesh and models",
92+
"dependency": "mesh",
93+
"dependencyType": "disabled",
94+
"main": true,
95+
"enabled": true,
96+
"label": "Northing core cell size (m)",
97+
"value": 25.0
98+
},
99+
"depth_core": {
100+
"min": 0.0,
101+
"group": "Mesh and models",
102+
"dependency": "mesh",
103+
"dependencyType": "disabled",
104+
"main": true,
105+
"enabled": true,
106+
"label": "Depth of core (m)",
107+
"value": 500.0
108+
},
109+
"horizontal_padding": {
110+
"min": 0.0,
111+
"group": "Mesh and models",
112+
"dependency": "mesh",
113+
"dependencyType": "disabled",
114+
"main": true,
115+
"enabled": true,
116+
"label": "Horizontal padding (m)",
117+
"value": 1000.0
118+
},
119+
"vertical_padding": {
120+
"min": 0.0,
121+
"group": "Mesh and models",
122+
"dependency": "mesh",
123+
"dependencyType": "disabled",
124+
"main": true,
125+
"label": "Vertical padding (m)",
126+
"value": 1000.0
127+
},
128+
"expansion_factor": {
129+
"main": true,
130+
"group": "Mesh and models",
131+
"dependency": "mesh",
132+
"dependencyType": "disabled",
133+
"label": "Expansion factor",
134+
"value": 1.1
135+
},
136+
"model_type": {
137+
"choiceList": [
138+
"Conductivity (S/m)",
139+
"Resistivity (Ohm-m)"
140+
],
141+
"main": true,
142+
"group": "Mesh and models",
143+
"label": "Model units",
144+
"tooltip": "Select the units of the model.",
145+
"value": "Conductivity (S/m)"
146+
},
147+
"starting_model": {
148+
"association": "Cell",
149+
"dataType": "Float",
150+
"group": "Mesh and models",
151+
"main": true,
152+
"isValue": true,
153+
"parent": "mesh",
154+
"label": "Value(s)",
155+
"property": "",
156+
"value": 0.001
157+
},
158+
"topography_object": {
159+
"main": true,
160+
"group": "Topography",
161+
"label": "Topography",
162+
"meshType": [
163+
"{202c5db1-a56d-4004-9cad-baafd8899406}",
164+
"{6a057fdc-b355-11e3-95be-fd84a7ffcb88}",
165+
"{f26feba3-aded-494b-b9e9-b2bbcbe298e1}",
166+
"{48f5054a-1c5c-4ca4-9048-80f36dc60a06}",
167+
"{b020a277-90e2-4cd7-84d6-612ee3f25051}"
168+
],
169+
"value": "",
170+
"optional": true,
171+
"enabled": true,
172+
"tooltip": "Select a topography object to define the active cells for inversion."
173+
},
174+
"topography": {
175+
"association": [
176+
"Vertex",
177+
"Cell"
178+
],
179+
"dataType": "Float",
180+
"group": "Topography",
181+
"main": true,
182+
"optional": true,
183+
"enabled": false,
184+
"label": "Elevation channel",
185+
"tooltip": "Set elevation from channel. If not set the topography will be set from the geometry of the selected 'topography' object.",
186+
"parent": "topography_object",
187+
"dependency": "topography_object",
188+
"dependencyType": "enabled",
189+
"value": "",
190+
"verbose": 2
191+
},
192+
"active_model": {
193+
"association": "Cell",
194+
"dataType": [
195+
"Referenced",
196+
"Boolean",
197+
"Integer"
198+
],
199+
"group": "Topography",
200+
"main": true,
201+
"enabled": false,
202+
"dependency": "topography_object",
203+
"dependencyType": "disabled",
204+
"label": "Active model",
205+
"tooltip": "Provide the active cell boolean model directly if topography not set.",
206+
"parent": "mesh",
207+
"value": ""
208+
},
209+
"output_tile_files": false,
210+
"parallelized": {
211+
"group": "Compute",
212+
"label": "Use parallelization",
213+
"value": true,
214+
"visible": false
215+
},
216+
"n_cpu": {
217+
"min": 1,
218+
"group": "Compute",
219+
"dependency": "parallelized",
220+
"dependencyType": "enabled",
221+
"optional": true,
222+
"enabled": false,
223+
"label": "Number of CPUs",
224+
"value": 1,
225+
"visible": false
226+
},
227+
"tile_spatial": 1,
228+
"max_chunk_size": {
229+
"min": 0,
230+
"group": "Compute",
231+
"optional": true,
232+
"enabled": true,
233+
"label": "Maximum chunk size (Mb)",
234+
"value": 128,
235+
"verbose": 3,
236+
"visible": false,
237+
"tooltip": "Limit the chunk size used by Dask for distributed computation."
238+
},
239+
"chunk_by_rows": {
240+
"group": "Compute",
241+
"label": "Chunk by rows",
242+
"value": true,
243+
"verbose": 3,
244+
"visible": false
245+
},
246+
"out_group": {
247+
"label": "SimPEG group",
248+
"value": "",
249+
"groupType": "{55ed3daf-c192-4d4b-a439-60fa987fe2b8}",
250+
"group": "Drag-and-drop options",
251+
"visible": true,
252+
"optional": true,
253+
"enabled": false,
254+
"tooltip": "Optionally set the SimPEG group to which results will be saved."
255+
},
256+
"generate_sweep": {
257+
"label": "Generate sweep file",
258+
"group": "Python run preferences",
259+
"main": true,
260+
"value": false,
261+
"tooltip": "Generates a file for sweeping parameters instead of running the application."
262+
},
263+
"distributed_workers": "",
264+
"gradient_type": {
265+
"choiceList": [
266+
"total",
267+
"components"
268+
],
269+
"group": "Sparse/blocky model",
270+
"label": "Gradient type",
271+
"value": "total",
272+
"verbose": 3,
273+
"tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients."
274+
}
275+
}

0 commit comments

Comments
 (0)