resistics.statistics.calculator module

class resistics.statistics.calculator.StatisticCalculator[source]

Bases: resistics.common.base.ResisticsBase

Calculate statistics for data restriction

Statistics are calculated out for each evaluation frequency in each window. Therefore, there are nwindow*nfreq statistics in total.

This class was written to speed up statistic calculations. Many statistics need the same data, for example power spectra. This class calculates and reuses some common values amongst the various statistics to improve calculation speed.

Attributes
evalFreqList

List of evaluation frequencies

winLenint

Window length for spectra calculations

winTypestr

Window function to apply to time data before fourier transform

inChansList[str]

Input channels

inSizeint

Number of input channels

outChansList[str]

Output channels

outSizeint

Number of output channels

specChansList[str]

The channels for which to calculate auto and cross power spectra

remoteChansList[str]

Remote reference channels

psdChansList[str]

Power spectral density channels

cohPairsList[List[str]]

Pairs of channels for coherence calculations

polDirsList[List[str]]

Pairs of channels of polarisation direction calculation

spec: Dict[str, np.ndarray]

The spectra data dictionary mapping channel to data array

tfCalculatedbool

Boolean flag to show that the transfer function has been calculated for a window

remoteCalculatedbool

Boolean flag to show if the remote transfer function has been calculated

interceptbool

Boolean flag to include an intercept into the

outData: Dict = {}

Methods

__init__()

getEvalFreq()

Get a list of the evaluation frequency

getInChans()

Get a list of the input channels for the transfer function calculation

getOutChans()

Get a list of the output channels for the transfer function calculation

getSpecChans()

Get a list of the spectra channels

getRemoteChans()

Get a list of the remote channels

getPSDChans()

Get a list of channels for which to calculate power spectral density

getCohPairs()

Get a list of coherence pairs to calculate

getPolDirs()

Get a list of polarisation direction channels to calculate

getAutoPower(chan)

Get auto power data for a channel

getAutoPowerEval(chan, eIdx)

Get auto power data for a channel calculated at evaluation frequencies

getCrossPower(chan1, chan2)

Get cross power data between two channels

getCrossPowerEval(chan1, chan2, eIdx)

Get cross power data between two channels at the evaluation frequencies

getOutData()

Get the output data

setInChans(inChans)

Set the input channels for transfer function statistics

setOutChans(outChans)

Set the output channels for the transfer function statistics

setSpectra(freq, winData, evalFreq)

Set the spectra data

setIntercept(intercept)

Boolean flag for adding an intercept term

calculateSpectralMatrix()

Calculate the cross power spectra matrix

calculateEvalMatrix()

Calculate the cross power spectra matrix at the evaluation frequencies

addRemoteSpec(remoteData, **kwargs)

Add a remote reference spectra

calculateRemoteSpectralMatrix()

Calculate the remote data power spectral matrix

calculateRemoteEvalMatrix()

Calculate the remote data power spectra matrix at the evaluation frequencies

calculateReferenceSpectralMatrix()

Calculate the power spectral matrix for remote reference processing

calculateReferenceEvalMatrix()

Calculate the power spectral matrix for remote reference processing at the evaluation frequencies

getRemoteAutoPower(chan)

Get remote data auto power spectra

getRemoteAutoPowerEval(chan, eIdx)

Get remote data auto power spectra at evaluation frequency

getRemoteCrossPower(chan1, chan2)

Get remote cross power spectra data

getRemoteCrossPowerEval(chan1, chan2, eIdx)

Get remote cross power spectra value at evaluation frequency

getReferenceCrossPower(dataChan, remoteChan)

Get the remote reference formulation cross power spectra

getReferenceCrossPowerEval(dataChan, remoteChan, eIdx)

Get the remote reference formulation cross power spectra at a given evaluation frequency

interpolateToEvalFreq(data)

Interpolate data to evaluation frequencies

prepareOutDict()

Prepare the output dictionary which will be returned

getDataForStatName(statName)

Get the statistic data for a statistic

winPSD()

Calculate window power spectral density

winCoherence()

Calculate window coherence for coherence pairs

winPolarisations()

Calculate polarisation directions

winPartials()

Calculate window partial coherences

winAbsVal()

Calculate window absolute values for the evaluation frequencies

winTransferFunction()

Calculate window transfer function

winRemoteCoherence()

Calculate window remote coherence with local data

winRemoteEqnCoherence()

Calculate remote equation coherence

winRemoteAbsVal()

Calculate remote absolute value

winRemoteTransferFunction()

Calculate remote transfer function

printList()

Class information returned as list of strings

addRemoteSpec(self, remoteData: resistics.spectra.data.SpectrumData, remoteChans: List[str] = []) → None[source]

Add coincident remote reference spectrum data

Parameters
remoteDataSpectrumData

Spectrum data (i.e. spectrum data for a window)

remoteChansList[str]

The channels to use from remote reference data

calculateEvalMatrix(self)[source]

Calculate out the cross power spectral matrix at the evaluation frequencies

The method calculates out the cross powers which will then be used in the other statistic calculations at the evaluation frequencies

