def test_plane_obs(): modfile = resource_filename('telewavesim', 'examples/models/model_Audet2016.txt') model = ut.read_model(modfile) npts = 2000 wvtype = 'P' dt = 0.05 slow = 0.04 baz = 0. dp = 1000 c = 1.5 rhof = 1027 ut.model2for(model) ut.wave2for(dt, slow, baz) ut.obs2for(dp, c, rhof) yx, yy, yz = pw_f.plane_obs(npts, model.nlay, np.array(wvtype, dtype='c')) ux = np.real(fft(yx)) uy = np.real(fft(yy)) uz = np.real(fft(yz)) # seismogram should be maximized on vertical component assert np.max(np.abs(uz)) > np.max(np.abs(ux)) > np.max(np.abs(uy)), \ 'Failed! Energy is not maximized on vertical component' # tangential component should all be close to zero assert np.allclose(uy, np.zeros(len(uy))), 'non-zero values in uy'
def test_plane_obs(load_params): yx, yy, yz = pw_f.plane_obs(cf.nt, cf.nlay, np.array(cf.wvtype, dtype='c')) ux = np.real(pyfftw.interfaces.numpy_fft.fft(yx)) uy = np.real(pyfftw.interfaces.numpy_fft.fft(yy)) uz = np.real(pyfftw.interfaces.numpy_fft.fft(yz)) # seismogram should be maximized on vertical component assert np.max(np.abs(uz)) > np.max(np.abs(ux)) > np.max(np.abs(uy)), \ 'Failed! Energy is not maximized on vertical component' # tangential component should all be close to zero assert np.allclose(uy, np.zeros(len(uy))), 'non-zero values in uy'
def run_plane(obs=False): """ Function to run the ``plane`` module and return 3-component seismograms as an ``obspy`` ``Stream`` object. .. note:: The ``conf`` global variables need to be set for this calculation to succeed. This function first checks to make sure the variables are all set before executing the main ``telewavesim.rmat_f.plane_****`` function. Args: fortran (book, option): Whether or not the Fortran modules are used obs (bool, optional): Whether or not the analysis is done for an OBS stations Returns: (obspy.stream): trxyz: Stream containing 3-component displacement seismograms """ # Check if all variables are set. If not, throw an Exception and stop check_cf(obs) # Pass variables to Fortran conf model2for() wave2for() # Run the ``plane`` module depending on land or OBS case. if obs: # If OBS, then further pass OBS-related paramters to Fortran conf obs2for() # Get the Fourier transform of seismograms for ``obs``case yx, yy, yz = pw_f.plane_obs(cf.nt,cf.nlay,np.array(cf.wvtype, dtype='c')) else: # Get the Fourier transform of seismograms for ``land`` case yx, yy, yz = pw_f.plane_land(cf.nt,cf.nlay,np.array(cf.wvtype, dtype='c')) # Transfer displacement seismograms to an ``obspy`` ``Stream`` object. trxyz = get_trxyz(yx, yy, yz) return trxyz
def run_plane(model, slow, npts, dt, baz=0, wvtype='P', obs=False, dp=100., c=1.5, rhof=1027): """ Function to run the ``plane`` module and return 3-component seismograms as an ``obspy.Stream`` object. This function builds the seismic response spectrum by frequency using the matrix propagation approach. Required arguments are the seismic model, slowness value, and the sampling properties (maximum number of samples and the sampling distance in seconds). By default, the function uses a back-azimuth value of 0 degree, which is suitable for events coming from the North pole or isotropic seismic velocity models (i.e., those that do not vary with direction of incoming waves). For anisotropic velocity models, users need to specify the back-azimuth value in degrees. Furthermore, the default type of the incoming teleseismic body wave is ``'P'`` for compressional wave. Other options are ``'SV'``, ``'SH'``, or ``'Si'`` for vertically-polarized shear wave, horizontally-polarized shear wave or isotropic shear wave, respectively. Wave modes cannot be mixed. Finally, it is possible to simulate the seismic response for ocean-bottom seismic (OBS) stations using the flag ``obs=True``. If the flag is set to ``True``, the user can specify the water depth below sea level (in meters, positive value) as well as the properties of the sea water (defaults are acoustic wavespeed of 1.5 km/s and density of 1027 kg/m^3). Args: model (Model): Instance of the ``Model`` class that contains the physical properties of subsurface layers. slow (float): Slowness (s/km) baz (float): Back-azimuth (degree) npts (int): Number of samples in time series dt (float): Sampling distance (s) baz (float, optional): Back-azimuth (degree) wvtype (str, optional, default: ``'P'``): Incident wavetype (``'P'``, ``'SV'``, ``'SH'``, ``'Si'``) obs (bool, optional): Whether or not the analysis is done for an OBS stations dp (float, optional): Deployment depth below sea level (m) c (float, optional): P-wave velocity of salt water (default = ``1.5`` km/s) rhof (float, optional): Density of salt water (default = ``1027.0`` kg/m^3) Returns: (obspy.stream): trxyz: Stream containing 3-component displacement seismograms Example ------- Basic example: >>> from telewavesim import utils >>> # Define three-layer model with isotropic crust and antigorite upper mantle layer over isotropic half-space >>> model = utils.Model([20, 10, 0], [2800., None, 3300.], [4.6, 0, 6.0], [2.6, 0, 3.6], ['iso', 'atg', 'iso'], [0, 0, 0], [0, 0, 0], [0, 0, 0]) >>> slow = 0.06 # s/km >>> npts = 1500 >>> dt = 0.025 # s >>> st = utils.run_plane(model, slow, npts, dt) >>> type(st) <class 'obspy.core.stream.Stream'> >>> print(st) 3 Trace(s) in Stream: ...N | 1970-01-01T00:00:00.000000Z - 1970-01-01T00:00:37.475000Z | 40.0 Hz, 1500 samples ...E | 1970-01-01T00:00:00.000000Z - 1970-01-01T00:00:37.475000Z | 40.0 Hz, 1500 samples ...Z | 1970-01-01T00:00:00.000000Z - 1970-01-01T00:00:37.475000Z | 40.0 Hz, 1500 samples >>> st.plot(size=(600, 450)) .. figure:: ../telewavesim/examples/picture/Figure_land.png :align: center OBS station: >>> from telewavesim import utils >>> # Define two-layer model with foliated eclogitic crust over isotropic half-space >>> model = utils.Model([20, 0], [None, 3300.], [0, 6.0], [0, 3.6], ['EC_f', 'iso'], [0, 0], [0, 0], [0, 0]) >>> slow = 0.06 # s/km >>> npts = 3000 >>> dt = 0.01 # s >>> wvtype = 'SV' >>> baz = 45. >>> dp = 1000. >>> st = utils.run_plane(model, slow, npts, dt, baz=baz, wvtype=wvtype, obs=True, dp=dp) >>> st.plot(size=(600, 450)) .. figure:: ../telewavesim/examples/picture/Figure_obs.png :align: center """ # Pass variables to Fortran conf model2for(model) wave2for(dt, slow, baz) # Run the ``plane`` module depending on land or OBS case. if obs: # If OBS, then further pass OBS-related paramters to Fortran conf obs2for(dp, c, rhof) # Get the Fourier transform of seismograms for ``obs``case yx, yy, yz = pw_f.plane_obs(npts, model.nlay, np.array(wvtype, dtype='c')) else: # Get the Fourier transform of seismograms for ``land`` case yx, yy, yz = pw_f.plane_land(npts, model.nlay, np.array(wvtype, dtype='c')) # Transfer displacement seismograms to an ``obspy`` ``Stream`` object. trxyz = get_trxyz(yx, yy, yz, npts, dt, slow, baz, wvtype) return trxyz