Package: dsmpy
dsmpyPython package for computation of synthetic waveforms in spherically homogeneous transversely isotropic (VTI) media using the Direct Solution Method (DSM;Kawai et al. 2006).Documentation and tutorials can be foundhere.INSTALLATIONRequirementsAsdsmpyrelies on mpi4py, you need to have a working MPI implementation installed (seempi4py documentation)gfotran >= 4.8Using pipIn a shell, typepip install dsmpyThis will download the dsmpy package and required dependencies from the PyPI repository.Check that dsmpy has been installed succesfully:python -c "import dsmpy"Note:Fortran sources for the DSM will be compiled during the installation (using numpy.f2py and the GNU Fortran compiler). If you get compilation errors, check the following:gfortran >= 4.8 is required for succesful compilation, because of the optimization flag '-Ofast'If you have gfortran <4.8, you should change the compiler flag from '-Ofast' to '-O3' in<path_of_dsmpy_folder>/pydsm/__init__.pyGETTING STARTEDTo get started, you should at least runpython test_tipsv.pyandpython test_tish.psvlocated in in<path_of_pydsm_folder>/pydsm/tests. These scripts checkdsmpyagainst pre-computed synthetics using the DSM (Fortran).EXAMPLESRunning dsmpy using an input file (run on multiple CPUs).
A template input file is in<path_of_pydsm_folder>/dsmpy/tests/input_files/template.txt:sac_files~/git/dsmpy/tests/sac_files/*T
output_folder~/git/dsmpy/tests/sac_files# duration of synthetics (in seconds)tlen3276.8# number of points of frequency-domain synthetics# minimum period Tmin = tlen / nspc (s)nspc256# sampling frequency for time-domain syntheticssampling_hz20# prem, ak135seismic_modelprem# 0: P-SV+SH, 1: P-SV, 2: SH (default: 0)mode0# 0: quiet, 1: talkative, 2: debug (default: 0)verbose0To run this input file on 2 CPUs:open a Terminalchange the current directory to the dsmpy directorypaste:mpiexec-n2pythonpydsm/main.pytests/input_files/template.txtRunning dsmpy from a python script.
Below is an example of python script using dsmpy to compute synthetics:fromdsmpyimportdsm,seismicmodelfromdsmpy.eventimportEventfromdsmpy.stationimportStationfromdsmpy.utils.cmtcatalogimportread_catalog# load gcmt catalogcatalog=read_catalog()# get event from catalogevent=Event.event_from_catalog(catalog,'200707211534A')# define station FCCstations=[Station(name='FCC',network='CN',latitude=58.7592,longitude=-94.0884),]# load (anisotropic) PREM modelseismic_model=seismicmodel.SeismicModel.prem()tlen=3276.8# duration of synthetics (s)nspc=256# number of points in frequency domainsampling_hz=20# sampling frequency for sythetics# create input parameters for pydsminput=dsm.PyDSMInput.input_from_arrays(event,stations,seismic_model,tlen,nspc,sampling_hz)# compute synthetics in frequency domain calling DSM Fortranoutput=dsm.compute(input)output.to_time_domain()# perform inverse FFToutput.filter(freq=0.04)# apply a 25 seconds low-pass filterus=output.us# synthetics. us.shape = (3,nr,tlen)ts=output.ts# time points [0, tlen]# brackets can be used to access component and stationu_Z_FCC=output['Z','FCC_CN']# to plot a three-component record section, useoutput.plot()plt.show()# to write synthetics to SAC files, useoutput.write(root_path='.',format='sac')Running dsmpy using a (Fortran) DSM input file.
Methods are provided to run dsmpy using an input file for the (Fortran) DSM:frompydsmimportdsm,rootdsm_shparameter_file=rootdsm_sh+'AK135_SH.inf'inputs=dsm.PyDSMInput.input_from_file(parameter_file,mode=2)outputs=dsm.compute(inputs,mode=2)outputs.to_time_domain()us=outputs.us# us.shape = (3,nr,tlen)ts=outputs.ts# len(ts) = tlenstations=outputs.stations# len(stations) = nrcomponents=outputs.components# len(components) = 3