예제 #1
0
    def test__norm_from_array__uses_array_to_get_vmin_and_max_if_no_manual_input(
        self, ):

        array = aa.Array2D.ones(shape_native=(2, 2), pixel_scales=1.0)
        array[0] = 0.0

        cmap = aplt.Cmap(vmin=None, vmax=None, norm="linear")

        norm = cmap.norm_from_array(array=array)

        assert isinstance(norm, colors.Normalize)
        assert norm.vmin == 0.0
        assert norm.vmax == 1.0

        cmap = aplt.Cmap(vmin=None, vmax=None, norm="log")

        norm = cmap.norm_from_array(array=array)

        assert isinstance(norm, colors.LogNorm)
        assert norm.vmin == 1.0e-4  # Increased from 0.0 to ensure min isn't inf
        assert norm.vmax == 1.0

        cmap = aplt.Cmap(vmin=None,
                         vmax=None,
                         linthresh=2.0,
                         linscale=3.0,
                         norm="symmetric_log")

        norm = cmap.norm_from_array(array=array)

        assert isinstance(norm, colors.SymLogNorm)
        assert norm.vmin == 0.0
        assert norm.vmax == 1.0
        assert norm.linthresh == 2.0
예제 #2
0
    def test__norm_from_array__uses_input_vmin_and_max_if_input(self):

        cmap = aplt.Cmap(vmin=0.0, vmax=1.0, norm="linear")

        norm = cmap.norm_from_array(array=None)

        assert isinstance(norm, colors.Normalize)
        assert norm.vmin == 0.0
        assert norm.vmax == 1.0

        cmap = aplt.Cmap(vmin=0.0, vmax=1.0, norm="log")

        norm = cmap.norm_from_array(array=None)

        assert isinstance(norm, colors.LogNorm)
        assert norm.vmin == 1.0e-4  # Increased from 0.0 to ensure min isn't inf
        assert norm.vmax == 1.0

        cmap = aplt.Cmap(vmin=0.0,
                         vmax=1.0,
                         linthresh=2.0,
                         linscale=3.0,
                         norm="symmetric_log")

        norm = cmap.norm_from_array(array=None)

        assert isinstance(norm, colors.SymLogNorm)
        assert norm.vmin == 0.0
        assert norm.vmax == 1.0
        assert norm.linthresh == 2.0
    def test__uses_figure_or_subplot_configs_correctly(self):

        figure = aplt.Figure(figsize=(8, 8))
        cmap = aplt.Cmap(cmap="warm")

        mat_plot_2d = aplt.MatPlot2D(figure=figure, cmap=cmap)

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=mat_plot_2d)

        assert plotter.mat_plot_2d.figure.config_dict["figsize"] == (8, 8)
        assert plotter.mat_plot_2d.figure.config_dict["aspect"] == "square"
        assert plotter.mat_plot_2d.cmap.config_dict["cmap"] == "warm"
        assert plotter.mat_plot_2d.cmap.config_dict["norm"] == "linear"

        figure = aplt.Figure()
        figure.is_for_subplot = True

        cmap = aplt.Cmap()
        cmap.is_for_subplot = True

        mat_plot_2d = aplt.MatPlot2D(figure=figure, cmap=cmap)

        plotter = abstract_plotters.AbstractPlotter(mat_plot_2d=mat_plot_2d)

        assert plotter.mat_plot_2d.figure.config_dict["figsize"] == None
        assert plotter.mat_plot_2d.figure.config_dict["aspect"] == "square"
        assert plotter.mat_plot_2d.cmap.config_dict["cmap"] == "jet"
        assert plotter.mat_plot_2d.cmap.config_dict["norm"] == "linear"
예제 #4
0
    def test__plot__works_for_reasonable_range_of_values(self):

        figure = aplt.Figure()

        figure.open()
        plt.imshow(np.ones((2, 2)))
        cb = aplt.Colorbar(fraction=1.0, pad=2.0)
        cb.set()
        figure.close()

        figure.open()
        plt.imshow(np.ones((2, 2)))
        cb = aplt.Colorbar(
            fraction=0.1,
            pad=0.5,
            manual_tick_values=[0.25, 0.5, 0.75],
            manual_tick_labels=[1.0, 2.0, 3.0],
        )
        cb.set()
        figure.close()

        figure.open()
        plt.imshow(np.ones((2, 2)))
        cb = aplt.Colorbar(fraction=0.1, pad=0.5)
        cb.set_with_color_values(cmap=aplt.Cmap().config_dict["cmap"],
                                 color_values=[1.0, 2.0, 3.0])
        figure.close()
예제 #5
0
    def test__draws_voronoi_pixels_for_sensible_input(self,
                                                      voronoi_mapper_9_3x3):

        voronoi_drawer = aplt.VoronoiDrawer(linewidth=0.5,
                                            edgecolor="r",
                                            alpha=1.0)

        voronoi_drawer.draw_voronoi_pixels(mapper=voronoi_mapper_9_3x3,
                                           values=None,
                                           cmap=aplt.Cmap(),
                                           colorbar=None)

        values = np.ones(9)
        values[0] = 0.0

        voronoi_drawer.draw_voronoi_pixels(
            mapper=voronoi_mapper_9_3x3,
            values=values,
            cmap=aplt.Cmap(),
            colorbar=aplt.Colorbar(fraction=0.1, pad=0.05),
        )
예제 #6
0
    def test__loads_values_from_config_if_not_manually_input(self):

        cmap = aplt.Cmap()

        assert cmap.config_dict["cmap"] == "jet"
        assert cmap.config_dict["norm"] == "linear"

        cmap = aplt.Cmap(cmap="cold")

        assert cmap.config_dict["cmap"] == "cold"
        assert cmap.config_dict["norm"] == "linear"

        cmap = aplt.Cmap()
        cmap.is_for_subplot = True

        assert cmap.config_dict["cmap"] == "jet"
        assert cmap.config_dict["norm"] == "linear"

        cmap = aplt.Cmap(cmap="cold")
        cmap.is_for_subplot = True

        assert cmap.config_dict["cmap"] == "cold"
        assert cmap.config_dict["norm"] == "linear"