pyatoa.utils.calculate

Custom math functions for faster calculations in other parts of Pyatoa

Module Contents

Functions

abs_max(array)

Find the absolute maximum of an array

myround(x[, base, choice])

Round value x to nearest base, round 'up','down' or to 'near'est base

enforce_angle_pi(angle[, bound])

Used for mapping mostly, sometimes when adding values to map bounds, you

overlapping_days(origin_time[, start_pad, end_pad])

Helper function to return a list of julian days based on a given

normalize_a_to_b(array[, a, b])

normalize an array from a to b for e.g. plotting, maths

amplitude_anomaly(a, b, dt)

Calculate the amplitude differences between two waveforms, a la.

vrl(d, s1, s2)

Logarithmic variance reduction. Approximately Gaussian distributed

time_offset(st, origintime)

Oft repeated calculation of finding the time offset between the start of

pyatoa.utils.calculate.abs_max(array)[source]

Find the absolute maximum of an array

Parameters:

array (np.array) – array to find abs max of

Return type:

float

Returns:

absolute maximum of array

pyatoa.utils.calculate.myround(x, base=5, choice='near')[source]

Round value x to nearest base, round ‘up’,’down’ or to ‘near’est base

Parameters:
  • x (float) – value to be rounded

  • base (int) – nearest integer to be rounded to

  • choice (str) – method of rounding, ‘up’, ‘down’ or ‘near’

Rtype roundout:

int

Returns:

rounded value

pyatoa.utils.calculate.enforce_angle_pi(angle, bound=180)[source]

Used for mapping mostly, sometimes when adding values to map bounds, you can cross over the accepted threshold, e.g., angle > 180deg. This function just keeps things within bounds

https://stackoverflow.com/questions/2320986/

easy-way-to-keeping-angles-between-179-and-180-degrees

pyatoa.utils.calculate.overlapping_days(origin_time, start_pad=20, end_pad=200)[source]

Helper function to return a list of julian days based on a given origin time with a specific padding on either side. used to catch if an origin time sits too close to midnight and two days need to be fetched

Parameters:
  • origin_time (obspy.core.UTCDateTime) – event origin time

  • start_pad – padding in seconds before the origin time of an event for waveform fetching, to be fed into lower level functions.

  • end_pad (int) – padding in seconds after the origin time of an event for wavefomr fetching.

Return type:

list of int

Returns:

list of available julian days

pyatoa.utils.calculate.normalize_a_to_b(array, a=0, b=1)[source]

normalize an array from a to b for e.g. plotting, maths

Parameters:
  • array (list) – values to be normalized

  • a (int) – lower bound of normalization

  • b (int) – upper bound of normalization

Rtype z:

numpy.array

Return z:

normalized array

pyatoa.utils.calculate.amplitude_anomaly(a, b, dt)[source]

Calculate the amplitude differences between two waveforms, a la. Equation A2 from Tape et al. 2010, which states that:

DlnA = ln(a/b) = 0.5 * ln[integral(a(t)**2 dt)/integral(b(t)**2 dt)] where a and b represent data and synthetics, respectively

Note

It is expected that a and b have the same value of dt, if they do not, they should be resampled before being passed to this function.

Parameters:
  • a (np.array) – waveform data to act as numerator of misfit definition

  • b (np.array) – waveform data to act as denominator of misfit definition

  • dt (float) – sampling rate for the integration

Return type:

float

Returns:

the value of DlnA, the amplitude anomaly

pyatoa.utils.calculate.vrl(d, s1, s2)[source]

Logarithmic variance reduction. Approximately Gaussian distributed reduction in variance based on full waveform difference. Based on Equation 8 in Tape et al. 2010.

Parameters:
  • d (np.array) – data array to compare against synthetic arrays

  • s1 (np.array) – synthetic array for model 1

  • s2 (np.array) – synthetic array for model 2

Return type:

float

Returns:

logarithmic variance reduction

pyatoa.utils.calculate.time_offset(st, origintime)[source]

Oft repeated calculation of finding the time offset between the start of a stream and the origin time of an event. Important when dealing with SPECFEM seismograms, which explicitely start at the time offset value, w.r.t. streams which set starttime at 0 but contain their own origin time information

Note

convention is that if the waveform starts BEFORE the event origin time, then time_offset will be NEGATIVE.

Parameters:
  • st (obspy.core.stream.Stream) – stream to check time offset of

  • origintime (obspy.UTCDateTime) – the origin time of the event

Return type:

float

Returns:

the time offset, or: origintime - stream_origin_time