Analysis functions for analysis of MRS data. These include a variety of functions that can be called independently, or through the interface provided in MRS.api.
Produce a boot-strap distribution of the mean of an array on axis 0
Combine data across coils based on the amplitude of the water peak, according to:
Where X is the resulting combined signal,  are the individual coil
signals and
 are the individual coil
signals and  are calculated as:
 are calculated as:
![w_i = mean(S_i) / var (S_i)
following [Hall2013]_. In addition, we apply a phase-correction, so that
all the phases of the signals from each coil are 0](../_images/math/e835caa22f142dcbaee3528ff3012af6755e4058.png)
| Parameters: | data : float array 
 | 
|---|
Fit a gaussian function to the difference spectra to be used for estimation of the GABA peak.
| Parameters: | spectra : array of shape (n_transients, n_points) 
 f_ppm : array lb, ub : floats 
 | 
|---|
Fit a lorentzian function to spectra
This is used in estimation of the water peak and for estimation of the NAA peak.
| Parameters: | spectra : array of shape (n_transients, n_points) 
 f_ppm : array lb, ub: floats : 
 | 
|---|
Fit a gaussian function to the difference spectra
This is useful for estimation of the Glx peak, which tends to have two peaks.
| Parameters: | spectra : array of shape (n_transients, n_points) 
 f_ppm : array lb, ub : floats 
 | 
|---|
Fit a lorentzian function to the sum spectra to be used for estimation of the creatine and choline peaks.
| Parameters: | spectra : array of shape (n_transients, n_points) 
 f_ppm : array lb, ub : floats 
 | 
|---|
Derive the spectra from MRS data
| Parameters: | data : nitime TimeSeries class instance or array 
 filt_method : dict 
 spect_method : dict 
 line_broadening : float 
 zerofill : int 
 | 
|---|---|
| Returns: | f : : 
 | 
Notes
This function performs the following operations:
2. Apodizing/windowing. Optionally, this is done with line-broadening (see page 92 of Keeler2005. 3. Spectral analysis.
| [Keeler2005] | Keeler, J (2005). Understanding NMR spectroscopy, second edition. Wiley (West Sussex, UK). | 
Integrate a function over the domain x
| Parameters: | func : callable 
 x : float array 
 args : tuple 
 offset : : | 
|---|
Notes
We apply the trapezoid rule for integration here, using scipy.integrate.trapz.
Given a scale factor, multiply by model to get scaled model
| Parameters: | model : array 
 scalefac : array of model.shape[0] 
 | 
|---|---|
| Returns: | scaledmodel : array 
 | 
Separate the water and non-water data from each other
| Parameters: | data : nd array 
 w_idx : list (optional) 
 | 
|---|---|
| Returns: | water_data, w_supp_data : tuple 
 | 
Calculates area under the curve (no fitting)
| Parameters: | spectrum : array of shape (n_transients, n_points) 
 center, bandwidth : float 
 | 
|---|
Notes
“The GABA signal was integrated over a 0.30-ppm bandwidth at 3.00ppm”
Ref: Sanacora, G., Mason, G. F., Rothman, D. L., Behar, K. L., Hyder, F., Petroff, O. A., ... & Krystal, J. H. (1999). Reduced cortical {gamma}-aminobutyric acid levels in depressed patients determined by proton magnetic resonance spectroscopy. Archives of general psychiatry, 56(11), 1043.
Integrate y(x) using samples along the given axis and the composite Simpson’s rule. If x is None, spacing of dx is assumed.
If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson’s rule requires an even number of intervals. The parameter ‘even’ controls how this is handled.
| Parameters: | y : array_like 
 x : array_like, optional 
 dx : int, optional 
 axis : int, optional 
 even : {‘avg’, ‘first’, ‘str’}, optional 
 | 
|---|
See also
Notes
For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less.
Subtract the residual water signal from the Normalize the water-suppressed signal by the signal that is not water-suppressed, to get rid of the residual water peak.
| Parameters: | w_sig : array with shape (n_reps, n_echos, n_points) 
 w_supp_sig :array with shape (n_reps, n_echos, n_points) : 
 | 
|---|---|
| Returns: | The water suppressed signal with the additional subtraction of a scaled : version of the signal that is presumably just due to water. : | 
Integrate along the given axis using the composite trapezoidal rule.
Integrate y (x) along given axis.
| Parameters: | y : array_like 
 x : array_like, optional 
 dx : scalar, optional 
 axis : int, optional 
 | 
|---|---|
| Returns: | trapz : float 
 | 
See also
sum, cumsum
Notes
Image [R2] illustrates trapezoidal rule – y-axis locations of points will be taken from y array, by default x-axis distances between points will be 1.0, alternatively they can be provided with x array or with dx scalar. Return value will be equal to combined area under the red lines.
References
| [R1] | Wikipedia page: http://en.wikipedia.org/wiki/Trapezoidal_rule | 
| [R2] | (1, 2) Illustration image: http://en.wikipedia.org/wiki/File:Composite_trapezoidal_rule_illustration.png | 
Examples
>>> np.trapz([1,2,3])
4.0
>>> np.trapz([1,2,3], x=[4,6,8])
8.0
>>> np.trapz([1,2,3], dx=2)
8.0
>>> a = np.arange(6).reshape(2, 3)
>>> a
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.trapz(a, axis=0)
array([ 1.5,  2.5,  3.5])
>>> np.trapz(a, axis=1)
array([ 2.,  8.])