| 1 |
|
| 2 |
## -*- cperl -*- |
| 3 |
## |
| 4 |
## This file is part of Athena, copyright (c) 2001-2009 Bruce Ravel |
| 5 |
## |
| 6 |
## This section of the code contains subroutines associated with |
| 7 |
## log-ratio/phase-difference analysis |
| 8 |
|
| 9 |
|
| 10 |
## missing features in the log-ratio interface: |
| 11 |
## -- widget for window functions |
| 12 |
|
| 13 |
|
| 14 |
## pop-up a palette for performing log-ratio/phase-difference analysis |
| 15 |
## between two scans |
| 16 |
sub log_ratio { |
| 17 |
Echo("No data!"), return unless $current; |
| 18 |
my $color = $plot_features{c1}; |
| 19 |
my %widg; |
| 20 |
my @cumul = (0, 0, 0, 0, 0); |
| 21 |
my @delta = (0, 0, 0, 0, 0); |
| 22 |
|
| 23 |
Echo("No data!"), return if ($current eq "Default Parameters"); |
| 24 |
|
| 25 |
my @keys = (); |
| 26 |
foreach my $k (&sorted_group_list) { |
| 27 |
(($groups{$k}->{is_xmu}) or ($groups{$k}->{is_chi})) and push @keys, $k; |
| 28 |
}; |
| 29 |
Echo("You need two or more xmu or chi groups to do log-ratio/phase-difference analysis"), |
| 30 |
return unless ($#keys >= 1); |
| 31 |
|
| 32 |
$widg{standard} = $keys[0]; |
| 33 |
$widg{keys} = \@keys; |
| 34 |
my $standard_label = "1:".$groups{$widg{standard}}->{label}; |
| 35 |
if ($widg{standard} eq $current) { # make sure $current is sensible given |
| 36 |
set_properties(1, $keys[1], 0); # that $keys[0] is the standard |
| 37 |
# adjust the view |
| 38 |
my $here = ($list->bbox($groups{$current}->{text}))[1] - 5 || 0; |
| 39 |
($here < 0) and ($here = 0); |
| 40 |
my $full = ($list->bbox(@skinny_list))[3] + 5; |
| 41 |
$list -> yview('moveto', $here/$full); |
| 42 |
}; |
| 43 |
$fat_showing = 'lograt'; |
| 44 |
$hash_pointer = \%widg; |
| 45 |
map {$_ -> configure(-state=>'disabled')} |
| 46 |
($data_menu, $merge_menu, $anal_menu, $settings_menu); |
| 47 |
$fat -> packForget; |
| 48 |
my $lr = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3) |
| 49 |
-> pack(-fill=>'both', -expand=>1); |
| 50 |
#$lr -> packPropagate(0); |
| 51 |
$which_showing = $lr; |
| 52 |
|
| 53 |
## select the standard |
| 54 |
my $frame = $lr -> Frame(-borderwidth=>2, -relief=>'flat') |
| 55 |
-> pack(-side=>'top', -fill=>'x'); |
| 56 |
|
| 57 |
$frame -> Label(-text=>"Log-Ratio/Phase-Difference Analysis", |
| 58 |
-font=>$config{fonts}{large}, |
| 59 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 60 |
-> grid(-row=>0, -column=>0, -columnspan=>2); |
| 61 |
|
| 62 |
$frame -> Label(-text=>"Standard: ", |
| 63 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 64 |
) |
| 65 |
-> grid(-row=>1, -column=>0, -sticky=>'e', -pady=>2); |
| 66 |
|
| 67 |
$widget{lr_menu} = $frame -> BrowseEntry(-variable => \$standard_label, |
| 68 |
@browseentry_list, |
| 69 |
-browsecmd => sub { |
| 70 |
my $text = $_[1]; |
| 71 |
my $this = $1 if ($text =~ /^(\d+):/); |
| 72 |
Echo("Failed to match in browsecmd. Yikes! Complain to Bruce."), return unless $this; |
| 73 |
$this -= 1; |
| 74 |
$widg{standard}=$widg{keys}->[$this]; |
| 75 |
#$standard_lab="$groups{$s}->{label} ($s)"; |
| 76 |
&reset_lr_data(\%widg, $widg{standard}, $current); |
| 77 |
@cumul = (1, 0, 0, 0, 0); |
| 78 |
}) |
| 79 |
-> grid(-row=>1, -column=>1, -sticky=>'w', -pady=>2); |
| 80 |
my $i = 1; |
| 81 |
foreach my $s (@keys) { |
| 82 |
$widget{lr_menu} -> insert("end", "$i: $groups{$s}->{label}"); |
| 83 |
++$i; |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
## select the unknown group |
| 88 |
$frame -> Label(-text=>"Unknown: ", |
| 89 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 90 |
) |
| 91 |
-> grid(-row=>2, -column=>0, -sticky=>'e', -pady=>2); |
| 92 |
$widget{lr_unknown} = $frame -> Label(-text=>$groups{$current}->{label}, |
| 93 |
-foreground=>$config{colors}{button}) |
| 94 |
-> grid(-row=>2, -column=>1, -sticky=>'w', -pady=>2, -padx=>2); |
| 95 |
|
| 96 |
$lr -> Frame(-background=>$config{colors}{darkbackground}) |
| 97 |
-> pack(-side=>'bottom', -expand=>1, -fill=>'both'); |
| 98 |
$lr -> Button(-text=>'Return to the main window', @button_list, |
| 99 |
-background=>$config{colors}{background2}, |
| 100 |
-activebackground=>$config{colors}{activebackground2}, |
| 101 |
-command=>sub{$groups{$current}->dispose("clean_lograt", $dmode); |
| 102 |
&reset_window($lr, "log-ratio analysis", 0); |
| 103 |
set_properties(1, $current, 0); |
| 104 |
}) |
| 105 |
-> pack(-side=>'bottom', -fill=>'x'); |
| 106 |
|
| 107 |
## help button |
| 108 |
$lr -> Button(-text=>'Document section: log ratio/phase difference analysis', @button_list, |
| 109 |
-command=>sub{pod_display("analysis::lr.pod")}) |
| 110 |
-> pack(-side=>'bottom', -fill=>'x', -pady=>4); |
| 111 |
|
| 112 |
## frame with fit params |
| 113 |
$frame = $lr -> LabFrame(-label => 'Fourier transform and fitting parameters', |
| 114 |
-foreground => $config{colors}{activehighlightcolor}, |
| 115 |
-labelside => 'acrosstop') |
| 116 |
-> pack(-fill=>'x', -padx=>3); |
| 117 |
|
| 118 |
$frame -> Label(-text=>"k-range of FT: ", |
| 119 |
) |
| 120 |
-> grid(-row=>0, -column=>0, -sticky=>'e'); |
| 121 |
$widget{lr_kmin} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 122 |
-validate=>'key', |
| 123 |
-validatecommand=>[\&set_lr_variable, 'lr_kmin'] |
| 124 |
) |
| 125 |
-> grid(-row=>0, -column=>1); |
| 126 |
$grab{lr_kmin} = $frame -> Button(@pluck_button, @pluck, -command=>[\&pluck, 'lr_kmin']) |
| 127 |
-> grid(-row=>0, -column=>2); |
| 128 |
$frame -> Label(-text=>" : ") |
| 129 |
-> grid(-row=>0, -column=>3); |
| 130 |
$widget{lr_kmax} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 131 |
-validate=>'key', |
| 132 |
-validatecommand=>[\&set_lr_variable, 'lr_kmax'] |
| 133 |
) |
| 134 |
-> grid(-row=>0, -column=>4); |
| 135 |
$grab{lr_kmax} = $frame -> Button(@pluck_button, @pluck, -command=>[\&pluck, 'lr_kmax']) |
| 136 |
-> grid(-row=>0, -column=>5); |
| 137 |
|
| 138 |
$frame -> Label(-text=>"k-weight: ", |
| 139 |
) |
| 140 |
-> grid(-row=>1, -column=>0, -sticky=>'e'); |
| 141 |
$widget{lr_kw} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 142 |
-validate=>'key', |
| 143 |
-validatecommand=>[\&set_lr_variable, 'lr_kw'] |
| 144 |
) |
| 145 |
-> grid(-row=>1, -column=>1); |
| 146 |
$frame -> Label(-text=>"dk: ", |
| 147 |
) |
| 148 |
-> grid(-row=>1, -column=>3, -sticky=>'e'); |
| 149 |
$widget{lr_dk} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 150 |
-validate=>'key', |
| 151 |
-validatecommand=>[\&set_lr_variable, 'lr_dk'] |
| 152 |
) |
| 153 |
-> grid(-row=>1, -column=>4); |
| 154 |
|
| 155 |
$frame -> Label(-text=>"R-range of BFT: ", |
| 156 |
) |
| 157 |
-> grid(-row=>2, -column=>0, -sticky=>'e'); |
| 158 |
$widget{lr_rmin} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 159 |
-validate=>'key', |
| 160 |
-validatecommand=>[\&set_lr_variable, 'lr_rmin'] |
| 161 |
) |
| 162 |
-> grid(-row=>2, -column=>1); |
| 163 |
$grab{lr_rmin} = $frame -> Button(@pluck_button, @pluck, -command=>[\&pluck, 'lr_rmin']) |
| 164 |
-> grid(-row=>2, -column=>2); |
| 165 |
$frame -> Label(-text=>" : ") |
| 166 |
-> grid(-row=>2, -column=>3,); |
| 167 |
$widget{lr_rmax} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 168 |
-validate=>'key', |
| 169 |
-validatecommand=>[\&set_lr_variable, 'lr_rmax'] |
| 170 |
) |
| 171 |
-> grid(-row=>2, -column=>4); |
| 172 |
$grab{lr_rmax} = $frame -> Button(@pluck_button, @pluck, -command=>[\&pluck, 'lr_rmax']) |
| 173 |
-> grid(-row=>2, -column=>5); |
| 174 |
|
| 175 |
$frame -> Label(-text=>"2pi jump: ", |
| 176 |
) |
| 177 |
-> grid(-row=>3, -column=>0, -sticky=>'e'); |
| 178 |
$widget{lr_npi} = $frame -> NumEntry(-width=>4, -orient=>'horizontal', |
| 179 |
-foreground=>$config{colors}{foreground}) |
| 180 |
-> grid(-row=>3, -column=>1, -sticky=>'w'); |
| 181 |
$frame -> Label(-text=>"dr: ", |
| 182 |
) |
| 183 |
-> grid(-row=>3, -column=>3, -sticky=>'e'); |
| 184 |
$widget{lr_dr} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 185 |
-validate=>'key', |
| 186 |
-validatecommand=>[\&set_lr_variable, 'lr_dr'] |
| 187 |
) |
| 188 |
-> grid(-row=>3, -column=>4, -sticky=>'w'); |
| 189 |
|
| 190 |
$frame -> Label(-text=>"k-range of fit: ", |
| 191 |
) |
| 192 |
-> grid(-row=>4, -column=>0, -sticky=>'e'); |
| 193 |
$widget{lr_fmin} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 194 |
-validate=>'key', |
| 195 |
-validatecommand=>[\&set_lr_variable, 'lr_fmin'] |
| 196 |
) |
| 197 |
-> grid(-row=>4, -column=>1); |
| 198 |
$grab{lr_fmin} = $frame -> Button(@pluck_button, @pluck, -command=>[\&pluck, 'lr_fmin']) |
| 199 |
-> grid(-row=>4, -column=>2); |
| 200 |
$frame -> Label(-text=>" : ") |
| 201 |
-> grid(-row=>4, -column=>3,); |
| 202 |
$widget{lr_fmax} = $frame -> Entry(-width=>8, -font=>$config{fonts}{entry}, |
| 203 |
-validate=>'key', |
| 204 |
-validatecommand=>[\&set_lr_variable, 'lr_fmax'] |
| 205 |
) |
| 206 |
-> grid(-row=>4, -column=>4); |
| 207 |
$grab{lr_fmax} = $frame -> Button(@pluck_button, @pluck, -command=>[\&pluck, 'lr_fmax']) |
| 208 |
-> grid(-row=>4, -column=>5); |
| 209 |
|
| 210 |
## $frame -> Label(-text=>"window function:") |
| 211 |
## -> grid(-row=>5, -column=>0, -sticky=>'e'); |
| 212 |
## $widget{lr_win} = $frame -> Optionmenu(-font=>$config{fonts}{small}, |
| 213 |
## -textvariable => \$menus{fft_win},) |
| 214 |
## -> grid(-row=>5, -column=>1, -columnspan=>4, -sticky=>'w'); |
| 215 |
## foreach my $i ($setup->Windows) { |
| 216 |
## $widget{lr_win} -> command(-label => $i, |
| 217 |
## -command=>sub{$menus{fft_win}=$i; |
| 218 |
## project_state(0); |
| 219 |
## $groups{$current}->make(fft_win=>$i, |
| 220 |
## update_fft=>1)}); |
| 221 |
## }; |
| 222 |
|
| 223 |
## frame with fit button |
| 224 |
$frame = $lr -> Frame(-borderwidth=>0, -relief=>'flat') |
| 225 |
-> pack(-fill=>'x', -padx=>3, -pady=>0, -ipadx=>2, -ipady=>0); |
| 226 |
|
| 227 |
$widget{lr_fit} = |
| 228 |
$frame -> Button(-text=>'Fit', @button_list, |
| 229 |
-command=>sub{my $ok = &do_lr_fit($widg{standard}, $current); |
| 230 |
return unless $ok; |
| 231 |
## post cumulant values; |
| 232 |
@cumul[0..2] = |
| 233 |
map {sprintf("%.5f", Ifeffit::get_scalar("c___" . $_))} |
| 234 |
(0 .. 2); |
| 235 |
@cumul[3..4] = |
| 236 |
map {sprintf("%.8f", Ifeffit::get_scalar("c___" . $_))} |
| 237 |
(3 .. 4); |
| 238 |
@delta[0..2] = |
| 239 |
map {sprintf("%.5f", Ifeffit::get_scalar("delta_c___" . $_))} |
| 240 |
(0 .. 2); |
| 241 |
@delta[3..4] = |
| 242 |
map {sprintf("%.8f", Ifeffit::get_scalar("delta_c___" . $_))} |
| 243 |
(3 .. 4); |
| 244 |
$widg{l0} -> |
| 245 |
configure(-text=>sprintf("%.5f +/- %.5f", |
| 246 |
exp($cumul[0]), |
| 247 |
$delta[0]*exp($cumul[0]))); |
| 248 |
map {$widg{"l".$_} -> |
| 249 |
configure(-text=>"$cumul[$_] +/- $delta[$_]")} (1..4); |
| 250 |
map {$widget{'lr_'.$_}->configure(-state=>'normal')} (qw(lr pd save log)); |
| 251 |
}) |
| 252 |
-> pack(-expand=>1, -fill=>'x'); |
| 253 |
|
| 254 |
|
| 255 |
## frame with plot buttons |
| 256 |
$frame = $lr -> LabFrame(-label => 'Plot standard and unknown in', |
| 257 |
-foreground => $config{colors}{activehighlightcolor}, |
| 258 |
-labelside => 'acrosstop') |
| 259 |
-> pack(-side=>'bottom', -fill=>'x', -padx=>3, -pady=>2, -ipadx=>2, -ipady=>2); |
| 260 |
|
| 261 |
$widget{lr_plotk} = |
| 262 |
$frame -> Button(-text=>'k', @button_list, |
| 263 |
-command=>sub{ |
| 264 |
$groups{$widg{standard}}->plot_marked($plot_features{k_w}, $dmode, \%groups, |
| 265 |
{$widg{standard}=>1, $current=>1}, |
| 266 |
\%plot_features, $list, \@indicator); |
| 267 |
$last_plot='k'; |
| 268 |
$last_plot_params = [$current, 'marked', 'k', $plot_features{k_w}]; |
| 269 |
$groups{$widg{standard}}->plot_window(0, 'k', $dmode, $config{plot}{c2}, \%plot_features); |
| 270 |
map { $grab{$_} -> configure(-state=>'normal') } |
| 271 |
(qw(lr_kmin lr_kmax lr_fmin lr_fmax)); |
| 272 |
map { $grab{$_} -> configure(-state=>'disabled') } |
| 273 |
(qw(lr_rmin lr_rmax)); |
| 274 |
}) |
| 275 |
-> pack(-side=>'left', -expand=>1, -fill=>'x'); |
| 276 |
$widget{lr_plotr} = |
| 277 |
$frame -> Button(-text=>'R', @button_list, |
| 278 |
-command=>sub{ |
| 279 |
$groups{$widg{standard}}->plot_marked($plot_features{r_marked}, $dmode, \%groups, |
| 280 |
{$widg{standard}=>1, $current=>1}, |
| 281 |
\%plot_features, $list, \@indicator); |
| 282 |
$last_plot='r'; |
| 283 |
$last_plot_params = [$current, 'marked', 'r', $plot_features{r_marked}]; |
| 284 |
$groups{$widg{standard}}->plot_window(0, 'r', $dmode, $config{plot}{c2}, \%plot_features); |
| 285 |
map { $grab{$_} -> configure(-state=>'disabled') } |
| 286 |
(qw(lr_kmin lr_kmax lr_fmin lr_fmax)); |
| 287 |
map { $grab{$_} -> configure(-state=>'normal') } |
| 288 |
(qw(lr_rmin lr_rmax)); |
| 289 |
}) |
| 290 |
-> pack(-side=>'left', -expand=>1, -fill=>'x'); |
| 291 |
$widget{lr_plotq} = |
| 292 |
$frame -> Button(-text=>'q', @button_list, |
| 293 |
-command=>sub{ |
| 294 |
$groups{$widg{standard}}->plot_marked($plot_features{q_marked}, $dmode, \%groups, |
| 295 |
{$widg{standard}=>1, $current=>1}, |
| 296 |
\%plot_features, $list, \@indicator); |
| 297 |
$last_plot='q'; |
| 298 |
$last_plot_params = [$current, 'marked', 'q', $plot_features{q_marked}]; |
| 299 |
$groups{$widg{standard}}->plot_window(0, 'q', $dmode, $config{plot}{c2}, \%plot_features); |
| 300 |
map { $grab{$_} -> configure(-state=>'normal') } |
| 301 |
(qw(lr_kmin lr_kmax lr_fmin lr_fmax)); |
| 302 |
map { $grab{$_} -> configure(-state=>'disabled') } |
| 303 |
(qw(lr_rmin lr_rmax)); |
| 304 |
}) |
| 305 |
-> pack(-side=>'left', -expand=>1, -fill=>'x'); |
| 306 |
|
| 307 |
|
| 308 |
## frame with plot buttons for results |
| 309 |
$frame = $lr -> Frame(-borderwidth=>0, -relief=>'flat') |
| 310 |
-> pack(-side=>'bottom', -fill=>'x', -padx=>3, -pady=>2); |
| 311 |
|
| 312 |
$widget{lr_save} = $frame -> Button(-text=>'Save ratio data & fit', @button_list, |
| 313 |
-command=>sub{&save_lr_fit($widg{standard}, \@cumul, \@delta)}, |
| 314 |
-width=>1, |
| 315 |
-state=>'disabled') |
| 316 |
-> pack(-expand=>1, -fill=>'x', -side=>'left'); |
| 317 |
$widget{lr_log} = $frame -> Button(-text=>'Write log file', @button_list, |
| 318 |
-command=>sub{ |
| 319 |
my $types = [['Log-ratio fit logs', '.lr_log'], ['All Files', '*']]; |
| 320 |
my $path = $current_data_dir || Cwd::cwd; |
| 321 |
my $initial = $groups{$current}->{label} . ".lr_log"; |
| 322 |
($initial =~ s/[\\:\/\*\?\'<>\|]/_/g); # if ($is_windows); |
| 323 |
my $file = $top -> |
| 324 |
getSaveFile(-filetypes=>$types, |
| 325 |
#(not $is_windows) ? |
| 326 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 327 |
-initialdir=>$path, |
| 328 |
-initialfile=>$initial, |
| 329 |
-title => "Athena: Save log-ratio log file"); |
| 330 |
return unless $file; |
| 331 |
my ($name, $pth, $suffix) = fileparse($file); |
| 332 |
$current_data_dir = $pth; |
| 333 |
open LOG, ">".$file or do { |
| 334 |
Error("You cannot write a log to \"$file\"."); return |
| 335 |
}; |
| 336 |
print LOG &lr_log($widg{standard}, \@cumul, \@delta); |
| 337 |
close LOG; |
| 338 |
}, |
| 339 |
-width=>1, |
| 340 |
-state=>'disabled') |
| 341 |
-> pack(-expand=>1, -fill=>'x', -side=>'left'); |
| 342 |
|
| 343 |
|
| 344 |
## frame with plot buttons for results |
| 345 |
$frame = $lr -> Frame(-borderwidth=>0, -relief=>'flat') |
| 346 |
-> pack(-side=>'bottom', -fill=>'x', -padx=>3, -pady=>2); |
| 347 |
|
| 348 |
$widget{lr_lr} = $frame -> Button(-text=>'Plot log-ratio + fit', @button_list, |
| 349 |
-command=>sub{ |
| 350 |
my ($qmin, $qmax) = |
| 351 |
($widget{lr_fmin}->get(), $widget{lr_fmax}->get()+1); |
| 352 |
$groups{$widg{standard}} -> |
| 353 |
dispose("plot_lograt $widg{standard} \"$groups{$widg{standard}}->{label}\" \"$groups{$current}->{label}\" $qmax", $dmode); |
| 354 |
$last_plot='q'; |
| 355 |
map { $grab{$_} -> configure(-state=>'normal') } |
| 356 |
(qw(lr_kmin lr_kmax lr_fmin lr_fmax)); |
| 357 |
map { $grab{$_} -> configure(-state=>'disabled') } |
| 358 |
(qw(lr_rmin lr_rmax)); |
| 359 |
}, |
| 360 |
-width=>1, |
| 361 |
-state=>'disabled') |
| 362 |
-> pack(-expand=>1, -fill=>'x', -side=>'left'); |
| 363 |
$widget{lr_pd} = $frame -> Button(-text=>'Plot phase-difference + fit', @button_list, |
| 364 |
-command=>sub{ |
| 365 |
my ($qmin, $qmax) = |
| 366 |
($widget{lr_fmin}->get(), $widget{lr_fmax}->get()+1); |
| 367 |
$groups{$widg{standard}} -> |
| 368 |
dispose("plot_phdiff $widg{standard} \"$groups{$widg{standard}}->{label}\" \"$groups{$current}->{label}\" $qmax", $dmode); |
| 369 |
$last_plot='q'; |
| 370 |
map { $grab{$_} -> configure(-state=>'normal') } |
| 371 |
(qw(lr_kmin lr_kmax lr_fmin lr_fmax)); |
| 372 |
map { $grab{$_} -> configure(-state=>'disabled') } |
| 373 |
(qw(lr_rmin lr_rmax)); |
| 374 |
}, |
| 375 |
-width=>1, |
| 376 |
-state=>'disabled') |
| 377 |
-> pack(-expand=>1, -fill=>'x', -side=>'left'); |
| 378 |
|
| 379 |
## frame with results |
| 380 |
$frame = $lr -> LabFrame(-label => 'Fit Results', |
| 381 |
-foreground => $config{colors}{activehighlightcolor}, |
| 382 |
-labelside => 'acrosstop') |
| 383 |
-> pack(-fill=>'x', -padx=>3); |
| 384 |
$frame -> Label(-text=>"Zeroth: ", -foreground=>$config{colors}{highlightcolor}) |
| 385 |
-> grid(-row=>0, -column=>0, -sticky=>'e'); |
| 386 |
$widg{l0} = $frame -> Label(-text=>exp($cumul[0]), -font => $config{fonts}{small},) |
| 387 |
-> grid(-row=>0, -column=>1, -sticky=>'w'); |
| 388 |
$frame -> Label(-text=>"First: ", -foreground=>$config{colors}{highlightcolor}) |
| 389 |
-> grid(-row=>1, -column=>0, -sticky=>'e'); |
| 390 |
$widg{l1} = $frame -> Label(-text=>$cumul[1], -font => $config{fonts}{small},) |
| 391 |
-> grid(-row=>1, -column=>1, -sticky=>'w'); |
| 392 |
$frame -> Label(-text=>"Second: ", -foreground=>$config{colors}{highlightcolor}) |
| 393 |
-> grid(-row=>2, -column=>0, -sticky=>'e'); |
| 394 |
$widg{l2} = $frame -> Label(-text=>$cumul[2], -font => $config{fonts}{small},) |
| 395 |
-> grid(-row=>2, -column=>1, -sticky=>'w'); |
| 396 |
$frame -> Label(-text=>" ", -foreground=>$config{colors}{highlightcolor}) |
| 397 |
-> grid(-row=>1, -column=>2, -sticky=>'e'); |
| 398 |
$frame -> Label(-text=>"Third: ", -foreground=>$config{colors}{highlightcolor}) |
| 399 |
-> grid(-row=>1, -column=>3, -sticky=>'e'); |
| 400 |
$widg{l3} = $frame -> Label(-text=>$cumul[3], -font => $config{fonts}{small},) |
| 401 |
-> grid(-row=>1, -column=>4, -sticky=>'w'); |
| 402 |
$frame -> Label(-text=>"Fourth: ", -foreground=>$config{colors}{highlightcolor}) |
| 403 |
-> grid(-row=>2, -column=>3, -sticky=>'e'); |
| 404 |
$widg{l4} = $frame -> Label(-text=>$cumul[4], -font => $config{fonts}{small},) |
| 405 |
-> grid(-row=>2, -column=>4, -sticky=>'w'); |
| 406 |
|
| 407 |
## set initial data |
| 408 |
&reset_lr_data(\%widg, $widg{standard}, $current); |
| 409 |
foreach my $widg (qw(lr_fmin lr_fmax)) { |
| 410 |
$widget{$widg} -> configure(-validate=>'none'); |
| 411 |
$widget{$widg} -> delete(qw/0 end/); |
| 412 |
$widget{$widg} -> insert(0, ($widg =~ /n$/) ? 3 : 12); |
| 413 |
$widget{$widg} -> configure(-validate=>'key'); |
| 414 |
}; |
| 415 |
|
| 416 |
Echo("Reminder: Data should be aligned BEFORE doing log-ratio analysis."); |
| 417 |
$plotsel -> raise('k'); |
| 418 |
$top -> update; |
| 419 |
}; |
| 420 |
|
| 421 |
|
| 422 |
sub set_lr_variable { |
| 423 |
my ($k, $entry, $prop) = (shift, shift, shift); |
| 424 |
($entry =~ /^\s*$/) and ($entry = 0); # error checking ... |
| 425 |
($entry =~ /^\s*-$/) and return 1; # error checking ... |
| 426 |
($entry =~ /^\s*-?(\d+\.?\d*|\.\d+)\s*$/) or return 0; |
| 427 |
return 1; |
| 428 |
}; |
| 429 |
|
| 430 |
sub do_lr_fit { |
| 431 |
my ($standard, $other) = @_; |
| 432 |
|
| 433 |
## some error checking |
| 434 |
Error("Log-ratio fit aborted: You selected the same data group as standard and unknown."), |
| 435 |
return 0 if ($standard eq $other); |
| 436 |
Error("Log-ratio fit aborted: " . $groups{$other}->{label} . " is not an xmu or chi group."), |
| 437 |
return 0 unless (($groups{$other}->{is_xmu}) or ($groups{$other}->{is_chi})); |
| 438 |
|
| 439 |
Echo("Doing log-ratio/phase-difference fit ..."); |
| 440 |
$top -> Busy; |
| 441 |
## set standard and unknown FT param values |
| 442 |
foreach my $k (qw(kmin kmax kw dk rmin rmax dr)){ |
| 443 |
my $widg = "lr_$k"; |
| 444 |
my $key = ($k =~ /r/) ? "bft_$k" : "fft_$k"; |
| 445 |
$groups{$standard}->make($key => $widget{$widg}->get()); |
| 446 |
$groups{$other}->make($key => $widget{$widg}->get()); |
| 447 |
}; |
| 448 |
## bring both up to date in q-space |
| 449 |
$groups{$standard}->do_fft($dmode, \%plot_features); |
| 450 |
$groups{$standard}->do_bft($dmode); |
| 451 |
$groups{$other}->do_fft($dmode, \%plot_features); |
| 452 |
$groups{$other}->do_bft($dmode); |
| 453 |
## call LR/PD fit macro |
| 454 |
my ($qmin, $qmax, $npi) = ($widget{lr_fmin}->get(), $widget{lr_fmax}->get(), |
| 455 |
$widget{lr_npi}->get(), ); |
| 456 |
$groups{$standard}-> dispose("do_lograt $standard $other $qmin $qmax $npi", $dmode); |
| 457 |
## plot phase diff |
| 458 |
$qmax += 1; |
| 459 |
$groups{$standard} -> |
| 460 |
dispose("plot_lograt $standard \"$groups{$standard}->{label}\" \"$groups{$current}->{label}\" $qmax", $dmode); |
| 461 |
$last_plot='q'; |
| 462 |
$top -> Unbusy; |
| 463 |
Echo("Doing log-ratio/phase-difference fit ... done!"); |
| 464 |
1; |
| 465 |
}; |
| 466 |
|
| 467 |
sub save_lr_fit { |
| 468 |
my ($standard, $r_c, $r_d) = @_; |
| 469 |
my $types = [['Log ratio fits', '.lr'], ['All Files', '*'],]; |
| 470 |
my $path = $current_data_dir || Cwd::cwd; |
| 471 |
my $initial = $groups{$current}->{label} . ".lr"; |
| 472 |
($initial =~ s/[\\:\/\*\?\'<>\|]/_/g);# if ($is_windows); |
| 473 |
my $file = $top -> getSaveFile(-filetypes=>$types, |
| 474 |
#(not $is_windows) ? |
| 475 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 476 |
-initialdir=>$path, |
| 477 |
-initialfile=>$initial, |
| 478 |
-title => "Athena: Save log-ratio fit"); |
| 479 |
return unless $file; |
| 480 |
## make sure I can write to $file |
| 481 |
open F, ">".$file or do { |
| 482 |
Error("You cannot write to \"$file\"."); return |
| 483 |
}; |
| 484 |
close F; |
| 485 |
my ($name, $pth, $suffix) = fileparse($file); |
| 486 |
$current_data_dir = $pth; |
| 487 |
my $titles = &lr_log($standard, $r_c, $r_d); |
| 488 |
my $i = 0; |
| 489 |
foreach my $t (split(/\n/, $titles)) { |
| 490 |
next if ($t =~ /^\s*$/); |
| 491 |
++$i; |
| 492 |
Ifeffit::put_string("\$l___r_title_$i", $t); |
| 493 |
}; |
| 494 |
my $command = "write_data(file=\"$file\", "; |
| 495 |
$command .= " \$l___r_title_*, $standard.q, c___.ratio, c___.even, c___.diff, c___.odd)"; |
| 496 |
$groups{$standard} -> dispose($command, $dmode); |
| 497 |
foreach (1 .. $i) { |
| 498 |
$groups{$standard} -> dispose("erase \$l___r_title_$_", $dmode); |
| 499 |
}; |
| 500 |
}; |
| 501 |
|
| 502 |
sub lr_log { |
| 503 |
my ($standard, $r_c, $r_d) = @_; |
| 504 |
my $string = "Log-ratio/phase-difference between " . $groups{$current}->{label} . |
| 505 |
" (the unknown)\n"; |
| 506 |
$string .= "and " . $groups{$standard}->{label} . " (the standard)\n\n"; |
| 507 |
$string .= sprintf("Zeroth cumulant = %.5f +/- %.5f\n", exp($$r_c[0]), $$r_d[0]*exp($$r_c[0])); |
| 508 |
$string .= "First cumulant = $$r_c[1] +/- $$r_d[1]\n"; |
| 509 |
$string .= "Second cumulant = $$r_c[2] +/- $$r_d[2]\n"; |
| 510 |
$string .= "Third cumulant = $$r_c[3] +/- $$r_d[3]\n"; |
| 511 |
$string .= "Fourth cumulant = $$r_c[4] +/- $$r_d[4]\n\n"; |
| 512 |
$string .= sprintf("Forward FT parameters: [%.2f:%.2f], dk=%.2f, kw=%s\n", |
| 513 |
$widget{lr_kmin}->get, |
| 514 |
$widget{lr_kmax}->get, |
| 515 |
$widget{lr_dk}->get, |
| 516 |
$widget{lr_kw}->get, ); |
| 517 |
$string .= sprintf("Backward FT parameters: [%.2f:%.2f] dr=%.2f\n", |
| 518 |
$widget{lr_rmin}->get, |
| 519 |
$widget{lr_rmax}->get, |
| 520 |
$widget{lr_dr}->get,); |
| 521 |
$string .= sprintf("Fitting range in q: [%.2f:%.2f]\n", |
| 522 |
$widget{lr_fmin}->get, |
| 523 |
$widget{lr_fmax}->get,); |
| 524 |
return $string; |
| 525 |
}; |
| 526 |
|
| 527 |
sub reset_lr_data { |
| 528 |
my ($r_widg, $standard, $other) = @_; |
| 529 |
## reset plot buttons |
| 530 |
map {$widget{'lr_'.$_}->configure(-state=>'disabled')} (qw(lr pd save log)); |
| 531 |
## plot new data |
| 532 |
$groups{$standard}->plot_marked($plot_features{k_w}, $dmode, \%groups, |
| 533 |
{$standard=>1, $other=>1}, \%plot_features, $list, \@indicator); |
| 534 |
$last_plot='k'; |
| 535 |
$last_plot_params = [$current, 'marked', 'k', $plot_features{k_w}]; |
| 536 |
$groups{$standard}->plot_window(0, 'k', $dmode, $config{plot}{c2}, \%plot_features); |
| 537 |
## enable/disable pluck buttons for k |
| 538 |
map { $grab{$_} -> configure(-state=>'normal') } |
| 539 |
(qw(lr_kmin lr_kmax lr_fmin lr_fmax)); |
| 540 |
map { $grab{$_} -> configure(-state=>'disabled') } |
| 541 |
(qw(lr_rmin lr_rmax)); |
| 542 |
## reset FT params |
| 543 |
foreach my $k (qw(kmin kmax kw dk rmin rmax dr)){ |
| 544 |
my $widg = "lr_$k"; |
| 545 |
my $key = ($k =~ /r/) ? "bft_$k" : "fft_$k"; |
| 546 |
$widget{$widg} -> configure(-validate=>'none'); |
| 547 |
$widget{$widg} -> delete(qw/0 end/); |
| 548 |
$widget{$widg} -> insert(0, $groups{$standard}->{$key}); |
| 549 |
$widget{$widg} -> configure(-validate=>'key'); |
| 550 |
}; |
| 551 |
## $widget{lr_win} -> |
| 552 |
## reset cumulants |
| 553 |
my @cumul = (1, 0, 0, 0, 0); |
| 554 |
map {$$r_widg{"l".$_}->configure(-text=>$cumul[$_])} (0 .. 4); |
| 555 |
}; |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
## END OF LOG-RATIO/PHASE_DIFFERENCE SUBSECTION |
| 560 |
########################################################################################## |