File: Align.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 (335 lines) | stat: -rw-r--r-- 12,182 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
package Demeter::UI::Athena::Align;
use strict;
use warnings;

use Wx qw( :everything );
use base 'Wx::Panel';
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_COMBOBOX EVT_TEXT EVT_TEXT_ENTER);
use Wx::Perl::TextValidator;
use Scalar::Util qw(looks_like_number);


use Demeter::UI::Wx::SpecialCharacters qw(:all);

use vars qw($label);
$label = "Align data";

my $tcsize = [60,-1];

sub new {
  my ($class, $parent, $app) = @_;
  my $this = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxMAXIMIZE_BOX );

  my $box = Wx::BoxSizer->new( wxVERTICAL );
  $this->{sizer}  = $box;

  my $gbs = Wx::GridBagSizer->new( 5, 5 );

  my $label = Wx::StaticText->new($this, -1, "Aligning");
  $gbs->Add($label, Wx::GBPosition->new(0,0));
  $label = Wx::StaticText->new($this, -1, "Standard");
  $gbs->Add($label, Wx::GBPosition->new(1,0));
  $label = Wx::StaticText->new($this, -1, "Plot as");
  $gbs->Add($label, Wx::GBPosition->new(2,0));
  $label = Wx::StaticText->new($this, -1, "Fit as");
  $gbs->Add($label, Wx::GBPosition->new(3,0));

  $this->{this}     = Wx::StaticText->new($this, -1, q{Group});
  $this->{standard} = Demeter::UI::Athena::GroupList -> new($this, $app, 1);
  #$this->{standard} = Wx::ComboBox->new($this, -1, q{}, wxDefaultPosition, [165,-1], [], wxCB_READONLY);
  $this->{plotas}   = Wx::Choice->new($this, -1, wxDefaultPosition, [165,-1],
				      ["$MU(E)", 'norm(E)', 'deriv(E)', 'smoothed deriv(E)']);
  $this->{fitas}    = Wx::Choice->new($this, -1, wxDefaultPosition, [165,-1],
				      ['deriv(E)', 'smoothed deriv(E)']);

  $this->{plotas} -> SetSelection(3);
  $this->{fitas}  -> SetSelection(1);

  $gbs->Add($this->{this},     Wx::GBPosition->new(0,1));
  $gbs->Add($this->{standard}, Wx::GBPosition->new(1,1));
  $gbs->Add($this->{plotas},   Wx::GBPosition->new(2,1));
  $gbs->Add($this->{fitas},    Wx::GBPosition->new(3,1));

  EVT_CHOICE($this, $this->{plotas}, sub{$this->plot($app->current_data)});
  EVT_COMBOBOX($this, $this->{standard}, sub{$this->plot($app->current_data)});

  $box -> Add($gbs, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);

  my @ps  = (wxDefaultPosition, [80, -1]);
  my @ps2 = (wxDefaultPosition, [165,-1]);

  my $hbox = Wx::BoxSizer->new( wxHORIZONTAL );
  $box -> Add($hbox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
  $this->{shiftlabel} = Wx::StaticText->new($this, -1, "Shift by");
  $this->{shift}      = Wx::TextCtrl->new($this, -1, 0, wxDefaultPosition, $tcsize, wxTE_PROCESS_ENTER);
  $this->{units}      = Wx::StaticText->new($this, -1, "eV     ");
  $this->{errorlabel} = Wx::StaticText->new($this, -1, "Uncertainty");
  $this->{error}      = Wx::TextCtrl->new($this, -1, 0, wxDefaultPosition, $tcsize, wxTE_READONLY);
  $hbox->Add($this->{shiftlabel}, 0, wxALL,          4);
  $hbox->Add($this->{shift},      0, wxLEFT|wxRIGHT, 2);
  $hbox->Add($this->{units},      0, wxALL,          4);
  $hbox->Add($this->{errorlabel}, 0, wxALL,          4);
  $hbox->Add($this->{error},      0, wxLEFT|wxRIGHT, 2);

  $hbox = Wx::BoxSizer->new( wxHORIZONTAL );
  $box -> Add($hbox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
  $this->{replot}     = Wx::Button->new($this, -1, "Replot", @ps2);
  $hbox->Add($this->{replot},     0, wxALL,         3);


  $this->{shift} -> SetValidator( Wx::Perl::TextValidator->new( qr([-0-9.]) ) );
  EVT_TEXT($this, $this->{shift}, sub{OnShift(@_, $app->current_data)});
  EVT_TEXT_ENTER($this, $this->{shift}, sub{$this->plot($app->current_data)});
  EVT_BUTTON($this, $this->{replot}, sub{$this->plot($app->current_data)});

  $gbs = Wx::GridBagSizer->new( 5, 5 );

  $this->{auto}   = Wx::Button->new($this, -1, "Auto align", @ps2);
  $this->{marked} = Wx::Button->new($this, -1, "Align marked groups", @ps2);
  $this->{m5}     = Wx::Button->new($this, -1, "-5",     @ps);
  $this->{p5}     = Wx::Button->new($this, -1, "+5",     @ps);
  $this->{m1}     = Wx::Button->new($this, -1, "-1",     @ps);
  $this->{p1}     = Wx::Button->new($this, -1, "+1",     @ps);
  $this->{mhalf}  = Wx::Button->new($this, -1, "-0.5",   @ps);
  $this->{phalf}  = Wx::Button->new($this, -1, "+0.5",   @ps);
  $this->{mtenth} = Wx::Button->new($this, -1, "-0.1",   @ps);
  $this->{ptenth} = Wx::Button->new($this, -1, "+0.1",   @ps);

  $gbs->Add($this->{auto},   Wx::GBPosition->new(0,0), Wx::GBSpan->new(1,2));
  $gbs->Add($this->{marked}, Wx::GBPosition->new(0,2));
  $gbs->Add($this->{m5},     Wx::GBPosition->new(1,0));
  $gbs->Add($this->{p5},     Wx::GBPosition->new(1,1));
  $gbs->Add($this->{m1},     Wx::GBPosition->new(2,0));
  $gbs->Add($this->{p1},     Wx::GBPosition->new(2,1));
  $gbs->Add($this->{mhalf},  Wx::GBPosition->new(3,0));
  $gbs->Add($this->{phalf},  Wx::GBPosition->new(3,1));
  $gbs->Add($this->{mtenth}, Wx::GBPosition->new(4,0));
  $gbs->Add($this->{ptenth}, Wx::GBPosition->new(4,1));

  EVT_BUTTON($this, $this->{auto},   sub{$this->autoalign($app->current_data, 'this')});
  EVT_BUTTON($this, $this->{marked}, sub{$this->autoalign($app->current_data, 'marked')});
  EVT_BUTTON($this, $this->{m5},     sub{$this->add($app->current_data, -5  )});
  EVT_BUTTON($this, $this->{p5},     sub{$this->add($app->current_data,  5  )});
  EVT_BUTTON($this, $this->{m1},     sub{$this->add($app->current_data, -1  )});
  EVT_BUTTON($this, $this->{p1},     sub{$this->add($app->current_data,  1  )});
  EVT_BUTTON($this, $this->{mhalf},  sub{$this->add($app->current_data, -0.5)});
  EVT_BUTTON($this, $this->{phalf},  sub{$this->add($app->current_data,  0.5)});
  EVT_BUTTON($this, $this->{mtenth}, sub{$this->add($app->current_data, -0.1)});
  EVT_BUTTON($this, $this->{ptenth}, sub{$this->add($app->current_data,  0.1)});

  $box -> Add($gbs, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);

  $box->Add(1,1,1);

  $this->{document} = Wx::Button->new($this, -1, 'Document section: alignment');
  $box -> Add($this->{document}, 0, wxGROW|wxALL, 2);
  EVT_BUTTON($this, $this->{document}, sub{  $app->document("process.align")});

  $this->SetSizerAndFit($box);
  return $this;
};

sub pull_values {
  my ($this, $data) = @_;
  1;
};
sub push_values {
  my ($this, $data) = @_;
  $this->{this}  -> SetLabel($data->name);
  ##$this->{shiftlabel} -> SetLabel("Shift " . $data->name . " by");
  $this->{shift} -> SetValue($data->bkg_eshift);
  $this->{error} -> SetEditable(1);
  $this->{error} -> SetValue($data->bkg_delta_eshift);
  $this->{error} -> SetEditable(0);
  my $count = 0;
  foreach my $i (0 .. $::app->{main}->{list}->GetCount - 1) {
    my $data = $::app->{main}->{list}->GetIndexedData($i);
    ++$count if $data->datatype ne 'chi';
  };
  $this->Enable(1);
  if ($count < 2) {
    $this->Enable(0);
    return;
  };
  if ($data->datatype eq 'chi') {
    $this->Enable(0);
    return;
  };
  my $was = $this->{standard}->GetStringSelection;
  $this->{standard}->fill($::app, 1, 1);

  if ((not $was) or ($was eq 'None')) {
    $this->{standard}->SetSelection(0);
  } else {
    $this->{standard}->SetStringSelection($was);
    $this->{standard}->SetSelection(0) if not scalar $this->{standard}->GetSelection;
  };

  # ((not $was) or ($was eq 'None')) ? $this->{standard}->SetSelection(0) : $this->{standard}->SetStringSelection($was);
  # if ((not defined $this->{standard}->GetSelection) or
  #     (not $this->{standard}->GetSelection) or
  #     (not defined $this->{standard}->GetClientData($this->{standard}->GetSelection)) ) {
  #   $this->{standard}->SetSelection(0);
  # };
  return if $::app->{plotting};
  return if ($this->{standard}->GetStringSelection eq 'None');
  my $stan = $this->{standard}->GetClientData(scalar $this->{standard}->GetSelection);
  if (not defined($stan) or ($stan->group eq $data->group)) {
    $::app->{main}->status("Not plotting -- the data and standard are the same!", 'error|nobuffer');
    return;
  } else {
    $this->plot($data);
  };
};
sub mode {
  my ($this, $data, $enabled, $frozen) = @_;
  1;
};

sub OnShift {
  my ($this, $event, $data) = @_;
  return if not looks_like_number($this->{shift}->GetValue);
  $data->bkg_eshift($this->{shift}->GetValue);
};
sub add {
  my ($this, $data, $amount) = @_;
  my $shift = $this->{shift}->GetValue;
  $this->{shift}->SetValue($shift+$amount);
  $this->{error}->SetValue(0);
  $data->bkg_delta_eshift(0);
  $this->plot($data);
  $::app->modified(1);
};

sub autoalign {
  my ($this, $data, $how) = @_;
  my $busy = Wx::BusyCursor->new();
  my $save = $data->po->e_smooth;
  my $stan = $this->{standard}->GetClientData(scalar $this->{standard}->GetSelection);

  if (($how eq 'this') and ($data eq $stan)) {
    $::app->{main}->status("Not aligning -- the data and standard are the same!", 'error|nobuffer');
    return;
  };

  if (not looks_like_number($this->{shift}->GetValue)) {
    $::app->{main}->status("Not aligning -- your shift value cannot be interpreted as a number", 'error|nobuffer');
    return;
  };

  my @all = ($data);
  if ($how eq 'marked') {
    @all = ();
    foreach my $i (0 .. $::app->{main}->{list}->GetCount - 1) {
      next if ($::app->{main}->{list}->GetIndexedData($i) eq $stan);
      push(@all, $::app->{main}->{list}->GetIndexedData($i))
	if $::app->{main}->{list}->IsChecked($i);
    };
    $stan->sentinal(sub{$this->alignment_sentinal});
  };
  $data->po->set(e_smooth=>0);
  $data->po->set(e_smooth=>3) if ($this->{fitas}->GetSelection == 1);
  $stan->align(@all);
  undef $busy;
  $this->{shift}->SetValue($data->bkg_eshift);
  $this->{error}->SetEditable(1);
  $this->{error}->SetValue($data->bkg_delta_eshift);
  $this->{error}->SetEditable(0);
  $this->plot($data);
  $data->po->e_smooth($save);
  $::app->modified(1);
};

sub alignment_sentinal {
  $::app->{main}->status("Aligning " . $::app->current_data->mo->current->name, 'nobuffer');
};

sub plot {
  my ($this, $data) = @_;
  my $busy = Wx::BusyCursor->new();
  my @sg = ($data->co->default("smooth", "sg_size"), $data->co->default("smooth", "sg_order"));
  $data->co->set_default("smooth", "sg_size", 21);
  $data->co->set_default("smooth", "sg_order", 4);

  my $save = $data->po->e_smooth;
  my $stan = $this->{standard}->GetClientData(scalar $this->{standard}->GetSelection);
  if (not defined($stan) or ($stan->group eq $data->group)) {
    $::app->{main}->status("Not plotting -- the data and standard are the same!", 'error|nobuffer');
    return;
  };

  if (not looks_like_number($this->{shift}->GetValue)) {
    $::app->{main}->status("Not plotting -- your shift value cannot be interpreted as a number", 'error|nobuffer');
    return;
  };

  $data->po->set(emin=>-30, emax=>50);
  $data->po->set(e_mu=>1, e_markers=>1, e_bkg=>0, e_pre=>0, e_post=>0, e_norm=>0, e_der=>0, e_sec=>0, e_i0=>0, e_signal=>0, e_smooth=>0);
  $data->po->e_norm(1) if ($this->{plotas}->GetSelection == 1);
  $data->po->e_der(1)  if ($this->{plotas}->GetSelection == 2);
  $data->po->set(e_der=>1, e_smooth=>3)  if ($this->{plotas}->GetSelection == 3);
  $data->po->start_plot;
  $_->plot('e') foreach ($stan, $data);

  $data->co->set_default("smooth", "sg_size",  $sg[0]);
  $data->co->set_default("smooth", "sg_order", $sg[1]);
  $data->po->e_smooth($save);
  $::app->{main}->status("Plotted ".$stan->name." and ".$data->name, 'nobuffer');
  undef $busy;
};

1;


=head1 NAME

Demeter::UI::Athena::Align - An alignment tool for Athena

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

This module provides a

=head1 CONFIGURATION


=head1 DEPENDENCIES

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

=head1 BUGS AND LIMITATIONS

=over 4

=item *

This 'n' that

=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