Ejemplo n.º 1
0
    def test_metric_psnr(self):
        """Test :func:`colour.utilities.metrics.metric_psnr` definition."""

        a = np.array([0.48222001, 0.31654775, 0.22070353])
        self.assertEqual(metric_psnr(a, a), np.inf)

        b = a * 0.9
        self.assertAlmostEqual(metric_psnr(a, b), 28.956851563141299, places=7)

        b = a * 1.1
        self.assertAlmostEqual(metric_psnr(a, b), 28.956851563141296, places=7)
Ejemplo n.º 2
0
    def test_metric_psnr(self):
        """
        Tests :func:`colour.utilities.metrics.metric_psnr` definition.
        """

        a = np.array([0.48222001, 0.31654775, 0.22070353])
        self.assertEqual(metric_psnr(a, a), np.inf)

        b = a * 0.9
        self.assertAlmostEqual(metric_psnr(a, b), 28.956851563141299, places=7)

        b = a * 1.1
        self.assertAlmostEqual(metric_psnr(a, b), 28.956851563141296, places=7)
Ejemplo n.º 3
0
def docs(ctx, plots=True, html=True, pdf=True):
    """
    Builds the documentation.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    plots : bool, optional
        Whether to generate the documentation plots.
    html : bool, optional
        Whether to build the *HTML* documentation.
    pdf : bool, optional
        Whether to build the *PDF* documentation.

    Returns
    -------
    bool
        Task success.
    """

    if plots:
        temporary_directory = tempfile.mkdtemp()
        test_directory = os.path.join('docs', '_static')
        reference_directory = os.path.join(temporary_directory, '_static')
        try:
            shutil.copytree(test_directory, reference_directory)
            similar_plots = []
            with ctx.cd('utilities'):
                message_box('Generating plots...')
                ctx.run('./generate_plots.py')

                png_files = glob.glob('{0}/*.png'.format(reference_directory))
                for reference_png_file in png_files:
                    test_png_file = os.path.join(
                        test_directory, os.path.basename(reference_png_file))
                    psnr = metric_psnr(
                        read_image(str(reference_png_file))[::3, ::3],
                        read_image(str(test_png_file))[::3, ::3])
                    if psnr > 70:
                        similar_plots.append(test_png_file)
            with ctx.cd('docs/_static'):
                for similar_plot in similar_plots:
                    ctx.run('git checkout -- {0}'.format(
                        os.path.basename(similar_plot)))
        finally:
            shutil.rmtree(temporary_directory)

    with ctx.prefix('export COLOUR_SCIENCE_DOCUMENTATION_BUILD=True'):
        with ctx.cd('docs'):
            if html:
                message_box('Building "HTML" documentation...')
                ctx.run('make html')

            if pdf:
                message_box('Building "PDF" documentation...')
                ctx.run('make latexpdf')
Ejemplo n.º 4
0
def docs(ctx, plots=True, html=True, pdf=True):
    """
    Builds the documentation.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    plots : bool, optional
        Whether to generate the documentation plots.
    html : bool, optional
        Whether to build the *HTML* documentation.
    pdf : bool, optional
        Whether to build the *PDF* documentation.

    Returns
    -------
    bool
        Task success.
    """

    if plots:
        temporary_directory = tempfile.mkdtemp()
        test_directory = os.path.join('docs', '_static')
        reference_directory = os.path.join(temporary_directory, '_static')
        try:
            shutil.copytree(test_directory, reference_directory)
            similar_plots = []
            with ctx.cd('utilities'):
                message_box('Generating plots...')
                ctx.run('./generate_plots.py')

                png_files = glob.glob('{0}/*.png'.format(reference_directory))
                for reference_png_file in png_files:
                    test_png_file = os.path.join(
                        test_directory, os.path.basename(reference_png_file))
                    psnr = metric_psnr(
                        read_image(str(reference_png_file))[::3, ::3],
                        read_image(str(test_png_file))[::3, ::3])
                    if psnr > 70:
                        similar_plots.append(test_png_file)
            with ctx.cd('docs/_static'):
                for similar_plot in similar_plots:
                    ctx.run('git checkout -- {0}'.format(
                        os.path.basename(similar_plot)))
        finally:
            shutil.rmtree(temporary_directory)

    with ctx.prefix('export COLOUR_SCIENCE_DOCUMENTATION_BUILD=True'):
        with ctx.cd('docs'):
            if html:
                message_box('Building "HTML" documentation...')
                ctx.run('make html')

            if pdf:
                message_box('Building "PDF" documentation...')
                ctx.run('make latexpdf')