File: LogRatio.pm

package info (click to toggle)
libdemeter-perl 0.9.27%2Bds6-9
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 74,028 kB
  • sloc: perl: 73,233; python: 2,196; makefile: 1,999; ansic: 1,368; lisp: 454; sh: 74
file content (258 lines) | stat: -rw-r--r-- 6,436 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package Demeter::LogRatio;

=for Copyright
 .
 Copyright (c) 2006-2019 Bruce Ravel (http://bruceravel.github.io/home).
 All rights reserved.
 .
 This file is free software; you can redistribute it and/or
 modify it under the same terms as Perl itself. See The Perl
 Artistic License.
 .
 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.

=cut

use Carp;

use Moose;
extends 'Demeter';

has '+name'         => (default => 'Log-Ratio/Phase-Difference' );
has 'standard'      => (is => 'rw', isa => 'Any',     default => q{},
			trigger => sub{ my($self, $new) = @_; $self->datagroup($new->group) if $new});
has 'standardgroup' => (is => 'rw', isa => 'Str',     default => q{});

has 'qmin'          => (is => 'rw', isa => 'LaxNum', default => 4);
has 'qmax'          => (is => 'rw', isa => 'LaxNum', default => 12);
has 'twopi'         => (is => 'rw', isa => 'Int',    default => 0);

has 'cumulants'     => (is => 'rw', isa => 'ArrayRef', default => sub{[]});
has 'errorbars'     => (is => 'rw', isa => 'ArrayRef', default => sub{[]});

sub BUILD {
  my ($self, @params) = @_;
  $self->mo->push_LogRatio($self);
  return $self;
};

sub fit {
  my ($self) = @_;
  foreach my $att (qw(fft_kmin fft_kmax fft_dk fft_kwindow
		      bft_rmin bft_rmax bft_dr bft_rwindow)) {
    $self->data->$att($self->standard->$att);
  };
  $self->data->_update('all');
  $self->standard->_update('all');

  $self->dispense("analysis", "lr_fit");
  my @cumulants = (sprintf("%.5f", $self->fetch_scalar("lr___pd0")),
		   sprintf("%.5f", $self->fetch_scalar("lr___pd1")),
		   sprintf("%.5f", $self->fetch_scalar("lr___pd2")),
		   sprintf("%.8f", $self->fetch_scalar("lr___pd3")),
		   sprintf("%.8f", $self->fetch_scalar("lr___pd4")));
  print join("|". @cumulants), $/;
  my @errorbars = (sprintf("%.5f", $self->fetch_scalar("delta_lr___pd0")),
		   sprintf("%.5f", $self->fetch_scalar("delta_lr___pd1")),
		   sprintf("%.5f", $self->fetch_scalar("delta_lr___pd2")),
		   sprintf("%.8f", $self->fetch_scalar("delta_lr___pd3")),
		   sprintf("%.8f", $self->fetch_scalar("delta_lr___pd4")));
  $self->cumulants(\@cumulants);
  $self->errorbars(\@errorbars);

  return $self;
};

sub report {
  my ($self) = @_;
  return $self->template("analysis", "lr_results", {cumulants=>$self->cumulants,
						    errorbars=>$self->errorbars});
};

sub plot_even {
  my ($self) = @_;
  $self->chart("plot", "lreven");
  return $self;
};

sub plot_odd {
  my ($self) = @_;
  $self->chart("plot", "lrodd");
  return $self;
};

sub save {
  my ($self, $fname) = @_;
  $fname ||= 'lrpd.dat';

  my $save_columns = {};
  my $text;
  my $hash = {1=>'wavenumber inverse Angstrom', 2=>'log ratio', 3=>'even fit', 4=>'phase difference', 5=>'odd fit'};
  $text = $self->template('analysis', 'lr_results', {cumulants=>$self->cumulants,
						     errorbars=>$self->errorbars});
  if ($self->data->xdi) {
    $save_columns  = $self->data->xdi->metadata->{Column};
    $self->data->xdi_set_columns($hash);
  };

  $self->data->xdi_output_header('data', $text, $hash);
  $self->dispense("analysis", "lr_save", {file=>$fname});
  $self->data->xdi_set_columns($save_columns) if ($self->data->xdi);
  return $fname;
};

1;

=head1 NAME

Demeter::LogRatio - Log-ratio/phase-difference analysis

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

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

  my $standard = Demeter::Data->new(file=>'../../data/fe.060.xmu', name => 'Fe 60K');
  my $data     = Demeter::Data->new(file=>'../../data/fe.300.xmu', name => 'Fe 60K');
  my $lrpd     = Demeter::LogRatio->new(standard=>$standard, data=>$data, qmax=>11);
  $lrpd->fit;
  print $lrpd->report;
  $lrpd->plot_odd;
  $lrpd->data->pause;

=head1 DESCRIPTION

Perform a log-ratio/phase difference analysis of two spectra in the
manner of “Application of the Ratio Method of EXAFS Analysis to
Disordered Systems”, G. Bunker, Nucl. Inst. Meth., 207, (1983)
p. 437-444.

=head1 ATTRIBUTES

=over 4

=item C<data>

The unknown Data object.

=item C<standard>

The standard Data object.

=item C<cumulants>

After the fit, this gets filled with a reference to an array of the
cumulants in order from zeroth to fourth.

=item C<errorbars>

After the fit, this gets filled with a reference to an array of the
uncertainties on the cumulants in order from zeroth to fourth.

=item C<qmin> [3]

The lower end in q of the fitting range.

=item C<qmax> [12]

The upper end in q of the fitting range.

=item C<twopi> [0]

Manually add an integer number of two-pi jumps to the phase-difference
spectrum.

=back

=head1 METHODS

=over 4

=item C<fit>

Perform the log-ratio and phase-difference fits.

  $lr -> fit;

Note that the forward and backward Fourier transform parameters of the
data are set to those of the standard before the fit is performed.
They are not restored, thus performing a fit might modify the
attributes of the unknown data.

=item C<report>

Return a text string reporting on the cumulant values.

  print $lr->report;

=item C<plot_even>

Make a plot of the log-ratio along with its polynomial fit.

  $lr->plot_even;

=item C<plot_odd>

Make a plot of the phase-difference along with its polynomial fit.

  $lr->plot_odd;

=back

=head1 SERIALIZATION AND DESERIALIZATION

Good question ...

=head1 CONFIGURATION AND ENVIRONMENT

See L<Demeter::Config> for a description of the configuration system.
See the lcf configuration group for the relevant parameters.

=head1 DEPENDENCIES

Demeter's dependencies are in the F<Build.PL> file.

=head1 BUGS AND LIMITATIONS

=over 4

=item *

Better error checking

=back

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

Patches are welcome.

=head1 AUTHOR

Bruce Ravel, L<http://bruceravel.github.io/home>

L<http://bruceravel.github.io/demeter/>


=head1 LICENCE AND COPYRIGHT

Copyright (c) 2006-2019 Bruce Ravel (L<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 L<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.

=cut