latools/D_obj.py
def calc_correlation(self, x_analyte, y_analyte, window=15, filt=True, recalc=True):
        """
        Calculate local correlation between two analytes.

        Parameters
        ----------
        x_analyte, y_analyte : str
            The names of the x and y analytes to correlate.
        window : int, None
            The rolling window used when calculating the correlation.
        filt : bool
            Whether or not to apply existing filters to the data before
            calculating this filter.
        recalc : bool
            If True, the correlation is re-calculated, even if it is already present.

        Returns
        -------
        None
        """
        label = '{:}_{:}_{:.0f}'.format(x_analyte, y_analyte, window)

        if label in self.correlations and not recalc:
            return

        # make window odd
        if window % 2 != 1:
            window += 1
        
        # get filter
        ind = self.filt.grab_filt(filt, [x_analyte, y_analyte])

        x = nominal_values(self.focus[x_analyte])
        x[~ind] = np.nan
        xr = rolling_window(x, window, pad=np.nan)

        y = nominal_values(self.focus[y_analyte])
        y[~ind] = np.nan
        yr = rolling_window(y, window, pad=np.nan)

        r, p = zip(*map(nan_pearsonr, xr, yr))

        r = np.array(r)
        p = np.array(p)

        # save correlation info
        
        self.correlations[label] = r, p
        return
def calc_correlation(self, x_analyte, y_analyte, window=15, filt=True, recalc=True):
        label = '{:}_{:}_{:.0f}'.format(x_analyte, y_analyte, window)

        if label in self.correlations and not recalc:
            return

        # make window odd
        if window % 2 != 1:
            window += 1
        
        # get filter
        ind = self.filt.grab_filt(filt, [x_analyte, y_analyte])

        x = nominal_values(self.focus[x_analyte])
        x[~ind] = np.nan
        xr = rolling_window(x, window, pad=np.nan)

        y = nominal_values(self.focus[y_analyte])
        y[~ind] = np.nan
        yr = rolling_window(y, window, pad=np.nan)

        r, p = zip(*map(nan_pearsonr, xr, yr))

        r = np.array(r)
        p = np.array(p)

        # save correlation info
        
        self.correlations[label] = r, p
        return
def calc_correlation ( self , x_analyte , y_analyte , window = 15 , filt = True , recalc = True ) : label = '{:}_{:}_{:.0f}' . format ( x_analyte , y_analyte , window ) if label in self . correlations and not recalc : return # make window odd if window % 2 != 1 : window += 1 # get filter ind = self . filt . grab_filt ( filt , [ x_analyte , y_analyte ] ) x = nominal_values ( self . focus [ x_analyte ] ) x [ ~ ind ] = np . nan xr = rolling_window ( x , window , pad = np . nan ) y = nominal_values ( self . focus [ y_analyte ] ) y [ ~ ind ] = np . nan yr = rolling_window ( y , window , pad = np . nan ) r , p = zip ( * map ( nan_pearsonr , xr , yr ) ) r = np . array ( r ) p = np . array ( p ) # save correlation info self . correlations [ label ] = r , p return
Calculate local correlation between two analytes.

        Parameters
        ----------
        x_analyte, y_analyte : str
            The names of the x and y analytes to correlate.
        window : int, None
            The rolling window used when calculating the correlation.
        filt : bool
            Whether or not to apply existing filters to the data before
            calculating this filter.
        recalc : bool
            If True, the correlation is re-calculated, even if it is already present.

        Returns
        -------
        None
Calculate local correlation between two analytes .