The cross powers spectral matrix for evaluation frequencies is a 3-D matrix of size: numChans * numChans * numEvaluationFrequencies The elements of this are calculated by taking the cross powers spectral matrix and using the result there to interpolate the values at the evaluation frequencies.

calculateReferenceEvalMatrix(self)[source]

Interpolate the remote and site cross powers spectral matrix to the evaluation frequencies.

calculateReferenceSpectralMatrix(self)[source]

Calculate out the cross power spectral matrix between the site spectral data and the remote reference spectral data

The reference cross powers spectral matrix is a 3-D matrix of size: numChans * numRemoteChans * numFrequencies The elements of this are calculated by multiplying a channel of the site spectral data by the complex conjugate of a channel from the remote reference.

calculateRemoteEvalMatrix(self)[source]

Calculate out the cross power spectral matrix for the remote reference data at the evaluation frequencies

Takes the cross power spectral data calculate for the remote reference channels and interpoaltes it to the evaluation frequencies

calculateRemoteSpectralMatrix(self)[source]

Calculate out the cross power spectral matrix for the remote reference data

The method calculates out the cross powers for the remote reference channels which will then be used in the other statistic calculations.

The remote reference cross powers spectral matrix is a 3-D matrix of size: numRemoteChans * numRemoteChans * numFrequencies The elements of this are calculated by multiplying the spectra of one channel by the complex conjugate of the spectra of another channel.

calculateSpectralMatrix(self) → None[source]

Calculate out the cross power spectral matrix

The method calculates out the cross powers which will then be used in the other statistic calculations.

The cross powers spectral matrix is a 3-D matrix of size: numChans * numChans * numFrequencies The elements of this are calculated by multiplying the spectra of one channel by the complex conjugate of the spectra of another channel.

getAutoPower(self, chan: str) → numpy.ndarray[source]

Get the auto power for a channel

Parameters
chanstr

The channel for which to get the autopower

Returns
np.ndarray

The auto power for the channel

getAutoPowerEval(self, chan: str, eIdx: int) → float[source]

Get the auto power value for an particular evaluation frequency

Parameters
chanstr

The channel for which to get the autopower

eIdxint

The index for the evaluation frequency

Returns
np.ndarray

The auto power for the channel

getCohPairs(self) → List[List[str]][source]

Get a copy of coherence channel pairs to calculate out

Returns
List[List[str]]

List of coherence pairs

getCrossPower(self, chan1: str, chan2: str) → numpy.ndarray[source]

Get the cross power between two channels

Parameters
chan1str

The first channel for the cross channels

chan2str

The second channl for the cross channels

Returns
np.ndarray

The cross power spectral density

getCrossPowerEval(self, chan1: str, chan2: str, eIdx: int) → float[source]

Get the cross power between two channels

Parameters
chan1str

The first channel for the cross channels

chan2str

The second channl for the cross channels

eIdexint

The index of the evaluation frequency

Returns
np.ndarray

The cross power spectral density

getDataForStatName(self, statName: str)[source]

Return the data for a statistic

Given a statitic name, this method returns data from the correct internal method.

Parameters
statNamestr

The name of the statistic to calculate out

Returns
Dict

The output dictionary

getEvalFreq(self)[source]

Get a copy of the evaluation frequency

Returns
List[float]

List of evaluation frequencies

getInChans(self) → List[str][source]

Get a copy of the input channels

Returns
List[str]

List of input channels

getOutChans(self) → List[str][source]

Get a copy of the output channels

Returns
List[str]

List of output channels

getOutData(self) → Dict[source]

Get the output data

Returns
Dict

The statistic output data

getPSDChans(self) → List[str][source]

Get a copy of the channels to include power spectral density

Returns
List[str]

List of power spectral density channels

getPolDirs(self) → List[List[str]][source]

Get a list of polarisation direction pairs

Returns
List[List[str]]

List of polarisation direction pairs

getReferenceCrossPower(self, dataChan: str, remoteChan: str) → numpy.ndarray[source]

Get the cross power of a data channel and a remote reference channel

Parameters
dataChanstr

The data channel

remoteChanstr

The remote reference channel

Returns
np.ndarray

The cross power array

getReferenceCrossPowerEval(self, dataChan: str, remoteChan: str, eIdx: int) → float[source]

Get the cross power of a data channel and a remote reference channel at a single evaluation frequency

Parameters
dataChanstr

The data channel

remoteChanstr

The remote reference channel

eIdxint

The evaluation frequency index

Returns
float

The value of the cross power at the evaluation frequency

getRemoteAutoPower(self, chan: str) → numpy.ndarray[source]

Get the auto power of a remote reference channel

Parameters
chanstr

The channel for which to get the autopower

Returns
np.ndarray

The autopower array (real for autopowers)

getRemoteAutoPowerEval(self, chan: str, eIdx: int) → float[source]

Get the auto power of a remote reference channel at an evaluation frequency

Parameters
chanstr

The channel for which to get the autopower

eIdxint

The evaluation frequency index

Returns
float

The autopower of the channel at the evaluation frequency

getRemoteChans(self) → List[str][source]

Get a copy of the remote reference channels

Returns
List[str]

List of remote reference channels

