This documentation is not for the latest stable Salvus version.
import os
import typing
import numpy as np
import xarray as xr
import salvus.namespace as sn
from salvus.project.tools.processing.seismology import (
get_bandpass_filter_processing_function,
)
n_ranks = 2
resolved_period = 100.0
salvus_flow_site_name = os.environ.get("SITE_NAME", "local")
d = sn.domain.dim2.CircularDomain(radius_in_meter=6371e3)
# !rm -rf proj # Uncomment to restart from scratch.
p = sn.Project.from_domain(path="proj", domain=d, load_if_exists=True)
d.plot()
SideSet...
variant of a source here. Accurately locating sources and receivers with respect to deformed mesh surfaces is a nonlinear problem in general. The SideSet...
specification here instructs Salvus to solve an optimization problem before any simulations begin, to accurately locate points given a reference surface. Here the "r1"
specification implies that the surface of Earth is our coordinate reference.src = [
sn.simple_config.source.seismology.SideSetMomentTensorPoint2D(
mrr=1e21,
mpp=1e21,
mrp=-1e21,
longitude=45.0,
depth_in_m=10e3,
side_set_name="r1",
)
]
SideSet...
prefix applies here, and a depth of 0
means that the receivers will be placed exactly at the surface.lons = np.linspace(175.0, 185.0, 101)
recs = [
sn.simple_config.receiver.seismology.SideSetPoint2D(
longitude=l,
depth_in_m=0.0,
side_set_name="r1",
fields=["velocity"],
station_code=f"{_i:06d}",
)
for _i, l in enumerate(lons)
]
EventCollection
. Adding this to our project means that the data will be saved to disk, so we don't need to worry about accidentally overwriting objects we've previously created. Additionally, it allows to shut down the notebook, and come back later to pick up our work.p.add_to_project(sn.EventCollection.from_sources(sources=src, receivers=recs))
"event_0000"
, "event_0001"
, and so on.p.domain.plot(events=p.events.get("event_0000"))
xarray
package eases this process even further. xarray
natively supports reading models saved as CF-compliant NetCDF files, including many of those stored in the IRIS Earth Model Catalogue. Here we'll create a model from scratch, which parameterizes a Gaussian heterogeneity in units of percent perturbation. First, let's initialize the xarray
data structure. The model here extends 2000 km from the surface, and spans longitudes 170 to 190. We'll perturb "VP"
in this case, and initialize the perturbation array to .lons = np.linspace(170, 190, 101)
deps = np.linspace(0, 1000e3, 101)
ll, dd = np.meshgrid(lons, deps, indexing="ij")
raw_model = xr.Dataset(
coords={"longitude": lons, "depth": deps},
data_vars={
"VP": (["longitude", "depth"], np.zeros_like(ll), {"units": "%"})
},
attrs={
"geospatial_lon_units": "degrees_east",
"geospatial_vertical_units": "m",
},
)
def gaussian_2d(
m