Debian Codegraph @

athena_parts/smooth.pl

raw
1 ## -*- cperl -*-
2 ##
3 ## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel
4 ##
5 ## This section of the code contains subroutines associated with
6 ## smoothing data.
7
8
9
10 sub smooth {
11 Echo("No data!"), return unless $current;
12 Echo("No data!"), return if ($current eq "Default Parameters");
13 my @keys = ();
14 foreach my $k (&sorted_group_list) {
15 ($groups{$k}->{is_xmu}) and push @keys, $k;
16 };
17 my $g = ($groups{$current}->{is_xmu}) ? $current : $keys[0];
18 my $g_label = $groups{$g}->{label};
19
20 my $mode = 0;
21 my $grey = '#9c9583';
22 my $ahc = $config{colors}{activehighlightcolor};
23 my %smooth_params = (rmax=>$config{smooth}{rmax},
24 nit =>$config{smooth}{iterations});
25
26 $fat_showing = 'smooth';
27 $hash_pointer = \%smooth_params;
28 map {$_ -> configure(-state=>'disabled')}
29 ($data_menu, $merge_menu, $anal_menu, $settings_menu);
30 $fat -> packForget;
31 my $sm = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3)
32 -> pack(-fill=>'both', -expand=>1);
33 #$sm -> packPropagate(0);
34 $which_showing = $sm;
35
36 $sm -> Label(-text=>"Data smoothing",
37 -font=>$config{fonts}{large},
38 -foreground=>$ahc)
39 -> pack(-side=>'top', -fill=>'x', -anchor=>'w');
40
41 my $frame = $sm -> Frame(-borderwidth=>2, -relief=>'flat')
42 -> pack(-ipadx=>3, -ipady=>3, -fill=>'x'); ## select the group to smooth
43 my $fr = $frame -> Frame(-borderwidth=>2, -relief=>'flat')
44 -> pack(-side=>'top', -ipady=>3, -ipady=>3);
45 $fr -> Label(-text=>"Group: ",
46 -foreground=>$config{colors}{activehighlightcolor},
47 )
48 -> grid(-row=>0, -column=>0, -sticky=>'e');
49 $widget{sm_group} = $fr -> Label(-text=>$groups{$current}->{label},
50 -foreground=>$config{colors}{button})
51 -> grid(-row=>0, -column=>1, -sticky=>'w');
52
53 $sm -> Frame(-background=>$config{colors}{darkbackground})
54 -> pack(-side=>'bottom', -expand=>1, -fill=>'both');
55 $sm -> Button(-text=>'Return to the main window', @button_list,
56 -background=>$config{colors}{background2},
57 -activebackground=>$config{colors}{activebackground2},
58 -command=>sub{&reset_window($sm, "smoothing", 0);})
59 -> pack(-side=>'bottom', -fill=>'x');
60 ## help button
61 $sm -> Button(-text=>'Document section: data smoothing', @button_list,
62 -command=>sub{pod_display("process::smooth.pod")})
63 -> pack(-side=>'bottom', -fill=>'x', -pady=>4);
64
65 ## frame with widgets in
66 $fr = $frame -> Frame()
67 -> pack(-fill=>'both');
68 ## choose smoothing method
69 $widget{sm_it_button} =
70 $fr ->
71 Radiobutton(-text=>"Interpolative smoothing", -variable=>\$mode, -value=>0,
72 -foreground=>$config{colors}{activehighlightcolor},
73 -activeforeground=>$config{colors}{activehighlightcolor},
74 -command=>sub{$widget{sm_it_lab}->configure(-foreground=>$ahc);
75 $widget{sm_it_ent}->configure(-state=>'normal');
76 $widget{sm_ff_lab}->configure(-foreground=>$grey);
77 $widget{sm_ff_ent}->configure(-state=>'disabled');
78 })
79 -> grid(-row=>0, -column=>0, -ipady=>4);
80 $widget{sm_it_lab} = $fr -> Label(-text=>" ",)
81 -> grid(-row=>0, -column=>1, -sticky=>'e');
82 $widget{sm_it_lab} = $fr -> Label(-text=>"Number of iterations:",
83 -foreground=>$config{colors}{activehighlightcolor},
84 )
85 -> grid(-row=>0, -column=>2, -sticky=>'e');
86 $widget{sm_it_ent} = $fr -> NumEntry(-width=>4, -value=>10, -minvalue=>1,
87 -foreground=>$config{colors}{foreground})
88 -> grid(-row=>0, -column=>3, -sticky=>'w');
89 $widget{sm_ff_button} =
90 $fr -> Radiobutton(-text=>"Fourier filter smoothing", -variable=>\$mode, -value=>1,
91 -foreground=>$config{colors}{activehighlightcolor},
92 -activeforeground=>$config{colors}{activehighlightcolor},
93 -command=>sub{$widget{sm_it_lab}->configure(-foreground=>$grey);
94 $widget{sm_it_ent}->configure(-state=>'disabled');
95 $widget{sm_ff_lab}->configure(-foreground=>$ahc);
96 $widget{sm_ff_ent}->configure(-state=>'normal');
97 })
98 -> grid(-row=>1, -column=>0, -ipady=>4);
99 $widget{sm_ff_lab} = $fr -> Label(-text=>"Rmax:",
100 -foreground=>$grey,
101 )
102 -> grid(-row=>1, -column=>2, -sticky=>'e');
103 $widget{sm_ff_ent} = $fr -> Entry(-width=>8, )
104 -> grid(-row=>1, -column=>3, -sticky=>'w');
105
106 ## buttons for doing smoothing and making smoothed group
107 $fr = $frame -> Frame(-borderwidth=>2, -relief=>'flat')
108 -> pack(-side=>'top', -fill=>'x', -padx=>2, -pady=>2, -ipadx=>2, -ipady=>2);
109 $widget{sm_plot} =
110 $fr -> Button(-text=>'Plot data and smoothed spectrum', @button_list,
111 -width=>1,
112 -command=>sub{&do_smoothing($current, $mode, $widget{sm_it_ent}->get,
113 $widget{sm_ff_ent}->get);
114 $widget{sm_save} -> configure(-state=>'normal'); })
115 -> pack(-fill=>'x', -expand=>1, -side=>'left');
116 $widget{sm_save} = $fr -> Button(-text=>'Make smoothed data group', @button_list,
117 -width=>1,
118 -state=>'disabled',
119 -command=>sub{&smooth_group($current, $mode,
120 $widget{sm_it_ent}->get,
121 $widget{sm_ff_ent}->get)})
122 -> pack(-fill=>'x', -expand=>1, -side=>'left');
123
124 $widget{sm_ff_ent} -> insert(0, '6');
125 $widget{sm_ff_ent} -> configure(-state=>'disabled');
126
127 $plotsel -> raise('e');
128 };
129
130
131 sub do_smoothing {
132 my ($group, $mode, $nit, $rmax) = @_;
133 Error("Smoothing aborted: " . $groups{$group}->{label} . " is not an xmu group."),
134 return unless ($groups{$group}->{is_xmu});
135 my $e0shift = $groups{$group}->{bkg_eshift};
136
137 SWITCH: {
138 ($mode == 0) and do { # interpolative
139 $groups{$group} -> dispose("set $group.smoothed = $group.xmu", $dmode);
140 foreach (1 .. $nit) {
141 $groups{$group} -> dispose("set $group.temp = smooth($group.smoothed) # $_", $dmode);
142 $groups{$group} -> dispose("set $group.smoothed = $group.temp", $dmode);
143 $groups{$group} -> dispose("erase $group.temp", $dmode);
144 Echo("Smoothed $groups{$group}->{label} using $nit smoothing iterations");
145 };
146 last SWITCH;
147 };
148 ($mode == 1) and do { # Fourier filter
149 $groups{$group} -> dispose("min_e = floor($group.energy)", $dmode);
150 $groups{$group} -> dispose("set tem___p.k = sqrt(($group.energy + $e0shift - min_e)*etok)", $dmode);
151 $groups{$group} -> dispose("set max_k = ceil(tem___p.k)", $dmode);
152 $groups{$group} -> dispose("set tem___p.kk = range(0, max_k, 0.01)", $dmode);
153 $groups{$group} -> dispose("set tem___p.xk = interp(tem___p.k, $group.xmu, tem___p.kk)",
154 $dmode);
155 ## build a symmetric function by doing a mirror transform at the end
156 ## of the data range
157 my @xarr = get_array("tem___p.kk");
158 my @x = ();
159 push @x, @xarr;
160 map {push @x, $xarr[$#xarr]+$_} @xarr; # this doubles the x-axis grid
161
162 my @backhalf = get_array("tem___p.xk");
163 my @y = ();
164 push @y, @backhalf;
165 @backhalf = reverse @backhalf;
166 push @y, @backhalf; # this is the data + the mirror of the data
167
168 ## stuff the mirrored data back into ifeffit
169 put_array("tem___p.x", \@x);
170 put_array("tem___p.y", \@y);
171
172 $groups{$group} -> dispose("## put mirrored arrays back into Ifeffit's memory ...", $dmode);
173 $groups{$group} -> dispose("fftf(tem___p.y, k=tem___p.x, kmin=0, kmax=2*max_k, dk=0)", $dmode);
174 #$groups{$group} -> dispose("show \@group tem___p", $dmode);
175 $groups{$group} -> dispose("fftr(real=tem___p.chir_re, imag=tem___p.chir_im, rmin=0, rmax=$rmax, dr=0)", $dmode);
176 $groups{$group} -> dispose("set $group.smoothed = interp(tem___p.q, tem___p.chiq_re, tem___p.k)", $dmode);
177 $groups{$group} -> dispose("erase \@group tem___p", $dmode);
178 Echo("Smoothed $groups{$group}->{label} by Fourier filtering to $rmax Angstroms");
179 last SWITCH;
180 };
181 };
182 ## plot it up
183 $groups{$group} -> plotE('em', $dmode, \%plot_features, \@indicator);
184 my $color = $plot_features{c1};
185 $groups{$group} -> dispose("plot(\"$group.energy+$e0shift\", $group.smoothed, style=lines, color=\"$color\", key=smoothed)", $dmode);
186 $last_plot='e';
187 };
188
189
190 sub smooth_group {
191 my ($parent, $mode, $nit, $rmax) = @_;
192 my ($group, $label) = ("SM ".$groups{$parent}->{label}, "");
193 ($group, $label) = group_name($group);
194 $groups{$group} = Ifeffit::Group -> new(group=>$group, label=>$label);
195 ## copy the titles
196 if ($mode == 0) {
197 push @{$groups{$group}->{titles}},
198 "$groups{$parent}->{label} smoothed by interpolative smoothing with $nit iterations";
199 $groups{$group} -> make(file=>"$groups{$parent}->{label} smoothed by interpolative smoothing with $nit iterations");
200 } elsif ($mode == 1) {
201 push @{$groups{$group}->{titles}},
202 "$groups{$parent}->{label} smoothed by Fourier filtering to $rmax Angstroms";
203 $groups{$group} -> make(file=>"$groups{$parent}->{label} smoothed by Fourier filtering to $rmax Angstroms");
204 };
205 foreach (@{$groups{$parent}->{titles}}) {
206 push @{$groups{$group}->{titles}}, $_;
207 };
208 $groups{$group} -> put_titles;
209 $groups{$group} -> set_to_another($groups{$parent});
210 $groups{$group} -> make(is_xmu => 1, is_chi => 0, is_rsp => 0, is_qsp => 0, is_bkg => 0,
211 not_data => 0,);
212 $groups{$group} -> dispose("set($group.energy = $parent.energy, $group.xmu = $parent.smoothed)", $dmode);
213 $groups{$group} -> dispose("erase $parent.smoothed", $dmode);
214 ++$line_count;
215 fill_skinny($list, $group, 1);
216 my $memory_ok = $groups{$group} -> memory_check($top, \&Echo, \%groups, $max_heap, 0, 0);
217 Echo ("WARNING: Ifeffit is out of memory!") if ($memory_ok == -1);
218 };
219
220
221
222 ## END OF DATA SMOOTHING SUBSECTION
223 ##########################################################################################