getRemoteCrossPower(self, chan1: str, chan2: str) → numpy.ndarray[source]

Get the cross power of two remote reference channels

Parameters
chan1str

The first channel for the cross power

chan2str

The second channel for the cross power

Returns
np.ndarray

The cross power array

getRemoteCrossPowerEval(self, chan1: str, chan2: str, eIdx: int) → float[source]

Get the cross power of two remote reference channels at a single evaluation frequency

Parameters
chan1str

The first channel for the cross power

chan2str

The second channel for the cross power

eIdxint

The evaluation frequency index

Returns
float

The value of the cross power at the evaluation frequency

getSpecChans(self)[source]

Get a copy of the channels for which to calculate spectra

Returns
List[str]

List of spectra channels

interpolateToEvalFreq(self, data: numpy.ndarray) → numpy.ndarray[source]

Interpolate data on to the evaluation frequency

Parameters
datanp.ndarray

Power spectral data defined at frequency points given in the freqs array

Returns
np.ndarray

Data interpolated to evaluation frequencies

prepareOutDict(self) → None[source]

Prepare output statistic output dictionary

The outData dictionary is indexed in the following way: outData[evaluation frequency][statistic component] = value

printList(self) → List[str][source]

Class information as a list of strings

Returns
outlist

List of strings with information

setCohPairs(self, cohPairs: List[List[str]]) → None[source]

Set the power spectral density channels

If cohPairs of [[“Ex”, “Hx”], [“Ex”, “Hy”], [“Ey”, “Hx”], [“Ey”, “Hy”]] are set, the following coherences will be calculated: ExHx ExHy EyHx EyHy

Parameters
cohPairsList[List[str]]

Set the coherence pairs using a list of channel pairs, for example: [[“Ex”, “Hx”], [“Ex”, “Hy”], [“Ey”, “Hx”], [“Ey”, “Hy”]]

setInChans(self, inChans: List[str]) → None[source]

Set the input channels

Parameters
inChansList[str]

Input channels for the magnetotelluric linear system

setIntercept(self, intercept: bool)[source]

Set the intercept boolean

Parameters
interceptbool

Boolean flag for having an intercept in the transfer function calculation

setOutChans(self, outChans: List[str])[source]

Set the output channels

Parameters
inChansList[str]

Output channels for the magnetotelluric linear system

setPSDChans(self, psdChans: List[str]) → None[source]

Set the power spectral density channels

Parameters
psdChansList[str]

Power spectral density channels. An example input would be: [“Ex”, “Ey”, “Hx”, “Hy”]

setPolDirs(self, polDirs: List[List[str]]) → None[source]

Set the polarisation direction pairs to calculate

If polDirs of [[“Ex”, “Ey”], [“Hx”, “Hy”]] are set, the following polarisation directions will be calculated: Ex Ey Hx Hy

Parameters
polDirsList[List[str]]

Set polarisation direction channel pairs, for example: [[“Ex”, “Ey”], [“Hx”, “Hy”]]

setRemoteChans(self, remoteChans)[source]

Set the input channels

Parameters
inChansList[str]

Input channels for the magnetotelluric linear system

setSpectra(self, freq: numpy.ndarray, specData: resistics.spectra.data.SpectrumData, evalFreq: numpy.ndarray) → None[source]

Set the spectra data

Parameters
freqnp.ndarray

The frequency points in the spectra data

specDataSpectrumData

Spectrum data (i.e. spectrum data for a window)

evalFreqnp.ndarray

Evaluation frequency array

winAbsVal(self)[source]

Absolute values of the cross power spectral matrix

This data is often useful for cross plotting

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winCoherence(self)[source]

Calculate spectral coherence pairs

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winPSD(self)[source]

Calculate power spectral densities

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winPartials(self)[source]

Calculate partial coherencies

Based on paper Weckmann, Magunia Ritter 2005. e.g. coherence Ex, Hx w.r.t Hy This currently only works for impedance tensor calculations and higher power partial coherencies are not supported.

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

Notes

Based on paper by Weckmann, Magunia Ritter 2005.

winPolarisations(self)[source]

Calculate polarisation directions

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winRemoteAbsVal(self)[source]

Absolute values of cross power spectral densities between remote refence channels and data channels

This data can be useful for cross plotting

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winRemoteCoherence(self)[source]

Calulate coherence between data channels and remote channels

For example, this is the coherence of Ex-HxR, Ex-HyR, Ey-HxR, Ey-HyR, Hx-HxR, Hx-HyR, Hy-HxR, Hy-HyR

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winRemoteEqnCoherence(self)[source]

Calulates coherences for the remote reference solver equations

For example, this is the coherence of Ex-HxR, Ex-HyR, Ey-HxR, Ey-HyR, Hx-HxR, Hx-HyR, Hy-HxR, Hy-HyR

todo: Write more information in these comments

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winRemoteTransferFunction(self)[source]

Calculate transfer function for the spectral data when remote reference is included too

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]

winTransferFunction(self)[source]

Calculate transfer function for the spectral data

Returns
Dict :

Dictionary with statistic values, indexed by [evaluation frequency][statistic component]