Debian Codegraph @

athena_parts/truncate.pl

raw
1 ## -*- cperl -*-
2 ##
3 ## This file is part of Athena, copyright (c) 2001-2009 Bruce Ravel
4 ##
5 ## This section of the code contains subroutines associated with
6 ## data truncation
7
8
9 sub truncate_palette {
10 Echo("No data!"), return unless $current;
11 Echo("You must select a data group to truncate"), return
12 if ($current eq "Default Parameters");
13
14 my @keys = ();
15 foreach my $k (&sorted_group_list) {
16 ($groups{$k}->{is_xmu}) and push @keys, $k;
17 };
18 Echo("You need at least one xmu group to truncate"), return unless (@keys);
19 my $group = $groups{$current}->{group};
20 my @e = get_array("$group.energy");
21 $groups{$current} -> make(etruncate=> $e[$#e]);
22 my %trun_params = ( etruncate => sprintf("%.3f", $e[$#e]+0.001),
23 beforeafter => 'after',
24 plot => 'mu(E)' );
25 $hash_pointer = \%trun_params;
26 my $ps = $project_saved;
27 my @save = ($plot_features{emin}, $plot_features{emax});
28 $plot_features{emax} = int(1.1*($trun_params{etruncate} - $groups{$current}->{bkg_e0}));
29 project_state($ps); # don't toggle if currently saved
30
31 $fat_showing = 'truncate';
32 #$hash_pointer = \%trun_params;
33 map {$_ -> configure(-state=>'disabled')}
34 ($data_menu, $merge_menu, $anal_menu, $settings_menu);
35 $fat -> packForget;
36 my $trun = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3)
37 -> pack(-fill=>'both', -expand=>1);
38 #$trun -> packPropagate(0);
39 $which_showing = $trun;
40
41 $trun -> Label(-text=>"Data truncation",
42 -font=>$config{fonts}{large},
43 -foreground=>$config{colors}{activehighlightcolor})
44 -> pack(-side=>'top', -fill=>'x', -anchor=>'w');
45
46 my $frame = $trun -> Frame(-borderwidth=>2, -relief=>'flat')
47 -> pack(-ipadx=>3, -ipady=>3, -fill=>'x');
48 my $fr = $frame -> Frame(-borderwidth=>2, -relief=>'flat')
49 -> pack(-ipadx=>3, -ipady=>3, -side=>'top');
50 $fr -> Label(-text=>"Group:",
51 -foreground=>$config{colors}{activehighlightcolor},
52 )
53 -> pack(-side=>'left');
54 $widget{trun_group} = $fr -> Label(-text=>$groups{$current}->{label},
55 -foreground=>$config{colors}{button})
56 -> pack(-side=>'right');
57
58
59 $fr = $frame -> Frame(-borderwidth=>2, -relief=>'flat')
60 -> pack(-side=>'top', -ipady=>3);
61
62 my $fr2 = $fr -> Frame(-borderwidth=>2, -relief=>'flat') -> pack();
63 $fr2 -> Label(-text=>'Drop points ',
64 -foreground=>$config{colors}{activehighlightcolor},
65 )
66 -> pack(-side=>'left');
67 $fr2 -> Optionmenu(-variable=>\$trun_params{beforeafter},
68 -textvariable=>\$trun_params{beforeafter},
69 -borderwidth=>1,
70 -options=>['before', 'after'],
71 )
72 -> pack(-side=>'left');
73 $fr2 -> Label(-text=>' E =',
74 -foreground=>$config{colors}{activehighlightcolor},
75 )
76 -> pack(-side=>'left');
77 $widget{etruncate} = $fr2 -> RetEntry(-textvariable=>\$trun_params{etruncate},
78 -command=>sub{$widget{trun_replot}->invoke},
79 -width=>10)
80 -> pack(-side=>'left');
81 $grab{etruncate} = $fr2 -> Button(@pluck_button, @pluck,
82 -command=>
83 sub{Echo("\"$groups{$current}->{label}\" is frozen"), return
84 if $groups{$current}->{frozen};
85 &pluck('etruncate');
86 $groups{$current} -> make(etruncate=>
87 $widget{etruncate}->get());
88 my $str;
89 map {$str .= $plot_features{$_}} (qw/e_mu e_norm e_der/);
90 ($str eq "e") and ($str = "em");
91 ($str eq "en") and ($str = "emn");
92 ($str eq "ed") and ($str = "emd");
93 $groups{$current} -> plotE($str,$dmode,\%plot_features, \@indicator);
94 $last_plot = 'e';
95 my $e = $groups{$current}->{etruncate};
96 my $suff = ($str =~ /n/) ? 'norm' : 'xmu';
97 ($suff = 'flat') if (($str =~ /n/) and $groups{$current}->{bkg_flatten});
98 my @x = Ifeffit::get_array("$current.energy");
99 my @y = Ifeffit::get_array("$current.$suff");
100 my ($ymin, $ymax) = Ifeffit::Group->floor_ceil(\@x, \@y, \%plot_features, 'e', $groups{$current}->{bkg_e0});
101 $groups{$current} -> plot_vertical_line($e, $ymin, $ymax,
102 $dmode, "truncate",
103 $groups{$current}->{plot_yoffset});
104 $trun_params{etruncate} = $groups{$current}->{etruncate};
105 })
106 -> pack(-side=>'left');
107
108 $widget{trun_replot} =
109 $fr -> Button(-text=>'Replot', @button_list,
110 -width=>1,
111 -command=>sub{my $str;
112 map {$str .= $plot_features{$_}} (qw/e_mu e_norm e_der/);
113 ($str eq "e") and ($str = "em");
114 ($str eq "en") and ($str = "emn");
115 ($str eq "ed") and ($str = "emd");
116 $groups{$current} -> plotE($str,$dmode,\%plot_features, \@indicator);
117 $last_plot='e';
118 my $g = $groups{$current}->{group};
119 $groups{$current} -> make(etruncate=> $widget{etruncate}->get());
120 my $e = $groups{$current}->{etruncate};
121 my $suff = ($str =~ /n/) ? 'norm' : 'xmu';
122 ($suff = 'flat') if (($str =~ /n/) and $groups{$current}->{bkg_flatten});
123 my @x = Ifeffit::get_array("$current.energy");
124 my @y = Ifeffit::get_array("$current.$suff");
125 my ($ymin, $ymax) = Ifeffit::Group->floor_ceil(\@x, \@y, \%plot_features, 'e', $groups{$current}->{bkg_e0});
126 $groups{$current} -> plot_vertical_line($e, $ymin, $ymax,
127 $dmode, "truncate",
128 $groups{$current}->{plot_yoffset});
129 })
130 -> pack(-expand=>1, -fill=>'x');
131
132 $widget{trun_truncate} =
133 $fr -> Button(-text=>'Truncate data', @button_list,
134 -width=>1,
135 -command=>sub{Echo("Truncation aborted: \"$groups{$current}->{label}\" is frozen"), return
136 if $groups{$current}->{frozen};
137 &truncate_data($current,0,$trun_params{beforeafter});
138 $widget{trun_replot} -> invoke;
139 $top -> update;})
140 -> pack(-expand=>1, -fill=>'x');
141 $widget{trun_truncate} =
142 $fr -> Button(-text=>'Truncate marked groups', @button_list,
143 -width=>1,
144 -command=>sub{
145 Echo("Truncating marked groups ...");
146 $top -> Busy;
147 my $restore = $current;
148 foreach my $g (&sorted_group_list) {
149 next unless $marked{$g};
150 next if $groups{$g}->{frozen};
151 set_properties(0, $g, 0);
152 &truncate_data($current,0,$trun_params{beforeafter});
153 $widget{trun_replot} -> invoke;
154 };
155 set_properties(1, $restore, 0);
156 $top -> Unbusy;
157 Echo("Truncating marked groups ... done!");
158 $top -> update;
159 })
160 -> pack(-expand=>1, -fill=>'x');
161
162
163 ## help button
164 $trun -> Button(-text=>'Document section: truncating data', @button_list,
165 -command=>sub{pod_display("process::trun.pod")})
166 -> pack(-fill=>'x', -pady=>4);
167
168 $trun -> Button(-text=>'Return to the main window', @button_list,
169 -background=>$config{colors}{background2},
170 -activebackground=>$config{colors}{activebackground2},
171 -command=>sub{&reset_window($trun, "truncation", \@save)}
172 )
173 -> pack(-fill=>'x');
174 $trun -> Frame(-background=>$config{colors}{darkbackground})
175 -> pack(-expand=>1, -fill=>'both');
176
177 my $str;
178 map {$str .= $plot_features{$_}} (qw/e_mu e_norm e_der/);
179 ($str eq "e") and ($str = "em");
180 ($str eq "en") and ($str = "emn");
181 ($str eq "ed") and ($str = "emd");
182 $groups{$current} -> plotE($str,$dmode,\%plot_features, \@indicator);
183 my $e = $groups{$current}->{etruncate};
184 my $suff = ($str =~ /n/) ? 'norm' : 'xmu';
185 ($suff = 'flat') if (($str =~ /n/) and $groups{$current}->{bkg_flatten});
186 my @x = Ifeffit::get_array("$current.energy");
187 my @y = Ifeffit::get_array("$current.$suff");
188 my ($ymin, $ymax) = Ifeffit::Group->floor_ceil(\@x, \@y, \%plot_features, 'e', $groups{$current}->{bkg_e0});
189 $groups{$current} -> plot_vertical_line($e, $ymin, $ymax, $dmode, "truncate",
190 $groups{$current}->{plot_yoffset});
191 $last_plot='e';
192 $plotsel -> raise('e');
193 $top -> update;
194 };
195
196
197 sub truncate_data {
198 my $g = $_[0];
199 Error("Truncation aborted: " . $groups{$g}->{label} . " is not an xmu group."),
200 return unless ($groups{$g}->{is_xmu});
201 my $etrun = $groups{$g}->{etruncate};
202 my $noplot = $_[1];
203 my $beforeafter = $_[2];
204 my @x = Ifeffit::get_array("$g.energy");
205 my @y = Ifeffit::get_array("$g.xmu");
206 my @i0 = Ifeffit::get_array($groups{$g}->{i0});
207 my $is_i0 = ($#i0 > 0) ? 1 : 0;
208 if (($etrun < $x[0]) or ($etrun > $x[-1])) {
209 Echo("Truncation aborted: truncation energy is outside the data range for $groups{$g}->{label}");
210 return;
211 };
212 #my (@newx, @newy);
213 my $last = 0;
214 foreach (0 .. $#x) {
215 $last = $_ -1, last if ($x[$_] > $etrun);
216 #$newx[$_] = $x[$_];
217 #$newy[$_] = $y[$_];
218 #print "$g $etrun $x[$_]\n";
219 };
220 if ($beforeafter eq 'after') {
221 $#x = $last;
222 $#y = $last;
223 $#i0 = $last if $is_i0;
224 } else {
225 @x = @x[ $last+1 .. $#x];
226 @y = @y[ $last+1 .. $#y];
227 @i0 = @i0[$last+1 .. $#i0] if $is_i0;
228 };
229 #$groups{$g}->dispose("erase $g.energy", $dmode);
230 #$groups{$g}->dispose("erase $g.xmu", $dmode);
231 Ifeffit::put_array("$g.energy", \@x);
232 Ifeffit::put_array("$g.xmu", \@y);
233 Ifeffit::put_array($groups{$g}->{i0}, \@i0) if $is_i0;
234 #$groups{$g}->dispose("show $g.energy", $dmode);
235
236 ## reset the various range parameters
237 my ($pre1, $pre2, $nor1, $nor2, $spl1, $spl2, $kmin, $kmax) =
238 set_range_params($g);
239 my $e0 = $groups{$g}->{bkg_e0};
240 if ($beforeafter eq 'after') {
241 $groups{$g}->dispose("set ___x = ceil($g.energy)\n");
242 my $maxe = Ifeffit::get_scalar("___x");
243 $groups{$g} -> make(bkg_nor1 => $nor1,
244 update_bkg => 1) if ($maxe < $groups{$g}->{bkg_nor1}+$e0);
245 $groups{$g} -> make(bkg_nor2 => $nor2,
246 update_bkg => 1) if ($maxe < $groups{$g}->{bkg_nor2}+$e0);
247 $groups{$g} -> make(bkg_spl1 => $spl1,
248 bkg_spl1e => $groups{$g}->k2e($spl1),
249 update_bkg => 1) if ($maxe < $groups{$g}->{bkg_spl1e}+$e0);
250 $groups{$g} -> make(bkg_spl2 => $spl2,
251 bkg_spl2e => $groups{$g}->k2e($spl2),
252 update_bkg => 1) if ($maxe < $groups{$g}->{bkg_spl2e}+$e0);
253 $groups{$g} -> make(fft_kmax => $kmax,
254 update_fft => 1) if ($groups{$g}->e2k($maxe) > $groups{$g}->{fft_kmax});
255 } else {
256 $groups{$g}->dispose("set ___x = floor($g.energy)\n");
257 my $mine = Ifeffit::get_scalar("___x");
258 $groups{$g} -> make(bkg_pre1 => $pre1,
259 update_bkg => 1) if ($mine > $groups{$g}->{bkg_pre1}+$e0);
260 $groups{$g} -> make(bkg_pre2 => $pre2,
261 update_bkg => 1) if ($mine > $groups{$g}->{bkg_pre2}+$e0);
262 };
263 $groups{$g} -> kmax_suggest(\%plot_features) if ($groups{$g}->{fft_kmax} == 999);
264 unless ($noplot) {
265 my $str;
266 map {$str .= $plot_features{$_}} (qw/e_mu e_norm e_der/);
267 ($str eq "e") and ($str = "em");
268 ($str eq "en") and ($str = "emn");
269 ($str eq "ed") and ($str = "emd");
270 $groups{$g} -> plotE($str,$dmode,\%plot_features, \@indicator);
271 $last_plot='e';
272 };
273 project_state(0);
274 };
275
276
277
278 ## END OF DATA TRUNCATION SUBSECTION
279 ##########################################################################################