def plot_line(
    y,
    x,
    as_subplot=False,
    label=None,
    plot_axis_type="semilogy",
    vertical_lines=None,
    vertical_line_labels=None,
    units="arcsec",
    kpc_per_arcsec=None,
    figsize=(7, 7),
    plot_legend=False,
    title="Quantity vs Radius",
    ylabel="Quantity",
    titlesize=16,
    xlabelsize=16,
    ylabelsize=16,
    xyticksize=16,
    legend_fontsize=12,
    output_path=None,
    output_format="show",
    output_filename="quantity_vs_radius",
):

    plotter_util.setup_figure(figsize=figsize, as_subplot=as_subplot)
    plotter_util.set_title(title=title, titlesize=titlesize)

    if x is None:
        x = np.arange(len(y))

    plot_y_vs_x(y=y, x=x, plot_axis_type=plot_axis_type, label=label)

    set_xy_labels_and_ticksize(
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        ylabel=ylabel,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
        xyticksize=xyticksize,
    )

    plot_vertical_lines(
        vertical_lines=vertical_lines,
        vertical_line_labels=vertical_line_labels,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
    )

    set_legend(plot_legend=plot_legend, legend_fontsize=legend_fontsize)

    plotter_util.output_figure(
        array=None,
        as_subplot=as_subplot,
        output_path=output_path,
        output_filename=output_filename,
        output_format=output_format,
    )
    plotter_util.close_figure(as_subplot=as_subplot)
def plot_pixelization_regularization_weights(
    inversion,
    plot_origin=True,
    positions=None,
    should_plot_centres=False,
    should_plot_grid=False,
    should_plot_border=False,
    image_pixels=None,
    source_pixels=None,
    as_subplot=False,
    units="arcsec",
    kpc_per_arcsec=None,
    figsize=(7, 7),
    aspect="square",
    cmap="jet",
    norm="linear",
    norm_min=None,
    norm_max=None,
    linthresh=0.05,
    linscale=0.01,
    cb_ticksize=10,
    cb_fraction=0.047,
    cb_pad=0.01,
    cb_tick_values=None,
    cb_tick_labels=None,
    title="Reconstructed Pixelization Regularization Weights",
    titlesize=16,
    xlabelsize=16,
    ylabelsize=16,
    xyticksize=16,
    output_path=None,
    output_format="show",
    output_filename="inversion_pixelization_regularization_weights",
):

    if output_format is "fits":
        return

    plotter_util.setup_figure(figsize=figsize, as_subplot=as_subplot)

    regularization_weights = inversion.regularization.regularization_weights_from_mapper(
        mapper=inversion.mapper)

    plot_inversion_with_source_values(
        inversion=inversion,
        source_pixel_values=regularization_weights,
        plot_origin=plot_origin,
        positions=positions,
        should_plot_centres=should_plot_centres,
        should_plot_grid=should_plot_grid,
        should_plot_border=should_plot_border,
        image_pixels=image_pixels,
        source_pixels=source_pixels,
        as_subplot=as_subplot,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        figsize=figsize,
        aspect=aspect,
        cmap=cmap,
        norm=norm,
        norm_min=norm_min,
        norm_max=norm_max,
        linthresh=linthresh,
        linscale=linscale,
        cb_ticksize=cb_ticksize,
        cb_fraction=cb_fraction,
        cb_pad=cb_pad,
        cb_tick_values=cb_tick_values,
        cb_tick_labels=cb_tick_labels,
        title=title,
        titlesize=titlesize,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
        xyticksize=xyticksize,
        output_path=output_path,
        output_format=output_format,
        output_filename=output_filename,
    )

    plotter_util.close_figure(as_subplot=as_subplot)
