def test_fitting_parameters_feature_on_signal_without_dicrotic_notches(): # common parameters in real signals: # lenght = 102 seconds, sampling frequency = 30 points per second x = np.linspace(0, 102, 3060) # simulated signal with dicrotic notches y = np.sin(x) features = double_gaussian_features.features_from_dicrotic_notch(x, y) fitting_params = np.asarray(features[0]).T # to easier access them later mean_fitting_params = np.mean(fitting_params, axis=1) # last one is the mean distance between gaussian2 and gaussian1 # variations under 1% of mean value are allowed since we have a discrete # periodic signal, so we expect fitting parameters with little variations due # to small difference in period duration or in total amplitude gap assert(np.all(np.logical_and(mean_fitting_params[0]*.99 < fitting_params[0], fitting_params[0] < mean_fitting_params[0]*1.01))) assert(np.all(np.logical_and(mean_fitting_params[2]*.99 < fitting_params[2], fitting_params[2] < mean_fitting_params[2]*1.01))) assert(np.all(np.logical_and(mean_fitting_params[3]*.99 < fitting_params[3], fitting_params[3] < mean_fitting_params[3]*1.01))) assert(np.all(np.logical_and(mean_fitting_params[5]*.99 < fitting_params[5], fitting_params[5] < mean_fitting_params[5]*1.01)))
def test_gaussian_distance_feature_on_signal_with_dicrotic_notches(): # common parameters in real signals: # lenght = 102 seconds, sampling frequency = 30 points per second x = np.linspace(0, 102, 3060) # simulated signal with dicrotic notches y = 2*(np.sin(x)+np.cos(x))+(np.sin(2*x)+np.cos(2*x)) features = double_gaussian_features.features_from_dicrotic_notch(x, y) fitting_params = np.asarray(features[0]).T # to easier access them later mean_fitting_params = np.mean(fitting_params, axis=1) # this is the tested feature, and represents the mean distance between # gaussian2 and gaussian1 mean_gaussians_distance = mean_fitting_params[4]-mean_fitting_params[1] # variations under 1% of mean value are allowed since we have a discrete # periodic signal, so we expect fitting parameters with little variations due # to small difference in period duration or in total amplitude gap assert(np.all(np.logical_and(mean_gaussians_distance*.99 < fitting_params[4]-fitting_params[1], fitting_params[4]-fitting_params[1] < mean_gaussians_distance*1.01)))
def test_duration_feature_on_signal_without_dicrotic_notches(): # common parameters in real signals: # lenght = 102 seconds, sampling frequency = 30 points per second x = np.linspace(0, 102, 3060) # simulated signal with dicrotic notches y = np.sin(x) features = double_gaussian_features.features_from_dicrotic_notch(x, y) mean_duration = np.mean(features[1]) # variations under 1% of mean value are allowed since we have a discrete # periodic signal, so we expect fitting parameters with little variations due # to small difference in period duration or in total amplitude gap assert(np.all(np.logical_and(mean_duration*.99 < features[1], features[1] < mean_duration*1.01)))
def test_output_shape_of_features_from_dicrotic_notch_on_signal_with_dicrotic_notches(): # common parameters in real signals: # lenght = 102 seconds, sampling frequency = 30 points per second x = np.linspace(0, 102, 3060) # simulated signal with dicrotic notches y = 2*(np.sin(x)+np.cos(x))+(np.sin(2*x)+np.cos(2*x)) features = double_gaussian_features.features_from_dicrotic_notch(x, y) # Please note that features is a tuple containing 4 elements: # a list of 6-element-lists (the inner 6 elements are the fitting parameters) # a list of beat durations (max(X)-min(X) done for each single period) # a list of beat total height gap (max(Y)-min(Y) done for each single period) # a list of x positions of maxima done for each single period assert(len(features[0]) == len(features[1]) == len(features[2])) assert(np.size(features[0]) == len(features[0])*6.) assert(np.size(features) == len(features[1])*3.)
def test_not_nan_output_of_features_from_dicrotic_notch_on_signal_with_dicrotic_notches(): # common parameters in real signals: # lenght = 102 seconds, sampling frequency = 30 points per second x = np.linspace(0, 102, 3060) # simulated signal with dicrotic notches y = 2*(np.sin(x)+np.cos(x))+(np.sin(2*x)+np.cos(2*x)) features = double_gaussian_features.features_from_dicrotic_notch(x, y) # Please note that features is a tuple containing 4 elements: # a list of 6-element-lists (the inner 6 elements are the fitting parameters) # a list of beat durations (max(X)-min(X) done for each single period) # a list of beat total height gap (max(Y)-min(Y) done for each single period) # a list of x positions of maxima done for each single period # 2 different asserts are needed since features[0] is more inner-nested than # features element from 1 to 3, so the np.isnan() function raises a TypeError assert(not np.any(np.isnan(features[0]))) assert(not np.any(np.isnan(features[1:])))