bactoscoop.signalcorrelation ============================ .. py:module:: bactoscoop.signalcorrelation Classes and public operations ----------------------------- SignalCorrelation ~~~~~~~~~~~~~~~~~ .. py:class:: SignalCorrelation(df, channel1, channel2, feature, method_name, prepared_feature=None) Compare the same feature between two channels for each cell. The feature must exist for both channels. calculate adds a measurement column to the supplied DataFrame and returns that same table. Invalid input pairs or undefined measurements yield NaN; prepared_feature optionally caches the input arrays. :param df: DataFrame to inspect, transform, or augment. Correlation mutates it in place and returns it. :param channel1: First channel prefix for the matching feature. :param channel2: Second channel prefix for the matching feature. :param feature: Unprefixed shared feature name; corresponding channel-prefixed columns must exist. :param method_name: Implemented correlation selector, such as pearson, manders, or ratio. :param prepared_feature: Optional cached signal arrays and validity mask for a channel/feature pair. :returns: None (no explicit return statement). **Assigned state:** ``self.df``, ``self.channel1``, ``self.channel2``, ``self.feature``, ``self.method_name``, ``self.prepared_feature``, ``self.method``. `View current source, line 16 <../source-code/signalcorrelation.html#signalcorrelation-16>`_. SignalCorrelation.get_method ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.get_method() Get method. **Return expressions in source:** .. code-block:: python methods[self.method_name] **Explicitly raised exceptions:** ``ValueError``. Errors from called functions can also propagate or be recorded. `View current source, line 35 <../source-code/signalcorrelation.html#signalcorrelation-35>`_. SignalCorrelation.validate_inputs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.validate_inputs() Validate inputs. :returns: None (no explicit return statement). **Explicitly raised exceptions:** ``ValueError``. Errors from called functions can also propagate or be recorded. `View current source, line 60 <../source-code/signalcorrelation.html#signalcorrelation-60>`_. SignalCorrelation.calculate ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.calculate() Add a between-channel measurement column, one value per cell. Requires matching prefixed columns. Modifies the supplied DataFrame and returns that same DataFrame. Invalid input pairs or undefined measurements yield NaN. **Return expressions in source:** .. code-block:: python self.df **Assigned state:** ``self.df``. `View current source, line 71 <../source-code/signalcorrelation.html#signalcorrelation-71>`_. .. raw:: html
Original docstring (legacy wording may differ from the current signature) .. code-block:: text Add a between-channel measurement column and return the same DataFrame. Measurements are calculated for each cell using the selected feature and method. Invalid input pairs or undefined measurements yield NaN. The supplied DataFrame is modified in place. .. raw:: html
SignalCorrelation.prepare_feature_pair ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.prepare_feature_pair(df, channel1, channel2, feature) Prepare feature pair. :param df: DataFrame to inspect, transform, or augment. Correlation mutates it in place and returns it. :param channel1: First channel prefix for the matching feature. :param channel2: Second channel prefix for the matching feature. :param feature: Unprefixed shared feature name; corresponding channel-prefixed columns must exist. **Return expressions in source:** .. code-block:: python {'signals1': signals1, 'signals2': signals2, 'valid_mask': valid_mask} `View current source, line 107 <../source-code/signalcorrelation.html#signalcorrelation-107>`_. SignalCorrelation.is_valid_signal ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.is_valid_signal(signal) Is valid signal. :param signal: Input ``signal`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python bool(signal_array.size and np.isfinite(signal_array).all()) False `View current source, line 123 <../source-code/signalcorrelation.html#signalcorrelation-123>`_. SignalCorrelation.ratio ~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.ratio(signal1, signal2) Ratio. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan signal1 / signal2 `View current source, line 131 <../source-code/signalcorrelation.html#signalcorrelation-131>`_. SignalCorrelation.manders_overlap_coefficient ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.manders_overlap_coefficient(signal1, signal2) Manders overlap coefficient. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.sum(signal1 * signal2) / np.sqrt(np.sum(signal1 ** 2) * np.sum(signal2 ** 2)) `View current source, line 143 <../source-code/signalcorrelation.html#signalcorrelation-143>`_. SignalCorrelation.pearson_correlation_coefficient ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.pearson_correlation_coefficient(signal1, signal2) Pearson correlation coefficient. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan stats.pearsonr(signal1, signal2)[0] `View current source, line 156 <../source-code/signalcorrelation.html#signalcorrelation-156>`_. SignalCorrelation.li_icq ~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.li_icq(signal1, signal2) Li icq. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan (np.sum(product) / len(signal1) - 0.5) * 2 `View current source, line 165 <../source-code/signalcorrelation.html#signalcorrelation-165>`_. SignalCorrelation.spearman_rank_correlation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.spearman_rank_correlation(signal1, signal2) Spearman rank correlation. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan stats.spearmanr(signal1, signal2)[0] `View current source, line 178 <../source-code/signalcorrelation.html#signalcorrelation-178>`_. SignalCorrelation.kendall_tau ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.kendall_tau(signal1, signal2) Kendall tau. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan corr `View current source, line 187 <../source-code/signalcorrelation.html#signalcorrelation-187>`_. SignalCorrelation.distance_correlation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.distance_correlation(signal1, signal2) Biased sample distance correlation; undefined profiles return NaN. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan float(np.sqrt(np.clip(correlation_squared, 0, 1))) `View current source, line 197 <../source-code/signalcorrelation.html#signalcorrelation-197>`_. .. raw:: html
Original docstring (legacy wording may differ from the current signature) .. code-block:: text Biased sample distance correlation; undefined profiles return NaN. .. raw:: html
SignalCorrelation.covariance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.covariance(signal1, signal2) Covariance. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.cov(signal1, signal2)[0, 1] `View current source, line 241 <../source-code/signalcorrelation.html#signalcorrelation-241>`_. SignalCorrelation.normalized_cross_correlation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.normalized_cross_correlation(signal1, signal2) Normalized cross correlation. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.correlate(signal1 - np.mean(signal1), signal2 - np.mean(signal2))[0] / (len(signal1) * np.std(signal1) * np.std(signal2)) `View current source, line 250 <../source-code/signalcorrelation.html#signalcorrelation-250>`_. SignalCorrelation.entropy_difference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.entropy_difference(signal1, signal2) Entropy difference. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.abs(entropy1 - entropy2) `View current source, line 261 <../source-code/signalcorrelation.html#signalcorrelation-261>`_. SignalCorrelation.kurtosis_ratio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.kurtosis_ratio(signal1, signal2) Kurtosis ratio. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.abs(kurtosis1 / kurtosis2) if kurtosis2 != 0 else np.nan `View current source, line 272 <../source-code/signalcorrelation.html#signalcorrelation-272>`_. SignalCorrelation.skewness_product ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.skewness_product(signal1, signal2) Skewness product. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan skew1 * skew2 `View current source, line 283 <../source-code/signalcorrelation.html#signalcorrelation-283>`_. SignalCorrelation.zero_crossings_difference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.zero_crossings_difference(signal1, signal2) Zero crossings difference. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.abs(zero_crossings1 - zero_crossings2) `View current source, line 294 <../source-code/signalcorrelation.html#signalcorrelation-294>`_. SignalCorrelation.fft_peak_ratio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.fft_peak_ratio(signal1, signal2) Fft peak ratio. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan peak1 / peak2 if peak2 != 0 else np.nan `View current source, line 305 <../source-code/signalcorrelation.html#signalcorrelation-305>`_. SignalCorrelation.fft_energy_ratio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.fft_energy_ratio(signal1, signal2) Fft energy ratio. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan energy1 / energy2 if energy2 != 0 else np.nan `View current source, line 318 <../source-code/signalcorrelation.html#signalcorrelation-318>`_. SignalCorrelation.histogram_intersection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.histogram_intersection(signal1, signal2, bins=10) Intersect probability histograms using shared bins for both profiles. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param bins: Input ``bins`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan float(np.minimum(hist1 / count1, hist2 / count2).sum()) `View current source, line 336 <../source-code/signalcorrelation.html#signalcorrelation-336>`_. .. raw:: html
Original docstring (legacy wording may differ from the current signature) .. code-block:: text Intersect probability histograms using shared bins for both profiles. .. raw:: html
SignalCorrelation.cosine_similarity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:method:: SignalCorrelation.cosine_similarity(signal1, signal2) Cosine similarity. :param signal1: Input ``signal1`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. :param signal2: Input ``signal2`` consumed by this implementation; its exact use is visible in the linked source below. No maintained parameter description is present in the original docstring. **Return expressions in source:** .. code-block:: python np.nan np.dot(signal1, signal2) / (np.linalg.norm(signal1) * np.linalg.norm(signal2)) `View current source, line 366 <../source-code/signalcorrelation.html#signalcorrelation-366>`_.