Beispiel #3
0
def plot_voronoi_mapper(
    mapper,
    source_pixel_values,
    should_plot_centres=True,
    should_plot_grid=True,
    should_plot_border=False,
    image_pixels=None,
    source_pixels=None,
    as_subplot=False,
    units="arcsec",
    kpc_per_arcsec=None,
    xyticksize=16,
    figsize=(7, 7),
    title="Rectangular Mapper",
    titlesize=16,
    xlabelsize=16,
    ylabelsize=16,
    cb_ticksize=10,
    cb_fraction=0.047,
    cb_pad=0.01,
    cb_tick_values=None,
    cb_tick_labels=None,
    output_path=None,
    output_filename="voronoi_mapper",
    output_format="show",
):

    plotter_util.setup_figure(figsize=figsize, as_subplot=as_subplot)

    set_axis_limits(mapper=mapper, units=units, kpc_per_arcsec=kpc_per_arcsec)

    regions_SP, vertices_SP = voronoi_finite_polygons_2d(mapper.voronoi)

    color_values = source_pixel_values[:] / np.max(source_pixel_values)
    cmap = plt.get_cmap("jet")

    set_colorbar(
        cmap=cmap,
        color_values=source_pixel_values,
        cb_fraction=cb_fraction,
        cb_pad=cb_pad,
        cb_tick_values=cb_tick_values,
        cb_tick_labels=cb_tick_labels,
    )

    for region, index in zip(regions_SP, range(mapper.pixels)):
        polygon = vertices_SP[region]
        col = cmap(color_values[index])
        plt.fill(*zip(*polygon), alpha=0.7, facecolor=col, lw=0.0)

    plotter_util.set_title(title=title, titlesize=titlesize)
    grid_plotters.set_xy_labels(
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
        xyticksize=xyticksize,
    )

    plot_centres(
        should_plot_centres=should_plot_centres,
        mapper=mapper,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
    )

    plot_plane_grid(
        should_plot_grid=should_plot_grid,
        mapper=mapper,
        as_subplot=True,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        pointsize=10,
        xyticksize=xyticksize,
        title=title,
        titlesize=titlesize,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
    )

    plot_border(
        should_plot_border=should_plot_border,
        mapper=mapper,
        as_subplot=True,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        pointsize=30,
        xyticksize=xyticksize,
        title=title,
        titlesize=titlesize,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
    )

    mapper_grid = convert_grid(
        grid=mapper.grid, units=units, kpc_per_arcsec=kpc_per_arcsec
    )

    point_colors = itertools.cycle(["y", "r", "k", "g", "m"])
    plot_source_plane_image_pixels(
        grid=mapper_grid, image_pixels=image_pixels, point_colors=point_colors
    )
    plot_source_plane_source_pixels(
        grid=mapper_grid,
        mapper=mapper,
        source_pixels=source_pixels,
        point_colors=point_colors,
    )

    plotter_util.output_figure(
        None,
        as_subplot=as_subplot,
        output_path=output_path,
        output_filename=output_filename,
        output_format=output_format,
    )
    plotter_util.close_figure(as_subplot=as_subplot)
