brutus_plots module¶
brutus: a set of Python modules to process datacubes from integral field spectrographs.
Copyright (C) 2016, F.P.A. Vogt
This file contains tools for the brutus routines to create pretty plots seamlessly.
Created April 2016, F.P.A. Vogt - frederic.vogt@alumni.anu.edu.au
-
class
brutus_plots.
ApManager
(fig, ax, points, rs)[source]¶ Bases:
object
The class managing the interactive aperture selection plot.
This class is designed to add and remove apertures of different radii to a matplotlib plot interactively. It handles right-clicks, left-clicks and keyPressEvents
Args: - fig: Figure instance from matplotlib
The Figure we are working with.
- ax: Axes instance from matplotlib
The axes we are working with.
- points: list instance from plt.plot
The points to pick.
- rs: list of int
The radius of the apertures, in pixels.
Notes: I understand 90% of this class, the rest being some black magic from the web.
-
onKeyPress
(event)[source]¶ Defines what happens when a key is pressed, while on a matplotlib window.
This function allows to change the aperture size by typing ‘u’ (radius += 1 pixel) or ‘d’ (radius -= 1 pixel). Minimum size set to 1 pixel.
-
class
brutus_plots.
SpecManager
(fig, ax1a, ax1b, ax3a, ax3b, ax3c, ax3d, patches, spectra, lams, data, lowess, ppxf, cont_mix, elines)[source]¶ Bases:
object
The class managing the interactive inspection of the fitted data.
This class is designed to select spaxels, and plot the associated fit.
Notes: This class is an evolution of brutus_plots.ApManager(). It will make anyone with experience in events handling cry of despair. It works for now, but it could be faster, and with no doubt A LOT more elegant. Suggestions welcome.
-
brutus_plots.
ap_outline
(x0, y0, radius)[source]¶ A function to construct the aperture outline as a function of the radius.
Args: - x0: int
x-coordinate of the aperture center, in pixels
- y0: int
y-coordinate of the aperture center, in pixels
- radius: int
aperture radius, in pixels.
Returns: - out: 2-D numpy array
The list of [xs,ys] coordinates of the aperture outline nodes, in pixels.
Notes: This function is in principle designed to construct the exact aperture outline for all pixels within “radius” of a given pixel. This works well for R <5, but breaks afterwards. Basically, the function starts missing pixels, and the area start looking like a diamond. The alternative is to define all the otuline polygons by hand - but I really do not feel like doing this manually. Is there a way to construct them with a smarter routine than below ? This function is left here for legacy purposes and remind me of what I did. But it is not used by brutus at the moment. Apertures are all shown as perfect circles for now.
-
brutus_plots.
build_ap_list
(data, start_aps=None, radius=3.0, automatic_mode=True, interactive_mode=False, lam=None, save_plot=None)[source]¶ Detects local maxima in an image, and allows the manual inspection of the result.
This function finds local maxima in 2-D array, and then offers the user the ability to check/modify the found peaks manually. It associate a fixed circular aperture to each peak (individually modifiable manually), used later to extract the integrated s pectra of these areas.
Args: - data: 2-D numpy array
The raw data from which to find maxima.
- start_aps: list of list [default: None]
A pre-existing list of apertures.
- radius: int [default: 3.0]
The default radius of the apertures associated with the local maxima detected automatically.
- automatic_mode: bool [default: True]
Whether to detect peaks and assign apertures automatically or not.
- interactive_mode: bool [default:True]
Whether to inspect the apertures manually or not.
- lam: float [default: False]
The wavelength of the data, to be added to the plot title if set.
- save_plot: string [default: None]
If set, the name of the file used to save the final aperture selection.
Returns: - out: 2-D numpy array
The array of apertures with shape (n,3), where n is the total number of apertures (1 per row), defined by (x,y,r) its center and radius (in pixels).
Notes: If start_aps are provided, then automatic_mode is False.
-
brutus_plots.
inspect_spaxels
(lams, data, lowess, ppxf, cont_mix, elines, map, vmap, irange, vrange, ofn=False)[source]¶ Interactive inspection fo the brutus fit output.
This function generates an interactive plot allowing to select individual spaxels and visualize how well/bad they were fitted.
Args: - lams: 1-D array
The wavelength array of the data.
- data: 3-D numpy array
The raw data.
- lowess: 3-D numpy array
The fitted lowess continuum cube.
- ppxf: 3-D numpy array
The fitted ppxf continuum cube.
- cont_mix:
The continuum cube that is already mixed,l according to the user choices.
- elines: 3-D numpy array
The pure emission line cube.
- map: 2-D numpy array
The line inetnsity map.
- vmap: 2-D numpy array
The gas velocity map.
- irange: list of int
The range of the colorbar for the intensity plot.
- vrange: list of int
The range of the colorbar for the velocity dispersion plot.
- ofn: string [default: None]
The filename (+path!) of the plot saved.
Returns: - out: True
Always.
-
brutus_plots.
make_2Dplot
(fn, ext=1, ofn='plot.pdf', contours=False, stretch='arcsinh', vmin=None, vmax=None, cmap=None, cblabel=None, cbticks=None, scalebar=None)[source]¶ Creates an image from a 2-D fits image with WCS info.
Args: - fn: string
The filename (+path!) fo the fits file to display.
- ext: int (default:1)
The extension of the image to display. The data in this extension MUST be 2-D.
- ofn: string [default:’plot.pdf’]
The output filename (+path!)
- contours: bool,list of floats [default: False]
If set, shows contours at said levels, e.g. [1,3,5,10.5]
- stretch: string [default:’arcsinh’]
The stretch of the image, fed to aplpy.FITSFigure. ‘linear’, ‘arcsinh’, ...
- vmin: float [default: None]
If set, the lower bound of the colorbar
- vmax: float [default: None]
If set, the upper bound of the colorbar
- cmap: string
If set, the colormap to use. Use ‘alligator’ for the special brutus cmap.
- cblabel: string [default:None]
If set, the label of the colorbar.
- cbticks: list of int [default: None]
If set, the colorbar ticks.
- scalebar: list [default: None]
If set, adds a scale bar to the plot. Format: [lenght arcsec, length kpc, loc]
Returns: - out: True
Always.
Notes: This function absolutely requires WCS coordinates, and a 2-D array.
-
brutus_plots.
make_2Dvelplot
(fn, ext=1, ofn='plot.pdf', contours=False, stretch='arcsinh', vmin=None, vmax=None, cmap=None, cblabel=None, cbticks=None, pa=None, center=None, scalebar=None)[source]¶ - Creates an image from a 2-D fits image of a velocity field with WCS info and a
- known position angle.
Args: - fn: string
The filename (+path!) fo the fits file to display.
- ext: int (default:1)
The extension of the image to display. The data in this extension MUST be 2-D.
- ofn: string [default:’plot.pdf’]
The output filename (+path!)
- contours: bool,list of floats [default: False]
If set, shows contours at said levels, e.g. [1,3,5,10.5]
- stretch: string [default:’arcsinh’]
The stretch of the image, fed to aplpy.FITSFigure. ‘linear’, ‘arcsinh’, ...
- vmin: float [default: None]
If set, the lower bound of the colorbar
- vmax: float [default: None]
If set, the upper bound of the colorbar
- cmap: string
If set, the colormap to use. Use ‘alligator’ for the special brutus cmap.
- cblabel: string [default: None]
If set, the label of the colorbar.
- cbticks: list of int [default: None]
If set, the colorbar ticks.
- scalebar: list [default: None]
If set, adds a scale bar to the plot. Format: [lenght arcsec, length kpc, loc]
- pa: list [default: None]
If set, the P.A. of the velocity field, drawn with a dashed line.
- center: list [default: None]
If set, the location of the center of the velocity field IN PIXELS.
Returns: - out: True
Always.
Notes: This function absolutely requires WCS coordinates, and a 2-D array.
-
brutus_plots.
make_RGBplot
(fns, ofn, stretch='linear', plims=[None, None, None, None, None, None], vlims=[None, None, None, None, None, None], title=None, scalebar=None)[source]¶ Creates an RGB image from three fits files.
Args: - fn: list strings
The filename (+path!) fo the 3 fits file to display (in R, G and B orders).
- ofn: string
The filneame (+path) of the output file.
- stretch: string [default: ‘log’]
The stretch to apply to the data, e.g. ‘linear’, ‘log’, ‘arcsinh’.
- plims: list of floats [default: [None, None, None, None, None, None]]
The limiting percentiles for the plot, as [pmin_r, pmax_r, pmin_g, pmax_g, pmin_b, pmax_b]
- vlims: list of floats [default: [None, None, None, None, None, None]]
The limtiing values for the plot (superseeds plims), as [vmin_r, vmax_r, vmin_g, vmax_g, vmin_b, vmax_b]
- scalebar: list [default: None]
If set, adds a scale bar to the plot. Format: [lenght arcsec, length kpc, loc]
Returns: - out: True
Always.
Notes: This function absolutely requires WCS coordinates, and a 2-D array.
-
brutus_plots.
make_galred_plot
(lams, alams, etau, Ab, Av, ofn)[source]¶ Plots the extinction Alambda and flux correction factor for galactic extinction.
Args: - lams: 1-D numpy array
The wavelength nodes.
- alams: 1-D numpy array
The corresponding values of Alambda.
- etau: 1-D numpy array
The flux correction factor, i.e. F_(unextinct)/F_(observed).
- Ab: float
The value of Ab.
- Av: float
The value of Av.
Returns: True Always.
-
brutus_plots.
my_ap_scatter
(ax, xs, ys, rs, **kwargs)[source]¶ A pseudo-plt.scatter function for easily displaying many apertures.
This function use the plt.Circle routine to show individual apertures of different radii. Importantly, the radii are thus expressed in data units, and not in points.
Args: - ax: Axes instance from matplotlib
The Figure axes to which to add the aperture.
- xs: list of int
The x-coordinates of the aperture centers, in pixels.
- ys: list of int
The y-coordinates of the aperture centers, in pixels.
- rs: list of int
The radii of the apertures, in pixels.
Returns: - out: True
Always.
Notes: In principle, each aperture could be shown “exactly” using plt.Polygon and the brutus_plots.ap_outline function. But the latter is not suitable for large apertures. Until fixed, each apertuyre is shown as a perfect circle using plt.Circle.
-
brutus_plots.
show_scale
(ax, scale_length=[10.0, 5.0], scale_loc='top left')[source]¶ Adds a scale bar to a given 2-D plot.
Args: - ax: aplpy ‘ax’ instance
The axes to which to add the sale.
- scale_length: list of float [default: [10.,5.0]]
The scale length in arcsec and kpc
- scale_loc: string [default: ‘top left’]
The locaqtion of the scale bar. e.g ‘top right’, ‘bottom left’, etc ...