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,
)
[2023-03-17 19:56:27,612] INFO: Adding new iteration #0.
[2023-03-17 19:56:27,627] INFO: Resuming iteration #0.

[2023-03-17 19:56:27,628] INFO: 1 new tasks have been issued.
[2023-03-17 19:56:27,628] INFO: Processing task `misfit_and_gradient`
[2023-03-17 19:56:28,145] INFO: 
Iteration 0: Number of events: 5	 chi = 0.017689824342681335	 ||g|| = 0.016261471373728662
pred = ---	ared = ---	norm_update = ---	tr_radius = ---
[2023-03-17 19:56:28,146] INFO: 1 new tasks have been issued.
[2023-03-17 19:56:28,146] INFO: Processing task `preconditioner`

[2023-03-17 19:56:28,376] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2023-03-17 19:56:38,401] INFO: Processing task `preconditioner`
[2023-03-17 19:56:38,610] INFO: 1 new tasks have been issued.
[2023-03-17 19:56:38,611] INFO: Processing task `misfit`
[2023-03-17 19:56:38,700] INFO: Submitting job array with 5 jobs ...

[2023-03-17 19:56:38,870] INFO: Launched simulations for 5 events. Please check again to see if they are finished.
[2023-03-17 19:56:38,872] INFO: Some tasks of iteration #0 are still running. Please check again later.
[2023-03-17 19:56:48,914] INFO: Processing task `misfit`
[2023-03-17 19:56:50,108] INFO: 
old misfit control group: 0.017689824342681335
new misfit control group: 0.006645707524480156
predicted reduction control group: -0.005735006652191734
actual reduction control group: -0.011044116818201178
5 out of 5 event(s) improved the misfit.
[2023-03-17 19:56:50,109] INFO: 
Model update accepted.
[2023-03-17 19:56:50,110] INFO: 1 new tasks have been issued.
[2023-03-17 19:56:50,110] INFO: Processing task `finalize_iteration`
[2023-03-17 19:56:50,169] INFO: Succesfully completed iteration #0.
[2023-03-17 19:56:50,171] 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")