initial upload
This commit is contained in:
14
test/old_tests/inversion_ASCII/README.md
Normal file
14
test/old_tests/inversion_ASCII/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Inversion test
|
||||
|
||||
This is a test setup for inversion calculation.
|
||||
|
||||
1. Run all cells of `make_test_model.ipynb` for creating
|
||||
- source, receiver file
|
||||
- true model
|
||||
- initial model
|
||||
|
||||
2. then run TOMOATT forward with `input_params_pre.yml` for calculating the true arrival times at the stations
|
||||
-> this will output src_rec_result.dat file which includes the arrival time at each station
|
||||
|
||||
3. run TOMOATT in inversion mode with `input_params.yml`.
|
||||
|
||||
66
test/old_tests/inversion_ASCII/check_obj_func.ipynb
Normal file
66
test/old_tests/inversion_ASCII/check_obj_func.ipynb
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# check the change of objective values\n",
|
||||
"\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"fpath='objective_function.txt'\n",
|
||||
"\n",
|
||||
"objs=[]\n",
|
||||
"\n",
|
||||
"with open(fpath) as f:\n",
|
||||
" lines = f.readlines()\n",
|
||||
"\n",
|
||||
" for l in lines:\n",
|
||||
" if(l.startswith('i_inv')):\n",
|
||||
" continue\n",
|
||||
" objs.append(float(l.strip().split(',')[1]))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.xlabel('iteration')\n",
|
||||
"plt.ylabel('objective function value')\n",
|
||||
"plt.plot(objs)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.9.1 64-bit ('3.9.1')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.1"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "02f83e1f4cd9619657a6845405e2dd67c4de23753ba48bca5dce2ebf57b3813a"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
185
test/old_tests/inversion_ASCII/check_src_rec_file.ipynb
Normal file
185
test/old_tests/inversion_ASCII/check_src_rec_file.ipynb
Normal file
@@ -0,0 +1,185 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# read src_rec file and check its arrival time and distance from src to rec\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"def read_src_rec_file(fpath):\n",
|
||||
"\n",
|
||||
" with open(fpath, \"r\") as f:\n",
|
||||
" lines = f.readlines()\n",
|
||||
"\n",
|
||||
" # list to store src lon lat\n",
|
||||
" src_pos = []\n",
|
||||
" # list to store rec lon lat\n",
|
||||
" rec_pos_tmp=[]\n",
|
||||
" rec_pos = []\n",
|
||||
"\n",
|
||||
" for line in lines:\n",
|
||||
" # src line if there are 13 elements\n",
|
||||
" if len(line.split()) == 13:\n",
|
||||
" # store source lon lat dep\n",
|
||||
" stlon = float(line.split()[8])\n",
|
||||
" stlat = float(line.split()[7])\n",
|
||||
" src_pos.append([stlon, stlat])\n",
|
||||
"\n",
|
||||
" nrec = float(line.split()[11])\n",
|
||||
" # rec line if there are 9 elements\n",
|
||||
" elif len(line.split()) == 9:\n",
|
||||
" # store receiver lon lat dep\n",
|
||||
" rclon = float(line.split()[4])\n",
|
||||
" rclat = float(line.split()[3])\n",
|
||||
" rctime= float(line.split()[8])\n",
|
||||
" # calc epicentral distance from src\n",
|
||||
" dist = np.sqrt((stlon-rclon)**2 + (stlat-rclat)**2)\n",
|
||||
" rec_pos_tmp.append([rclon, rclat, rctime, dist])\n",
|
||||
"\n",
|
||||
" nrec-=1\n",
|
||||
" else:\n",
|
||||
" raise ValueError(\"src_rec_test_out.dat file is not correct\")\n",
|
||||
"\n",
|
||||
" if nrec==0:\n",
|
||||
" rec_pos.append(rec_pos_tmp)\n",
|
||||
" # remove all rec_pos_tmp\n",
|
||||
" rec_pos_tmp = []\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" src_pos = np.array(src_pos)\n",
|
||||
" rec_pos = np.array(rec_pos)\n",
|
||||
"\n",
|
||||
" return src_pos, rec_pos"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"src_pos_true, rec_pos_true = read_src_rec_file(\"./src_rec_test_out.dat\")\n",
|
||||
"src_pos_try, rec_pos_try = read_src_rec_file(\"./src_rec_test_out_out.dat\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# plot rec_pos for each src_pos with color by 3rd element\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def plot_srcrec(src_pos, rec_pos):\n",
|
||||
"\n",
|
||||
" # selected source\n",
|
||||
" id_src = 1\n",
|
||||
" \n",
|
||||
" fig, axs = plt.subplots(2,1,figsize=(10,10))\n",
|
||||
" \n",
|
||||
" # plot arrival time\n",
|
||||
" # src\n",
|
||||
" axs[0].scatter(src_pos[id_src,0], src_pos[id_src,1], c='r', marker='o', s=100)\n",
|
||||
" # rec\n",
|
||||
" axs[0].scatter(rec_pos[id_src][:,0], rec_pos[id_src][:,1], c=rec_pos[id_src][:,2], s=10, marker='o')\n",
|
||||
" \n",
|
||||
" # colorbar\n",
|
||||
" cbar = plt.colorbar(axs[0].scatter(rec_pos[id_src][:,0], rec_pos[id_src][:,1], c=rec_pos[id_src][:,2], s=100, marker='o'))\n",
|
||||
" cbar.set_label('arrival time')\n",
|
||||
" \n",
|
||||
" # plot epicentral distance\n",
|
||||
" # src\n",
|
||||
" axs[1].scatter(src_pos[id_src,0], src_pos[id_src,1], c='r', marker='o', s=100)\n",
|
||||
" # rec\n",
|
||||
" axs[1].scatter(rec_pos[id_src][:,0], rec_pos[id_src][:,1], c=rec_pos[id_src][:,3], s=100, marker='o')\n",
|
||||
" \n",
|
||||
" # colorbar\n",
|
||||
" cbar = plt.colorbar(axs[1].scatter(rec_pos[id_src][:,0], rec_pos[id_src][:,1], c=rec_pos[id_src][:,3], s=10, marker='o'))\n",
|
||||
" cbar.set_label('epicentral distance')\n",
|
||||
" \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plot_srcrec(src_pos_true, rec_pos_true)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plot_srcrec(src_pos_try, rec_pos_try)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rec_pos_diff = rec_pos_true[:][:][2]-rec_pos_try[:][:][2]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rec_pos_diff.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rec_pos_true.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "02f83e1f4cd9619657a6845405e2dd67c4de23753ba48bca5dce2ebf57b3813a"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.9.1 64-bit ('3.9.1')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
51
test/old_tests/inversion_ASCII/input_params.yml
Normal file
51
test/old_tests/inversion_ASCII/input_params.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
version : 2
|
||||
|
||||
domain :
|
||||
#min_max_dep : [-2.863,17.137] # depth in km
|
||||
min_max_dep : [-10.0, 10.0] # depth in km
|
||||
min_max_lat : [37.7,42.3] # latitude in degree
|
||||
min_max_lon : [22.7,27.3] # longitude in degree
|
||||
n_rtp : [10,50,50] # number of nodes
|
||||
|
||||
source :
|
||||
#src_dep_lat_lon : [5.0,40.0,24.0] # source depth in km, latitude, longitude in degree
|
||||
#src_dep_lat_lon : [5750.6370,46.0,36.0] # source depth in km, latitude, longitude in degree
|
||||
src_rec_file : 'src_rec_test_out.dat' # source receiver file (if found, src_dep_lat_lon is ignored)
|
||||
swap_src_rec : 1 # swap source and receiver (1: yes, 0: no)
|
||||
|
||||
model :
|
||||
init_model_type : '' # 'fd' (input file) or '1d_ak135'
|
||||
init_model_path : './test_model_init.h5' # path to initial model file (ignored if init_model_type is '1d_*')
|
||||
|
||||
inversion :
|
||||
run_mode : 1 # 0 for forward simulation only, 1 for inversion
|
||||
optim_method : 0 # optimization method. 0 : "grad_descent", 1 : "lbfgs", 2 : "halve-stepping"
|
||||
smooth_method : 0 # 0: multigrid parametrization, 1: laplacian smoothing with CG
|
||||
max_iterations_inv : 100 # maximum number of inversion iterations
|
||||
step_size : 0.01 # step size for inversion
|
||||
# parameters for multiparametric inversion
|
||||
n_inversion_grid : 5 # number of inversion grid sets
|
||||
n_inv_dep_lat_lon : [5,10,10] # number of the base inversion grid points
|
||||
min_max_dep_inv : [-10.0, 10.0] # depth in km with R = 6371.0
|
||||
min_max_lat_inv : [37.7,42.3] # latitude in degree
|
||||
min_max_lon_inv : [22.7,27.3] # longitude in degree
|
||||
# parameters for laplacian smoothing
|
||||
l_smooth_rtp : [10,10,10] # smoothing coefficients for each direction
|
||||
regularization_weight : 1.0 # regularization weight NOTWORKING
|
||||
# parameter for halving-stepping or lbfgs
|
||||
max_sub_iterations : 100 # maximum number of sub-iterations
|
||||
|
||||
|
||||
parallel :
|
||||
n_sims : 1 # number of simultaneous run
|
||||
ndiv_rtp : [1,2,2] # number of subdomains
|
||||
nproc_sub : 2 # number of subprocess used for each subdomain
|
||||
use_gpu : 0 # 0: CPU, 1: GPU
|
||||
|
||||
calculation :
|
||||
convergence_tolerance : 1e-6
|
||||
max_iterations : 200
|
||||
stencil_order : 3 # 1 or 3
|
||||
sweep_type : 2 # 0: legacy, 1: cuthill-mckee with shm parallelization
|
||||
|
||||
|
||||
37
test/old_tests/inversion_ASCII/input_params_pre.yml
Normal file
37
test/old_tests/inversion_ASCII/input_params_pre.yml
Normal file
@@ -0,0 +1,37 @@
|
||||
version : 2
|
||||
|
||||
domain :
|
||||
#min_max_dep : [-2.863,17.137] # depth in km
|
||||
min_max_dep : [-10.0, 10.0] # depth in km
|
||||
min_max_lat : [37.7,42.3] # latitude in degree
|
||||
min_max_lon : [22.7,27.3] # longitude in degree
|
||||
n_rtp : [10,50,50] # number of nodes
|
||||
|
||||
source :
|
||||
#src_dep_lat_lon : [5.0,40.0,24.0] # source depth in km, latitude, longitude in degree
|
||||
#src_dep_lat_lon : [5750.6370,46.0,36.0] # source depth in km, latitude, longitude in degree
|
||||
src_rec_file : 'src_rec_test.dat' # source receiver file (if found, src_dep_lat_lon is ignored)
|
||||
swap_src_rec : 1 # swap source and receiver (1: yes, 0: no)
|
||||
|
||||
model :
|
||||
init_model_type : '' # 'fd' (input file) or '1d_ak135'
|
||||
init_model_path : './test_model_true.dat' # path to initial model file (ignored if init_model_type is '1d_*')
|
||||
|
||||
inversion :
|
||||
run_mode : 0 # 0 for forward simulation only, 1 for inversion
|
||||
n_inversion_grid : 1
|
||||
|
||||
|
||||
parallel :
|
||||
n_sims : 1 # number of simultaneous run
|
||||
ndiv_rtp : [2,1,2] # number of subdomains
|
||||
nproc_sub : 2 # number of subprocess used for each subdomain
|
||||
|
||||
calculation :
|
||||
convergence_tolerance : 1e-6
|
||||
max_iterations : 200
|
||||
stencil_order : 3 # 1 or 3
|
||||
sweep_type : 2 # 0: legacy, 1: cuthill-mckee with shm parallelization
|
||||
output_file_format : 1 # 0: hdf5, 1: ascii
|
||||
|
||||
|
||||
338
test/old_tests/inversion_ASCII/make_test_model.ipynb
Normal file
338
test/old_tests/inversion_ASCII/make_test_model.ipynb
Normal file
@@ -0,0 +1,338 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# notebook for create init and true test model"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import math\n",
|
||||
"\n",
|
||||
"# grid\n",
|
||||
"#R_earth = 6378.1370\n",
|
||||
"R_earth = 6371.0\n",
|
||||
"\n",
|
||||
"rr1=6361 \n",
|
||||
"rr2=6381\n",
|
||||
"tt1=(38.0-0.3)/180*math.pi\n",
|
||||
"tt2=(42.0+0.3)/180*math.pi\n",
|
||||
"pp1=(23.0-0.3)/180*math.pi\n",
|
||||
"pp2=(27.0+0.3)/180*math.pi\n",
|
||||
"\n",
|
||||
"n_rtp = [10,50,50]\n",
|
||||
"n_rtp.reverse()\n",
|
||||
"dr = (rr2-rr1)/(n_rtp[2]-1)\n",
|
||||
"dt = (tt2-tt1)/(n_rtp[1]-1)\n",
|
||||
"dp = (pp2-pp1)/(n_rtp[0]-1)\n",
|
||||
"rr = np.array([rr1 + x*dr for x in range(n_rtp[2])])\n",
|
||||
"tt = np.array([tt1 + x*dt for x in range(n_rtp[1])])\n",
|
||||
"pp = np.array([pp1 + x*dp for x in range(n_rtp[0])])\n",
|
||||
"\n",
|
||||
"# initial model\n",
|
||||
"gamma = 0.0\n",
|
||||
"s0 = 1.0/6.0\n",
|
||||
"slow_p=0.06\n",
|
||||
"ani_p=0.04\n",
|
||||
"\n",
|
||||
"eta_init = np.zeros(n_rtp)\n",
|
||||
"xi_init = np.zeros(n_rtp)\n",
|
||||
"zeta_init = np.zeros(n_rtp)\n",
|
||||
"fun_init = np.zeros(n_rtp)\n",
|
||||
"vel_init = np.zeros(n_rtp)\n",
|
||||
"a_init = np.zeros(n_rtp)\n",
|
||||
"b_init = np.zeros(n_rtp)\n",
|
||||
"c_init = np.zeros(n_rtp)\n",
|
||||
"f_init = np.zeros(n_rtp)\n",
|
||||
"\n",
|
||||
"# true model\n",
|
||||
"eta_true = np.zeros(n_rtp)\n",
|
||||
"xi_true = np.zeros(n_rtp)\n",
|
||||
"zeta_true = np.zeros(n_rtp)\n",
|
||||
"fun_true = np.zeros(n_rtp)\n",
|
||||
"vel_true = np.zeros(n_rtp)\n",
|
||||
"a_true = np.zeros(n_rtp)\n",
|
||||
"b_true = np.zeros(n_rtp)\n",
|
||||
"c_true = np.zeros(n_rtp)\n",
|
||||
"f_true = np.zeros(n_rtp)\n",
|
||||
"\n",
|
||||
"c=0\n",
|
||||
"for ir in range(n_rtp[2]):\n",
|
||||
" for it in range(n_rtp[1]):\n",
|
||||
" for ip in range(n_rtp[0]):\n",
|
||||
" #eta_init[ip,it,ir] = 0.0\n",
|
||||
" #xi_init[ip,it,ir] = 0.0\n",
|
||||
" zeta_init[ip,it,ir] = gamma*math.sqrt(eta_init[ip,it,ir]**2 + xi_init[ip,it,ir]**2)\n",
|
||||
" fun_init[ip,it,ir] = s0\n",
|
||||
" vel_init[ip,it,ir] = 1.0/s0\n",
|
||||
" a_init[ip,it,ir] = 1.0 + 2.0*zeta_init[ip,it,ir]\n",
|
||||
" b_init[ip,it,ir] = 1.0 - 2.0*xi_init[ip,it,ir]\n",
|
||||
" c_init[ip,it,ir] = 1.0 + 2.0*xi_init[ip,it,ir]\n",
|
||||
" f_init[ip,it,ir] = -2.0 * eta_init[ip,it,ir]\n",
|
||||
"\n",
|
||||
" # true model\n",
|
||||
" if (tt[it] >= 38.0/180.0*math.pi and tt[it] <= 42.0/180.0*math.pi \\\n",
|
||||
" and pp[ip] >= 23.0/180.0*math.pi and pp[ip] <= 27.0/180.0*math.pi):\n",
|
||||
" c+=1\n",
|
||||
" sigma = math.sin(2.0*math.pi*(tt[it]-38.0/180.0*math.pi)/(4.0/180.0*math.pi))*math.sin(2.0*math.pi*(pp[ip]-23.0/180.0*math.pi)/(4.0/180.0*math.pi))\n",
|
||||
" else:\n",
|
||||
" sigma = 0.0\n",
|
||||
"\n",
|
||||
" if sigma < 0:\n",
|
||||
" psi = 60.0/180.0*math.pi\n",
|
||||
" elif sigma > 0:\n",
|
||||
" psi = 120.0/180.0*math.pi\n",
|
||||
" else:\n",
|
||||
" psi = 0.0\n",
|
||||
"\n",
|
||||
" eta_true[ip,it,ir] = ani_p*abs(sigma)*math.sin(2.0*psi)\n",
|
||||
" xi_true[ip,it,ir] = ani_p*abs(sigma)*math.cos(2.0*psi)\n",
|
||||
" zeta_true[ip,it,ir] = gamma*math.sqrt(eta_true[ip,it,ir]**2 + xi_true[ip,it,ir]**2)\n",
|
||||
" fun_true[ip,it,ir] = s0/(1.0+sigma*slow_p)\n",
|
||||
" vel_true[ip,it,ir] = 1.0/fun_true[ip,it,ir] \n",
|
||||
" a_true[ip,it,ir] = 1.0 + 2.0*zeta_true[ip,it,ir]\n",
|
||||
" b_true[ip,it,ir] = 1.0 - 2.0*xi_true[ip,it,ir]\n",
|
||||
" c_true[ip,it,ir] = 1.0 + 2.0*xi_true[ip,it,ir]\n",
|
||||
" f_true[ip,it,ir] = -2.0 * eta_true[ip,it,ir]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#r_earth = 6378.1370\n",
|
||||
"print(\"depminmax {} {}\".format(R_earth-rr1,R_earth-rr2))\n",
|
||||
"print(c)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# write out in ASCIII\n",
|
||||
"\n",
|
||||
"#\n",
|
||||
"\n",
|
||||
"fname_init = 'test_model_init.dat'\n",
|
||||
"fname_true = 'test_model_true.dat'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# write init model\n",
|
||||
"with open(fname_init, 'w') as f:\n",
|
||||
" # write nodes in rtp\n",
|
||||
" for ir in range(n_rtp[2]):\n",
|
||||
" for it in range(n_rtp[1]):\n",
|
||||
" for ip in range(n_rtp[0]):\n",
|
||||
" # write out eta xi zeta fun fac_a fac_b fac_c fac_f\n",
|
||||
" f.write(\"{} {} {} {} {} {} {} {} {}\\n\".format(eta_init[ip,it,ir],xi_init[ip,it,ir],zeta_init[ip,it,ir],fun_init[ip,it,ir],vel_init[ip,it,ir],a_init[ip,it,ir],b_init[ip,it,ir],c_init[ip,it,ir],f_init[ip,it,ir]))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# write true model\n",
|
||||
"with open(fname_true, 'w') as f:\n",
|
||||
" # write nodes in rtp\n",
|
||||
" for ir in range(n_rtp[2]):\n",
|
||||
" for it in range(n_rtp[1]):\n",
|
||||
" for ip in range(n_rtp[0]):\n",
|
||||
" # write out eta xi zeta fun fac_a fac_b fac_c fac_f\n",
|
||||
" f.write(\"{} {} {} {} {} {} {} {} {}\\n\".format(eta_true[ip,it,ir],xi_true[ip,it,ir],zeta_true[ip,it,ir],fun_true[ip,it,ir],vel_true[ip,it,ir],a_true[ip,it,ir],b_true[ip,it,ir],c_true[ip,it,ir],f_true[ip,it,ir]))\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# prepare src station file\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
" 26 1992 1 1 2 43 56.900 1.8000 98.9000 137.00 2.80 8 305644 <- src : id_src year month day hour min sec lat lon dep_km mag num_recs id_event\n",
|
||||
" 26 1 PCBI 1.8900 98.9253 1000.0000 P 10.40 18.000 <- arrival : id_src id_rec name_rec lat lon elevation_m phase epicentral_distance_km arrival_time_sec\n",
|
||||
" 26 2 MRPI 1.6125 99.3172 1100.0000 P 50.84 19.400\n",
|
||||
" 26 3 HUTI 2.3153 98.9711 1600.0000 P 57.84 19.200\n",
|
||||
"\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import random\n",
|
||||
"random.seed(1145141919810)\n",
|
||||
"\n",
|
||||
"# dummys\n",
|
||||
"year_dummy = 1998\n",
|
||||
"month_dummy = 1\n",
|
||||
"day_dummy = 1\n",
|
||||
"hour_dummy = 0\n",
|
||||
"minute_dummy = 0\n",
|
||||
"second_dummy = 0\n",
|
||||
"mag_dummy = 3.0\n",
|
||||
"id_dummy = 1000\n",
|
||||
"st_name_dummy = 'AAAA'\n",
|
||||
"phase_dummy = 'P'\n",
|
||||
"dist_dummy = 100.0\n",
|
||||
"arriv_t_dummy = 0.0\n",
|
||||
"\n",
|
||||
"tt1deg = tt1 * 180.0/math.pi\n",
|
||||
"tt2deg = tt2 * 180.0/math.pi\n",
|
||||
"pp1deg = pp1 * 180.0/math.pi\n",
|
||||
"pp2deg = pp2 * 180.0/math.pi\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"n_src = 500\n",
|
||||
"n_rec = [30 for x in range(n_src)]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"lines = []\n",
|
||||
"\n",
|
||||
"nij_src = math.sqrt(n_src)\n",
|
||||
"nij_rec = math.sqrt(n_rec[0])\n",
|
||||
"\n",
|
||||
"pos_src=[]\n",
|
||||
"pos_rec=[]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# create receiver coordinates\n",
|
||||
"elev_recs=[]\n",
|
||||
"lon_recs=[]\n",
|
||||
"lat_recs=[]\n",
|
||||
"rec_names=[]\n",
|
||||
"for i in range(n_rec[0]):\n",
|
||||
" #elev_recs.append(random.uniform(-100.0,-100.0)) # elevation in m\n",
|
||||
" #elev_recs.append(0) # elevation in m\n",
|
||||
" #lon_recs .append(random.uniform(pp1deg*1.1,pp2deg*0.9))\n",
|
||||
" #lat_recs .append(random.uniform(tt1deg*1.1,tt2deg*0.9))\n",
|
||||
" rec_names.append(i)\n",
|
||||
" # regularly\n",
|
||||
" elev_recs.append(0.0)\n",
|
||||
" tmp_ilon = i%nij_rec\n",
|
||||
" tmp_ilat = int(i/nij_rec)\n",
|
||||
" lon_recs.append(pp1deg + tmp_ilon*(pp2deg-pp1deg)/nij_rec)\n",
|
||||
" lat_recs.append(tt1deg + tmp_ilat*(tt2deg-tt1deg)/nij_rec)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# create dummy src\n",
|
||||
"for i_src in range(n_src):\n",
|
||||
" # define one point in the domain (rr1 bottom, rr2 top)\n",
|
||||
" # random\n",
|
||||
" #dep = random.uniform((R_earth-rr1)*0.5,(R_earth-rr1)*0.98)\n",
|
||||
" #lon = random.uniform(pp1deg,pp2deg)\n",
|
||||
" #lat = random.uniform(tt1deg,tt2deg)\n",
|
||||
"\n",
|
||||
" # regularl\n",
|
||||
" dep = (R_earth-rr1)*0.9\n",
|
||||
" tmp_ilon = i_src%nij_src\n",
|
||||
" tmp_ilat = int(i_src/nij_src)\n",
|
||||
" lon = pp1deg + tmp_ilon*(pp2deg-pp1deg)/nij_src\n",
|
||||
" lat = tt1deg + tmp_ilat*(tt2deg-tt1deg)/nij_src\n",
|
||||
"\n",
|
||||
" src = [i_src, year_dummy, month_dummy, day_dummy, hour_dummy, minute_dummy, second_dummy, lat, lon, dep, mag_dummy, n_rec[i_src], id_dummy]\n",
|
||||
" lines.append(src)\n",
|
||||
"\n",
|
||||
" pos_src.append([lon,lat,dep])\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" # create dummy station\n",
|
||||
" for i_rec in range(n_rec[i_src]):\n",
|
||||
" #elev_rec = 0.0 #random.uniform(0.0,-10.0) # elevation in m\n",
|
||||
" #lon_rec = random.uniform(pp1deg,pp2deg)\n",
|
||||
" #lat_rec = random.uniform(tt1deg,tt2deg)\n",
|
||||
" # regularly\n",
|
||||
" #elev_rec = -10.0\n",
|
||||
" #tmp_ilon = i_rec%nij_rec\n",
|
||||
" #tmp_ilat = int(i_rec/nij_rec)\n",
|
||||
" #lon_rec = pp1deg + tmp_ilon*(pp2deg-pp1deg)/nij_rec\n",
|
||||
" #lat_rec = tt1deg + tmp_ilat*(tt2deg-tt1deg)/nij_rec\n",
|
||||
"\n",
|
||||
" # \n",
|
||||
" elev_rec = elev_recs[i_rec]\n",
|
||||
" lon_rec = lon_recs[i_rec]\n",
|
||||
" lat_rec = lat_recs[i_rec]\n",
|
||||
" st_name_dummy = rec_names[i_rec]\n",
|
||||
"\n",
|
||||
" rec = [i_src, i_rec, st_name_dummy, lat_rec, lon_rec, elev_rec, phase_dummy, dist_dummy, arriv_t_dummy]\n",
|
||||
" lines.append(rec)\n",
|
||||
"\n",
|
||||
" pos_rec.append([lon_rec,lat_rec,elev_rec])\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# write out ev_arrivals file\n",
|
||||
"fname = 'src_rec_test.dat'\n",
|
||||
"\n",
|
||||
"with open(fname, 'w') as f:\n",
|
||||
" for line in lines:\n",
|
||||
" for elem in line:\n",
|
||||
" f.write('{} '.format(elem))\n",
|
||||
" f.write('\\n')\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# draw src and rec positions\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"for i_src in range(n_src):\n",
|
||||
" plt.scatter(pos_src[i_src][1],pos_src[i_src][0],c='r',marker='o')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# plot receivers\n",
|
||||
"for i_rec in range(n_rec[0]):\n",
|
||||
" plt.scatter(pos_rec[i_rec][1],pos_rec[i_rec][0],c='b',marker='o')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.9.1 64-bit ('3.9.1')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.1"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "fbd0b2a7df497f398d93ab2f589d8a5daa3108cfb7ff2b90736653cca3aeadc0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
94
test/old_tests/inversion_ASCII/view_result.ipynb
Normal file
94
test/old_tests/inversion_ASCII/view_result.ipynb
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np \n",
|
||||
"import sys\n",
|
||||
"sys.path.append(\"../../utils/\")\n",
|
||||
"\n",
|
||||
"from tomoatt_data_retrieval import get_data_from_ascii\n",
|
||||
"\n",
|
||||
"#\n",
|
||||
"# plot calculated travel time field\n",
|
||||
"\n",
|
||||
"# number of grids\n",
|
||||
"nx = 50 \n",
|
||||
"ny = 50\n",
|
||||
"nz = 10\n",
|
||||
"\n",
|
||||
"# read coordiantes from file\n",
|
||||
"fname_grid = \"OUTPUT_FILES/out_grid.out\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# read data\n",
|
||||
"_src_id = 0\n",
|
||||
"_inv_id = 0\n",
|
||||
"\n",
|
||||
"# filling 0 for digit\n",
|
||||
"inv_id = str(_inv_id).zfill(4)\n",
|
||||
"src_id = str(_src_id).zfill(4)\n",
|
||||
"fname_data = \"OUTPUT_FILES/T_res_inv_{}_src_{}.dat\".format(inv_id, src_id)\n",
|
||||
"\n",
|
||||
"data = get_data_from_ascii(fname_data, fname_grid, nz, ny, nx, 2, 1,2, verbose=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# plot\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"fig, axs = plt.subplots(3, 1, figsize=(15, 5))\n",
|
||||
"\n",
|
||||
"axs[0].imshow(data[5,:,:], cmap='jet', interpolation='nearest')\n",
|
||||
"axs[0].set_title('lon-lat')\n",
|
||||
"\n",
|
||||
"axs[1].imshow(data[:,25,:], cmap='jet', interpolation='nearest')\n",
|
||||
"axs[1].set_title('r-lon')\n",
|
||||
"\n",
|
||||
"axs[2].imshow(data[:,:,25], cmap='jet', interpolation='nearest')\n",
|
||||
"axs[2].set_title('r-lat')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.9.1 64-bit ('3.9.1')",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.1"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "02f83e1f4cd9619657a6845405e2dd67c4de23753ba48bca5dce2ebf57b3813a"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user