plotpy Package

Plotpy package for data plotting and analyzing for different instruments.

Subpackages and modules:

Name P/M Description
config P Configurational parameters for many modules
fio P Datafile input and output functionality. Can be used by external projects to read datafiles (from plotpy.fio import reader)
gtkgui P Graphical user interface modules
plugins P Plugin facility autoloading available modules
sessions P Modules for the dfferent experimental types
configobj M A configuration writer with .ini format
fitdata M Fit function framework and set of default functions
mds M Measurement data structure classes used to store and process data.
message M Plotpy message facility used for GUI and command line.
peakfinder M Continous wavelet transform peakfinder routine, can be used as stand alone module.
plotting M Functions to communicate with gnuplot

The program is started using the _run function.

initialize Module

Function to initialize the program either with command line or GTK+ interface.

The scripts create one session object according to the selected type of the data and reads all files specified by the user. The session object is then either used for a direct plotting or piped to a plotting_gui for later use.

plotpy.initialize.import_session_from_module_info(module_info, arguments)[source]

Import a session object from two strings containing module name and class.

Returns:The class instance for the measurement type
plotpy.initialize.import_session_from_name(arguments, measurement_type)[source]

Import a session object from a string. In this way we don’t need to import all sessions in advance.

Parameters:
  • arguments – The command line arguments to pass to the object
  • measurement_type – The names of the module and object to import
Returns:

The class instance for the measurement type

plotpy.initialize.initialize(argv)[source]

initialize session and read data files

plotpy.initialize.initialize_debug(log_file='debug.log')[source]

Initialize logging and output for debug mode.

plotpy.initialize.initialize_gui(session, status_dialog=None)[source]

Initialize the gui main window.

Parameters:session – An object derived from sessions.generic.GenericSession
Returns:An ApplicationMainWindow instance ( class defined in {toolkit}gui.generic )
plotpy.initialize.initialize_gui_toolkit()[source]

Load GUI modules dependent on the toolkit.

plotpy.initialize.ipdrop(session)[source]

Inizialize some convenience functions and drop to an IPython console.

plotpy.initialize.run(argv=None)[source]

Start the program.

configobj Module

A config file reader/writer that supports nested sections in config files.
Copyright (C) 2005-2008 Michael Foord, Nicola Larosa
E-mail: fuzzyman AT voidspace DOT org DOT uk
nico AT tekNico DOT net
exception plotpy.configobj.ConfigObjError(message='', line_number=None, line='')[source]

Bases: exceptions.SyntaxError

This is the base class for all errors that ConfigObj raises. It is a subclass of SyntaxError.

exception plotpy.configobj.NestingError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

This error indicates a level of nesting that doesn’t match.

exception plotpy.configobj.ParseError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

This error indicates that a line is badly written. It is neither a valid key = value line, nor a valid section marker line.

exception plotpy.configobj.DuplicateError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

The keyword or section specified already exists.

exception plotpy.configobj.ConfigspecError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

An error occured whilst parsing a configspec.

class plotpy.configobj.ConfigObj(infile=None, options=None, **kwargs)[source]

Bases: plotpy.configobj.Section

An object to read, create, and write config files.

reload()[source]

Reload a ConfigObj from file.

This method raises a ReloadError if the ConfigObj doesn’t have a filename attribute pointing to a file.

reset()[source]

Clear ConfigObj instance and restore to ‘freshly created’ state.

validate(validator, preserve_errors=False, copy=False, section=None)[source]

Test the ConfigObj against a configspec.

It uses the validator object from validate.py.

To run validate on the current ConfigObj, call:

test = config.validate(validator)

(Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the configspec attribute of a section though).

It returns True if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value True. (It also returns False if all members fail).

In addition, it converts the values from strings to their native types if their checks pass (and stringify is set).

If preserve_errors is True (False is default) then instead of a marking a fail with a False, it will preserve the actual exception object. This can contain info about the reason for failure. For example the VdtValueTooSmallError indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as False.

You must have the validate module to use preserve_errors=True.

You can then use the flatten_errors function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages.

write(outfile=None, section=None)[source]

Write the current ConfigObj as a file

tekNico: FIXME: use StringIO instead of real files

>>> filename = a.filename
>>> a.filename = 'test.ini'
>>> a.write()
>>> a.filename = filename
>>> a == ConfigObj('test.ini', raise_errors=True)
1
class plotpy.configobj.SimpleVal[source]

Bases: object

A simple validator. Can be used to check that all members expected are present.

To use it, provide a configspec with all your members in (the value given will be ignored). Pass an instance of SimpleVal to the validate method of your ConfigObj. validate will return True if all members are present, or a dictionary with True/False meaning present/missing. (Whole missing sections will be replaced with False)

check(check, member, missing=False)[source]

A dummy check method, always returns the value unchanged.

exception plotpy.configobj.InterpolationError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

Base class for the two interpolation errors.

exception plotpy.configobj.InterpolationLoopError(option)[source]

Bases: plotpy.configobj.InterpolationError

Maximum interpolation depth exceeded in string interpolation.

exception plotpy.configobj.MissingInterpolationOption(option)[source]

Bases: plotpy.configobj.InterpolationError

A value specified for interpolation was missing.

exception plotpy.configobj.RepeatSectionError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

This error indicates additional sections in a section with a __many__ (repeated) section.

exception plotpy.configobj.ReloadError[source]

Bases: exceptions.IOError

A ‘reload’ operation failed. This exception is a subclass of IOError.

exception plotpy.configobj.UnreprError(message='', line_number=None, line='')[source]

Bases: plotpy.configobj.ConfigObjError

An error parsing in unrepr mode.

plotpy.configobj.flatten_errors(cfg, res, levels=None, results=None)[source]

An example function that will turn a nested dictionary of results (as returned by ConfigObj.validate) into a flat list.

cfg is the ConfigObj instance being checked, res is the results dictionary returned by validate.

