Skip to content

Commit 394994b

Browse files
author
George Bisbas
committed
examples: Minor edits
1 parent f2cb28b commit 394994b

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

examples/seismic/tutorials/03_fwi.ipynb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
"from examples.seismic import AcquisitionGeometry\n",
174174
"\n",
175175
"t0 = 0.\n",
176-
"tn = 1000. \n",
176+
"tn = 1000.\n",
177177
"f0 = 0.010\n",
178178
"# First, position source centrally in all dimensions, then set depth\n",
179179
"src_coordinates = np.empty((1, 2))\n",
@@ -419,11 +419,10 @@
419419
"outputs": [],
420420
"source": [
421421
"# Create FWI gradient kernel \n",
422-
"from devito import Function, TimeFunction, norm\n",
422+
"from devito import Function, norm\n",
423423
"from examples.seismic import Receiver\n",
424424
"\n",
425-
"import scipy\n",
426-
"def fwi_gradient(vp_in): \n",
425+
"def fwi_gradient(vp_in):\n",
427426
" # Create symbols to hold the gradient\n",
428427
" grad = Function(name=\"grad\", grid=model.grid)\n",
429428
" # Create placeholders for the data residual and data\n",
@@ -440,19 +439,19 @@
440439
" for i in range(nshots):\n",
441440
" # Update source location\n",
442441
" geometry.src_positions[0, :] = source_locations[i, :]\n",
443-
" \n",
442+
"\n",
444443
" # Generate synthetic data from true model\n",
445444
" _, _, _ = solver.forward(vp=model.vp, rec=d_obs)\n",
446-
" \n",
445+
"\n",
447446
" # Compute smooth data and full forward wavefield u0\n",
448447
" _, u0, _ = solver.forward(vp=vp_in, save=True, rec=d_syn)\n",
449-
" \n",
448+
"\n",
450449
" # Compute gradient from data residual and update objective function \n",
451450
" compute_residual(residual, d_obs, d_syn)\n",
452-
" \n",
451+
"\n",
453452
" objective += .5*norm(residual)**2\n",
454453
" solver.gradient(rec=residual, u=u0, vp=vp_in, grad=grad)\n",
455-
" \n",
454+
"\n",
456455
" return objective, grad"
457456
]
458457
},
@@ -571,11 +570,11 @@
571570
"name": "stdout",
572571
"output_type": "stream",
573572
"text": [
574-
"Objective value is 39292.605833 at iteration 1\n",
575-
"Objective value is 24506.628229 at iteration 2\n",
576-
"Objective value is 14386.573665 at iteration 3\n",
577-
"Objective value is 7907.616850 at iteration 4\n",
578-
"Objective value is 3960.106497 at iteration 5\n"
573+
"Objective value is 39293.304688 at iteration 1\n",
574+
"Objective value is 24506.697266 at iteration 2\n",
575+
"Objective value is 14386.468750 at iteration 3\n",
576+
"Objective value is 7907.354492 at iteration 4\n",
577+
"Objective value is 3959.922607 at iteration 5\n"
579578
]
580579
}
581580
],
@@ -590,19 +589,19 @@
590589
" # Compute the functional value and gradient for the current\n",
591590
" # model estimate\n",
592591
" phi, direction = fwi_gradient(model0.vp)\n",
593-
" \n",
592+
"\n",
594593
" # Store the history of the functional values\n",
595594
" history[i] = phi\n",
596-
" \n",
595+
"\n",
597596
" # Artificial Step length for gradient descent\n",
598597
" # In practice this would be replaced by a Linesearch (Wolfe, ...)\n",
599598
" # that would guarantee functional decrease Phi(m-alpha g) <= epsilon Phi(m)\n",
600599
" # where epsilon is a minimum decrease constant\n",
601600
" alpha = .05 / mmax(direction)\n",
602-
" \n",
601+
"\n",
603602
" # Update the model estimate and enforce minimum/maximum values\n",
604603
" update_with_box(model0.vp , alpha , direction)\n",
605-
" \n",
604+
"\n",
606605
" # Log the progress made\n",
607606
" print('Objective value is %f at iteration %d' % (phi, i+1))"
608607
]

examples/seismic/tutorials/05_staggered_acoustic.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"from devito import *\n",
18+
"from devito import (SpaceDimension, Grid, TimeFunction, Constant, solve,\n",
19+
" Operator, Eq, VectorTimeFunction, norm)\n",
20+
"from devito.types import NODE\n",
1921
"from examples.seismic.source import DGaussSource, TimeAxis\n",
2022
"from examples.seismic import plot_image\n",
2123
"import numpy as np\n",
2224
"\n",
23-
"from sympy import init_printing, latex\n",
25+
"from sympy import init_printing\n",
2426
"init_printing(use_latex='mathjax')"
2527
]
2628
},
@@ -32,7 +34,7 @@
3234
},
3335
"outputs": [],
3436
"source": [
35-
"# Initial grid: 1km x 1km, with spacing 100m\n",
37+
"# Set up initial grid: 1km x 1km, with spacing 100m\n",
3638
"extent = (2000., 2000.)\n",
3739
"shape = (81, 81)\n",
3840
"x = SpaceDimension(name='x', spacing=Constant(name='h_x', value=extent[0]/(shape[0]-1)))\n",

0 commit comments

Comments
 (0)