Beispiel #4
0
def plot_rectangular_mapper(
    mapper,
    should_plot_centres=False,
    should_plot_grid=False,
    should_plot_border=False,
    image_pixels=None,
    source_pixels=None,
    as_subplot=False,
    units="arcsec",
    kpc_per_arcsec=None,
    xyticksize=16,
    figsize=(7, 7),
    title="Rectangular Mapper",
    titlesize=16,
    xlabelsize=16,
    ylabelsize=16,
    output_path=None,
    output_filename="rectangular_mapper",
    output_format="show",
):

    plotter_util.setup_figure(figsize=figsize, as_subplot=as_subplot)

    set_axis_limits(mapper=mapper, units=units, kpc_per_arcsec=kpc_per_arcsec)
    plot_rectangular_pixelization_lines(
        mapper=mapper, units=units, kpc_per_arcsec=kpc_per_arcsec
    )

    plotter_util.set_title(title=title, titlesize=titlesize)
    grid_plotters.set_xy_labels(
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
        xyticksize=xyticksize,
    )

    plot_centres(
        should_plot_centres=should_plot_centres,
        mapper=mapper,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
    )

    plot_plane_grid(
        should_plot_grid=should_plot_grid,
        mapper=mapper,
        as_subplot=True,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        pointsize=10,
        xyticksize=xyticksize,
        title=title,
        titlesize=titlesize,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
    )

    plot_border(
        should_plot_border=should_plot_border,
        mapper=mapper,
        as_subplot=True,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        pointsize=30,
        xyticksize=xyticksize,
        title=title,
        titlesize=titlesize,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
    )

    mapper_grid = convert_grid(
        grid=mapper.grid, units=units, kpc_per_arcsec=kpc_per_arcsec
    )

    point_colors = itertools.cycle(["y", "r", "k", "g", "m"])
    plot_source_plane_image_pixels(
        grid=mapper_grid, image_pixels=image_pixels, point_colors=point_colors
    )
    plot_source_plane_source_pixels(
        grid=mapper_grid,
        mapper=mapper,
        source_pixels=source_pixels,
        point_colors=point_colors,
    )

    plotter_util.output_figure(
        None,
        as_subplot=as_subplot,
        output_path=output_path,
        output_filename=output_filename,
        output_format=output_format,
    )
    plotter_util.close_figure(as_subplot=as_subplot)
def plot_figure(
    array,
    as_subplot,
    units,
    kpc_per_arcsec,
    figsize,
    aspect,
    cmap,
    norm,
    norm_min,
    norm_max,
    linthresh,
    linscale,
    xticks_manual,
    yticks_manual,
):
    """Open a matplotlib figure and plot the array of data_type on it.

    Parameters
    -----------
    array : data_type.array.scaled_array.ScaledArray
        The 2D array of data_type which is plotted.
    as_subplot : bool
        Whether the array is plotted as part of a subplot, in which case the grid figure is not opened / closed.
    units : str
        The units of the y / x axis of the plots, in arc-seconds ('arcsec') or kiloparsecs ('kpc').
    kpc_per_arcsec : float or None
        The conversion factor between arc-seconds and kiloparsecs, required to plot the units in kpc.
    figsize : (int, int)
        The size of the figure in (rows, columns).
    aspect : str
        The aspect ratio of the array, specifically whether it is forced to be square ('equal') or adapts its size to \
        the figure size ('auto').
    cmap : str
        The colormap the array is plotted using, which may be chosen from the standard matplotlib colormaps.
    norm : str
        The normalization of the colormap used to plot the image, specifically whether it is linear ('linear'), log \
        ('log') or a symmetric log normalization ('symmetric_log').
    norm_min : float or None
        The minimum array value the colormap map spans (all values below this value are plotted the same color).
    norm_max : float or None
        The maximum array value the colormap map spans (all values above this value are plotted the same color).
    linthresh : float
        For the 'symmetric_log' colormap normalization ,this specifies the range of values within which the colormap \
        is linear.
    linscale : float
        For the 'symmetric_log' colormap normalization, this allowws the linear range set by linthresh to be stretched \
        relative to the logarithmic range.
    xticks_manual :  [] or None
        If input, the xticks do not use the array's default xticks but instead overwrite them as these values.
    yticks_manual :  [] or None
        If input, the yticks do not use the array's default yticks but instead overwrite them as these values.
    """

    fig = plotter_util.setup_figure(figsize=figsize, as_subplot=as_subplot)

    norm_min, norm_max = get_normalization_min_max(array=array,
                                                   norm_min=norm_min,
                                                   norm_max=norm_max)
    norm_scale = get_normalization_scale(
        norm=norm,
        norm_min=norm_min,
        norm_max=norm_max,
        linthresh=linthresh,
        linscale=linscale,
    )

    extent = get_extent(
        array=array,
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        xticks_manual=xticks_manual,
        yticks_manual=yticks_manual,
    )

    plt.imshow(array, aspect=aspect, cmap=cmap, norm=norm_scale, extent=extent)
    return fig
