def gen_coseismic_disp_file(): reader = vj.EpochalFileReader('../../tsana/post_fit/cumu_post.h5') co_disp = reader[0].reshape([-1, 3]) sites = vj.Sites([ii.decode() for ii in reader['sites']]) text = tempfile.NamedTemporaryFile(mode='w+t') _text = '# lon lat x y * * * name of station\n' for ci, site in zip(co_disp, sites): _text += '%f %f %f %f 0. 0. 0. %s\n'%\ (site.lon, site.lat, ci[0], ci[1], site.name) text.write(_text) text.seek(0, 0) return text
def gen_codisp_hor_mag_file(): reader = vj.EpochalFileReader('../../tsana/post_fit/cumu_post.h5') co_disp = reader[0].reshape([-1, 3]) sites = vj.Sites([ii.decode() for ii in reader['sites']]) text = tempfile.NamedTemporaryFile(mode='w+t') _text = '# lon lat hor_mag\n' for ci, site in zip(co_disp, sites): _text += '%f %f %f \n'%\ (site.lon, site.lat, np.sqrt(ci[0]**2+ci[1]**2)) text.write(_text) text.seek(0, 0) return text
def gen_coseismic_vertical_file(): reader = vj.EpochalFileReader('../../tsana/post_fit/cumu_post.h5') co_disp = reader[0].reshape([-1, 3]) # print(np.max(co_disp[:,2])) sites = vj.Sites([ii.decode() for ii in reader['sites']]) text = tempfile.NamedTemporaryFile(mode='w+t') _text = '# lon lat vertical\n' for ci, site in zip(co_disp, sites): _text += '%f %f %f \n'%\ (site.lon, site.lat, ci[2]) text.write(_text) text.seek(0, 0) return text
import viscojapan as vj with vj.EpochalFileReader( '../../tsana/post_fit/cumu_post_with_seafloor.h5') as reader: reader['']
import viscojapan as vj import numpy as np reader = vj.EpochalFileReader('G.h5') G = reader[0] res_file = '../run2_seafloor_01/outs/nrough_14_ntop_02.h5' fault_file = '../../fault_model/fault_bott60km.h5' reader = vj.ResultFileReader(res_file) slip = reader.slip d_pred = np.dot(G, slip).reshape([-1, 3]) sites = np.loadtxt('sites.in', '4a, f, f') _txt = np.array([(s[1], s[2], d[0], d[1], s[0]) for s, d in zip(sites, d_pred)], ('f, f, f, f, U4')) np.savetxt('pred_disp', _txt, fmt='%f %f %f %f %s') _txt = np.array([(s[1], s[2], np.sqrt(d[0]**2 + d[1]**2), s[0]) for s, d in zip(sites, d_pred)], ('f, f, f, U4')) np.savetxt('pred_disp_mag', _txt, fmt='%f %f %f %s')
import viscojapan as vj sites = vj.EpochalFileReader('../obs/cumu_post_with_seafloor.h5')['sites'] vj.tsana.GenUniformOnshoreSDWithInfiniteSeafloorSD( sites=sites, days=range(1201), sd_co_hor=1., sd_co_ver=1., sd_post_hor=1., sd_post_ver=1., sd_seafloor=1.).save('sd_uniform.h5')
import viscojapan as vj from pylab import plt nth_epoch = 28 fault_file = '../../../fault_model/fault_bott80km.h5' reader = vj.EpochalFileReader('slip0.h5') epochs = reader.get_epochs() slip = reader[epochs[nth_epoch]] plt.subplot(1, 2, 1) mplt = vj.plots.MapPlotFault(fault_file) mplt.plot_slip(slip) ############# fault_file = '../../../../iter0/fault_model/fault_bott120km.h5' reader = vj.inv.ResultFileReader('nco_06_naslip_10.h5', fault_file) slip = reader.get_incr_slip_at_nth_epoch(nth_epoch) plt.subplot(1, 2, 2) mplt = vj.plots.MapPlotFault(fault_file) mplt.plot_slip(slip) plt.show() plt.close()
import numpy as np import viscojapan as vj reader = vj.EpochalFileReader('../../tsana/post_fit/cumu_post.h5') co_disp = reader[0].reshape([-1, 3]) sites = vj.Sites([ii.decode() for ii in reader['sites']]) _txt = np.array([(site.lon, site.lat, abs(ci[2]), site.name) for ci, site in zip(co_disp, sites)], ("f,f,f,U4")) np.savetxt('verticals_abs', _txt, '%f %f %f %s') _txt = np.array([(site.lon, site.lat, ci[2], site.name) for ci, site in zip(co_disp, sites)], ("f,f,f,U4")) np.savetxt('verticals', _txt, '%f %f %f %s')
import numpy as np import viscojapan as vj base_dir = '/home/zy/workspace/viscojapan/inversions/static_inversion/static_inversion2' res_file = join( base_dir, 'coseismic/run2_seafloor_01/outs/nrough_14_ntop_02.h5') G_file = join( base_dir, 'green_function_china_korea/G5_He63km_VisM1.0E19_Rake83.h5') reader = vj.ResultFileReader(res_file) slip = reader.slip reader = vj.EpochalFileReader(G_file) G = reader[0] sites = reader['sites'] sites = vj.Sites([site.decode() for site in sites]) d_pred = np.dot(G,slip).reshape([-1,3]) with open('disp','wt') as fid: for d, site in zip(d_pred, sites): fid.write('%f %f %f %f 0. 0. 0. %s\n'%\ (site.lon, site.lat, d[0], d[1], site.name))
import glob from os.path import basename import viscojapan as vj G_olds = glob.glob('../../iter0/green_function/G*.h5') for G_old in G_olds: print(G_old) G_new = basename(G_old) reader = vj.EpochalFileReader(G_old) epochs = reader.get_epochs() with vj.EpochalFileWriter(G_new) as writer: for epoch in epochs: tp = reader[epoch] writer[epoch] = tp[:, :336] writer.copy_info_from(G_old)
reader = vj.inv.DispResultReader(res_file) sites = reader.sites disp = reader.get_post_pred_at_epoch(epoch) mplt = vj.plots.MapPlotDisplacement(bm) mplt.plot_disp(disp.flatten(), sites, color='red', X=X, Y=Y, U=U, label=label_pred, scale=scale) # observation: reader = vj.EpochalFileReader(disp_obs_file) dips_obs = reader[epoch] - reader[0] sites_obs = [site.decode() for site in reader['sites']] mplt = vj.plots.MapPlotDisplacement(bm) mplt.plot_disp(dips_obs, sites_obs, color='black', X=X, Y=Y + 0.1, U=U, label=label_obs, scale=scale) # trench: mplt = vj.plots.MapPlotSlab() mplt.plot_top()