예제 #1
0
def test_line_phase_options(sine):
    """Test parameters that are unique to the phase plot."""

    parameter_list = [['line_phase_deg.png', True, False],
                      ['line_phase_unwrap.png', False, True],
                      ['line_phase_deg_unwrap.png', True, True]]

    for param in parameter_list:
        print(f"Testing: {param[0]}")
        # file names
        filename = param[0]
        baseline = os.path.join(baseline_path, filename)
        output = os.path.join(output_path, filename)
        # plotting
        matplotlib.use('Agg')
        mpt.set_reproducibility_for_testing()
        plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi for testing
        plot.line.phase(sine, deg=param[1], unwrap=param[2])

        # save baseline if it does not exist
        # make sure to visually check the baseline uppon creation
        if create_baseline:
            plt.savefig(baseline)
        # safe test image
        plt.savefig(output)
        # close current figure
        plt.close()

        # testing
        compare_images(baseline, output, tol=10)
    def setUp(self):
        self.path_prefix = os.path.dirname(visualization.__file__) + \
                           '/tests/images/'
        np.random.seed(0)
        self.X, self.y = make_classification(n_features=2,
                                             n_redundant=0,
                                             random_state=0)
        train_indices = np.random.randint(0, len(self.X), size=20)
        cand_indices = np.setdiff1d(np.arange(len(self.X)), train_indices)
        self.X_train = self.X[train_indices]
        self.y_train = self.y[train_indices]
        self.X_cand = self.X[cand_indices]
        self.clf = PWC()
        self.clf.fit(self.X_train, self.y_train)
        self.qs = UncertaintySampling()
        self.qs_dict = {'clf': self.clf, 'X': self.X_train, 'y': self.y_train}

        x1_min = min(self.X[:, 0])
        x1_max = max(self.X[:, 0])
        x2_min = min(self.X[:, 1])
        x2_max = max(self.X[:, 1])
        self.bound = [[x1_min, x2_min], [x1_max, x2_max]]

        self.cmap = 'jet'

        testing.set_font_settings_for_testing()
        testing.set_reproducibility_for_testing()
        testing.setup()
예제 #3
0
def test_line_plots_frequency_data(frequency_data_three_points):
    """Test all line plots with default arguments and hold functionality."""

    function_list = [plot.line.freq, plot.line.phase, plot.line.freq_phase]

    for function in function_list:
        print(f"Testing: {function.__name__}")
        # file names
        filename = 'line_frequency_data_' + function.__name__ + '.png'
        baseline = os.path.join(baseline_path, filename)
        output = os.path.join(output_path, filename)

        # plotting
        matplotlib.use('Agg')
        mpt.set_reproducibility_for_testing()
        plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi for testing
        function(frequency_data_three_points)

        # save baseline if it does not exist
        # make sure to visually check the baseline uppon creation
        if create_baseline:
            plt.savefig(baseline)
        # safe test image
        plt.savefig(output)

        # testing
        compare_images(baseline, output, tol=10)

        # close current figure
        plt.close()
예제 #4
0
def test_use():
    """Test if use changes the plot style."""

    for style in ["dark", "default"]:

        # file names
        filename = 'use_' + style + '.png'
        baseline = os.path.join(baseline_path, filename)
        output = os.path.join(output_path, filename)

        # plotting
        matplotlib.use('Agg')
        mpt.set_reproducibility_for_testing()
        plot.utils.use(style)
        plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi for testing
        plt.plot([1, 2, 3], [1, 2, 3])

        # save baseline if it does not exist
        # make sure to visually check the baseline uppon creation
        if create_baseline:
            plt.savefig(baseline)
        # safe test image
        plt.savefig(output)

        plt.close()

        # testing
        compare_images(baseline, output, tol=10)
예제 #5
0
def test_time_unit(impulse_group_delay):
    """Test plottin with different units."""
    function_list = [
        plot.line.time, plot.line.group_delay, plot.line.spectrogram
    ]

    for function in function_list:
        for unit in [None, 's', 'ms', 'mus', 'samples']:
            print(f"Testing: {function.__name__} (unit={unit})")
            # file names
            filename = f'line_{function.__name__}_unit_{str(unit)}.png'
            baseline = os.path.join(baseline_path, filename)
            output = os.path.join(output_path, filename)

            # plotting
            matplotlib.use('Agg')
            mpt.set_reproducibility_for_testing()
            plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi
            plot.line.group_delay(impulse_group_delay[0], unit=unit)

            # save baseline if it does not exist
            # make sure to visually check the baseline uppon creation
            if create_baseline:
                plt.savefig(baseline)
            # safe test image
            plt.savefig(output)

            # close current figure
            plt.close()

            # testing
            compare_images(baseline, output, tol=10)