def plot_grid(
    grid,
    colors=None,
    axis_limits=None,
    points=None,
    lines=None,
    as_subplot=False,
    units="arcsec",
    kpc_per_arcsec=None,
    figsize=(12, 8),
    pointsize=5,
    pointcolor="k",
    xyticksize=16,
    cmap="jet",
    cb_ticksize=10,
    cb_fraction=0.047,
    cb_pad=0.01,
    cb_tick_values=None,
    cb_tick_labels=None,
    title="Grid",
    titlesize=16,
    xlabelsize=16,
    ylabelsize=16,
    symmetric_around_centre=True,
    output_path=None,
    output_format="show",
    output_filename="grid",
):
    """Plot a grid of (y,x) Cartesian coordinates as a scatter plot of points.

    Parameters
    -----------
    grid : data_type.array.grids.Grid
        The (y,x) coordinates of the grid, in an array of shape (total_coordinates, 2).
    axis_limits : []
        The axis limits of the figure on which the grid is plotted, following [xmin, xmax, ymin, ymax].
    points : []
        A set of points that are plotted in a different colour for emphasis (e.g. to show the mappings between \
        different planes).
    as_subplot : bool
        Whether the grid is plotted as part of a subplot, in which case the grid figure is not opened / closed.
    units : str
        The units of the y / x axis of the plots, in arc-seconds ('arcsec') or kiloparsecs ('kpc').
    kpc_per_arcsec : float
        The conversion factor between arc-seconds and kiloparsecs, required to plot the units in kpc.
    figsize : (int, int)
        The size of the figure in (rows, columns).
    pointsize : int
        The size of the points plotted on the grid.
    xyticksize : int
        The font size of the x and y ticks on the figure axes.
    title : str
        The text of the title.
    titlesize : int
        The size of of the title of the figure.
    xlabelsize : int
        The fontsize of the x axes label.
    ylabelsize : int
        The fontsize of the y axes label.
    output_path : str
        The path on the hard-disk where the figure is output.
    output_filename : str
        The filename of the figure that is output.
    output_format : str
        The format the figue is output:
        'show' - display on computer screen.
        'png' - output to hard-disk as a png.
    """

    plotter_util.setup_figure(figsize=figsize, as_subplot=as_subplot)
    grid = convert_grid_units(grid_arcsec=grid,
                              units=units,
                              kpc_per_arcsec=kpc_per_arcsec)

    if colors is not None:

        plt.cm.get_cmap(cmap)

    plt.scatter(
        y=np.asarray(grid[:, 0]),
        x=np.asarray(grid[:, 1]),
        c=colors,
        s=pointsize,
        marker=".",
        cmap=cmap,
    )

    if colors is not None:

        plotter_util.set_colorbar(
            cb_ticksize=cb_ticksize,
            cb_fraction=cb_fraction,
            cb_pad=cb_pad,
            cb_tick_values=cb_tick_values,
            cb_tick_labels=cb_tick_labels,
        )

    plotter_util.set_title(title=title, titlesize=titlesize)
    set_xy_labels(
        units=units,
        kpc_per_arcsec=kpc_per_arcsec,
        xlabelsize=xlabelsize,
        ylabelsize=ylabelsize,
        xyticksize=xyticksize,
    )

    set_axis_limits(
        axis_limits=axis_limits,
        grid=grid,
        symmetric_around_centre=symmetric_around_centre,
    )
    plot_points(grid=grid, points=points, pointcolor=pointcolor)
    plotter_util.plot_lines(line_lists=lines)

    plt.tick_params(labelsize=xyticksize)
    plotter_util.output_figure(
        array=None,
        as_subplot=as_subplot,
        output_path=output_path,
        output_filename=output_filename,
        output_format=output_format,
    )
    plotter_util.close_figure(as_subplot=as_subplot)