The EasyLEED API

The EasyLEED package is divided into several subpackages:

  • base: Core functionality (fitting procedures, Tracker class, etc.)
  • kalman: Implementation of Kalman filter classes
  • io: Input/Output functionality (reading FITS, PIL, and IMG files)
  • gui: Graphical User Interface

easyleed.base

Base class providing common functionality for analyzing Leed patterns.

class easyleed.base.SpotModel[source]

Data model for a Spot that stores all the information in various lists.

class easyleed.base.Tracker(x_in, y_in, radius, energy, x_c=None, y_c=None, input_precision=1, window_scaling=False)[source]

Tracks spots through intensity information and velocity prediction.

easyleed.base.adjust_slice(image, x_sl_min, x_sl_max, y_sl_min, y_sl_max)[source]

Adjusts slice if it is trying to get pieces outside the image.

>>> image = np.ones((2, 2))
>>> adjust_slice(image, 0, 1.5, 0, 2)
(0, 1, 0, 2)
>>> adjust_slice(image, -5.5, 2, -0.5, 10)
(0, 2, 0, 2)
easyleed.base.calc_distances(shape, x, y, squared=True)[source]

Helper function that returns an array of distances to x, y. This array can be useful for fancy indexing of numpy arrays.

squared: return the squared distance (default: True)

easyleed.base.calc_intensity(npimage, x, y, radius, background_substraction=True)[source]

Calculates the intensity of a spot.

npimage: numpy array of intensity values x, y: position of the spot radius: radius of the spot background_substraction: boolean to turn substraction on/off

easyleed.base.gaussian2d(height, center_x, center_y, width_x, width_y=None, offset=0)[source]

Returns a two dimensional gaussian function with the given parameters

easyleed.base.guess_from_Gaussian(image, *args, **kwargs)[source]

Guess position of spot from a Gaussian fit.

easyleed.base.moments(data)[source]

Calculates the moments of 2d data. Returns [height, x, y, width_x, width_y] the gaussian parameters of a 2D distribution by calculating its moments.

easyleed.kalman

Kalman filters for tracking the spots

class easyleed.kalman.AbstractKalmanFilter(x, P, H)[source]

Abstract implementation of a Kalman filter.

Matrices and Vectors can be given in any input format np.matrix() understands. Vectors are internally transposed and should therefore be given as column vectors.

measurement_distance(z, R=None)[source]

Returns the squared Mahalanobis distance of the given measurement.

z: measurement vector

predict(F, Q=array([[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.]]))[source]

Predict next state.

F: state transition matrix Q: process covariance matrix

predict_measurement()[source]

Returns the predicted measurement.

predict_measurement_covariance(R=None)[source]

Returns the covariance matrix of a predicted measurement.

update(z, R)[source]

Update state estimate.

z: measurement vector R: measurement covariance matrix

class easyleed.kalman.AbstractPVKalmanFilter(x_in, y_in, P, time, vx_in=0, vy_in=0)[source]

Kalman filter for 2d-tracking using position and velocity as state variables.

easyleed.io

Import routines for different LEED file formats

class easyleed.io.FitsImageLoader(image_paths, regex)[source]

Load .fits image files.

class easyleed.io.ImageFormat(abbrev, loader)[source]

Class describing an image format.

class easyleed.io.ImageLoader(image_paths, regex)[source]

Abstract base class for a class loading LEED images.

Subclasses need to provide
  • get_image(image_path)
Subclasses may override (default: from filename with regex)
  • get_energy(image_path)
current_energy()[source]

Get current energy.

custom_iter(energies)[source]

Returns an iterator to iter over the given energies.

goto(energy)[source]

Get image at given beam energy.

next()

Get image at next higher beam energy.

previous()[source]

Get image at next lower beam energy.

restart()[source]

Start at lowest energy again.

class easyleed.io.ImgImageLoader(image_paths, regex)[source]

Load .img image files (HotLeed format).

class easyleed.io.PILImageLoader(image_paths, regex)[source]

Load image files supported by Python Imaging Library (PIL).

easyleed.io.normalize255(array)[source]

Returns a normalized array of uint8.

easyleed.io.npimage2qimage(npimage)[source]

Converts numpy grayscale image to qimage.

easyleed.gui

Various classes for providing a graphical user interface.

class easyleed.gui.AboutWidget[source]

PyQt widget for About Box Panel

