Changeset 1181 for trunk


Ignore:
Timestamp:
Nov 25, 2011 4:15:38 PM (9 years ago)
Author:
toby
Message:

move Topas-able liveplot to stable release

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/liveplot.html

    r1166 r1181  
    5151Some of the features available in LIVEPLOT are:
    5252<UL>
    53 <LI><IMG SRC="new.gif" alt="New!">
     53<LI><IMG SRC="new.gif" alt="New!">
     54  Plotting of Topas refinement results in LIVEPLOT:
     55  Upon request, LIVEPLOT has been augmented to read in results from
     56  Topas, as well as GENLES.
     57  <a HREF="#Topas">See below for details.</a>
     58<LI><IMG SRC="new.gif" alt="New!"> 
    5459Regions of the plot can be magnified to show more detail, for example
    5560  in regions at high Q.
     
    432437 
    433438</UL>
     439<a name="Topas"></a>
     440<B>Plotting of Topas refinement results in LIVEPLOT</B>
     441Upon request, LIVEPLOT has been augmented to read in results from
     442Topas. Follow the procedure
     443<A
     444  HREF="http://topas.dur.ac.uk/topaswiki/doku.php?id=outputting_publication_quality_plots_using_expgui">Publication
     445  Quality Plots using Liveplot in EXPGUI</A> from the <A
     446  HREF="http://topas.dur.ac.uk/topaswiki">Durham University Topas Wiki</A> to
     447  generate an output file that LIVEPLOT can read. Then use the "Import
     448from Topas" menu item in the File menu to open a dialog window where
     449the file can be imported. It is optimal to use the extension
     450<tt>.ascii</tt> for the Topas export file.
     451<P>
     452Note that in normal use, LIVEPLOT is started from inside EXPGUI with
     453an open .EXP file. If LIVEPLOT will be used frequently for Topas, it
     454may be useful to create a shortcut to start LIVEPLOT directly. This
     455can be done in Windows by following these
     456<A
     457HREF="https://subversion.xor.aps.anl.gov/trac/EXPGUI/wiki/InstallWindows#shortcut">instructions
     458to make a short cut</A>, but reference file <tt>.../expgui/liveplot</tt>
     459rather than file <tt>.../expgui/expgui</tt>. Similar things can be
     460done in Linux and on the Mac.
    434461
    435462<hr><h2>LIVEPLOT/BKGEDIT Keyboard Shortcuts</h2>
  • trunk/liveplot

    r1166 r1181  
    1515set exitstat 0
    1616set expnam [file root [lindex $argv 0]]
    17 if {$expnam == ""} {catch {puts "error -- no experiment name"}; set exitstat 1}
     17#if {$expnam == ""} {catch {puts "error -- no experiment name"}; set exitstat 1}
    1818if $exitstat {
    1919    catch {puts "usage: $argv0 expnam \[hist #\] \[legend\]"}
     
    107107}
    108108set expgui(RadiiList) {}
     109set ::expmap(phaselist) {}
    109110
    110111proc waitmsg {message} {
     
    252253    global expgui modtime expnam
    253254    if [catch {
    254         set modtime [file mtime $expnam.EXP]
    255255        set loadtime [time {
    256             if {$expgui(tcldump) == ""} {
     256        set modtime 0
     257            if {$::topasfile != ""} {
     258                set p "TOPAS import"
     259                readdata_topas $box
     260            } elseif {$expgui(tcldump) == ""} {
     261                set modtime [file mtime $expnam.EXP]
    257262                set p HSTDMP
    258263                readdata_hst $box
    259264            } else {
     265                set modtime [file mtime $expnam.EXP]
    260266                set p TCLDUMP
    261267                readdata_tcl $box
     
    357363    calcvec set $calclist
    358364    bckvec set $bcklist
    359     diffvec set [obsvec - calcvec]
    360     foreach vec {obsvec calcvec diffvec} {
     365    #diffvec set [obsvec - calcvec]
     366    foreach vec {obsvec calcvec} {
    361367        # probably not needed with recent versions of BLT:
    362368        global $vec
     
    450456}
    451457
     458set ::topasfile ""
     459proc get_topas_file {} {
     460    set ::topasfile [tk_getOpenFile -title "Select Topas File" -parent . \
     461                         -defaultextension .ascii \
     462                         -filetypes {
     463                             {"Topas ascii export" ".ascii"}
     464                             {"all files" "*"}
     465                         }]
     466    if {$::topasfile == ""} return
     467    if {[catch {set input [open $::topasfile r]} errmsg]} {
     468        MyMessageBox -parent . -title "Open Error" \
     469            -message "An error occured trying to open file $::topasfile: $errmsg" \
     470            -icon error -type Ignore -default ignore
     471        set ::topasfile ""
     472        return
     473    }
     474    close $input
     475    readdata .g
     476}
     477
     478proc readdata_topas {box} {
     479    global expgui expnam reflns graph
     480    global lasthst
     481    global hst peakinfo xunits weightlist
     482    #set file "liveplot_output.ascii"
     483    if {$::topasfile == ""} return
     484    if {[catch {set input [open $::topasfile r]} errmsg]} {
     485        MyMessageBox -parent . -title "Open Error" \
     486            -message "An error occured trying to open file $::topasfile: $errmsg" \
     487            -icon error -type Ignore -default ignore
     488        return
     489    }
     490
     491    $box config -title "(TOPAS import in progress)"
     492    update
     493    # parse the output of a file
     494    set lasthst $hst
     495    # initalize arrays
     496    set num -1
     497    set xlist {}
     498    set obslist {}
     499    set calclist {}
     500    set bcklist {}
     501    set xunits {}
     502    set weightlist {}
     503    global refhkllist refphaselist refpos
     504    set refhkllist {}
     505    set refphaselist {}
     506    set refpos {}
     507    # define a list of reflection positions for each phase
     508    for {set i 1} {$i < 10} {incr i} {
     509        set reflns($i) {}
     510    }
     511    set i 0
     512    while {[gets $input line] >= 0} {
     513        incr i
     514        if {[string first ":" $line] != -1} continue
     515        # run update every 50th line
     516        if {$i > 50} {set i 0; update}
     517        if {[llength $line] == 5} {
     518            scan $line %e%e%e%e%e X d Iobs Icalc Isig
     519            if {$Isig > 0} {
     520                if {$graph(xunits) == 0} {
     521                    lappend xlist $X
     522                } elseif {$graph(xunits) == 1} {
     523                    lappend xlist $d
     524                } else {
     525                    lappend xlist [expr {6.283185307179586 / $d}]
     526                }
     527                lappend obslist $Iobs
     528                lappend calclist $Icalc
     529                #lappend bcklist 0
     530                lappend weightlist [expr {1./($Isig * $Isig)}]
     531            }
     532        } elseif {[llength $line] == 7} {
     533            scan $line %e%e%e%e%e%e%d h k l m d tt ph
     534            if {$graph(xunits) == 0} {
     535                set x $tt
     536            } elseif {$graph(xunits) == 1} {
     537                set x $d
     538            } else {
     539                set x [expr {6.283185307179586 / $d}]
     540            }
     541            set ph [expr {int($ph)}]
     542            lappend reflns($ph) $x
     543            lappend refhkllist "$h,$k,$l"
     544            lappend refphaselist $ph
     545            lappend refpos $x
     546        } elseif {[llength $line] == 3} {
     547            scan $line %e%e%e x d b
     548            lappend bcklist $b
     549        } else {
     550            puts "unexpected input: $line"
     551        }
     552    }
     553    close $input
     554
     555    if {$graph(xunits) == 0} {
     556        set xunits "2-Theta"
     557    } elseif {$graph(xunits) == 1} {
     558        set xunits "d"
     559    } else {
     560        set xunits "Q"
     561    }
     562    foreach elem [$box element names] {
     563        eval $box element config $elem $graph(ElementShowOption)
     564    }
     565    xvec set $xlist
     566    obsvec set $obslist
     567    calcvec set $calclist
     568    bckvec set $bcklist
     569    #diffvec set [obsvec - calcvec]
     570    refposvec set $refpos
     571    set ::expmap(phaselist) [lsort -unique $refphaselist]
     572    RegisterPhases $::expmap(phaselist)
     573    if {$expgui(autotick)} {
     574        foreach i $::expmap(phaselist) {
     575            set peakinfo(flag$i) 1
     576        }
     577    }
     578    #wifdvec length 0
     579    # if {$graph(chi2)} {
     580    #     wifdvec set $WGT
     581    #     wifdvec set [wifdvec * diffvec]
     582    #     wifdvec set [wifdvec * diffvec]
     583    #     # now do a running sum
     584    #     set sum 0
     585    #     set sumlist {}
     586    #     foreach n [wifdvec range 0 end] {
     587    #         set sum [expr {$sum + $n}]
     588    #         lappend sumlist $sum
     589    #     }
     590    #     wifdvec set $sumlist
     591    #     wifdvec set [wifdvec / [wifdvec length]]
     592    # } elseif {$graph(OmCoS)} {
     593    #     wifdvec set $WGT
     594    #     wifdvec expr sqrt(wifdvec)
     595    #     wifdvec set [wifdvec * diffvec]
     596    # }
     597    if $graph(backsub) {
     598        obsvec set [obsvec - bckvec]
     599        calcvec set [calcvec - bckvec]
     600    }
     601    foreach vec {obsvec calcvec} {
     602        # probably not needed with recent versions of BLT:
     603        global $vec
     604        # sometimes needed for latest version of BLT (2.4z)
     605        catch {$vec variable $vec}
     606    }
     607    ApplyMag
     608    plotdata
     609}
     610
    452611proc SetTitle {} {
    453612    set bx .title
     
    572731    global expnam hst peakinfo xunits yunits cycle reflns modtime
    573732    global lasthst graph expgui box
    574     global obsvec calcvec diffvec
    575 
    576     if {$graph(yunits) == 2} {
     733    global obsvec calcvec diffvec bckvec
     734
     735    if {$graph(yunits) == 0} {
     736        diffvec set [obsvec - calcvec]
     737        $box element config 1 -label bckgr -line 1 -hide 0
     738        $box element config 4 -label diff  -line 1 -hide 0
     739    } elseif {$graph(yunits) == 1} {
     740        diffvec set [obsvec - calcvec]
     741        $box element config 1 -label bckgr -line 1 -hide 0
     742        $box element config 4 -label diff  -line 1 -hide 0
     743    } elseif {$graph(yunits) == 2} {
    577744        set yunits {Intensity/sigma(I)}
    578745        wifdvec set $::weightlist
     
    584751        wifdvec set {}
    585752        $box element config 1 -label {} -line 0 -hide 1
     753        $box element config 4 -label diff  -line 1 -hide 0
     754    } elseif {$graph(yunits) == 3} {
     755        bckvec expr 0*bckvec
     756        set msg {}
     757        if {[set calcvec(min)] <= 0} {
     758            if {$msg != ""} {append msg ", "}
     759            append msg "calculated"
     760        }
     761        if {[set obsvec(min)] <= 0} {
     762            if {$msg != ""} {append msg " & "}
     763            append msg "observed"
     764        }
     765        if {$msg != ""} {
     766            MyMessageBox -parent . -title "Invalid Range" \
     767                -message "Log computation impossible due to zero or negative $msg intensity values" \
     768                -icon warning -type Continue -default continue
     769        } else {
     770            set yunits {log(Intensity)}
     771            obsvec expr log10(obsvec)
     772            calcvec expr log10(calcvec)
     773            if {[set bckvec(min)] <= 0} {
     774                bckvec set {}
     775                $box element config 1 -label {} -line 0 -hide 1
     776            } else {
     777                bckvec expr log10(bckvec)
     778                $box element config 1 -label bckgr -line 1 -hide 0
     779            }
     780            diffvec set {}
     781            $box element config 4 -label {} -line 0 -hide 1
     782        }
    586783    } else {
    587784        $box element config 1 -label bckgr -line 1 -hide 0
     785        $box element config 4 -label diff  -line 1 -hide 0
    588786    }
    589787
     
    691889        }
    692890    }
    693     # offset the difference pattern
    694     set maxdiff  [set diffvec(max)]
    695     if {$expgui(autotick)} {
    696         diffvec set [diffvec + [expr {$cmin - $maxdiff}]]
    697     } else {
    698         diffvec set [diffvec + [expr {$cmin - 1.1*$maxdiff}]]
    699     }
    700     diffvec notify now
    701 
     891    catch {
     892        # offset the difference pattern
     893        set maxdiff  [set diffvec(max)]
     894        if {$expgui(autotick)} {
     895            diffvec set [diffvec + [expr {$cmin - $maxdiff}]]
     896        } else {
     897            diffvec set [diffvec + [expr {$cmin - 1.1*$maxdiff}]]
     898        }
     899        diffvec notify now
     900    }
    702901    # force an update of the plot as BLT may not
    703902    $box config -title [$box cget -title]
     
    21562355    .a.file.menu.export add command -label "to PDF" -command ExportPDF
    21572356}
     2357
     2358.a.file.menu add command -label "Import from Topas" \
     2359    -command {get_topas_file}
    21582360
    21592361.a.file.menu add command -label Quit -command "destroy ."
     
    23662568    .g marker create line -coords "$xl -Inf $xl Inf" -name mag[incr i]
    23672569    .g marker create text -coords "$xl Inf" -name mag[incr i] -text "x$ym" -anchor w
    2368     foreach vec {obsvec calcvec bckvec diffvec} {
     2570    foreach vec {obsvec calcvec bckvec} {
    23692571        global $vec
    23702572        $vec expr {$vec * ymult}
     
    25222724    .a.options.menu.yunits add radiobutton -label "I/Sigma(I)" \
    25232725            -variable graph(yunits) -value 2 \
     2726            -command {set cycle [getcycle];readdata .g}
     2727    .a.options.menu.yunits add radiobutton -label "log(I)" \
     2728            -variable graph(yunits) -value 3 \
    25242729            -command {set cycle [getcycle];readdata .g}
    25252730    .a.options.menu add command -label "HKL labeling" -command setlblopts
     
    27122917}
    27132918
    2714 expload $expnam.EXP
    2715 mapexp
    2716 if {$expgui(autotick)} {
    2717     foreach i $::expmap(phaselist) {
    2718         set peakinfo(flag$i) 1
    2719     }
    2720 }
    2721        
     2919if {$expnam != ""} {
     2920    expload $expnam.EXP
     2921    mapexp
     2922    if {$expgui(autotick)} {
     2923        foreach i $::expmap(phaselist) {
     2924            set peakinfo(flag$i) 1
     2925        }
     2926    }
     2927} else {
     2928    mapexp
     2929}
     2930
    27222931# fill the histogram menu
    27232932if {[llength $expmap(powderlist)] > 15} {
     
    27702979}
    27712980
    2772 foreach num $expmap(phaselist) {
    2773     .a.file.menu.tick add checkbutton -label "Phase $num" \
     2981proc RegisterPhases {phaselist } {
     2982    foreach num $phaselist {
     2983        .a.file.menu.tick add checkbutton -label "Phase $num" \
    27742984            -variable  peakinfo(flag$num) \
    27752985            -command plotdata
    2776     if {$program != "bkgedit"}  {
    2777         bind . <Key-$num> ".a.file.menu.tick invoke [.a.file.menu.tick index end]"
    2778     }
    2779     .a.options.menu.tick add command -label "Phase $num opts" \
     2986        if {$::program != "bkgedit"}  {
     2987            bind . <Key-$num> ".a.file.menu.tick invoke [.a.file.menu.tick index end]"
     2988        }
     2989        .a.options.menu.tick add command -label "Phase $num opts" \
    27802990            -command "minioptionsbox $num"
    2781 }
     2991    }
     2992}
     2993RegisterPhases $expmap(phaselist)
    27822994
    27832995# N = load next histogram
Note: See TracChangeset for help on using the changeset viewer.