import vmodel import copy import matplotlib.pyplot as plt import numpy as np model = vmodel.Model1d(modelindex=2) model.read_axisem_bm( '/home/leon/code/axisem/SOLVER/MESHES/prem_aniso_10s/1dmodel_axisem.bm')
def getdisp(self, workingdir, dt=0.1, N2=12, nmodes=1, mode=0, hr=0., hs=0., deletemod=False, verbose=True, noq=True): """ Get theoretical dispersion curves for all vertical profiles and save them to ASDF file ========================================================================================== Input Parameters: dt - time interval N2 - npts = 2**N2 nmodes - number of modes mode - mode index (0 for fundamental mode, 1 for 1st overtone ...) hr - receiver depth hs - source depth workingdir - working directory for Computer Program for Seismology deletemod - delete model files or not ========================================================================================== """ ingroup = self['3Dmodel'] header = {'H': 0, 'vs': 1, 'vp': 2, 'rho': 3, 'Qs': 4} npts = 2**N2 FNULL = open(os.devnull, 'w') if mode + 1 > nmodes: nmodes = mode + 1 warnings.warn( 'Mode required is not available, re-assign nmodes = mode+1 !', UserWarning, stacklevel=1) if not os.path.isdir(workingdir): os.makedirs(workingdir) minlat = self.attrs['minlat'] maxlat = self.attrs['maxlat'] minlon = self.attrs['minlon'] maxlon = self.attrs['maxlon'] dlon = self.attrs['dlon'] dlat = self.attrs['dlat'] latarr = minlat + np.arange((maxlat - minlat) / dlat + 1) * dlat lonarr = minlon + np.arange((maxlon - minlon) / dlon + 1) * dlon tempCPS = workingdir + '/run_dispersion.sh' ############################################################################ # Get theoretical dispersion curve for each vertical profile ############################################################################ outgroup = self.create_group(name='phase_vel') for lat in latarr: for lon in lonarr: name = '%g_%g' % (lon, lat) VProf = ingroup[name][...] model1d = vmodel.Model1d() QpArr = 3 / 4. * VProf[:, header['Qs']] * ( VProf[:, header['vp']] / VProf[:, header['vs']])**2 model1d.getmodel(modelname=name, HArr=VProf[:, header['H']], VpArr=VProf[:, header['vp']], VsArr=VProf[:, header['vs']], rhoArr=VProf[:, header['rho']], QpArr=QpArr, QsArr=VProf[:, header['Qs']]) model1d.check_model() tempmod = workingdir + '/temp_' + name + '.mod' model1d.write(tempmod) with open(tempCPS, 'wb') as f: f.writelines( 'sprep96 -DT %f -NPTS %d -HR %f -HS %f -M %s -NMOD %d -R \n' % (dt, npts, hr, hs, tempmod, nmodes)) if noq: f.writelines( 'sdisp96 \nsregn96 -NOQ \nsdpegn96 -R -U -ASC -TXT -PER \n' ) else: f.writelines( 'sdisp96 \nsregn96 \nsdpegn96 -R -U -ASC -TXT -PER \n' ) if verbose == False: subprocess.call(['bash', tempCPS], stdout=FNULL, stderr=subprocess.STDOUT) else: subprocess.call(['bash', tempCPS]) os.remove('sdisp96.dat') os.remove('sdisp96.ray') os.remove('sregn96.egn') os.remove('SREGN.ASC') os.remove('SREGNU.PLT') dispfile = cpsfile.DispFile('SREGN.TXT') os.remove('SREGN.TXT') os.remove(tempCPS) if deletemod: os.remove(tempmod) dispcurve = dispfile.DispLst[mode] dispcurve.InterpDisp() auxArr = np.append(dispcurve.period, dispcurve.Vph) auxArr = np.append(auxArr, dispcurve.Vgr) if noq: auxArr = auxArr.reshape(3, dispcurve.period.size) # # vs/dvs vp/dvp rho/drho Rmax Rmin z0 H x y dtype # parameters={'Rmax': self.Vprofile.RmaxArr[i], 'Rmin': self.Vprofile.RminArr[i], 'x': self.Vprofile.xArr[i], # 'y': self.Vprofile.yArr[i], 'T': 0, 'Vph': 1, 'Vgr': 2} else: auxArr = np.append(auxArr, dispcurve.gamma) auxArr = auxArr.reshape(4, dispcurve.period.size) # parameters={'Rmax': self.Vprofile.RmaxArr[i], 'Rmin': self.Vprofile.RminArr[i], 'x': self.Vprofile.xArr[i], # 'y': self.Vprofile.yArr[i], 'T': 0, 'Vph': 1, 'Vgr': 2, 'gamma': 3} dset = outgroup.create_dataset(name=name, shape=auxArr.shape, data=auxArr) dset.attrs.create(name='lon', data=lon, dtype='f') dset.attrs.create(name='lat', data=lat, dtype='f') FNULL.close() return
import modesum import vmodel dset = modesum.modesumASDF() model = vmodel.Model1d(modelindex=2, earthindex=2) model.read_axisem_bm( '/home/leon/code/axisem/SOLVER/MESHES/prem_aniso_10s/1dmodel_axisem.bm') # model.trim(zmax=1000.) dset.getmodel(inmodel=model) dset.run_disp(workingdir='/home/leon/code/CPSPy/axisem_benchmark', outfname='/home/leon/code/CPSPy/axisem_benchmark.asdf', nmodes=1) dset.run_eigen(hs=10., runtype='SYN', infname='/home/leon/code/CPSPy/axisem_benchmark.asdf', outfname='/home/leon/code/CPSPy/axisem_benchmark.asdf', run=True) # dset.run_pulse(infname='/home/leon/code/CPSPy/axisem_benchmark.asdf', run=False, dist0=1000, Nd=1)
def cpsmodel1d(self): self.model1d = vmodel.Model1d() self.model1d.ak135() return