class easyleed.gui.GraphicsScene(parent=None)[source]

Custom GraphicScene having all the main content.

drawBackground(painter, rect)[source]

Draws image in background if it exists.

keyPressEvent(event)[source]
Processes key events through either
  • deleting the focus item
or
  • propagating the event
mousePressEvent(event)[source]
Processes mouse events through either
  • propagating the event
or
  • instantiating a new Circle (on left-click)
  • instantiating a new Center (on right-click)
removeAll()[source]

Remove all spots from the scene (leaves background unchanged).

removeCenter()[source]

Remove center from the scene (leaves background unchanged).

setBackground(image, labeltext)[source]

Sets the background image.

class easyleed.gui.GraphicsView(parent=None)[source]

Custom GraphicsView to display the scene.

class easyleed.gui.MainWindow(parent=None)[source]

EasyLEED’s main window.

addActions(target, actions)[source]

Convenience function that adds the actions to the target. If an action is None a separator will be added.

createAction(text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal='triggered()')[source]

Convenience function that creates an action with the specified attributes.

custEnBtnClicked()[source]

Action when custom energy button is clicked

fileOpen()[source]

Prompts the user to select input image files.

fileQuit()[source]

Special quit-function as the normal window closing might leave something on the background

liveSmoothParameters()[source]

Real time setting smoothing parameters from Parameter Settings panel into actual smoothed curve

loadCenter()[source]

Load Center location from csv file

loadSpots()[source]

Load Spots location from csv file

restart()[source]

Delete stored plot information and start fresh

saveCenter()[source]

Saves the center locations to a file, uses workers saveCenter-method

saveScreenShot()[source]

Save Screenshot

saveSpots()[source]

Saves the spot locations to a file, uses workers saveLoc-method

setCustEnergy()[source]

Take energy from custom energy text and move the corresponding frame

slider_moved(sliderNewPos)[source]

This function tracks what to do with a slider movement.

class easyleed.gui.ParameterSettingWidget[source]

PyQt widget for setting tracking parameters

applyParameters()[source]

Parameter setting control

collectParameters()[source]

Parameter setting control

loadValues()[source]

Load a file of set parameter values that has been saved with the widget

saveValues()[source]

Basic saving of the set parameter values to a file

class easyleed.gui.PlotWidget[source]

Custom PyQt widget canvas for plotting

create_main_frame()[source]

Create the mpl Figure and FigCanvas objects.

save()[source]

Saving the plot

updatePlot()[source]

Basic Matplotlib plotting I(E)-curve

class easyleed.gui.QGraphicsCenterItem(point, size, parent=None)[source]

Provides an QGraphicsItem to display the center position on a QGraphicsScene.

class easyleed.gui.QGraphicsMovableItem(parent=None)[source]

Provides an QGraphicsItem that can be moved with the arrow keys.

Pressing Shift at the same time allows fine adjustments.

keyPressEvent(event)[source]

Handles keyPressEvents.

The item can be moved using the arrow keys. Applying Shift at the same time allows fine adjustments.

moveDown(distance)[source]

Moves the circle distance down.

moveLeft(distance)[source]

Moves the circle distance to the left.

moveRight(distance)[source]

Moves the circle distance to the right.

moveUp(distance)[source]

Moves the circle distance up.

onPositionChange(point)[source]

Handles incoming position change request.

class easyleed.gui.QGraphicsSpotItem(point, radius, parent=None)[source]

Provides an QGraphicsItem to display a Spot on a QGraphicsScene.

changeSize(inc)[source]

Change radius by inc.

inc > 0: increase inc < 0: decrease

keyPressEvent(event)[source]

Handles keyPressEvents.

The circles radius can be changed using the plus and minus keys.

onRadiusChange(radius)[source]

Handles incoming radius change request.

class easyleed.gui.QSpotModel(parent=None)[source]

Wraps a SpotModel to offer signals.

Provides the following signals: - intensityChanged - positionChanged - radiusChanged

class easyleed.gui.Worker(spots, center, energy, parent=None)[source]

Worker that manages the spots.

spots_map: - key: spot - value: SpotModel, Tracker

createDataframe()[source]

Create internal dataframe with intensities, spot locations, and center

numProcessed()[source]

Return the number of processed images.

saveCenter(filename)[source]

save center location

saveIntensity(filename)[source]

save intensities

saveLoc(filename)[source]

save spots location

Fork me on GitHub