Version:
This tutorial is presented as Python code running inside a Jupyter Notebook, the recommended way to use Salvus. To run it yourself you can copy/type each individual cell or directly download the full notebook, including all required files.

Full-Waveform Inversion

Part 5 - Extensions

Copy
%matplotlib inline
# This notebook will use this variable to determine which
# remote site to run on.
import os
import numpy as np
import salvus.namespace as sn

SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")
p = sn.Project(path="project")
In a typical USCT setup, there is always enough space between the ultrasound transducers and the phantom. What if we include that information as prior knowledge into our problem formulation?
An easy way of doing this, is to define a region of interest and restrict the reconstruction to this area.
To keep it simple, we just define a sphere with a radius of 6.5 cm as the target region.
mesh = p.simulations.get_mesh(simulation_configuration="initial_model")
# define the region of interest
roi = np.zeros_like(mesh.connectivity)
mask = np.linalg.norm(mesh.points[mesh.connectivity], axis=2) < 0.065
roi[mask] = 1.0
mesh.attach_field("region_of_interest", roi)
Let's see if this helps with the iterations. To be able to compare the results, we just create a new inverse problem within the same project, initialize the region of interest, and start iterating.
p += sn.InverseProblemConfiguration(
    name="my_second_inversion",
    prior_model="initial_model",
    events=[e.event_name for e in p.events.get_all()],
    mapping=sn.Mapping(
        scaling="absolute",
        inversion_parameters=["VP", "RHO"],
        region_of_interest=mesh,
    ),
    preconditioner=sn.ConstantSmoothing({"VP": 0.01, "RHO": 0.01}),
    method=sn.TrustRegion(initial_trust_region_linf=10.0),
    misfit_configuration="L2",
    wavefield_compression=sn.WavefieldCompression(
        forward_wavefield_sampling_interval=10
    ),
    job_submission=sn.SiteConfig(
        site_name=SALVUS_FLOW_SITE_NAME, ranks_per_job=4
    ),
)
p.inversions.iterate(
    inverse_problem_configuration="my_second_inversion",
    timeout_in_seconds=360,
    ping_interval_in_seconds=10,
)
[2022-08-03 09:09:00,845] INFO: Adding new iteration #0.
[2022-08-03 09:09:00,861] INFO: Resuming iteration #0.

[2022-08-03 09:09:00,862] INFO: 1 new tasks have been issued.
[2022-08-03 09:09:00,863] INFO: Processing task `misfit_and_gradient`
[2022-08-03 09:09:11,884] INFO: Processing task `misfit_and_gradient`
[2022-08-03 09:09:12,949] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689826462271286	 ||g|| = 0.016261473616319685
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2022-08-03 09:09:12,972] INFO: 1 new tasks have been issued.
[2022-08-03 09:09:12,973] INFO: Processing task `preconditioner`

[2022-08-03 09:09:23,348] INFO: Processing task `preconditioner`
[2022-08-03 09:09:23,683] INFO: 1 new tasks have been issued.
[2022-08-03 09:09:23,684] INFO: Processing task `misfit`
[2022-08-03 09:09:23,845] INFO: Submitting job array with 5 jobs ...

[2022-08-03 09:09:24,303] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2022-08-03 09:09:34,380] INFO: Processing task `misfit`
[2022-08-03 09:09:34,634] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2022-08-03 09:09:44,688] INFO: Processing task `misfit`
[2022-08-03 09:09:46,589] INFO: 
old misfit control group: 0.017689826462271286
new misfit control group: 0.006645706895226028
predicted reduction control group: -0.005735009901748848
actual reduction control group: -0.011044119567045258
5 out of 5 event(s) improved the misfit.
[2022-08-03 09:09:46,590] INFO: 
Model update accepted.
[2022-08-03 09:09:46,653] INFO: 1 new tasks have been issued.
[2022-08-03 09:09:46,655] INFO: Processing task `finalize_iteration`
[2022-08-03 09:09:46,744] INFO: Succesfully completed iteration #0.
[2022-08-03 09:09:46,749] INFO: Adding new iteration #1.
Let's see if the region of interest was considered when the model was updated.
p.viz.nb.inversion(inverse_problem_configuration="my_second_inversion")