예제 #6
0
def test_line_xscale_option(sine):
    """Test all line plots that have an xscale option."""

    function_list = [plot.line.freq, plot.line.phase, plot.line.group_delay]

    # test if dB option is working
    for function in function_list:
        for xscale in ['log', 'linear']:
            print(f"Testing: {function.__name__} (xscale={xscale})")
            # file names
            filename = 'line_' + function.__name__ + '_xscale_' + xscale + \
                       '.png'
            baseline = os.path.join(baseline_path, filename)
            output = os.path.join(output_path, filename)

            # plotting
            matplotlib.use('Agg')
            mpt.set_reproducibility_for_testing()
            plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi
            function(sine, xscale=xscale)

            # save baseline if it does not exist
            # make sure to visually check the baseline uppon creation
            if create_baseline:
                plt.savefig(baseline)
            # safe test image
            plt.savefig(output)

            # close current figure
            plt.close()

            # testing
            compare_images(baseline, output, tol=10)
예제 #7
0
    def setUp(self):
        self.path_prefix = os.path.dirname(visualization.__file__) + \
                           '/multi/tests/images/'

        self.X, self.y_true = make_classification(n_features=2,
                                                  n_redundant=0,
                                                  random_state=0)

        self.n_samples = self.X.shape[0]
        self.n_annotators = 5

        rng = np.random.default_rng(seed=0)

        noise = rng.binomial(n=1,
                             p=.2,
                             size=(self.n_samples, self.n_annotators))

        self.y = (self.y_true.reshape(-1, 1) + noise) % 2

        estimators = []
        for a in range(self.n_annotators):
            estimators.append((f'pwc_{a}', PWC(random_state=0)))
        self.clf_multi = MultiAnnotEnsemble(estimators=estimators,
                                            voting='soft')
        self.clf = PWC(random_state=0)
        self.ma_qs = IEThresh(random_state=0, n_annotators=self.n_annotators)

        testing.set_font_settings_for_testing()
        testing.set_reproducibility_for_testing()
        testing.setup()
예제 #8
0
def test_line_dB_option(sine):
    """Test all line plots that have a dB option."""

    function_list = [plot.line.time, plot.line.freq, plot.line.spectrogram]

    # test if dB option is working
    for function in function_list:
        for dB in [True, False]:
            print(f"Testing: {function.__name__} (dB={dB})")
            # file names
            filename = 'line_' + function.__name__ + '_dB_' + str(dB) + '.png'
            baseline = os.path.join(baseline_path, filename)
            output = os.path.join(output_path, filename)

            # plotting
            matplotlib.use('Agg')
            mpt.set_reproducibility_for_testing()
            plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi
            function(sine, dB=dB)

            # save baseline if it does not exist
            # make sure to visually check the baseline uppon creation
            if create_baseline:
                plt.savefig(baseline)
            # safe test image
            plt.savefig(output)

            # close current figure
            plt.close()

            # testing
            compare_images(baseline, output, tol=10)

    # test if log_prefix and log_reference are working
    for function in function_list:
        print(f"Testing: {function.__name__} (log parameters)")
        # file names
        filename = 'line_' + function.__name__ + '_logParams.png'
        baseline = os.path.join(baseline_path, filename)
        output = os.path.join(output_path, filename)

        # plotting
        matplotlib.use('Agg')
        mpt.set_reproducibility_for_testing()
        plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi
        function(sine, log_prefix=10, log_reference=.5, dB=True)

        # save baseline if it does not exist
        # make sure to visually check the baseline uppon creation
        if create_baseline:
            plt.savefig(baseline)
        # safe test image
        plt.savefig(output)

        # close current figure
        plt.close()

        # testing
        compare_images(baseline, output, tol=10)
예제 #9
0
def test_line_custom_subplots(sine, impulse_group_delay):
    """
    Test custom subplots in row, column, and mixed layout including hold
    functionality.
    """

    # plot layouts to be tested
    plots = {
        'row': [plot.line.time, plot.line.freq],
        'col': [[plot.line.time], [plot.line.freq]],
        'mix': [[plot.line.time, plot.line.freq],
                [plot.line.phase, plot.line.group_delay]]
    }

    for p in plots:
        print(f"Testing: {p}")
        # file names
        filename = 'line_custom_subplots_' + p + '.png'
        baseline = os.path.join(baseline_path, filename)
        output = os.path.join(output_path, filename)

        # plotting
        matplotlib.use('Agg')
        mpt.set_reproducibility_for_testing()
        plt.figure(1, (f_width, f_height), f_dpi)  # force size/dpi for testing
        plot.line.custom_subplots(sine, plots[p])

        # save baseline if it does not exist
        # make sure to visually check the baseline uppon creation
        if create_baseline:
            plt.savefig(baseline)
        # safe test image
        plt.savefig(output)

        # testing
        compare_images(baseline, output, tol=10)

        # test hold functionality
        # file names
        filename = 'line_custom_subplots_' + p + '_hold.png'
        baseline = os.path.join(baseline_path, filename)
        output = os.path.join(output_path, filename)

        # plotting
        plot.line.custom_subplots(impulse_group_delay[0], plots[p])

        # save baseline if it does not exist
        # make sure to visually check the baseline uppon creation
        if create_baseline:
            plt.savefig(baseline)
        # safe test image
        plt.savefig(output)

        # close current figure
        plt.close()

        # testing
        compare_images(baseline, output, tol=10)