def __init__(self, factor=1., thresh=0.5, waterdepth=-1., vpwater=1.5, stdfactor=2.): self.data = data.data1d() self.factor = factor self.thresh = thresh self.stdfactor = stdfactor # models self.avg_model = vmodel.model1d() self.min_model = vmodel.model1d() self.init_model = vmodel.model1d() self.real_model = vmodel.model1d() self.temp_model = vmodel.model1d() # self.vprfwrd = vprofile.vprofile1d() self.waterdepth = waterdepth self.vpwater = vpwater # self.avg_misfit = 0. self.code = '' return
import vprofile import modparam vpr = vprofile.vprofile1d() vpr.readdisp(infname='./disp_-112.2_36.4_lov.txt', wtype='l') vpr.readdisp(infname='./disp_-112.2_36.4_ray.txt', wtype='r') vpr.readaziamp(infname='./aziamp_-112.2_36.4.txt', wtype='r') vpr.readaziphi(infname='./aziphi_-112.2_36.4.txt', wtype='r') vpr.readmod(infname='mod_-112.2.36.4.mod', mtype='tti') vpr.getpara(mtype='tti') vpr.update_mod(mtype='tti') vpr.model.ttimod.get_rho() vpr.get_vmodel(mtype='tti') vpr.get_period() vpr.compute_tcps(wtype='ray') vpr.compute_tcps(wtype='love') vpr.model.ttimod.mod2para() # # vpr.model.ttimod.para.new_paraval(1) vpr.model.ttimod.para2mod() vpr.model.ttimod.update() vpr.get_vmodel(mtype='tti') vpr.model.dipArr[vpr.model.dipArr != 0.] = 90. vpr.model.strikeArr[vpr.model.strikeArr != 0.] = 33. vpr.model.init_etensor() vpr.model.rot_dip_strike()
def mc_inv_iso(self, instafname=None, ref=True, phase=True, group=False, outdir='./workingdir', wdisp=0.2, rffactor=40.,\ monoc=True, verbose=False, step4uwalk=1500, numbrun=10000, subsize=1000, nprocess=None, parallel=True): """ Bayesian Monte Carlo joint inversion of receiver function and surface wave data for an isotropic model ================================================================================================================== ::: input ::: instafname - input station list file indicating the stations for joint inversion ref - include receiver function data or not phase/group - include phase/group velocity dispersion data or not outdir - output directory wdisp - weight of dispersion curve data (0. ~ 1.) rffactor - factor for downweighting the misfit for likelihood computation of rf monoc - require monotonical increase in the crust or not step4uwalk - step interval for uniform random walk in the parameter space numbrun - total number of runs subsize - size of subsets, used if the number of elements in the parallel list is too large to avoid deadlock nprocess - number of process parallel - run the inversion in parallel or not ================================================================================================================== """ if not os.path.isdir(outdir): os.makedirs(outdir) if instafname is None: stalst = self.waveforms.list() else: stalst = [] with open(instafname, 'r') as fid: for line in fid.readlines(): sline = line.split() if sline[2] == '1': stalst.append(sline[0]) if not ref and wdisp != 1.: wdisp = 1. print 'wdisp is forced to be 1. for inversion without receiver function data' if phase and group: dispdtype = 'both' elif phase and not group: dispdtype = 'ph' else: dispdtype = 'gr' ista = 0 Nsta = len(stalst) for staid in stalst: netcode, stacode = staid.split('.') staid_aux = netcode+'_'+stacode stla, elev, stlo = self.waveforms[staid].coordinates.values() #----------------------------- # get data #----------------------------- vpr = vprofile.vprofile1d() if phase: try: indisp = self.auxiliary_data['RayDISPcurve']['ray']['ph'][staid_aux].data.value vpr.get_disp(indata=indisp, dtype='ph', wtype='ray') except KeyError: print 'WARNING: No phase dispersion data for station: '+staid if group: try: indisp = self.auxiliary_data['RayDISPcurve']['ray']['gr'][staid_aux].data.value vpr.get_disp(indata=indisp, dtype='gr', wtype='ray') except KeyError: print 'WARNING: No group dispersion data for station: '+staid if vpr.data.dispR.npper == 0 and vpr.data.dispR.ngper == 0: print 'WARNING: No dispersion data for station: '+staid continue if ref: try: inrf = self.auxiliary_data['RefR'][staid_aux+'_P'].data.value N = self.auxiliary_data['RefR'][staid_aux+'_P'].parameters['npts'] dt = self.auxiliary_data['RefR'][staid_aux+'_P'].parameters['delta'] indata = np.zeros((3, N)) indata[0, :]= np.arange(N)*dt indata[1, :]= inrf[0, :] indata[2, :]= inrf[3, :] vpr.get_rf(indata = indata) except KeyError: print 'WARNING: No receiver function data for station: '+staid #----------------------------- # initial model parameters #----------------------------- vsdata = self.auxiliary_data['ReferenceModel'][staid_aux].data.value crtthk = self.auxiliary_data['MohoDepth'][staid_aux].parameters['moho_depth'] sedthk = self.auxiliary_data['SediDepth'][staid_aux].parameters['sedi_depth'] vpr.model.isomod.parameterize_input(zarr=vsdata[:, 0], vsarr=vsdata[:, 1], crtthk=crtthk, sedthk=sedthk, maxdepth=200.) vpr.getpara() ista += 1 # if staid != 'AK.HDA': continue # # # if np.random.rand() > 0.9: # # # print staid # # # return vpr, vsdata # # # else: # # # continue print '--- Joint MC inversion for station: '+staid+' '+str(ista)+'/'+str(Nsta) if parallel: vpr.mc_joint_inv_iso_mp(outdir=outdir, dispdtype=dispdtype, wdisp=wdisp, rffactor=rffactor,\ monoc=monoc, pfx=staid, verbose=verbose, step4uwalk=step4uwalk, numbrun=numbrun, subsize=subsize, nprocess=nprocess) else: vpr.mc_joint_inv_iso(outdir=outdir, dispdtype=dispdtype, wdisp=wdisp, rffactor=rffactor,\ monoc=monoc, pfx=staid, verbose=verbose, step4uwalk=step4uwalk, numbrun=numbrun) # vpr.mc_joint_inv_iso(outdir=outdir, wdisp=wdisp, rffactor=rffactor,\ # monoc=monoc, pfx=staid, verbose=verbose, step4uwalk=step4uwalk, numbrun=numbrun) # if staid == 'AK.COLD': # return vpr return