Package: eqsig
eqsigA Python package for seismic signal processing.FeaturesThis package provides common functions for computing ground motion parameters and performing signal processing.
The functions are implemented on either numpy arrays or on a signal object that uses caching to avoid expensive
recalculation of widely used parameters.Compute the acceleration response spectrum and elastic response time series using the fast Nigam and Jennings (1968) algorithm.Compute the Fourier amplitude spectrum (using the scipy.signal.fft algorithm)Compute the smooth Fourier amplitude spectrum according to Konno and Ohmachi (1998)Compute velocity and displacement from acceleration time seriesCompute peak ground motion quantities (PGA, PGV, PGD)Compute common ground motion intensity measures (Arias intensity, CAV, CAV_dp5, significant duration, bracketed duration, dominant period)Compute signal features (zero crossings, global peaks, local peaks)Compute rotated ground motion or intensity measure from two ground motion componentsResampling of ground motion through interpolation or periodic resamplingButterworth filter (using scipy), running average, polynomial fittingFast loading of, and saving of, plain text to and from Signal objectsHow to Use[Eqsig documentation](https://eqsig.readthedocs.io)ExamplesGenerate response spectraimportnumpyasnpimportmatplotlib.pyplotaspltimporteqsig.singlebf,sub_fig=plt.subplots()a=np.loadtxt("<path-to-acceleration-time-series>")dt=0.005# time step of acceleration time seriesperiods=np.linspace(0.2,5,100)# compute the response for 100 periods between T=0.2s and 5.0srecord=eqsig.AccSignal(a*9.8,dt)record.generate_response_spectrum(response_times=periods)times=record.response_timessub_fig.plot(times,record.s_a,label="eqsig")plt.show()Generate Stockwell transformimportnumpyasnpimportmatplotlib.pyplotaspltimporteqsigfrommatplotlibimportrcrc('font',family='Helvetica',size=9,weight='light')plt.rcParams['pdf.fonttype']=42dt=0.01time=np.arange(0,10,dt)f1=0.5factor=10.f2=f1*factoracc=np.cos(2*np.pi*time*f1)+factor/5*np.cos(2*np.pi*time*f2)asig=eqsig.AccSignal(acc,dt)asig.swtf=eqsig.stockwell.transform(asig.values)bf,ax=plt.subplots(nrows=2,sharex=True,figsize=(5.0,4.0))ax[0].plot(asig.time,asig.values,lw=0.7,c='b',label='Signal')in_pcm=eqsig.stockwell.plot_stock(ax[1],asig)ax[1].set_ylim([0.0,10])ax[0].set_xlim([0,10])ax[0].set_ylabel('Amplitude [$m/s^2$]',fontsize=8)ax[1].set_ylabel('$\it{Stockwell}$\nFrequency [Hz]',fontsize=8)ax[-1].set_xlabel('Time [s]',fontsize=8)frommpl_toolkits.axes_grid1.inset_locatorimportinset_axescbaxes=inset_axes(ax[1],width="20%",height="3%",loc='upper right')cbaxes.set_facecolor([1,1,1])cb=plt.colorbar(in_pcm,cax=cbaxes,orientation='horizontal')cb.outline.set_edgecolor('white')cbaxes.tick_params(axis='both',colors='white')ax[0].legend(loc='upper right')forspinax:sp.tick_params(axis='both',which='major',labelsize=8)plt.tight_layout()plt.show()Useful materialContributingHow do I get set up?Runpip install-rrequirements.txtPackage conventionsA function that calculates a property that takes a Signal object as an input, should be named ascalc_<property>,
if the calculation has multiple different implementations, then include the citation as author and year
as wellcalc_<property>_<author>_<year>If the function takes a raw array then it should contain the word array (or values or vals).TestingTests are run with pytestLocally run:pyteston the command line.Tests are run on every push using travis, see the.travis.ymlfileDeploymentTo deploy the package to pypi.com you need to:Push to thepypibranch. This executes the tests on circleci.comCreate a git tag and push to github, run:trigger_deploy.pyor manually:gittag0.5.2-m"version 0.5.2"gitpush--tagsoriginpypiDocumentationBuilt via Sphinx following:https://codeandchaos.wordpress.com/2012/07/30/sphinx-autodoc-tutorial-for-dummies/For development modecd to docsRunmake htmlDocstrings follow numpy convention (in progress):https://numpydoc.readthedocs.io/en/latest/format.htmlTo fix long_description in setup.py:pip install collective.checkdocs,python setup.py checkdocsRelease instructionsOn zenodo.org use the github integration tool, click on the eqsig package and click create new release.History1.2.10 (2020-11-24)Adjustedeqsig.stockwell.plot_stock, since min freq was out by factor of 0.5.1.2.5 (2020-11-24)Addedgen_ricker_wavelet_asigto create an acceleration signal that is a Ricker waveletAddedeqsig.sdof.calc_input_energy_spectrumto compute the input energy into an SDOFCan now load a Signal with a scale factor by passing in the keywordm=<scale factor>The left interpolation function interp_left now returns the same size as x, which can be a scalar, and ifyis None then assumes index (0,1,2,…,n)1.2.4 (2020-07-20)Fixed issue with computation of surface energy spectraSupport for numpy==1.191.2.3 (2020-05-05)Fixed docs for generation of FAS, changed kwargn_plustop2_plussince this adds to the power of 2.1.2.2 (2020-05-05)Switched to numpy for computing the Fourier amplitude spectrum1.2.1 (2020-05-05)Addedresponse_period_rangeto AccSignal object initial inputs to define response periods using an upper and lower limitImproved speed of surface energy calculationcalc_surface_energyand returns correct size based on input dimensionsRemoved global import of scipy - done at function levelAdded aninterp_leftfunction to interpolate an array and take lower valueFixed issue with inverse of stockwell transformstockwell.itransform, it no longer doubles the time stepIncreased speed of stockwell transformstockwell.transform.Addedremove_polyfunction to remove a polynomial fit from an arrayAdded option to accessfa_frequenciesandsmooth_fa_frequenciesasfa_freqsandsmooth_fa_freqs.Added option for computing smoothed FAS with extra zero paddingAdded function for computing smoothed fas using a custom smoothing matrix.1.2.0 (2019-11-03)Addedinterp2dfast interpolation of a 2D array to obtain a new 2D arrayNo longer raises warning when period is 0.0 for computing response spectrumFixed issue with computation of smoothed response spectrum for dealing with zeroth frequencyIncreased speed of`generate_smooth_fa_spectrum`Can now directly setAccSignal.smooth_fa_frequenciesDeprecatedAccSignal.smooth_freq_pointsandAccSignal.smooth_freq_rangewill be removed in later version1.1.2 (2019-10-31)More accuracy incalc_surface_energy- now interpolates between time steps. More tests added.1.1.1 (2019-10-29)Fixed issue inget_zero_crossings_array_indiceswhere it would fail if array did not contain any zeros.Added calculation of equivalent number of cycles and equivalent uniform amplitude using power law relationship as intensity measuresAdded functionget_n_cyc_arrayto compute number of cycles series from a loading seriesAdded intensity measureim.calc_unit_kinetic_energy()to compute the cumulative change in kinetic energy according to Millen et al. (2019)Addedsurface.pywith calculation of surface energy and cumulative change in surface energy time series versus depth from surface1.1.0 (2019-10-08)Fixed issue with second order term in sdof response spectrum calculation which effected high frequency response, updated example to show difference1.0.0 (2019-07-01)First production release