Signal processing for field and experimental data for earthquake engineering

## eqsig

A Python package for seismic signal processing.

### Features

This 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 series
• Compute 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 components
• Resampling of ground motion through interpolation or periodic resampling
• Butterworth filter (using scipy), running average, polynomial fitting
• Fast loading of, and saving of, plain text to and from Signal objects

### How to Use

#### Examples

Generate response spectra

```import numpy as np
import matplotlib.pyplot as plt
import eqsig.single

bf, sub_fig = plt.subplots()
dt = 0.005  # time step of acceleration time series
periods = np.linspace(0.2, 5, 100)  # compute the response for 100 periods between T=0.2s and 5.0s
record = eqsig.AccSignal(a * 9.8, dt)
record.generate_response_spectrum(response_times=periods)
times = record.response_times

sub_fig.plot(times, record.s_a, label="eqsig")
plt.show()
```

### Contributing

#### How do I get set up?

1. Run pip install -r requirements.txt

#### Package conventions

• A function that calculates a property the takes a signal as an input, should be named as calc_<property>, if the calculation has multiple different implementations, then include the citation as author and year as well calc_<property>_<author>_<year>
• If the function takes a raw array then it should contain the word array (or values or vals).

#### Testing

Tests are run with pytest

• Locally run: pytest on the command line.
• Tests are run on every push using travis, see the .travis.yml file

#### Deployment

To deploy the package to pypi.com you need to:

1. Push to the pypi branch. This executes the tests on circleci.com
2. Create a git tag and push to github, run: trigger_deploy.py or manually:
```git tag 0.5.2 -m "version 0.5.2"
git push --tags origin pypi
```

#### Documentation

Built via Sphinx following: https://codeandchaos.wordpress.com/2012/07/30/sphinx-autodoc-tutorial-for-dummies/

For development mode

1. cd to docs
2. Run make html

To fix long_description in setup.py: pip install collective.checkdocs, python setup.py checkdocs

#### Release instructions

On zenodo.org use the github integration tool, click on the eqsig package and click create new release.

#### 1.2.4 (2020-07-20)

• Fixed issue with computation of surface energy spectra
• Support for numpy==1.19

#### 1.2.3 (2020-05-05)

• Fixed docs for generation of FAS, changed kwarg n_plus to p2_plus since this adds to the power of 2.

#### 1.2.2 (2020-05-05)

• Switched to numpy for computing the Fourier amplitude spectrum

#### 1.2.1 (2020-05-05)

• Added response_period_range to AccSignal object initial inputs to define response periods using an upper and lower limit
• Improved speed of surface energy calculation calc_surface_energy and returns correct size based on input dimensions
• Removed global import of scipy - done at function level
• Added an interp_left function to interpolate an array and take lower value
• Fixed issue with inverse of stockwell transform stockwell.itransform, it no longer doubles the time step
• Increased speed of stockwell transform stockwell.transform.
• Added remove_poly function to remove a polynomial fit from an array
• Added option to access fa_frequencies and smooth_fa_frequencies as fa_freqs and smooth_fa_freqs.
• Added function for computing smoothed fas using a custom smoothing matrix.

#### 1.2.0 (2019-11-03)

• Added interp2d fast interpolation of a 2D array to obtain a new 2D array
• No longer raises warning when period is 0.0 for computing response spectrum
• Fixed issue with computation of smoothed response spectrum for dealing with zeroth frequency
• Increased speed of`generate_smooth_fa_spectrum`
• Can now directly set AccSignal.smooth_fa_frequencies
• Deprecated AccSignal.smooth_freq_points and AccSignal.smooth_freq_range will be removed in later version

#### 1.1.2 (2019-10-31)

• More accuracy in calc_surface_energy - now interpolates between time steps. More tests added.

#### 1.1.1 (2019-10-29)

• Fixed issue in get_zero_crossings_array_indices where 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 measures
• Added intensity measure im.calc_unit_kinetic_energy() to compute the cumulative change in kinetic energy according to Millen et al. (2019)
• Added surface.py with calculation of surface energy and cumulative change in surface energy time series versus depth from surface

#### 1.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 difference

#### 1.0.0 (2019-07-01)

• First production release