Helper Modules and Utility Functions

Here is a collection of other useful modules and functions that come with HHG-Analysis-Python:

Blobs

This module can find overflow areas in images (“blobs”). It makes heavy use of OpenCV.

blobs.find_blobs(img_data, verbose=False, min_area=None)[source]

Find second level contours in 16bit images

Here is an example to illustrate the contours of the blob this function can find:

_images/blobs-contours.png
blobs.fix_image(img, blobs)[source]

This function can fix images where blobs have been found using find_blobs().

Here is an example of what this does:

_images/blob-fix.png
blobs.main()[source]

This function is a demonstration of how this module is being used. It is implemented as a command line tool. Run this module file to see how it works.

It can serve for unit tests too.

Mathematical Tools

A collection of useful mathematical tools and functions.

mathtools.scoreatpercentile(a, per, limit=())[source]

Calculate the score at the given percentile per of the sequence a.

Largely the same as http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.scoreatpercentile.html .

Geometry Classes

class geometry.coordinates(x=None, y=None)[source]

2-dimensional coordinates

move(offset)[source]

Move the coordinates by offset

x = None
y = None
class geometry.rectangle(pos=None, dim=None)[source]

A rectangle in 2-dimensional space.

corners()[source]

Return a tuple of two corners of the rectangle.

dim = None

The size (dimensions) of the rectangle.

fully_in(other)[source]

Tests if another rectangle lies entierely in this rectangle.

get_rectangle_inside(size, center)[source]

Create a new rectangle that must be inside this rectangle. If it would overlap with this rectangle, it would be moved to the inside.

move(by)[source]

Move this rectangle to a different position.

pos = None

The position of the rectangle.

Signal Processing

A collection of useful signal processing functions

signalprocessing.calculate_sum(signal, val_from, val_to, baseline)[source]

A function to calculate the sum of a selection of values from which a baseline value has been substracted.

signalprocessing.remove_high_frequency_noise(signal, cutoff=15.0)[source]

A Low-pass filter. See http://en.wikipedia.org/wiki/Low-pass_filter . :param cutoff: defines the limit at which higher frequencies should be removed (from 0. to 100.). :type cutoff: float.

signalprocessing.smooth(signal)[source]

Smoothing a signal using the Savitzky–Golay filter.

Savitzky–Golay smoothing

A module that implements the useful Savitzky–Golay filter. See http://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_smoothing_filter .

sg_filter.calc_coeff(num_points, pol_degree, diff_order=0)[source]

Calculates filter coefficients for symmetric Savitzky–Golay filter. see: http://www.nrbook.com/a/bookcpdf/c14-8.pdf

Parameters:
  • num_points (int.) – means that 2*num_points+1 values contribute to the smoother.
  • pol_degree (int.) – is degree of fitting polynomial
  • diff_order (int.) – is degree of implicit differentiation. 0 means that filter results in smoothing of function. 1 means that filter results in smoothing the first derivative of function.
Returns:

numpy.array – The coefficients for the Savitzky–Golay filter.

sg_filter.smooth(signal, coeff)[source]

Applies coefficients calculated by calc_coeff() to signal.

Keycodes

Key codes for OpenCV’s cv2.waitKey()

keycode.KEY_DOWN = 63233

The Arrow Down key

keycode.KEY_ESCAPE = 27

The ESC key

keycode.KEY_LEFT = 63234

The Arrow Left key

keycode.KEY_RIGHT = 63235

The Arrow Right key

keycode.KEY_SPACE = 32

The Space key

keycode.KEY_UP = 63232

The Arrow Up key

Table Of Contents

Previous topic

Documentation of the Classes

This Page