resistics.regression.local module¶
-
class
resistics.regression.local.
LocalRegressor
(winSelector: resistics.window.selector.WindowSelector, outpath: str)[source]¶ Bases:
resistics.common.base.ResisticsBase
Performs single site (or intersite) transfer function calculations
By default, the LocalRegression is setup to calculate the impedance tensor using Hx, Hy as input channels and Ex, Ey as output channels. To calculate the Tipper, the appropriate input and output channels have to be set.
- Attributes
- winSelectorWindowSelector
A window selector object which defines which windows to use in the linear model
- decParamsDecimationParameters
DecimationParameters object with information about the decimation scheme
- winParamsWindowParameters
WindowParameters object with information about the windowing
- outpathstr
Location to put the calculated transfer functions (Edi files)
- inSitestr
The site to use for the input channels
- inChannels: List[str] ([“Hx”, “Hy”])
List of hannels to use as input channels for the linear system
- inSizeint
Number of input channels
- outSitestr
The site to use for the output channels
- outChannelsList[str] ([“Ex”, “Ey”])
List of channels to use as output channels for the linear system
- outSizeint
Number of output channels
- allChannelsList[str]
inChannels and outChannels combined into a single list
- crossChannelsList[str]
The channels to calculate the cross spectra out for
- interceptbool (default False)
Flag for including an intercept (static) term in the linear system
- methodstr (options, “ols”, “cm”)
String for describing what solution method to use
- winstr (default hanning)
Window function to use in robust solution
- winSmoothint (default -1)
The size of the window smoother. If -1, this will be autocalculated based on data size
- postpendstr (default “”)
String to postpend to the output filename to help file management
- evalFreqList[float] or np.ndarray
The evaluation frequencies
- impedancesList
- variancesList
Methods
__init__(proj, winSelector, outpath)
Initialise with a Project instance and MaskData instance
setInput(inSite, inChannels)
Set the input site and channels
setOutput(outSite, outChannels)
Set the output site and channels
process()
Process the spectra to calculate the transfer function
getWindowSmooth()
Get the window smooth length
checkForBadValues(numWindows, data)
Check the spectral data for bad values that might cause an error
prepareLinearEqn(data)
Prepare regressors and observations for regression from cross-power data
robustProcess(numWindows, obs, reg)
Robust regression processing
olsProcess(numWindows, obs, reg)
Ordinary least squares processing
stackedProcess(data)
Stacked processing
printList()
Class status returned as list of strings
-
checkForBadValues
(self, numWindows: int, data: numpy.ndarray)[source]¶ Check data for bad values and remove
- Parameters
- numWindowsint
The number of windows
- datanp.ndarray
Cross-spectra data
- Returns
- numGoodWindowsint
The number of good windows
- goodDatanp.ndarray
The cross-spectra data with bad windows removed
-
getWindowSmooth
(self, **kwargs)[source]¶ Window smoothing length
Power spectra data is smoothed. This returns the size of the smoothing window.
- Parameters
- datasizeint
The size of the data
- Returns
- smoothLenint
Smoothing size
-
olsProcess
(self, numWindows: int, obs: numpy.ndarray, reg: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray][source]¶ Ordinary least squares regression processing
Perform ordinary least regression processing using observations and regressors for a single evaluation frequency.
- Parameters
- numWindowsint
The number of windows
- obsnp.ndarray
The observations
- regnp.ndarray
The regressors
- Returns
- outputnp.ndarray
The solution to the regression problem
- varOutputnp.ndarray
The variance
-
prepareLinearEqn
(self, data: numpy.ndarray)[source]¶ Prepare data as a linear equation for the robust regression
This prepares the data for the following type of solution,
\[y = Ax,\]where \(y\) is the observations, \(A\) is the regressors and \(x\) is the unknown.
The number of observations is number of windows * number of cross-power channels The shapes of the arrays are as follows:
y is (number of output channels, number of observations)
A is (number of output channels, number of observations, number of input channels)
x is (number of output channels, number of input channels)
Consider the impedance tensor,
\begin{eqnarray} E_x & = & Z_{xx} H_x + Z_{xy} H_y \\ E_y & = & Z_{yx} H_x + Z_{yy} H_y \end{eqnarray}Here, there are two input channels, \(H_x\), \(H_y\) and two output channels \(E_x\) and \(E_y\). In total, there are four components of the unknown impedance tensor, \(Z_{xx}\), \(Z_{xy}\), \(Z_{yx}\), \(Z_{yy}\) (number of input channels * number of output channels). The number of observations is the number of windows multiplied by the number of channels used for cross-power spectra.
- Parameters
- datanp.ndarray
Cross-power spectral data at evaluation frequencies
- Returns
- numWindowsint
The number of windows included in the regression (after bad value removal)
- obsnp.ndarray
Observations array
- regnp.ndarray
Regressors array
-
printList
(self) → List[str][source]¶ Class information as a list of strings
- Returns
- list
List of strings with information
-
process
(self, ncores: int = 0) → None[source]¶ Process spectra data
The processing sequence for each decimation level is as below:
Get shared (unmasked) windows for all relevant sites (inSite and outSite)
For shared unmasked windows
Calculate out the cross-power spectra.
Interpolate calculated cross-power data to the evaluation frequencies for the decimation level.
For each evaluation frequency
Do the robust processing to calculate the transfer function at that evaluation frequency.
The spectral power data is smoothed as this tends to improve results. The smoothing can be changed by setting the smoothing parameters. This method is still subject to change in the future as it is an area of active work
-
robustProcess
(self, numWindows: int, obs: numpy.ndarray, reg: numpy.ndarray) → Tuple[numpy.ndarray][source]¶ Robust regression processing
Perform robust regression processing using observations and regressors for a single evaluation frequency.
- Parameters
- numWindowsint
The number of windows
- obsnp.ndarray
The observations
- regnp.ndarray
The regressors
- Returns
- outputnp.ndarray
The solution to the regression problem
- varOutputnp.ndarray
The variance
-
setInput
(self, inSite: str, inChannels: List[str]) → None[source]¶ Set information about input site and channels
- Parameters
- inSitestr
Site to use for input channel data
- inChannelsList[str]
Channels to use as the input in the linear system
-
setOutput
(self, outSite: str, outChannels: List[str]) → None[source]¶ Set information about output site and channels
- Parameters
- inSitestr
Site to use for output channel data
- inChannelsList[str]
Channels to use as the output in the linear system
-
stackedProcess
(self, data: numpy.ndarray) → numpy.ndarray[source]¶ Ordinary least squares processing after stacking
- Parameters
- datanp.ndarray
Cross-spectra data
- Returns
- outputnp.ndarray
The solution to the regression problem
- varOutputnp.ndarray
The variance
-
writeTF
(self, specdir: str, postpend: str, freq, data: numpy.ndarray, variances: numpy.ndarray, **kwargs)[source]¶ Write the transfer function file
- Parameters
- specdirstr
The spectra data being used for the transfer function estimate
- postpendstr
The optional postpend to the transfer function file
- datanp.ndarray
The transfer function estimates
- variancesnp.ndarray
The transfer function variances
- remotesitestr, optional
Optionally, if there is a remote site
- remotechansList[str], optional
Optionally add the remote channels if there is a remote site