Exemple #1
0
 def test_if_pointcare_plot_features_features_are_correct(self):
     nn_intervals = load_test_data(TEST_DATA_FILENAME)
     function_pointcare_plot_features = get_poincare_plot_features(
         nn_intervals)
     real_pointcare_plot_features = {
         'sd1': 13.80919037557993,
         'sd2': 59.38670497373513,
         'ratio_sd2_sd1': 4.300520404060338
     }
     self.assertAlmostEqual(function_pointcare_plot_features,
                            real_pointcare_plot_features)
Exemple #2
0
                temp_RR, 'welch', 360)

            # Frequency domain components
            time_series_total_power.append(frequency_domain['total_power'])
            time_series_hf.append(frequency_domain['hf'])

            # Non linear features require minimum 3 RR intervals

            if (i == 1):

                time_series_sd1.append(0)
                time_series_sample_entropy.append(0)

            else:

                poincare = get_poincare_plot_features(temp_RR)

                # Get non linear features
                time_series_sd1.append(poincare['sd1'])

                RR_entropy = entropy(temp_RR)

                time_series_sample_entropy.append(RR_entropy)

    mean_nni.append(time_series_mean_nni)
    sdnn.append(time_series_sdnn)
    sdsd.append(time_series_sdsd)
    pnni_20.append(time_series_pnni_20)
    pnni_50.append(time_series_pnni_50)
    range_nni.append(time_series_range_nni)
    total_power.append(time_series_total_power)
Exemple #3
0
def plot_poincare(nn_intervals: List[float], plot_sd_features: bool = True):
    """
    Pointcare / Lorentz Plot of the NN Intervals

    Arguments
    ---------
    nn_intervals : list
        list of NN intervals
    plot_sd_features : bool
        Option to show or not SD1 and SD2 features on plot. By default, set to True.

    Notes
    ---------
    The transverse axis (T) reflects beat-to-beat variation
    the longitudinal axis (L) reflects the overall fluctuation
    """
    # For Lorentz / poincaré Plot
    ax1 = nn_intervals[:-1]
    ax2 = nn_intervals[1:]

    # compute features for ellipse's height, width and center
    dict_sd1_sd2 = get_poincare_plot_features(nn_intervals)
    sd1 = dict_sd1_sd2["sd1"]
    sd2 = dict_sd1_sd2["sd2"]
    mean_nni = np.mean(nn_intervals)

    # Plot options and settings
    style.use("seaborn-darkgrid")
    fig = plt.figure(figsize=(12, 12))
    ax = fig.add_subplot(111)
    plt.title("Poincaré / Lorentz Plot", fontsize=20)
    plt.xlabel('NN_n (s)', fontsize=15)
    plt.ylabel('NN_n+1 (s)', fontsize=15)
    plt.xlim(min(nn_intervals) - 10, max(nn_intervals) + 10)
    plt.ylim(min(nn_intervals) - 10, max(nn_intervals) + 10)

    # Poincaré Plot
    ax.scatter(ax1, ax2, c='b', s=2)

    if plot_sd_features:
        # Ellipse plot settings
        ells = Ellipse(xy=(mean_nni, mean_nni),
                       width=2 * sd2 + 1,
                       height=2 * sd1 + 1,
                       angle=45,
                       linewidth=2,
                       fill=False)
        ax.add_patch(ells)

        ells = Ellipse(xy=(mean_nni, mean_nni),
                       width=2 * sd2,
                       height=2 * sd1,
                       angle=45)
        ells.set_alpha(0.05)
        ells.set_facecolor("blue")
        ax.add_patch(ells)

        # Arrow plot settings
        sd1_arrow = ax.arrow(mean_nni,
                             mean_nni,
                             -sd1 * np.sqrt(2) / 2,
                             sd1 * np.sqrt(2) / 2,
                             linewidth=3,
                             ec='r',
                             fc="r",
                             label="SD1")
        sd2_arrow = ax.arrow(mean_nni,
                             mean_nni,
                             sd2 * np.sqrt(2) / 2,
                             sd2 * np.sqrt(2) / 2,
                             linewidth=3,
                             ec='g',
                             fc="g",
                             label="SD2")

        plt.legend(handles=[sd1_arrow, sd2_arrow], fontsize=12, loc="best")
    plt.show()