Demeter

Description Perl tools for X-ray Absorption Spectroscopy
Demeter > Perl Modules > Demeter::PeakFit
Source

NAME

Demeter::PeakFit - A peak fitting object for Demeter

VERSION

This documentation refers to Demeter version 0.9.26.

SYNOPSIS

Here is a simple fit of three peak shapes to normalized XES data.

  #!/usr/bin/perl
  use Demeter qw(:ui=screen :plotwith=gnuplot);

  my $xes = Demeter::XES->new(file=>'../XES/7725.11',
                              energy => 2, emission => 3,
                              e1 => 7610, e2 => 7624, e3 => 7664, e4 => 7690,
                             );
  my $peak = Demeter::PeakFit->new(screen => 0, yaxis=> 'norm', name=>'fit');
  $peak -> data($xes);

  $peak -> add('gaussian',   center=>7649.5, name=>'peak 1');
  $peak -> add('gaussian',   center=>7647.7, name=>'peak 2');
  $peak -> add('lorentzian', center=>7636.8, name=>'peak 3');

  $peak -> fit;
  print $peak -> report;
  $_  -> plot('norm') foreach ($xes, $peak, @{$peak->lineshapes});
  $peak -> pause;

DESCRIPTION

This object is a sort of container for holding Data (either XANES data in a normal Data object or XES data in an XES object) along with some number of lineshapes. It organizes the parameterization of the lineshapes and shuffles all of this off to the fitting engine for fitting, all wihtout having to master whatever quirky syntax it might have.

FITTING ENGINES

This module provides an abstract framework for enabling peak fitting in Demeter. This abstraction allows (well ... in principle) the use of various backends for performing the actual fit. Currently the only one available is Fityk (http://www.unipress.waw.pl/fityk/), which is implemented as Demeter::PeakFit::Fityk.

Any suggestions?

ATTRIBUTES

screen (boolean) [0]

This is a flag telling Demeter to echo instructions to the screen.

engine (boolean) [1]

This is a flag telling Demeter to echo instructions to the fitting engine process.

buffer

Dispose commands to a string or array when given a reference to a string or array. This allows you to accumulate instructions in a string or an array an save them for future use, e.g. writing a script or displaying a text widget in a GUI.

xaxis (string) [energy]

The string denoting the array containing the ordinate axis of the data. For most XANES and XES data, this is energy.

yaxis (string) [flat]

The string denoting the array containing the abscisa axis of the data. For most XANES, this is typically either flat or norm. For XES data, this might be raw, sub, or norm. Note that the default will trigger an error if you try to fit XES data without changing its value appropriately.

sigma (string) []

The string denoting the array containing the varience of the data.

xmin (float)

The lower bound of the fit range. For XANES data, this will be interpreted relative to the edge, while for XES data it is intepretated as an absolute energy.

xmax (float)

The upper bound of the fit range. For XANES data, this will be interpreted relative to the edge, while for XES data it is intepretated as an absolute energy.

lineshapes

This contains a reference to the array of LineShape objects included in the fit. This array can be manipulated with the standard Moose-y sort of automatically generated methods:

  push_lineshapes
  pop_lineshapes
  shift_lineshapes
  unshift_lineshapes
  clear_lineshapes

METHODS

add

Use this to add new lineshapes to the fitting model.

  $ls = $peak -> add("Gaussian", center => 4967, name => "First peak")

This returns a Demeter::PeakFit::LineShape object. This is the standard way of creating such an object as this properly associates the LineShape object with the current peak fitting effort. It should never be necessary (or desirable) to create a LineShape by hand.

fit

Perform the fit after adding one or more LineShapes.

  $peak -> fit;

After the fit finishes, the statistics of the fit will be accumulated from the fitting engine and stored in this and all the LineShape objects.

engine_object

This returns the object for interacting with the fitting engine (if there is one). This is used extensively by Demeter::PeakFit::LineShape.

plot

Use this to plot the result of the fit. Note that this only plots the full model and (optionally) the residual. To plot the individual function, use the plot method of the the LineShape object.

This plots the data along with the fitting model and each function:

  $xanes_data -> po -> e_norm(1);
  $_ -> plot('E') foreach ($xanes_data, $peak, @{$peak->lineshapes});

Note that the C('E') argument and the setting of e_norm are ignored by the PeakFit and LineShape objects, but they are required to plot a fit to XANES data as the fit is made to the normalized data. In fact, the fit is made to the flattened data if the Data's bkg_flatten attribute is true.

For a fit to raw XES data, you might make the plot like so:

  $_ -> plot('raw') foreach ($xanes_data, $peak, @{$peak->lineshapes});

Specifically, you want to plot the data in the manner indicated by the yaxis attribute of the PeakFit object, which indicates the form of the data used in the fit.

When the PeakFit object is plotted, the residual from the fit will also be plotted if the plot_res attribute of the Plot object is true.

pf_dispose

This is the choke point for sending instructions to the fitting engine, much like the normal dispose method handles text intended for Ifeffit or Gnuplot. See the descriptions of the engine and screen attributes.

report

This returns a tring summarizing the results of a fit.

  print $peak->report;

CONFIGURATION AND ENVIRONMENT

See Demeter::Config for a description of the configuration system.

DEPENDENCIES

Demeter's dependencies are in the Build.PL file.

BUGS AND LIMITATIONS

Please report problems to the Ifeffit Mailing List (http://cars9.uchicago.edu/mailman/listinfo/ifeffit/)

Patches are welcome.

AUTHOR

Bruce Ravel, http://bruceravel.github.io/home

http://bruceravel.github.io/demeter/

LICENCE AND COPYRIGHT

Copyright (c) 2006-2018 Bruce Ravel (http://bruceravel.github.io/home). All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlgpl.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.