21
21
FloatText ,
22
22
IntText ,
23
23
SelectMultiple ,
24
+ RadioButtons ,
24
25
)
25
26
import ipywidgets as widgets
26
27
27
28
28
- class LinearInversionApp (object ):
29
+ class LinearInversionCGApp (object ):
29
30
"""docstring for LinearInversionApp"""
30
31
31
32
# Parameters for sensitivity matrix, G
@@ -53,7 +54,7 @@ class LinearInversionApp(object):
53
54
save = None
54
55
55
56
def __init__ (self ):
56
- super (LinearInversionApp , self ).__init__ ()
57
+ super (LinearInversionCGApp , self ).__init__ ()
57
58
58
59
@property
59
60
def G (self ):
@@ -205,6 +206,7 @@ def plot_model(
205
206
self .floor = floor
206
207
207
208
option_bools = [False , False , False ]
209
+
208
210
for item in option :
209
211
if item == "kernel" :
210
212
option_bools [0 ] = True
@@ -263,7 +265,7 @@ def get_problem_survey(self):
263
265
survey .pair (prob )
264
266
return survey , prob
265
267
266
- def run_inversion (
268
+ def run_inversion_cg (
267
269
self ,
268
270
maxIter = 60 ,
269
271
m0 = 0.0 ,
@@ -327,6 +329,7 @@ def run_inversion(
327
329
328
330
def plot_inversion (
329
331
self ,
332
+ mode = "Run" ,
330
333
maxIter = 60 ,
331
334
m0 = 0.0 ,
332
335
mref = 0.0 ,
@@ -339,13 +342,12 @@ def plot_inversion(
339
342
alpha_s = 1.0 ,
340
343
alpha_x = 1.0 ,
341
344
use_target = False ,
342
- run = True ,
343
345
option = "model" ,
344
346
i_iteration = 1 ,
345
347
):
346
348
347
- if run :
348
- self .model , self .pred , self .save = self .run_inversion (
349
+ if mode == "Run" :
350
+ self .model , self .pred , self .save = self .run_inversion_cg (
349
351
maxIter = maxIter ,
350
352
m0 = m0 ,
351
353
mref = mref ,
@@ -371,12 +373,12 @@ def plot_inversion(
371
373
fig , axes = plt .subplots (1 , 3 , figsize = (14 * 1.2 , 3 * 1.2 ))
372
374
373
375
axes [0 ].plot (self .mesh .vectorCCx , self .m )
374
- if run :
376
+ if mode == "Run" :
375
377
axes [0 ].plot (self .mesh .vectorCCx , self .model [i_plot ])
376
378
axes [0 ].set_ylim ([- 2.5 , 2.5 ])
377
379
axes [1 ].errorbar (x = self .jk , y = self .data , yerr = self .uncertainty , color = "k" , lw = 1 )
378
380
axes [1 ].plot (self .jk , self .data , "ko" )
379
- if run :
381
+ if mode == "Run" :
380
382
axes [1 ].plot (self .jk , self .pred [i_plot ], "bx" )
381
383
axes [1 ].legend (("Observed" , "Predicted" ))
382
384
axes [0 ].legend (("True" , "Pred" ))
@@ -400,7 +402,7 @@ def plot_inversion(
400
402
i_iteration = max_iteration
401
403
402
404
if option == "misfit" :
403
- if not run :
405
+ if mode == "Explore" :
404
406
axes [0 ].plot (self .mesh .vectorCCx , self .model [i_iteration ])
405
407
axes [1 ].plot (self .jk , self .pred [i_iteration ], "bx" )
406
408
# axes[0].legend(("True", "Pred", ("%ith")%(i_iteration)))
@@ -444,7 +446,7 @@ def plot_inversion(
444
446
axes [2 ].set_title ("Misfit curves" )
445
447
446
448
elif option == "tikhonov" :
447
- if not run :
449
+ if mode == "Explore" :
448
450
axes [0 ].plot (self .mesh .vectorCCx , self .model [i_iteration ])
449
451
axes [1 ].plot (self .jk , self .pred [i_iteration ], "bx" )
450
452
# axes[0].legend(("True", "Pred", ("%ith")%(i_iteration)))
@@ -567,6 +569,9 @@ def interact_plot_model(self):
567
569
def interact_plot_inversion (self , maxIter = 30 ):
568
570
interact (
569
571
self .plot_inversion ,
572
+ mode = RadioButtons (
573
+ description = "mode" , options = ["Run" , "Explore" ], value = "Run"
574
+ ),
570
575
maxIter = IntText (value = maxIter ),
571
576
m0 = FloatSlider (
572
577
min = - 2 , max = 2 , step = 0.05 , value = 0.0 , continuous_update = False
@@ -586,7 +591,6 @@ def interact_plot_inversion(self, maxIter=30):
586
591
),
587
592
alpha_s = FloatText (value = 1e-10 ),
588
593
alpha_x = FloatText (value = 0 ),
589
- run = True ,
590
594
target = False ,
591
595
option = ToggleButtons (options = ["misfit" , "tikhonov" ], value = "misfit" ),
592
596
i_iteration = IntSlider (
0 commit comments