Skip to Content

Preparations for inversion

This part prepares necessary files to run this examples, including:

  • Download input file for source and receiver locations raw link 
  • Build a 1-D isotropic initial model.
  • Build a 1-D checkerboard true model by adding perturbations to the initial model.
  • Calculate the traveltimes in the true model (checkerboard model) as the observed traveltimes.

Users can directly run the following codes to generate all necessary files automatically.

python prepare_input_files.py mpirun -n 8 TOMOATT -i 3_input_params/input_params_1dinv_signal.yaml

Here, we demonstrate the preparation step-by-step. First, please load necessary modules in Python Script:

import os import numpy as np import sys from pytomoatt.model import ATTModel from pytomoatt.checkerboard import Checker from pytomoatt.src_rec import SrcRec

Prepare the initial model

The initial model is built as an isotropic 1D model, satisfying:

  • a constant velocity of 5.0 km/s above 0 km depth.
  • a constant velocity gradient from 5.0 km/s at 0 km to 8.0 km/s at 40 km.
  • a constant velocity of 8.0 km/s below 40 km depth.

Users can build the initial model by

class BuildInitialModel(): def __init__(self, par_file="./3_input_params/input_params_signal.yaml", output_dir="2_models"): """ Build initial model for tomography inversion """ self.am = ATTModel(par_file) self.output_dir = output_dir def build_initial_model(self, vel_min=5.0, vel_max=8.0): """ Build initial model for tomography inversion """ self.am.vel[self.am.depths < 0, :, :] = vel_min idx = np.where((0 <= self.am.depths) & (self.am.depths < 40.0))[0] self.am.vel[idx, :, :] = np.linspace(vel_min, vel_max, idx.size)[::-1][:, np.newaxis, np.newaxis] self.am.vel[self.am.depths >= 40.0, :, :] = vel_max def build_ckb_model(self): """ Build checkerboard model for tomography inversion """ nr = self.am.n_rtp[0] for ir in range(nr): dep = self.am.depths[ir] self.am.vel[ir, :, :] = (1 + 0.05 * np.sin(np.pi * dep / 10.0)) * self.am.vel[ir, :, :] if __name__ == "__main__": # build initial model output_dir = "2_models" os.makedirs(output_dir, exist_ok=True) bim = BuildInitialModel(output_dir=output_dir) bim.build_initial_model() bim.am.write('{}/model_init_N{:d}_{:d}_{:d}.h5'.format(bim.output_dir, *bim.am.n_rtp))

The initial model file is generated as 2_models/model_init_N61_61_61.h5

Prepare the true model (checkerboard model)

The 1D true model is built by adding positive and negative 5% velocity perturbations with the vertical size of 10 km are assigned to the 1D initial model:

V_true = V_init * (1 + 0.05 * sin(pi * dep/10))

Users can build the true model by

if __name__ == "__main__": bim.build_ckb_model() bim.am.write('{}/model_ckb_N{:d}_{:d}_{:d}.h5'.format(bim.output_dir, *bim.am.n_rtp))

The true model file is generated as 2_models/model_ckb_N61_61_61.h5

Prepare observed traveltime file

The observed traveltimes are generated by calculating the traveltimes in the true model (checkerboard model).

First, we can download the data file here , by using

url = 'https://zenodo.org/records/14053821/files/src_rec_config.dat' path = "1_src_rec_files/src_rec_config.dat" os.makedirs(os.path.dirname(path), exist_ok=True) if not os.path.exists(path): sr = SrcRec.read(url) sr.write(path)

Then, we can run TomoATT in bash to calculate the traveltimes in the true model

mpirun -n 8 TOMOATT -i 3_input_params/input_params_1dinv_signal.yaml

Here we use 8 processors in parallel.

If users want to change the number of used processors, please correspondingly change the parallel setting n_sims in the YAML file 3_input_params/input_params_1dinv_signal.yaml:

parallel: # parameters for parallel computation n_sims: 8 # number of simultaneous runs (parallel the sources)

After calculating the traveltimes, we can find the calculated data file in OUTPUT_FILES/OUTPUT_FILES_1dinv_signal/src_rec_file_step_0000.dat

Last updated on