(This is a recursive function, so you shouldn’t use the levels or results arguments - they are used by the function.

Returns a list of keys that failed. Each member of the list is a tuple :

([list of sections...], key, result)

If validate was called with preserve_errors=False (the default) then result will always be False.

list of sections is a flattened list of sections that the key was found in.

If the section was missing then key will be None.

If the value (or section) was missing then result will be False.

If validate was called with preserve_errors=True and a value was present, but failed the check, then result will be the exception object returned. You can use this as a string that describes the failure.

For example The value “3” is of the wrong type.

>>> import validate
>>> vtor = validate.Validator()
>>> my_ini = '''
...     option1 = True
...     [section1]
...     option1 = True
...     [section2]
...     another_option = Probably
...     [section3]
...     another_option = True
...     [[section3b]]
...     value = 3
...     value2 = a
...     value3 = 11
...     '''
>>> my_cfg = '''
...     option1 = boolean()
...     option2 = boolean()
...     option3 = boolean(default=Bad_value)
...     [section1]
...     option1 = boolean()
...     option2 = boolean()
...     option3 = boolean(default=Bad_value)
...     [section2]
...     another_option = boolean()
...     [section3]
...     another_option = boolean()
...     [[section3b]]
...     value = integer
...     value2 = integer
...     value3 = integer(0, 10)
...         [[[section3b-sub]]]
...         value = string
...     [section4]
...     another_option = boolean()
...     '''
>>> cs = my_cfg.split('\n')
>>> ini = my_ini.split('\n')
>>> cfg = ConfigObj(ini, configspec=cs)
>>> res = cfg.validate(vtor, preserve_errors=True)
>>> errors = []
>>> for entry in flatten_errors(cfg, res):
...     section_list, key, error = entry
...     section_list.insert(0, '[root]')
...     if key is not None:
...        section_list.append(key)
...     else:
...         section_list.append('[missing]')
...     section_string = ', '.join(section_list)
...     errors.append((section_string, ' = ', error))
>>> errors.sort()
>>> for entry in errors:
...     print entry[0], entry[1], (entry[2] or 0)
[root], option2  =  0
[root], option3  =  the value "Bad_value" is of the wrong type.
[root], section1, option2  =  0
[root], section1, option3  =  the value "Bad_value" is of the wrong type.
[root], section2, another_option  =  the value "Probably" is of the wrong type.
[root], section3, section3b, section3b-sub, [missing]  =  0
[root], section3, section3b, value2  =  the value "a" is of the wrong type.
[root], section3, section3b, value3  =  the value "11" is too big.
[root], section4, [missing]  =  0

decorators Module

Module for usefull decorators e.g. for logging function calls, input and output.

class plotpy.decorators.check_input(types, try_convert=True)[source]

Bases: object

Decorator checking the input to a function.

plotpy.decorators.decorator(caller)[source]

General purpose decorator factory: takes a caller function as input and returns a decorator with the same attributes.

plotpy.decorators.getinfo(func)[source]

Returns an info dictionary containing: - name (the name of the function : str) - argnames (the names of the arguments : list) - defaults (the values of the default arguments : tuple) - signature (the signature : str) - doc (the docstring : str) - module (the module name : str) - dict (the function __dict__ : str)

plotpy.decorators.log_both(f)[source]

Decoratore to log a method call with input and output.

plotpy.decorators.log_call(f)[source]

Decoratore to log a method call.

plotpy.decorators.log_input(f)[source]

Decoratore to log a method call with input.

plotpy.decorators.log_output(f)[source]

Decoratore to log a method call with output. If combined with log_input the input is logged at the time before the call and the output after.

plotpy.decorators.test(func)[source]

Put the function as private and call it with the returned function while adding an additional argument. The docstring is altered to point to the private function.

plotpy.decorators.test1(func)[source]

Register function call inputs.

plotpy.decorators.update_wrapper(wrapper, wrapped, create=False)[source]

An improvement over functools.update_wrapper. By default it works the same, but if the ‘create’ flag is set, generates a copy of the wrapper with the right signature and update the copy, not the original. Moreovoer, ‘wrapped’ can be a dictionary with keys ‘name’, ‘doc’, ‘module’, ‘dict’, ‘defaults’.

fitdata Module

Module containing a class for nonlinear fitting, a root class for a fit function and several child classes with optimized common fit functions. Can in principal be used for any python function which returns floats or an array of floats.

plotpy.fitdata.B_J(p, x)[source]

Brillouine function of x.

class plotpy.fitdata.ConnectedDict(dict1, dict2, split_index)[source]

Bases: dict

Dictionary connecting two constrain dictionaries depending on the index.

class plotpy.fitdata.FitBrillouineB(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Fit a Brillouine’s function for the magnetic behaviour of a paramagnet against field.

brillouine(p, B)[source]

Brillouine function of B.

fit_function(p, B)[source]

Return the brillouine function of B.

class plotpy.fitdata.FitBrillouineT(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Fit a Brillouine’s function for the magnetic behaviour of a paramagnet against field.

brillouine(p, T)[source]

Brillouine function of B.

fit_function(p, T)[source]

Return the brillouine function of B.

class plotpy.fitdata.FitCrystalLayer(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Simulate diffraction from a crystal layer with finite size and roughness.

amplitude(x, x_0, d, a)[source]

Return the aplitude of a scattered wave on a crystal layer.

fit_function(p, x)[source]

Return the Voigt profile of x. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.FitCuK(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Simulate Cu-Kα radiation for fitting θ-2θ scans of x-ray diffraction as douple peak (α1,α2) with two coupled voigt profiles.

fit_function(p, x)[source]

Return the Voigt profile of x. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.FitCuK3D(initial_parameters)[source]

Bases: plotpy.fitdata.FitPsdVoigt3D

Simulate x-ray reciprocal space meshes measured with CuK radiation including a measured wavelength distribution for the Bremsberg and other characteristic radiations.

radiaion(x)[source]

Return the intensity of the x-ray radiaion for a wavelength

class plotpy.fitdata.FitDiamagnetism(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Fit two linear functions with the same slope, an offset and a hole around zero.

fit_function(p, x)[source]

Two linear functions with different offsets, split left and right from the y-axes.

class plotpy.fitdata.FitExponential(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a exponential function.

class plotpy.fitdata.FitFerromagnetic(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Fit a Brillouine’s function for the magnetic behaviour of a ferromagnet against temperature.

brillouine(p, M, T)[source]

Brillouine function whith M=Ms*B_J(y) which has to be solved for specific parameters.

fit_function(p, T)[source]

Return the brillouine function of T.

residuals(params, y, x, yerror=None)[source]

As the fit with fsolve is quite slow we tell the user about the state of the fit.

class plotpy.fitdata.FitFerromagneticOrderparameter(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Order parameter from
    1. Kuz’min, PRL 94, 107204 (2005)
class plotpy.fitdata.FitFunction(initial_parameters=[])[source]

Bases: plotpy.gtkgui.gui_fit_data.FitFunctionGUI

Root class for fittable functions. Parant of all other functions.

refine(dataset_x, dataset_y, dataset_yerror=None, progress_bar_update=None)[source]

Do the least square refinement to the given dataset. If the fit converges the new parameters are stored.

Parameters:
  • dataset_x – list of x values from the dataset
  • dataset_y – list of y values from the dataset
  • dataset_yerror – list of errors from the dataset or None for no weighting
Returns:

The message string of leastsq and the covariance matrix

refine_mpfit(residuals, parameters, x, y, dy, progress_bar_update=None)[source]

Refine the function using a constrained fit with the Sequential Least SQuares Programming algorithm.

The constrains can be boundaries, equalitiy and inequality fuctions. progress_bar_update can be an optional function, which is called after each iteration.

residuals(params, y, x, yerror=None)[source]

Function used by leastsq to compute the difference between the simulation and data. For normal functions this is just the difference between y and simulation(x) but can be overwritten e.g. to increase speed or fit to log(x). If the dataset has yerror values they are used as weight.

Parameters:
  • params – Parameters for the function in this iteration
  • y – List of y values measured
  • x – List of x values for the measured points
  • yerror – List of error values for the y values or None if the fit is not weighted
Returns:

Residuals (meaning the value to be minimized) of the fit function and the measured data

residuals_log(params, y, x, yerror=None)[source]

Function used by leastsq to compute the difference between the logarithms of the simulation and data. For normal functions this is just the difference between log(y) and log(simulation(x)) but can be overwritten e.g. to increase speed or fit to log(x). If the dataset has yerror values they are used as weight.

Parameters:
  • params – Parameters for the function in this iteration
  • y – List of y values measured
  • x – List of x values for the measured points
  • yerror – List of error values for the y values or None if the fit is not weighted
Returns:

Residuals (meaning the value to be minimized) of the fit function and the measured data

set_parameters(new_params)[source]

Set new parameters and store old ones in history.

Parameters:new_params – List of new parameters
simulate(x, interpolate=5, inside_fitrange=False)[source]

Calculate the function for the active parameters for x values and some values in between.

Parameters:
  • x – List of x values to calculate the function for
  • interpolate – Number of points to interpolate in between the x values
  • inside_fitrange – Only simulate points inside the x-constrains of the fit
Returns:

simulated y-values for a list of giver x-values.

simulate_mp(x, interpolate=5, inside_fitrange=False)[source]

Multiprocessing version of simulate.

toggle_refine_parameter(action, index)[source]

Add or remove a parameter index to the list of refined parameters for the fit.

class plotpy.fitdata.FitFunction3D(initial_parameters)[source]

Bases: plotpy.gtkgui.gui_fit_data.FitFunctionGUI

Root class for fittable functions with x,y and z data. Parant of all other functions.

refine(dataset_x, dataset_y, dataset_z, dataset_zerror=None, progress_bar_update=None)[source]

Do the least square refinement to the given dataset. If the fit converges the new parameters are stored.

Parameters:
  • dataset_x – list of x values from the dataset
  • dataset_y – list of y values from the dataset
  • dataset_z – list of z values from the dataset
  • dataset_zerror – list of errors from the dataset or None for no weighting
Returns:

The message string of leastsq and the covariance matrix

refine_mpfit(residuals, parameters, x, y, z, dz, progress_bar_update=None)[source]

Refine the function using a constrained fit with the Sequential Least SQuares Programming algorithm.

The constrains can be boundaries, equalitiy and inequality fuctions.

residuals(params, z, y, x, zerror=None)[source]

Function used by leastsq to compute the difference between the simulation and data. For normal functions this is just the difference between y and simulation(x) but can be overwritten e.g. to increase speed or fit to log(x). If the dataset has yerror values they are used as weight.

Parameters:
  • params – Parameters for the function in this iteration
  • z – List of z values measured
  • y – List of y values for the measured points
  • x – List of x values for the measured points
  • yerror – List of error values for the y values or None if the fit is not weighted
Returns:

Residuals (meaning the value to be minimized) of the fit function and the measured data

residuals_log(params, z, y, x, zerror=None)[source]

Function used by leastsq to compute the difference between the logarithms of the simulation and data. For normal functions this is just the difference between log(y) and log(simulation(x)) but can be overwritten e.g. to increase speed or fit to log(x). If the dataset has yerror values they are used as weight.

Parameters:
  • params – Parameters for the function in this iteration
  • y – List of y values measured
  • x – List of x values for the measured points
  • yerror – List of error values for the y values or None if the fit is not weighted
Returns:

Residuals (meaning the value to be minimized) of the fit function and the measured data

set_parameters(new_params)[source]

Set new parameters and store old ones in history.

Parameters:new_params – List of new parameters
simulate(y, x)[source]

Calculate the function for the active parameters for x values and some values in between.

Parameters:
  • x – List of x values to calculate the function for
  • interpolate – Number of points to interpolate in between the x values
Returns:

simulated y-values for a list of giver x-values.

simulate_mp(y, x)[source]

Multiprocessing version of simulate.

toggle_refine_parameter(action, index)[source]

Add or remove a parameter index to the list of refined parameters for the fit.

class plotpy.fitdata.FitGaussian(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a gaussian function.

class plotpy.fitdata.FitGaussian3D(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction3D

Fit a gaussian function of x and y.

class plotpy.fitdata.FitHysteresis(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit two Langevin functions with hysteretic offset and exchange bias shift.

fit_function(p, x)[source]

Fit two Langevin functions with horizontal offset. Use the x change direction to determine hysteresis branches.

class plotpy.fitdata.FitInterpolation(initial_parameters=[], method='cubic')[source]

Bases: plotpy.fitdata.FitFunction

Fit a spline interpolation to up to 6 points.

fit_function(p, x)[source]

Spline interpolate the different points.

class plotpy.fitdata.FitLangevin(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit Langevin function.

class plotpy.fitdata.FitLinear(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a linear regression.

class plotpy.fitdata.FitLorentzian(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a lorentz function.

class plotpy.fitdata.FitLorentzian3D(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction3D

Fit a Lorentz function in x and y.

fit_function(p, x, y)[source]

Return the 2d Voigt profile of x and y. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.FitLorentzianAsymmetric(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a asymmetric lorentz function.

class plotpy.fitdata.FitMultiply(func1, func2)[source]

Bases: plotpy.fitdata.FitFunction

Fit the Multiplication of two FitFunctions.

fit_function(p, x)[source]

Combine the functions by adding their values together.

set_parameters(new_params)[source]

Set new parameters and pass them to origin functions.

toggle_refine_parameter(action, index)[source]

Change the refined parameters in the origin functions.

class plotpy.fitdata.FitMultiply3D(func1, func2)[source]

Bases: plotpy.fitdata.FitFunction3D

Fit the Multiplication of two FitFunctions3D.

fit_function(p, x, y)[source]

Combine the functions by adding their values together.

set_parameters(new_params)[source]

Set new parameters and pass them to origin functions.

toggle_refine_parameter(action, index)[source]

Change the refined parameters in the origin functions.

class plotpy.fitdata.FitNanoparticleZFC(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit zero field cooled curves of Nanoparticles.

class plotpy.fitdata.FitNanoparticleZFC2(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit zero field cooled curves of Nanoparticles.

fit_function(p, x)[source]

Calculate the ZFC curve of a nanoparticle distribution.

class plotpy.fitdata.FitOffspecular(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit the offspecular diffuse scattering from roughness.

fit_function(p, x)[source]

Return the Offspecular profile of th.

class plotpy.fitdata.FitOneOverX(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a one over x function.

plotpy.fitdata.FitPolynomialPowerlaw

alias of FitPowerlaw

class plotpy.fitdata.FitPowerlaw(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a powerlaw function.

class plotpy.fitdata.FitPsdVoigt3D(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction3D

Fit a voigt function using the representation as real part of the complex error function.

fit_function(p, x, y)[source]

Return the 2d Voigt profile of x and y. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.FitQuadratic(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a quadratic function.

class plotpy.fitdata.FitRelaxingCrystalLayer(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Simulate diffraction from a crystal layer with relaxing lattice constant from top to bottom. In contrast to FitCrystalLayer this uses a purly numeric approach with sum of scattering layers. The strain is released with a exponential decaying function

calculate_substrate_roughness(q, sigma)[source]

Calculate a sum of amplitudes with different offset phases. As the phase factore e^{iqd} averedged over gaussian distributed offsets d is the fourier transform of the gaussian distribution this is again a simple gaussian function in q.

get_amplitude(plane_positions, q, mu)[source]

Return the scattering amplitude from a set of layers. Uses a matrix of equal columns to compute for all q position at once.

get_strained_plains(a_bottom, a_inf, epsilon, d)[source]

Return an array of plane distances, exponentially decaying. The distances have to be calculated iteratively.

get_substrate_amplitude(q, a_substrate, mu)[source]

Calculate the scattering amplitude of the substrate with a attenuation length of mu. As the real space structure is the product of the heaveside step function (u{x}), an exponential decay and the crystal structure the amplitude can be calculated as the convolution of delta functions with the fourier transform of the u{x}*exp(-ax)->F(q)=1./[sqrt(2π)·(a+iq)]

class plotpy.fitdata.FitSQUIDSignal(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Fit three gaussians to SQUID raw data to calculate magnetic moments.

class plotpy.fitdata.FitSession(dataset)[source]

Bases: plotpy.gtkgui.gui_fit_data.FitSessionGUI

Class used to fit a set of functions to a given mds. Provides the interface between the MeasurementData and the FitFunction.

add_function(function_name)[source]

Add a function to the list of fitted functions.

del_function(function_obj)[source]

Delete a function to the list of fitted functions.

fit()[source]

Fit all funcions in the list where the fit parameter is set to True.

Returns:The covariance matrices of the fits or [[None]]
fit3d()[source]

Fit all funcions in the list where the fit parameter is set to True.

Returns:The covariance matrices of the fits or [[None]]
get_functions()[source]

Return a list of the available functions.

multiply(index_1, index_2)[source]

Create a multiplication of the functions with index 1 and 2. Function 1 and 2 are set not to be fitted.

resolution(index_f)[source]

Create a multiplication of the functions with index 1 and 2. Function 1 and 2 are set not to be fitted.

simulate()[source]

Create MeasurementData objects for every FitFunction.

simulate3d()[source]

Create MeasurementData objects for every FitFunction.

sum(index_1, index_2)[source]

Create a sum of the functions with index 1 and 2. Function 1 and 2 are set not to be fitted.

class plotpy.fitdata.FitSinus(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a sinus function.

refine(dataset_x, dataset_y, dataset_yerror=None, progress_bar_update=None)[source]

Refine the function for given x and y data and set the φ0 value to be between -180° and 180°.

class plotpy.fitdata.FitSum(func1, func2)[source]

Bases: plotpy.fitdata.FitFunction

Fit the Sum of two FitFunctions.

fit_function(p, x)[source]

Combine the functions by adding their values together.

set_parameters(new_params)[source]

Set new parameters and pass them to origin functions.

toggle_refine_parameter(action, index)[source]

Change the refined parameters in the origin functions.

class plotpy.fitdata.FitSum3D(func1, func2)[source]

Bases: plotpy.fitdata.FitFunction3D

Fit the Sum of two FitFunctions3D.

fit_function(p, x, y)[source]

Combine the functions by adding their values together.

set_parameters(new_params)[source]

Set new parameters and pass them to origin functions.

toggle_refine_parameter(action, index)[source]

Change the refined parameters in the origin functions.

class plotpy.fitdata.FitSuperlattice(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction

Fit a bragg reflex from a multilayer. Formulas are taken from:

“Structural refinement of superlattices from x-ray diffraction”, Eric E. Fullerton, Ivan K. Schuller, H.Vanderstraeten and Y.Bruynseraede Physical Review B, Volume 45, Number 16 (1992)

With additions from related publications, referenced in the paper mentioned above.

calc_F_ML(q)[source]

Calculate the structure factor for a superlattice without any roughness using eq(3) from PRB paper.

Parameters:q – Reciprocal lattice vector q
Returns:the complete structure factor of the multilayer (without substrate)
calc_F_ML_roughness(q)[source]

Calculate the avaraged structure factor for the multilayer with thickness variations.

Parameters:q – Reciprocal lattice vector q
Returns:the complete structure factor of the multilayer (without substrate)
calc_F_bilayer(q)[source]

Calculate the structure factor for a bilayer

Parameters:q – Reciprocal lattice vector q
Returns:the complete Intensity of the multilayer without the substrate
calc_F_layer(q, I, q0, t_j)[source]

Calculate the structurefactor by summing up all unit cells in the region.

Parameters:
  • q – Reciprocal lattice vector q
  • I – Scaling factor
  • q0 – Position of the corresponding bragg peak
  • t_j – Thickness of the layer
Returns:

structure factor for this layer at the origin position.

calc_F_layer_(q, I, q0, t_j)[source]

Calculate the structurefactor by summing up all unit cells in the region.

Parameters:
  • q – Reciprocal lattice vector q
  • I – Scaling factor
  • q0 – Position of the corresponding bragg peak
  • t_j – Thickness of the layer
Returns:

structure factor for this layer at the origin position.

calc_F_layer__(q, I, q0, t_j)[source]

Calculate the structure factor function for one layer. This is the structure factor of a crystal with the thickness t_j at the bragg peak q0.

Parameters:
  • q – Reciprocal lattice vector q
  • I – Scaling factor
  • q0 – Position of the corresponding bragg peak
  • t_j – Thickness of the layer
Returns:

structure factor for this layer at the origin position.

calc_F_substrat(q)[source]

Calculate the structure factor of the substrate (crystal truncation rod at substrate peak position.

Parameters:q – Reciprocal lattice vector q
Returns:structure factor for the substrate
calc_I_ML_fluctuation(q)[source]

Calculate the structure factor for a superlattice including fluctuations of the interface distance using eq(1) from J.-P. Locquet et al., PRB 38, No. 5 (1988).

Parameters:q – Reciprocal lattice vector q
Returns:the complete Intensity of the multilayer without the substrate
calc_I_ML_roughness(q)[source]

Calculate the structure factor for a superlattice including fluctuations and of the interface distance roughness using eq(7)-eq(10) from E.E.Fullerton et al., PRB 45, No. 16 (1992).

Parameters:q – Reciprocal lattice vector q
Returns:the complete Intensity of the multilayer without the substrate
calc_Pj(tj)[source]

Calculate the propability for every thickness fluctuation tj.

Returns:the propability for the jth deviation
calc_tj()[source]

Calculate deviation of thickness as discrete gaussians.

Returns:deviation of thickness from -3ω to +3ω as numpy array
calc_xj()[source]

Calculate xoffset of bilayer.

Returns:offset position for every layer
convolute_with_resolutions(I, q)[source]

Convolute the calculated intensity with the resolution function.

Parameters:
  • I – Calculated intensity to convolute
  • q – Reciprocal lattice vector q
Returns:

Convoluted intensity

fit_function(p, q)[source]

Calculate the intensities of the multilayer at reciprocal lattice positions q. The user can select which parts of the structure factor should be plotted by changing the F_select parameter. A negativ parameter means no convolution with the resolution function.

Parameters:
  • p – Parameters for the function
  • q – Reciprocal lattice vector q
Returns:

The calculated intensities for the selected structure factor + background

rebuild_param_dictionary(p)[source]

Create a dictionary of the parameters for better readability of all funcions.

Parameters:p – List of parameters to be used
class plotpy.fitdata.FitVoigt(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a voigt function using the representation as real part of the complex error function.

fit_function(p, x)[source]

Return the Voigt profile of x. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.FitVoigt3D(initial_parameters)[source]

Bases: plotpy.fitdata.FitFunction3D

Fit a voigt function using the representation as real part of the complex error function.

fit_function(p, x, y)[source]

Return the 2d Voigt profile of x and y. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.FitVoigtAsymmetric(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a voigt function using the representation as real part of the complex error function.

fit_function(p, x)[source]

Return the Voigt profile of x. It is calculated using the complex error function, see Wikipedia articel on Voigt-profile for the details.

class plotpy.fitdata.GaussianResolution(func)[source]

Bases: plotpy.fitdata.FitFunction

Combine a given function with a gaussian resolution function.

fit_function(p, x)[source]

Combine the functions by adding their values together.

set_parameters(new_params)[source]

Set new parameters and pass them to origin functions.

toggle_refine_parameter(action, index)[source]

Change the refined parameters in the origin functions.

class plotpy.fitdata.InteractiveFit(function, function_name, parameters, parameter_names, free_params=None, fit_logarithmic=False)[source]

Bases: plotpy.fitdata.FitFunction

A class to allow interactive definition of fits, which still are pickleable.

class plotpy.fitdata.InteractiveFit3D(function, function_name, parameters, parameter_names, free_params=None, fit_logarithmic=False)[source]

Bases: plotpy.fitdata.FitFunction3D

A class to allow interactive definition of fits, which still are pickleable.

class plotpy.fitdata.InteractiveFitConstructor(function_text, function_name, parameters, parameter_names, free_params=None, fit_logarithmic=False, is_3d=None)[source]

Bases: object

Class that allows to create InteractiveFit objects on demand.

class plotpy.fitdata.ThetaCorrection(initial_parameters=[])[source]

Bases: plotpy.fitdata.FitFunction

Fit a function to peak positions to get a reciprocal lattice parameter and Θ-offset.

fit_function(p, x)[source]

Fit a function to the peak positions.

plotpy.fitdata.new_function(function_text, function_name=None, parameters=None, parameter_names=None, free_params=None, fit_logarithmic=False, is_3d=None)[source]

Create a new fit function from a string. Function text is evaluated as one line of code contining parameter list items p and coordinates x (,y).

Parameters:
  • function_name – Name of the function in the GUI (default-function_text)
  • parameters – Initial fit parameters (default all zero)
  • parameter_names – Name of the fit parameters (default p_i)
  • free_params – List of parameter indices of fitted parameters
  • fit_logarithmic – Should the function be fittet logarithmic as default
  • is_3d – If the function is intended for one or two variables (default, search for y in function_text)
Example:
new_function(‘p[0]*x+p[1]’, function_name=’Line’)
-> Create a linear regression funciont
new_function(‘x**p[0]+y**p[1]’, ‘Double Powerlaw’, [1.,1.],[‘α’,’β’],
fit_logarithmic=True)
plotpy.fitdata.register_class(function_class)[source]

Convenience method to add a new FitFunction derived class to the list of fittables.

plotpy.fitdata.register_function(function, function_parameter_names=None, function_parameter_default=None, function_name=None)[source]

Convenience method to add a new fittable function.

Parameters:
  • function – The function to be fitted as f(p,x) or f(p,x,y) with p as list of parameters
  • function_parameter_names – Names of the parameters supplied to the function as p
  • function_parameter_default – Default values of the parameters when the function is first created
  • function_name – Name of the function

ipkernel_handler Module

Module to create an ipython kernel with access to the running plot.py instance.

plotting Module

Functions to plot measurements (MeasurementData objects) by gnuplot script. These functions are used by the GUI and script mode.

plotpy.plotting.check_gnuplot_version(session)[source]

Return the version of the installed gnuplot program.

plotpy.plotting.create_plotpy(session, datasets, file_name_prefix, file_name_postfix, title, names, with_errorbars, output_file='[name]_[add_info][nr].png', additional_info='', fit_lorentz=False, output_file_prefix=None, sample_name=None, show_persistent=False)[source]

Create a script for the gnuplot program.

Returns:The text of the script
plotpy.plotting.further_replacement(string)[source]

String replacements done last, for example when an Item has empty unit replace [] with nothing.

plotpy.plotting.gnuplot_plotpy(session, datasets, file_name_prefix, file_name_postfix, title, names, with_errorbars, output_file='[name]_[add_info][nr].png', additional_info='', fit_lorentz=False, sample_name=None, show_persistent=False, get_xy_ranges=False)[source]

Function to plot with an additional data and gnuplot file and calling to the gnuplot program. Files are stored in temporary folder set in gp.

Parameters:
  • session – The session object to use
  • file_name_prefix – Prefix of the used data and gnuplot files
  • title – The title of the plot
  • names – The names of the plotted functions
  • with_errorbars – Use errorbars layout when plotting
  • output_file – File name for the output picture_height
  • additional_info – Additional info string for the title
  • fit_lorentz – Is a fit included in this measurement?
Returns:

Gnuplot error message or empty string

plotpy.plotting.postscript_replace(string)[source]

Replace special characters when using Postscript export instead of png.

plotpy.plotting.replace_ph(session, string, datasets, file_name_prefix, file_numbers, title, names, sample_name, number, postscript_export=False, additional_info='')[source]

Replace place holders in a string.

Returns:The altered string
plotpy.plotting.script_header(show_persistent, datasets, output_file)[source]

Create the header of the script with global settings.

plotpy.plotting.script_plotlines(session, datasets, file_name_prefix, output_file_prefix, file_numbers, title, names, sample_name, postscript_export, additional_info, with_errorbars)[source]

Plot lines for 2d plots. (x vs. y)

plotpy.plotting.script_plotlines_3d(session, datasets, file_name_prefix, output_file_prefix, file_numbers, title, names, sample_name, postscript_export, additional_info, with_errorbars)[source]

Plot lines for 3d plots. (x,y vs. z)

plotpy.plotting.script_plotlines_3d_projection(session, datasets, file_name_prefix, output_file_prefix, file_numbers, title, names, sample_name, postscript_export, additional_info, with_errorbars)[source]

Plot lines for 3d plots with projections on the axes. (x,y vs. z)

plotpy.plotting.script_plotlines_multiplot_3d(session, datasets, file_name_prefix, output_file_prefix, file_numbers, title, names, sample_name, postscript_export, additional_info, with_errorbars)[source]

Plot lines for 3d plots as multiplot layout (data, fit, data-fit, log(data)-log(fit)). (x,y vs. z)

mds Module

Classes for storing the measurement data of any session. Units and dimensions are also stored for easier accessing and transformation.

class plotpy.mds.HugeMD(*args, **opts)[source]

Bases: plotpy.mds.MeasurementData

For huge datasets (50 000 points +) this datastructure uses a arbitrary temporary file to sotre exported data. The data is only reexported after a change or changes to the filters.

do_export(file_name, print_info=True, seperator=u' ', xfrom=None, xto=None, only_fitted_columns=False, format_string=None)

Write data in text file.

Parameters:
  • file_name – Name of the export file
  • print_info – Put a header ontop of the data
  • seperator – Seperator characters to be used between columns
  • xfrom – Start value of x for the export
  • xto – End value of x for the export
  • only_fitted_columns – Only export columns used for fitting.
Returns:

The number of data lines exported

process_function(function)[source]

Wrapper to MeasurementData.process_function which sets the data to be reexported after change.

store_data()[source]

Pickle the data in this object to save memory.

unit_trans(unit_list)[source]

Wrapper to MeasurementData.unit_trans which sets the data to be reexported after change.

unit_trans_one(col, unit_lit)[source]

Wrapper to MeasurementData.unit_trans_one which sets the data to be reexported after change.

class plotpy.mds.LinkedList(data)[source]

Bases: list

A list which is linked to a PhysicalProperty so every change to the list data will also be made for the PhysicalProperty.

class plotpy.mds.MeasurementData(columns=[], const=[], x=0, y=1, yerror=-1, zdata=-1, dtype=<type 'numpy.float32'>)[source]

Bases: object

The main class for the data storage. Stores the data as a list of PhysicalProperty objects. Sample name and measurement informations are stored as well as plot options and columns which have to stay constant in one sequence.

Main Attributes Description
number_of_points Number of datapoints stored in the class
data List of PhysicalProperty instances for every data column
[x,y,z]data/.yerror Indices of the plotted columns in the .data list. If z=-1 the plot is 2d
log[x,y,z] Boolean defining the logarithmic scale plotting of the columns
crop_zdata Boolean to set z data to be croped when the zrange is smaller than the data range. For plot to be without empty spots
short_info Second part of the plot title and name of line in multiplot
sample_name First part of the plot title.
filters List of filters which are applied to the dataset before export for plotting.
plot_options PlotOptions object storing the visualization options
Main Methods Description
append Append a datapoint at the end of the dataset
append_column Add a new datacolumn to the object
dimensions Return the dimensions of all columns
export Export the data to a file
process_function Call a function for all data of the object, e.g. square the y data
sort Sort the datapoints for one column
unit_trans Transform units
units Return the units of all columns
append(point)[source]

Add a point to this sequence.

Parameters:point – List of entries by columns
Returns:The added point or u’NULL’ if an error has occured
append_column(column, dimension=u'', unit=u'')[source]

Append a new column to the datastructure. If the column is already a PhysicalProperty, a copy of it is used, otherwise a new PhysicalProperty object is created with the column data.

create_interpolation()[source]

Use scipy.interpolate to create a functional representation of the data.

dimensions()[source]

Return dimensions of all columns-

export(file_name, print_info=True, seperator=u' ', xfrom=None, xto=None, only_fitted_columns=False, format_string=None)[source]

Write data in text file.

Parameters:
  • file_name – Name of the export file
  • print_info – Put a header ontop of the data
  • seperator – Seperator characters to be used between columns
  • xfrom – Start value of x for the export
  • xto – End value of x for the export
  • only_fitted_columns – Only export columns used for fitting.
Returns:

The number of data lines exported

export_matrix(file_name)[source]

Quick export only the xyz values as binary file.

export_npz(file_name)[source]

Export data into a numpy npz file.

export_projections(file_name, numpoints=None)[source]

Export x and y projections to a 4-column file.

first()[source]

Return the first datapoint.

get_approx_size()[source]

Return the approximate data size in bytes.

get_data(index)

MeasurementData[index] returns one datapoint.

get_filter_indices()[source]

Return the boolean array of not filtered data points.

Returns:numpy array of filters
get_filtered_data_matrix()[source]

Return the data as numpy array with applied filters.

Returns:numpy array of point lists
get_info()[source]

Return a string containing some information about the data stored in this object.

get_xprojection(numpoints)[source]

Return the projection of 3d data on the x-axis.

get_yprojection(numpoints)[source]

Return the projection of 3d data on the y-axis.

is_type(dataset)[source]

Check if a point is consistent with constant data of this sequence.

join(other)[source]

Return a joined instance of two measurements with the same columns.

last()[source]

Return the last datapoint.

list()[source]

Get x-y-(z) list of all data points. If x or y columns are negative the index is returned instead

list_err()[source]

Get x-y-dy list of all data. If x or y columns are negative the index is returned instead

listxy(x, y)[source]

Get x-y list of data with different x,y values.

max(xstart=None, xstop=None)[source]

Returns x and y value of point with maximum x.

min(xstart=None, xstop=None)[source]

Returns x and y value of point with minimum x.

process_function(function)[source]

Processing a function on every data point. When numpy is installed this is done via one proccess call for arrays. (This leads to a huge speedup)

Parameters:function – Python function to execute on each point
Returns:Last point after function execution
process_function_nonumpy(function)[source]

Processing a function on every data point.

Parameters:function – Python function to execute on each point
Returns:Last point after function execution
rough_sort(ds1, ds2, sensitivity)[source]

Return the sorting indices from a first and second column ignoring small differences.

set_data(index, item)

Set data at index reverse of __getitem__

sort(column=None)[source]

Sort the datapoints for one column.

string_from_data_matrix(seperator, data, split_indices, format_string=u'%g')[source]

Create a string that can be written to a file from a given data matrix. The function may look quite strange because of a lot of optimization, thus the result is almost as fast as c-code (faster if the c-code is not optimized) while having the flexibility to define empty line indices and format options.

Parameters:
  • seperator – A string to seperate each data value.
  • data – A matrix of data points
  • split_indices – Index of the points where empty lines should be added
  • format_string – Specifies the format option to be used for string conversion of the numbers
Returns:

A string with the data.

type()[source]

Short form to get the first constant data column.

unit_trans(unit_list)[source]

Change units of all columns according to a given list of translations.

Returns:List of new dimensions and units
unit_trans_one(col, unit_list)[source]

Change units of one column according to a given list of translations and return this column.

Returns:The changed column and the applied translation
units()[source]

Return units of all columns.

x

Get the data for column x

xdim()[source]

Get dimension of xcolumn.

xunit()[source]

Get unit of xcolumn.

y

Get the data for column y

ydim()[source]

Get dimension of ycolumn.

yerror

Implement the possibility to ither define the error as extra column or property of y/z data.

yunit()[source]

Get unit of ycolumn.

z

Get the data for column z

zdim()[source]

Get dimension of ycolumn.

zunit()[source]

Get unit of ycolumn.

class plotpy.mds.MeasurementData4D(columns=[], const=[], x=0, y=1, error=-1, z=3, y2=-1, slice_width=None, slice_center=None, gridsize_x=100, gridsize_y=100)[source]

Bases: plotpy.mds.MeasurementData

A dataset of x,y,z and I data which can be sliced or projected on a given grid. The grid can be a clolumn of the data or calculated as a function of columns.

export_matrix(file_name)[source]

Export the filtered data points. If slicing is enabled the data are filtered to be inside the slice. The data is then projected onto a regular grid in x and y.

classmethod from_md(other, y2=-1)[source]

Create a new instance of this class using a MeasurementData object.

slice_center

The center in y2 to plot

slice_width

The width of the slice in y2 to plot

y2

Get the data for column y2

class plotpy.mds.MultiplotList(input_list=None)[source]

Bases: list

A list of measurements for a multiplot.

class plotpy.mds.PhysicalConstant[source]

Bases: numpy.ndarray

Class to store physical constants. Adds a unit, symbol/name and discription to the float value. Quite similar to PhysicalProperty but only as scalar.

unit_trans(transfere)[source]

Transform one unit to another. transfere variable is of type [from,b,a,to].

class plotpy.mds.PhysicalProperty[source]

Bases: numpy.ndarray

Class for any physical property. Stores the data, unit and dimension to make unit transformations possible. Can be used with numpy functions. Error values are stored and propagated in arithmetric operations.

Attributes  
dimension String for the dimension of the instance
unit PhysicalUnit object
error Error value as array
Hints:

PhysicalProperty can be used with different convenience operators/functions, for a PhysicalProperty u’P’ these are e.g.:

P % [unit] Transform the instance to the unit
P % ([name], [mul], [add]) Transform the instance to [name] using the multiplyer [mul] and adding [add]
P // [dim] Get P with different dimension name [dim]
P // ([dim], [unit]) Get P with different dimension and unit name

Additionally PhysicalProperty instances can be used like numpy arrays in functions and with respect to slicing. Addition and subtraction is unit dependent and angular functions only take angles as input.

append(item)[source]

Append an item to the end of the data, if the array is to small it is enlarged.

copy()[source]

Return a copy of self.

dim_unit_trans(transfere)[source]

Transform dimension and unit to another. Variable transfere is of type [from_dim,from_unit,b,a,to_dim,to_unit].

flatten()[source]

Reduce data to one dimension.

get_approx_size()[source]

Return the data size in bytes.

join(other)[source]

Combine two PhysicalProperty objects of the same unit.

max()[source]

Get maximal value as PhysicalProperty object.

mean()[source]

Get (weighted) mean value as PhysicalProperty object.

min()[source]

Get minimal value as PhysicalProperty object.

reshape(*a, **opts)[source]

Change the dimensional order of the data.

sum(*args, **opts)[source]

Get the sum of value as PhysicalProperty object.

unit_save = True

if true changes units after arithmetic operation and checks if correct

unit_trans(transfere)[source]

Transform one unit to another. transfere variable is of type [from,b,a,to].

values

Wrapper to simulate the old .values list

class plotpy.mds.PhysicalUnit(entry_str)[source]

Bases: object

Object to store physical units. Implements combining units and exponential of units.

get_transformation(conversion)[source]

Try to calculate a transformation to a given unit.

str()[source]

Construct a combined string for the unit.

exception plotpy.mds.PhysicalWarning[source]

Bases: exceptions.UserWarning

Warning raised when array operations don’t make physical sense.

class plotpy.mds.PlotOptions(initial_text=u'')[source]

Bases: object

Object for storing information about the illustration of the data in the plot.

input_string(text)[source]

Get setting information from a text.

overwrite_copy(other)[source]

Overwrite an other Plot option with the settings from this one.

class plotpy.mds.PlotStyle[source]

Bases: object

Class to define the plot style of one line. Automatically creates the u”with” settings for gnuplot according to some options.

class plotpy.mds.PysicalProperty(dimension_in, unit_in)[source]

Class for any physical property. Stores the data, unit and dimension to make unit transformations possible.

append(number)[source]

Add value.

dim_unit_trans(transfere)[source]

Transform dimension and unit to another. Variable transfere is of type [from_dim,from_unit,b,a,to_dim,to_unit].

max(from_index=0, to_index=None)[source]

Return maximum value in data.

min(from_index=0, to_index=None)[source]

Return minimum value in data.

next()[source]

Function to iterate through the data-points, object can be used in u”for bla in data:”.

unit_trans(transfere)[source]

Transform one unit to another. transfere variable is of type [from,b,a,to].

plotpy.mds.calculate_transformations(transformations)[source]

Use a dictionary of unit transformations to calculate all combinations of the transformations inside.

message Module

Module to provide a general message system for command line and GUI usage. Messages are one of information, warning or error and can be grouped into global groups and item messages. For example:

When reading a bunch of files (10) the reader would call:

info(None, group='Reading files', numitems=10)
for item in items:
  info('Reading...', group='Reading files', item=item)

Each item could call info again to update the progress or show additional information using the same group and item argument.

mpfit Module

Fitting routine module.

option_types Module

Types used to stor option information for different other classes. The main purpose is to make the code more readable and automate the creation of option dialogs.

class plotpy.option_types.MultiSelection(items, selection, name='')[source]

Bases: object

A list of string items from which several can be selected. The object can be compared with integer or string values to check, which item is selected.

select(item, activate=True)[source]

Add or remove an object to the selection.

class plotpy.option_types.OptionSwitch(value, value_types_names=[(<type 'float'>, 'value')], name='')[source]

Bases: object

A class to simplify switch settings which can be of different types. Can be used e.g. to be an integer in one state or dict in an other.

from_dict(in_dict)[source]

Define how the object is restored from a dicitonary.

items()[source]

Return list of value active, value types, names and defaults.

to_dict()[source]

Define how the object is stored in a dictionary.

class plotpy.option_types.PatternList(input_, pattern, description=None, name='')[source]

Bases: list

A list containing list items with specified types.

from_dict(in_dict)[source]

Define how this is restored from a dictionary.

to_dict()[source]

Define how this can be stored in a dictionary.

class plotpy.option_types.Selection(items, selection, name='')[source]

Bases: object

A list of string items from which one can be selected. The object can be compared with integer or string values to check, which item is selected.

from_dict(in_dict)[source]

Define how this is restored from a dictionary.

to_dict()[source]

Define how this can be stored in a dictionary.

class plotpy.option_types.StringList(input_, name='')[source]

Bases: list

A list that only accepts string entries.

from_dict(in_dict)[source]

Define how this is restored from a dictionary.

to_dict()[source]

Define how this can be stored in a dictionary.

plotpy.option_types.pystring(string)[source]

Change entry n to etc.

parallel Module

Functions to parallelize some functions of the program using the IPython multiprocessing features.

peakfinder Module

Peak finder algorithm based on the continuous wavelet transform (CWT) method discribed in:

Du P, Kibbe WA, Lin SM. Improved peak detection in mass spectrum by incorporating continuous wavelet transform-based pattern matching Bioinformatics 22(17) (2006)

Implemented by Artur Glavic (artur.glavic@fz-juelich.de) 2012

class plotpy.peakfinder.Cwt(data, largestscale=1, notes=0, order=2, scaling='log')[source]

Base class for continuous wavelet transforms Implements cwt via the Fourier transform Used by subclass which provides the method wf(self,s_omega) wf is the Fourier transform of the wavelet function. Returns an instance.

getdata()[source]

returns wavelet coefficient array

getnscale()[source]

return number of scales

getpower()[source]

returns square of wavelet coefficient array

getscales()[source]

returns array containing scales used in transform

class plotpy.peakfinder.MexicanHat(data, largestscale=1, notes=0, order=2, scaling='log')[source]

Bases: plotpy.peakfinder.Cwt

2nd Derivative Gaussian (mexican hat) wavelet

class plotpy.peakfinder.PeakFinder(xdata, ydata, resolution=5)[source]

Bases: object

Peak finder which can be reevaluated with different thresholds without recalculation all steps. The steps performed are:

  • CWT of the dataset (which also removes the baseline)
  • Finding ridged lines by walking through different CWT scales
  • Calculate signal to noise ratio (SNR)
  • Identify the peaks from the ridged lines (this is where the user parameters enter and can be recalculated fast)
get_peaks(snr=2.5, min_width=None, max_width=None, ridge_length=15, analyze=False, double_peak_detection=False, double_peak_reduced_ridge_length=3)[source]

Return a list of peaks fulfilling the defined conditions.

Parameters:
  • snr – Minimal signal to noise ratio
  • min_width – Minimal peak width
  • max_width – Maximal peak width
  • ridge_length – Minimal ridge line length
  • analyze – Store information to analyze the filtering
  • double_peak_detection – Perform a second run, where the ridge_length is reduced near found peaks
visualize(snr=2.5, min_width=None, max_width=None, ridge_length=15, double_peak_detection=False, double_peak_reduced_ridge_length=3)[source]

Use matplotlib to visualize the peak finding routine.