-
Notifications
You must be signed in to change notification settings - Fork 11
SpectrumImagePlotter
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.
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
SpectrumImagePlotter(SI, filepath=os.getcwd())
Required:
- SI: SpectrumImage object
Optional:
- filepath: the filepath to a folder to save exported images and spectra in, default is the current working directory
There are five axes inside the SpectrumImagePlotter figure. From the top left, these are:
- Contrast histogram axis
- Displays the contrast levels of the image axis
- 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
- Extracted image axis
- Displays the patches currently being used to extract spectra from the areas selected in image axis
- Colourbar axis
- Displays the current contrast limits of the image axis
- Spectrum axis
- Displays the spectra averaged over the different patches created in the image axis
Function to add a patch onto the Extracted Image Patch axis
Adjusts the contrast limits in the extracted patch axis (not working yet)
Connects interactive keyboard events to the figure, run automatically
Run when the user selects a span on the contrast histogram, updates the contrast on the image axis
Run when a keyboard key is pressed while the mouse is over top of the extracted image axis
- e to run SaveSpectrumAndPatch
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
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
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.
Plots the extracted image patches, showing where the spectra are taken from
Plots the image of the selected range on the spectrum, with the contrast limits set by ContrastSpan
Initialize a SpectrumPlotter instance on the spectrum axis and plot the current extracted spectrum
Function to remove a patch from the Extracted Image Patch axis
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)
Shows the figure
Interactive selection tool allowing user to select an energy/wavelength range on the spectrum
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')