Skip to content

SpectrumImagePlotter

icbicket edited this page Dec 19, 2017 · 2 revisions

The SpectrumImagePlotter takes a SpectrumImage (can be either EELSSpectrumImage or CLSpectrumImage) and plots it such that the user can interact with it in all three dimensions, including exporting images from selected spectrum ranges, and spectra from selected image areas.

Interface

On the image axis, the following keyboard and mouse commands may be used:

  • e: export the current image to a png file, and the current colourbar to a png file.
  • n: start a new polygon (from which to extract data)
  • mouse left click: add vertices to the polygon (active after n has been pressed until a mouse right click)
  • mouse right click: finish adding vertices to the current active polygon (hitting n again will start a new polygon of the same group - contributing to the same extracted spectrum)
  • enter: extract the spectra underneath the active polygon and display the averaged spectrum in the spectrum axis
  • m: enter move mode, in which the vertices of the active polygon become large dots and can be dragged with the mouse (mouse left click and drag, hit enter to refresh after movement is done)
  • +: start a new group of polygons (to display a new spectrum from a different area)
  • left arrow: change the active polygon within a group, cycling through the available polygons in that group
  • right arrow: change the active polygon within a group, cycling in the opposite direction from the left arrow key through the available polygons in that group
  • up arrow: change the active group of polygons, cycling through the available groups
  • down arrow: change the active group of polygons, cycling through the available groups in the opposite direction to the up arrow key

On the spectrum axis, the following keyboard and mouse commands may be used:

  • mouse left click and drag: creates a slice and extracts the averaged image over this slice and displays it in the image axis
  • e: export the current active spectrum as a csv file and the patch image (showing which area on the image the spectrum is extracted from) as a png file

Syntax

SpectrumImagePlotter(SI, filepath=os.getcwd())

Input:

Required:

  • SI: SpectrumImage object

Optional:

  • filepath: the filepath to a folder to save exported images and spectra in, default is the current working directory

Layout

There are five axes inside the SpectrumImagePlotter figure. From the top left, these are:

  1. Contrast histogram axis
    • Displays the contrast levels of the image axis
  2. Image axis
    • Displays the current image, as obtained by summing over a selected range on the spectrum axis
    • Interactivity allows the user to define patches and plot the spectra averaged over these patches
  3. Extracted image axis
    • Displays the patches currently being used to extract spectra from the areas selected in image axis
  4. Colourbar axis
    • Displays the current contrast limits of the image axis
  5. Spectrum axis
    • Displays the spectra averaged over the different patches created in the image axis

Methods

AddExtractedImagePatch

Function to add a patch onto the Extracted Image Patch axis

AdjustContrastExtractedImage

Adjusts the contrast limits in the extracted patch axis (not working yet)

connect

Connects interactive keyboard events to the figure, run automatically

ContrastSpan

Run when the user selects a span on the contrast histogram, updates the contrast on the image axis

ExtractedImageKeyCommands

Run when a keyboard key is pressed while the mouse is over top of the extracted image axis

  • e to run SaveSpectrumAndPatch

ImageKeyCommands

Run when a keyboard key is pressed while the mouse is over the image axis

  • enter: the spectrum corresponding to the active patch is toggled on and off in the spectrum axis
  • e: the current image and scalebar are exported into the filepath given in the filepath keyword, with the energy selection window in the name (e.g. 'Image_0.3to0.4eV.png', 'Colourbar_0.3to0.4eV.png'). The export function uses the contrast limits set with the contrast histogram and exports a grayscale image.
  • Any other key press is sent to the image_key_commands function of ImagePlotter

keyboard_press

Run when a key is pressed, runs interactive commands dependent on which axis the mouse was over when the key was pressed

  • If the mouse is over the spectrum or patch axes, ExtractedImageKeyCommands is run
  • If the mouse is over the image axis, ImageKeyCommands is run

PlotContrastHistogram

Plots the contrast histogram of the currently displayed image and allows the user to select the contrast limits by clicking and dragging the mouse over the histogram.

PlotExtractedImage

Plots the extracted image patches, showing where the spectra are taken from

PlotImage

Plots the image of the selected range on the spectrum, with the contrast limits set by ContrastSpan

PlotSpectrum

Initialize a SpectrumPlotter instance on the spectrum axis and plot the current extracted spectrum

RemoveExtractedImagePatch

Function to remove a patch from the Extracted Image Patch axis

SaveSpectrumAndPatch

Saves the spectrum as a csv file and the extracted image patch (as png with transparency) indicating from where in the image the spectrum was averaged

  • Saved files are put into the folder given in the filepath keyword
  • Files are named according to which patch they come from (e.g. starting from patch 0: Spectrum_0.csv, Patch_0.csv)

ShowPlot

Shows the figure

SpectrumSpan

Interactive selection tool allowing user to select an energy/wavelength range on the spectrum

Example

import SpectrumImagePlotter

import SpectrumImage

dispersion = 0.01

calibration = 5e-9

SI = SpectrumImage.EELSSpectrumImage(data, dispersion=dispersion, calibration=calibration)

p = SpectrumImagePlotter.SpectrumImagePlotter(SI, filepath = '/home/user/data')