- Timestamp:
- Feb 18, 2016 4:13:14 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 46 edited
- 21 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
-
trunk/Makefile.in
r5811 r6021 40 40 endif 41 41 ifneq ($(ENABLE_GUI),) 42 TARGETS += gui builder tester examples 42 TARGETS += gui builder tester examples puq 43 43 endif 44 44 ifneq ($(HAVE_FFMPEG),) … … 57 57 $(MAKE) -C test all 58 58 59 install: 59 install: 60 60 for i in $(TARGETS) ; do \ 61 61 $(MAKE) -C $$i install || exit 1 ;\ 62 62 done 63 63 64 clean: 64 clean: 65 65 for i in $(TARGETS) ; do \ 66 66 $(MAKE) -C $$i clean || exit 1 ;\ … … 73 73 done 74 74 75 package: 75 package: 76 76 tar -C $(pkg_path) -czlf $(rappture_binary_tarfile) $(pkg_name) 77 77 78 distrib: 78 distrib: 79 79 $(RM) -r exported 80 80 $(MKDIR_P) -m 0755 exported -
trunk/configure
r5999 r6021 10216 10216 10217 10217 10218 ac_config_files="$ac_config_files Makefile packages/Makefile src/Makefile src/core/Makefile src/core2/Makefile src/objects/Makefile src/objects/RpHash.h gui/Makefile gui/apps/Makefile gui/apps/about gui/apps/copy_rappture_examples gui/apps/encodedata gui/apps/rappture gui/apps/rappture-csh.env gui/apps/rappture.env gui/apps/rappture.use gui/apps/rerun gui/apps/simsim gui/apps/xmldiff gui/pkgIndex.tcl gui/scripts/Makefile gui/src/Makefile builder/Makefile builder/pkgIndex.tcl builder/scripts/Makefile tester/Makefile tester/pkgIndex.tcl tester/scripts/Makefile lang/Makefile lang/java/Makefile lang/java/rappture/Makefile lang/perl/Makefile lang/perl/Makefile.PL lang/python/Makefile lang/python/setup.py lang/matlab/Makefile lang/octave/Makefile lang/octave/octave2/Makefile lang/octave/octave3/Makefile lang/R/Makefile lang/ruby/Makefile lang/ruby/build.rb lang/tcl/Makefile lang/tcl/pkgIndex.tcl lang/tcl/scripts/Makefile lang/tcl/src/Makefile lang/tcl/tests/Makefile lib/Makefile examples/3D/Makefile examples/Makefile examples/app-fermi/2.0/Makefile examples/app-fermi/Makefile examples/app-fermi/cee/Makefile examples/app-fermi/fortran/Makefile examples/app-fermi/java/Makefile examples/app-fermi/matlab/Makefile examples/app-fermi/matlab/compiled/Makefile examples/app-fermi/matlab/uncompiled/Makefile examples/app-fermi/octave/octave2/Makefile examples/app-fermi/octave/octave3/Makefile examples/app-fermi/octave/Makefile examples/app-fermi/perl/Makefile examples/app-fermi/python/Makefile examples/app-fermi/ruby/Makefile examples/app-fermi/tcl/Makefile examples/app-fermi/wrapper/Makefile examples/app-fermi/wrapper/cee/Makefile examples/app-fermi/wrapper/perl/Makefile examples/app-fermi/wrapper/python/Makefile examples/app-fermi/wrapper/tcl/Makefile examples/app-fermi/R/Makefile examples/c-example/Makefile examples/canvas/Makefile examples/demo.bash examples/flow/Makefile examples/flow/demo1/Makefile examples/flow/demo2/Makefile examples/flow/demo3/Makefile examples/graph/Makefile examples/objects/Makefile examples/objects/axis/Makefile examples/objects/curve/Makefile examples/objects/dxWriter/Makefile examples/objects/floatBuffer/Makefile examples/objects/histogram/Makefile examples/objects/library/Makefile examples/objects/number/Makefile examples/objects/path/Makefile examples/objects/plot/Makefile examples/objects/scatter/Makefile examples/objects/string/Makefile examples/objects/tree/Makefile examples/objects/xmlparser/Makefile examples/zoo/Makefile examples/zoo/binary/Makefile examples/zoo/boolean/Makefile examples/zoo/choice/Makefile examples/zoo/curve/Makefile examples/zoo/drawing/Makefile examples/zoo/enable/Makefile examples/zoo/field/Makefile examples/zoo/group/Makefile examples/zoo/histogram/Makefile examples/zoo/image/Makefile examples/zoo/image/docs/Makefile examples/zoo/image/examples/Makefile examples/zoo/integer/Makefile examples/zoo/integer2/Makefile examples/zoo/loader/Makefile examples/zoo/loader/examples/Makefile examples/zoo/log/Makefile examples/zoo/mesh/Makefile examples/zoo/note/Makefile examples/zoo/note/docs/Makefile examples/zoo/number/Makefile examples/zoo/number2/Makefile examples/zoo/parallelepiped/Makefile examples/zoo/periodicelement/Makefile examples/zoo/phase/Makefile examples/zoo/sequence/Makefile examples/zoo/sequence/examples/Makefile examples/zoo/string/Makefile examples/zoo/structure/Makefile examples/zoo/structure/examples/Makefile examples/zoo/table/Makefile video/Makefile video/pkgIndex.tcl oldtest/Makefile oldtest/src/Makefile "10218 ac_config_files="$ac_config_files Makefile packages/Makefile src/Makefile src/core/Makefile src/core2/Makefile src/objects/Makefile src/objects/RpHash.h gui/Makefile gui/apps/Makefile gui/apps/about gui/apps/copy_rappture_examples gui/apps/encodedata gui/apps/rappture gui/apps/rappture-csh.env gui/apps/rappture.env gui/apps/rappture.use gui/apps/rerun gui/apps/simsim gui/apps/xmldiff gui/pkgIndex.tcl gui/scripts/Makefile gui/src/Makefile builder/Makefile builder/pkgIndex.tcl builder/scripts/Makefile tester/Makefile tester/pkgIndex.tcl tester/scripts/Makefile lang/Makefile lang/java/Makefile lang/java/rappture/Makefile lang/perl/Makefile lang/perl/Makefile.PL lang/python/Makefile lang/python/setup.py lang/matlab/Makefile lang/octave/Makefile lang/octave/octave2/Makefile lang/octave/octave3/Makefile lang/R/Makefile lang/ruby/Makefile lang/ruby/build.rb lang/tcl/Makefile lang/tcl/pkgIndex.tcl lang/tcl/scripts/Makefile lang/tcl/src/Makefile lang/tcl/tests/Makefile lib/Makefile examples/3D/Makefile examples/Makefile examples/app-fermi/2.0/Makefile examples/app-fermi/Makefile examples/app-fermi/cee/Makefile examples/app-fermi/fortran/Makefile examples/app-fermi/java/Makefile examples/app-fermi/matlab/Makefile examples/app-fermi/matlab/compiled/Makefile examples/app-fermi/matlab/uncompiled/Makefile examples/app-fermi/octave/octave2/Makefile examples/app-fermi/octave/octave3/Makefile examples/app-fermi/octave/Makefile examples/app-fermi/perl/Makefile examples/app-fermi/python/Makefile examples/app-fermi/ruby/Makefile examples/app-fermi/tcl/Makefile examples/app-fermi/wrapper/Makefile examples/app-fermi/wrapper/cee/Makefile examples/app-fermi/wrapper/perl/Makefile examples/app-fermi/wrapper/python/Makefile examples/app-fermi/wrapper/tcl/Makefile examples/app-fermi/R/Makefile examples/c-example/Makefile examples/canvas/Makefile examples/demo.bash examples/flow/Makefile examples/flow/demo1/Makefile examples/flow/demo2/Makefile examples/flow/demo3/Makefile examples/graph/Makefile examples/objects/Makefile examples/objects/axis/Makefile examples/objects/curve/Makefile examples/objects/dxWriter/Makefile examples/objects/floatBuffer/Makefile examples/objects/histogram/Makefile examples/objects/library/Makefile examples/objects/number/Makefile examples/objects/path/Makefile examples/objects/plot/Makefile examples/objects/scatter/Makefile examples/objects/string/Makefile examples/objects/tree/Makefile examples/objects/xmlparser/Makefile examples/zoo/Makefile examples/zoo/binary/Makefile examples/zoo/boolean/Makefile examples/zoo/choice/Makefile examples/zoo/curve/Makefile examples/zoo/drawing/Makefile examples/zoo/enable/Makefile examples/zoo/field/Makefile examples/zoo/group/Makefile examples/zoo/histogram/Makefile examples/zoo/image/Makefile examples/zoo/image/docs/Makefile examples/zoo/image/examples/Makefile examples/zoo/integer/Makefile examples/zoo/integer2/Makefile examples/zoo/loader/Makefile examples/zoo/loader/examples/Makefile examples/zoo/log/Makefile examples/zoo/mesh/Makefile examples/zoo/note/Makefile examples/zoo/note/docs/Makefile examples/zoo/number/Makefile examples/zoo/number2/Makefile examples/zoo/parallelepiped/Makefile examples/zoo/periodicelement/Makefile examples/zoo/phase/Makefile examples/zoo/sequence/Makefile examples/zoo/sequence/examples/Makefile examples/zoo/string/Makefile examples/zoo/structure/Makefile examples/zoo/structure/examples/Makefile examples/zoo/table/Makefile video/Makefile video/pkgIndex.tcl oldtest/Makefile oldtest/src/Makefile puq/Makefile" 10219 10219 10220 10220 cat >confcache <<\_ACEOF … … 11040 11040 "oldtest/Makefile") CONFIG_FILES="$CONFIG_FILES oldtest/Makefile" ;; 11041 11041 "oldtest/src/Makefile") CONFIG_FILES="$CONFIG_FILES oldtest/src/Makefile" ;; 11042 "puq/Makefile") CONFIG_FILES="$CONFIG_FILES puq/Makefile" ;; 11042 11043 11043 11044 *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; -
trunk/configure.in
r5999 r6021 343 343 AC_CHECK_FUNCS(av_close_input_file) 344 344 AC_CHECK_FUNCS(avformat_close_input) 345 345 346 346 AC_CHECK_FUNC(avcodec_find_decoder,, 347 347 AC_MSG_ERROR(oops! no av_codec_find_decoder ?!?)) … … 600 600 oldtest/Makefile 601 601 oldtest/src/Makefile 602 puq/Makefile 602 603 ]) 603 604 AC_OUTPUT 604 605 -
trunk/examples/app-fermi/python/fermi.py
r5681 r6021 38 38 # y-axis label, and y-axis units 39 39 f12 = rx['output.curve(f12)'] # a shortcut to save typing 40 f12[' label'] = 'Fermi-Dirac Factor'40 f12['about.label'] = 'Fermi-Dirac Factor' 41 41 f12['xaxis.label'] = 'Fermi-Dirac Factor' 42 42 f12['yaxis.label'] = 'Energy' -
trunk/examples/zoo/boolean/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/boolean.py \ 18 19 $(srcdir)/boolean.tcl \ 19 20 $(srcdir)/boolean.gif \ -
trunk/examples/zoo/boolean/tool.xml
r1076 r6021 11 11 </about> 12 12 <command> 13 tclsh @tool/boolean.tcl@driver13 python @tool/boolean.py @driver 14 14 </command> 15 15 </tool> -
trunk/examples/zoo/enable/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/enable.py \ 18 19 $(srcdir)/enable.tcl \ 19 20 $(srcdir)/tool.xml \ -
trunk/examples/zoo/enable/tool.xml
r1594 r6021 10 10 </about> 11 11 <command> 12 tclsh @tool/enable.tcl@driver12 python @tool/enable.py @driver 13 13 </command> 14 14 </tool> -
trunk/examples/zoo/field/tool.xml
r5693 r6021 10 10 </about> 11 11 <command> 12 python @tool/field.py@driver12 tclsh @tool/field.tcl @driver 13 13 </command> 14 14 <limits> -
trunk/examples/zoo/group/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/group.py \ 18 19 $(srcdir)/group.tcl \ 19 20 $(srcdir)/group1.gif \ -
trunk/examples/zoo/group/tool.xml
r3642 r6021 12 12 </about> 13 13 <command> 14 tclsh @tool/group.tcl@driver14 python @tool/group.py @driver 15 15 </command> 16 16 </tool> -
trunk/examples/zoo/image/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/image.py \ 18 19 $(srcdir)/image.tcl \ 19 20 $(srcdir)/image1.gif \ -
trunk/examples/zoo/image/tool.xml
r3645 r6021 10 10 </about> 11 11 <command> 12 tclsh @tool/image.tcl@driver12 python @tool/image.py @driver 13 13 </command> 14 14 </tool> … … 28 28 <diffs>ignore</diffs> 29 29 </about> 30 <convert>bmp</convert>31 30 </image> 32 31 <number id="angle"> -
trunk/examples/zoo/integer/Makefile.in
r3471 r6021 17 17 FILES = \ 18 18 $(srcdir)/integer.gif \ 19 $(srcdir)/integer.py \ 19 20 $(srcdir)/integer.tcl \ 20 21 $(srcdir)/tool.xml -
trunk/examples/zoo/integer/tool.xml
r1587 r6021 11 11 </about> 12 12 <command> 13 tclsh @tool/integer.tcl@driver13 python @tool/integer.py @driver 14 14 </command> 15 15 </tool> -
trunk/examples/zoo/integer2/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/integer.py \ 18 19 $(srcdir)/integer.tcl \ 19 20 $(srcdir)/tool.xml -
trunk/examples/zoo/integer2/tool.xml
r1075 r6021 7 7 </about> 8 8 <command> 9 tclsh @tool/integer.tcl@driver9 python @tool/integer.py @driver 10 10 </command> 11 11 </tool> -
trunk/examples/zoo/loader/Makefile.in
r3471 r6021 17 17 FILES = \ 18 18 $(srcdir)/loader.gif \ 19 $(srcdir)/loader.py \ 19 20 $(srcdir)/loader.tcl \ 20 21 $(srcdir)/loader2.gif \ -
trunk/examples/zoo/loader/tool.xml
r711 r6021 12 12 </about> 13 13 <command> 14 tclsh @tool/loader.tcl@driver14 python @tool/loader.py @driver 15 15 </command> 16 16 </tool> -
trunk/examples/zoo/number/tool.xml
r5681 r6021 10 10 When you click the Simulate button, the input numbers will be used to generate output numbers. 11 11 </about> 12 <uq>off</uq> 12 13 <command> 13 14 python @tool/number.py @driver -
trunk/examples/zoo/number2/tool.xml
r5681 r6021 6 6 Each number object has a different color range. 7 7 </about> 8 <uq>false</uq> 8 9 <command> 9 10 python @tool/number.py @driver -
trunk/examples/zoo/parallelepiped/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/parallelepiped.py \ 18 19 $(srcdir)/parallelepiped.tcl \ 19 20 $(srcdir)/tool.xml -
trunk/examples/zoo/parallelepiped/tool.xml
r1957 r6021 3 3 <tool> 4 4 <about>Press Simulate to view results.</about> 5 <command> tclsh @tool/parallelepiped.tcl@driver</command>5 <command>python @tool/parallelepiped.py @driver</command> 6 6 </tool> 7 7 <input> -
trunk/examples/zoo/sequence/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/sequence.py \ 18 19 $(srcdir)/sequence.tcl \ 19 20 $(srcdir)/sequence2.tcl \ -
trunk/examples/zoo/sequence/tool.xml
r998 r6021 10 10 </about> 11 11 <command> 12 tclsh @tool/sequence.tcl@driver12 python @tool/sequence.py @driver 13 13 </command> 14 14 </tool> -
trunk/examples/zoo/string/Makefile.in
r3471 r6021 16 16 17 17 FILES = \ 18 $(srcdir)/string_test.py \ 18 19 $(srcdir)/string.tcl \ 19 20 $(srcdir)/string1.gif \ -
trunk/examples/zoo/string/tool.xml
r1587 r6021 11 11 </about> 12 12 <command> 13 tclsh @tool/string.tcl@driver13 python @tool/string_test.py @driver 14 14 </command> 15 15 </tool> -
trunk/gui/apps/rappture.use.in
r4657 r6021 1 1 2 2 conflict RAPPTURE_CHOICE 3 4 use -r -e anaconda-2.3.0 5 use -r -e puq-2.2.14 3 6 4 7 desc "The Rappture tool environment (released version)." -
trunk/gui/scripts/Makefile.in
r5959 r6021 94 94 $(srcdir)/periodictable.tcl \ 95 95 $(srcdir)/postern.tcl \ 96 $(srcdir)/probdisteditor.tcl \ 96 97 $(srcdir)/progress.tcl \ 97 98 $(srcdir)/pushbutton.tcl \ 98 99 $(srcdir)/radiodial.tcl \ 99 100 $(srcdir)/resultset.tcl \ 101 $(srcdir)/response.tcl \ 102 $(srcdir)/responseviewer.tcl \ 100 103 $(srcdir)/resultselector.tcl \ 101 104 $(srcdir)/resultviewer.tcl \ … … 121 124 $(srcdir)/units.tcl \ 122 125 $(srcdir)/utils.tcl \ 126 $(srcdir)/uq.tcl \ 127 $(srcdir)/uqcurve.tcl \ 128 $(srcdir)/uqinfo.tcl \ 129 $(srcdir)/uqnotebook.tcl \ 123 130 $(srcdir)/valueresult.tcl \ 124 131 $(srcdir)/videochooser.tcl \ … … 157 164 --outfile tclIndex 158 165 159 install: all install_scripts install_images 166 install: all install_scripts install_images 160 167 161 install_scripts: 168 install_scripts: 162 169 $(MKDIR_P) -m 0755 $(destdir) 163 170 @for i in $(FILES); do \ 164 171 echo "Installing $$i" ; \ 165 172 $(INSTALL) -m 0444 $$i $(destdir) ; \ 166 done 173 done 167 174 $(INSTALL) -m 0444 tclIndex $(destdir) 168 175 … … 172 179 echo "Installing $$i" ; \ 173 180 $(INSTALL) -m 0444 $$i $(destdir)/images ; \ 174 done 181 done 175 182 176 183 clean: -
trunk/gui/scripts/analyzer.tcl
r5880 r6021 79 79 protected method _lammpsToSequence {xmlobj path id child data} 80 80 protected method _trajToSequence {xmlobj {path ""}} 81 protected method _pop_uq_dialog {win} 82 protected method _setWaitVariable {state} 83 protected method _adjust_level {win} 81 84 82 85 private variable _tool "" ;# belongs to this tool … … 92 95 private variable _lastPlot 93 96 private common job ;# array var used for blt::bgexec jobs 97 private variable _uq_active 0 ;# a UQ variables has been used 98 private variable _wait_uq 0 94 99 } 95 100 … … 328 333 } 329 334 pack $itk_component(resultpages) -expand yes -fill both 330 331 set f [$itk_component(results) insert end -fraction 0.1] 335 set f [$itk_component(results) insert end -fraction 0.1] 332 336 itk_component add resultselector { 333 337 Rappture::ResultSelector $f.rsel -resultset $_resultset \ … … 395 399 # ---------------------------------------------------------------------- 396 400 itcl::body Rappture::Analyzer::simulate {args} { 397 if {$args == "-ifneeded"} { 401 #puts "simulate args='$args'" 402 403 set uq [$_tool get_uq -uq_type smolyak -uq_args 2] 404 405 # pop up UQ window 406 if {[$uq num_runs] > 1} { 407 set _uq_active 1 408 set status [$uq run_dialog $itk_component(simulate)] 409 if {$status == 0} { 410 # cancelled 411 return 412 } 413 lappend args -uq_type [$uq type] 414 lappend args -uq_args [$uq args] 415 # Need to put these UQ values into the driver file 416 # so the call to resultset::contains will be correct. 417 set _xml [$_tool xml object] 418 $_xml put uq.type.current [$uq type] 419 $_xml put uq.args.current [$uq args] 420 $_xml put uq.args.about.label "level" 421 $_xml put uq.args.about.description "Polynomial Degree of Smolyak GPC method." 422 } 423 #puts "simulate args=$args" 424 425 if {[lindex $args 0] == "-ifneeded"} { 398 426 # check to see if simulation is really needed 399 427 $_tool sync … … 404 432 return 405 433 } 406 set args ""434 set args [lreplace $args 0 0] 407 435 } 408 436 … … 427 455 428 456 # execute the job 457 #puts "$_tool run $args" 458 429 459 foreach {status result} [eval $_tool run $args] break 430 460 … … 470 500 } 471 501 502 472 503 # ---------------------------------------------------------------------- 473 504 # USAGE: reset ?-eventually|-now? … … 515 546 clear 516 547 } 548 #puts "Analyzer::load" 517 549 $_resultset add $xmlobj 518 550 … … 652 684 # ---------------------------------------------------------------------- 653 685 itcl::body Rappture::Analyzer::_plot {args} { 686 #puts "analyzer::_plot" 654 687 set _plotlist $args 655 688 … … 755 788 } elseif {$page != ""} { 756 789 set _lastlabel $name 757 set win [winfo toplevel $itk_component(hull)]758 790 $itk_component(resultpages) current $page 759 791 set f [$itk_component(resultpages) page $page] 760 761 792 # We don't want to replot if we're using an existing viewer with the 762 793 # the same list of objects to plot. So track the viewer and the list. 763 794 if { ![info exists _lastPlot($f)] || $_plotlist != $_lastPlot($f) } { 764 795 set _lastPlot($f) $_plotlist 796 set win [winfo toplevel $itk_component(hull)] 765 797 blt::busy hold $win 798 #puts "rviewer = $f.rviewer" 799 #puts "_plotlist = $_plotlist" 766 800 $f.rviewer plot clear 767 801 eval $f.rviewer plot add $_plotlist 768 blt::busy release [winfo toplevel $itk_component(hull)]802 blt::busy release $win 769 803 } 770 804 Rappture::Logger::log output $_label2item($name) … … 782 816 # ---------------------------------------------------------------------- 783 817 itcl::body Rappture::Analyzer::_fixResultSet {args} { 818 #puts "Analyzer::_fixResultSet $args" 784 819 array set eventData $args 785 820 switch -- $eventData(op) { … … 794 829 set haveresults 0 795 830 foreach item [_reorder [$xmlobj children output]] { 796 switch -glob -- $item { 797 log* { 798 _autoLabel $xmlobj output.$item "Output Log" counters 799 } 800 number* { 801 _autoLabel $xmlobj output.$item "Number" counters 802 } 803 integer* { 804 _autoLabel $xmlobj output.$item "Integer" counters 805 } 806 mesh* { 807 _autoLabel $xmlobj output.$item "Mesh" counters 808 } 809 string* { 810 _autoLabel $xmlobj output.$item "String" counters 811 } 812 histogram* - curve* - field* { 813 _autoLabel $xmlobj output.$item "Plot" counters 814 } 815 map* { 816 _autoLabel $xmlobj output.$item "Map" counters 817 } 818 drawing* { 819 _autoLabel $xmlobj output.$item "Drawing" counters 820 } 821 structure* { 822 _autoLabel $xmlobj output.$item "Structure" counters 823 } 824 table* { 825 _autoLabel $xmlobj output.$item "Energy Levels" counters 826 } 827 sequence* { 828 _autoLabel $xmlobj output.$item "Sequence" counters 831 if {[$xmlobj get output.$item.about.uqtype] == ""} { 832 switch -glob -- $item { 833 log* { 834 _autoLabel $xmlobj output.$item "Output Log" counters 835 } 836 number* { 837 _autoLabel $xmlobj output.$item "Number" counters 838 } 839 integer* { 840 _autoLabel $xmlobj output.$item "Integer" counters 841 } 842 mesh* { 843 _autoLabel $xmlobj output.$item "Mesh" counters 844 } 845 string* { 846 _autoLabel $xmlobj output.$item "String" counters 847 } 848 histogram* - curve* - field* { 849 _autoLabel $xmlobj output.$item "Plot" counters 850 } 851 drawing* { 852 _autoLabel $xmlobj output.$item "Drawing" counters 853 } 854 structure* { 855 _autoLabel $xmlobj output.$item "Structure" counters 856 } 857 table* { 858 _autoLabel $xmlobj output.$item "Energy Levels" counters 859 } 860 sequence* { 861 _autoLabel $xmlobj output.$item "Sequence" counters 862 } 829 863 } 830 864 } … … 853 887 } 854 888 set hidden [$xmlobj get output.$item.hide] 855 if { $hidden == ""} {889 if {$hidden == ""} { 856 890 set hidden 0 857 891 } 858 892 if {"" != $label && !$hidden} { 893 set uq_part [$xmlobj get output.$item.about.uqtype] 894 895 #puts "label=$label uq_part=$uq_part" 896 859 897 if {![info exists _label2page($label)]} { 898 #puts "Adding label: '$label'" 860 899 set name "page[incr _pages]" 900 #puts "Inserting $name into resultpages" 861 901 set page [$itk_component(resultpages) \ 862 902 insert end $name] … … 884 924 set reset($page) 1 885 925 } 886 $page.rviewer add $index $xmlobj output.$item 926 $page.rviewer add $index $xmlobj output.$item $label $uq_part 887 927 } 888 928 } … … 1037 1077 configure -simcontrolcolor $simcbg 1038 1078 1039 $itk_component(simulate) configure -state disabled 1079 if {$_uq_active == 0} { 1080 $itk_component(simulate) configure -state disabled 1081 } 1040 1082 $itk_component(abort) configure -state normal 1041 1083 … … 1065 1107 # Scan through and pick out any =RAPPTURE-PROGRESS=> messages first. 1066 1108 # 1109 1067 1110 while {[regexp -indices \ 1068 1111 {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \ … … 1080 1123 foreach {i0 i1} $match break 1081 1124 set message [string replace $message $i0 $i1] 1125 } 1126 1127 # 1128 # Now handle SUBMIT-PROGRESS 1129 # 1130 while {[regexp -indices {=SUBMIT-PROGRESS=> aborted=([0-9]+) finished=([0-9]+) failed=([0-9]+) executing=([0-9]+)\ 1131 waiting=([0-9]+) setting_up=([0-9]+) setup=([0-9]+) %done=([0-9.]+) timestamp=([0-9.]+)(\n|$)} $message \ 1132 match aborted finished failed executing waiting setting_up setup percent ts mesg]} { 1133 1134 set mesg "" 1135 foreach {i0 i1} $percent break 1136 set percent [string range $message $i0 $i1] 1137 foreach {i0 i1} $failed break 1138 set failed [string range $message $i0 $i1] 1139 foreach {i0 i1} $match break 1140 set message [string replace $message $i0 $i1] 1141 1142 if {$failed != 0} {set mesg "$failed jobs failed!"} 1143 if {$percent >= 100} { set mesg "Jobs finished. Analyzing results..."} 1144 1145 pack $itk_component(progress) -fill x -padx 10 -pady 10 1146 $itk_component(progress) settings -percent $percent -message $mesg 1082 1147 } 1083 1148 -
trunk/gui/scripts/gauge.tcl
r5659 r6021 42 42 itk_option define -sampleheight sampleHeight SampleHeight 0 43 43 itk_option define -log log Log "" 44 itk_option define -varname varname Varname "" 45 itk_option define -label label Label "" 44 46 itk_option define -validatecommand validateCommand ValidateCommand "" 47 itk_option define -uq uq Uq no 45 48 46 49 constructor {args} { # defined below } … … 57 60 protected method _layout {} 58 61 protected method _log {event args} 62 protected method _change_param_type {choice} 63 protected method _pop_uq {win} 64 protected method _pop_uq_deactivate {} 59 65 60 66 private variable _value 0 ;# value for this widget 67 private variable _mode exact ;# current mode 68 private variable _pde "" ;# ProbDistEditor 69 private variable _val "" ;# value choice combobox 70 private variable uq no 61 71 62 72 blt::bitmap define GaugeArrow { … … 77 87 # ---------------------------------------------------------------------- 78 88 itcl::body Rappture::Gauge::constructor {args} { 89 # puts "GAUGE CONS: $args" 90 array set attrs $args 91 79 92 itk_option remove hull.borderwidth hull.relief 80 93 component hull configure -borderwidth 0 … … 90 103 bind $itk_component(icon) <Configure> [itcl::code $this _redraw] 91 104 105 if {[info exists attrs(-uq)]} { 106 set uq $attrs(-uq) 107 if {[string is true $uq]} { 108 set uq 1 109 itk_component add uq { 110 button $itk_interior.uq -image [Rappture::icon UQ] \ 111 -command [itcl::code $this _pop_uq $itk_interior] 112 } 113 pack $itk_component(uq) -side right -padx 10 114 } else { 115 set uq 0 116 } 117 } else { 118 set uq 0 119 } 120 92 121 itk_component add -protected vframe { 93 122 frame $itk_interior.vframe … … 97 126 98 127 itk_component add value { 99 label $itk_component(vframe).value -width 7\128 label $itk_component(vframe).value -width 20 \ 100 129 -borderwidth 1 -relief flat -textvariable [itcl::scope _value] 101 130 } { … … 199 228 # ---------------------------------------------------------------------- 200 229 itcl::body Rappture::Gauge::value {args} { 201 set onlycheck 0 230 #puts "Gauge value: $args" 231 232 # Query. Just return the current value. 233 if {[llength $args] == 0} { 234 return $_value 235 } 236 202 237 set i [lsearch -exact $args -check] 203 238 if {$i >= 0} { 204 239 set onlycheck 1 205 240 set args [lreplace $args $i $i] 206 } 207 208 if {[llength $args] == 1} { 209 # 210 # If this gauge has -units, try to convert the incoming 211 # value to that system of units. Also, make sure that 212 # the value is bound by any min/max value constraints. 213 # 214 # Keep track of the inputted units so we can give a 215 # response about min and max values in familiar units. 216 # 217 set newval [set nv [string trim [lindex $args 0]]] 218 set units $itk_option(-units) 219 if {"" != $units} { 220 set newval [Rappture::Units::convert $newval -context $units] 221 set nvUnits [Rappture::Units::Search::for $newval] 222 if { "" == $nvUnits} { 223 set msg [Rappture::Units::description $units] 224 error "unrecognized units in value \"$newval\": should be value with units of $msg" 225 } 226 set nv [Rappture::Units::convert $nv \ 227 -context $units -to $units -units off] 228 229 # Normalize the units name 230 set newval [Rappture::Units::convert $newval -units off]$nvUnits 231 } 232 233 switch -- $itk_option(-type) { 234 integer { 235 if { [scan $nv "%g" value] != 1 || int($nv) != $value } { 236 error "bad value \"$nv\": should be an integer value" 237 } 238 } 239 real { 240 # "scan" will reject the number if the string is "NaN" or 241 # "Inf" or the empty string. It also is accepts large numbers 242 # (e.g. 111111111111111111111) that "string is double" 243 # rejects. The problem with "scan" is that it doesn't care if 244 # there are extra characters trailing the number (eg. "123a"). 245 # The extra %s substitution is used to detect this case. 246 if { [scan $nv "%g%s" dummy1 dummy2] != 1 } { 247 error "bad value \"$nv\": should be a real number" 248 } 249 } 250 } 251 252 if {"" != $itk_option(-minvalue)} { 253 set convMinVal [set minv $itk_option(-minvalue)] 254 if {"" != $units} { 255 set minv [Rappture::Units::convert $minv \ 256 -context $units -to $units -units off] 257 set convMinVal [Rappture::Units::convert \ 258 $itk_option(-minvalue) -context $units -to $nvUnits] 259 } else { 260 set newval [format "%g" $newval] 261 } 262 263 # fix for the case when the user tries to 264 # compare values like minv=-500 nv=-0600 265 set nv [format "%g" $nv] 266 set minv [format "%g" $minv] 267 268 if {$nv < $minv} { 269 error "minimum value allowed here is $convMinVal" 270 } 271 } 272 273 if {"" != $itk_option(-maxvalue)} { 274 set convMaxVal [set maxv $itk_option(-maxvalue)] 275 if {"" != $units} { 276 set maxv [Rappture::Units::convert $maxv \ 277 -context $units -to $units -units off] 278 set convMaxVal [Rappture::Units::convert \ 279 $itk_option(-maxvalue) -context $units -to $nvUnits] 280 } else { 281 set newval [format "%g" $newval] 282 } 283 284 # fix for the case when the user tries to 285 # compare values like maxv=500 nv=0600 286 set nv [format "%g" $nv] 287 set maxv [format "%g" $maxv] 288 289 if {$nv > $maxv} { 290 error "maximum value allowed here is $convMaxVal" 291 } 292 } 293 294 # 295 # If there's a -validatecommand option, then invoke the code 296 # now to check the new value. 297 # 298 if {[string length $itk_option(-validatecommand)] > 0} { 299 set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]" 300 set result [eval $cmd] 301 } 302 303 if {$onlycheck} { 304 return 305 } 306 307 set _value $newval 308 309 _redraw 310 event generate $itk_component(hull) <<Value>> 311 312 } elseif {[llength $args] != 0} { 241 } else { 242 set onlycheck 0 243 } 244 245 if {[llength $args] != 1} { 313 246 error "wrong # args: should be \"value ?-check? ?newval?\"" 247 } 248 249 set newval [Rappture::Units::mcheck_range [lindex $args 0] \ 250 $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units)] 251 252 set newmode [lindex $newval 0] 253 switch -- $newmode { 254 uniform - 255 gaussian { 256 set _mode $newmode 257 } 258 exact - 259 default { 260 set _mode exact 261 } 262 } 263 264 switch -- $itk_option(-type) { 265 integer { 266 if { [scan $newval "%g" value] != 1 || int($newval) != $value } { 267 error "bad value \"$newval\": should be an integer value" 268 } 269 } 270 } 271 272 # 273 # If there's a -validatecommand option, then invoke the code 274 # now to check the new value. 275 # 276 if {[string length $itk_option(-validatecommand)] > 0} { 277 set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]" 278 set result [eval $cmd] 279 } 280 281 if {$onlycheck} { 282 return 283 } 284 285 set _value $newval 286 $itk_component(value) configure -width [string length $_value] 287 _redraw 288 event generate $itk_component(hull) <<Value>> 289 290 if {"" != $_pde} { 291 set val [$_val translate [$_val value]] 292 $_val value $_mode 293 $_pde value $_value 294 314 295 } 315 296 return $_value … … 494 475 # ---------------------------------------------------------------------- 495 476 itcl::body Rappture::Gauge::_editor {option args} { 477 # puts "Gauge::editor option=$option args=$args" 496 478 if {$itk_option(-state) == "disabled"} { 497 479 return ;# disabled? then bail out here! … … 515 497 } 516 498 set val [lindex $args 0] 517 518 499 if {[catch {value -check $val} result]} { 519 500 if {[regexp {allowed here is (.+)} $result match newval]} { … … 597 578 } 598 579 580 if {$itk_option(-type) != "integer" && $uq} { 581 pack $itk_component(uq) -side right -padx 10 582 } 583 599 584 array set side2anchor { 600 585 left e … … 744 729 } 745 730 } 731 732 itcl::body Rappture::Gauge::_pop_uq {win} { 733 # puts "min=$itk_option(-minvalue) max=$itk_option(-maxvalue) units=$itk_option(-units)" 734 set varname $itk_option(-varname) 735 set popup .pop_uq_$varname 736 if { ![winfo exists $popup] } { 737 Rappture::Balloon $popup -title $itk_option(-label) 738 set inner [$popup component inner] 739 frame $inner.type 740 pack $inner.type -side top -fill x 741 label $inner.type.l -text "Parameter Value:" 742 pack $inner.type.l -side left 743 744 set _val [Rappture::Combobox $inner.type.val -width 20 -editable no] 745 pack $_val -side left -expand yes -fill x 746 $_val choices insert end exact "Exact Value" 747 $_val choices insert end uniform "Uniform Distribution" 748 $_val choices insert end gaussian "Gaussian Distribution" 749 bind $_val <<Value>> [itcl::code $this _change_param_type $inner] 750 751 set _pde [Rappture::ProbDistEditor $inner.entry \ 752 $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units) $_value] 753 $_val value $_mode 754 $_pde value $_value 755 pack $inner.entry -expand yes -fill both -pady {10 0} 756 757 $popup configure \ 758 -deactivatecommand [itcl::code $this _pop_uq_deactivate] 759 } 760 update 761 $popup activate $win right 762 } 763 764 itcl::body Rappture::Gauge::_pop_uq_deactivate {} { 765 # puts "deactivate [$_pde value]" 766 value [$_pde value] 767 } 768 769 itcl::body Rappture::Gauge::_change_param_type {inner} { 770 set val [$_val translate [$_val value]] 771 $_pde mode $val 772 } -
trunk/gui/scripts/main.tcl
r5659 r6021 97 97 } 98 98 99 proc ReadToolParameters { numTries } { 100 incr numTries -1 101 if { $numTries < 0 } { 102 return 103 } 104 global env 105 set paramsFile $env(TOOL_PARAMETERS) 106 if { ![file readable $paramsFile] } { 107 after 500 ReadToolParmeters $numTries 108 return 109 } 110 catch { 111 set f [open $paramsFile "r"] 112 set contents [read $f] 113 close $f 114 set pattern {^file\((.*)\):(.*)$} 115 foreach line [split $contents "\n"] { 116 if { [regexp $pattern $line match path rest] } { 117 set ::Rappture::parameters($path) $rest 118 } 119 } 120 } 121 } 122 123 if { [info exists env(TOOL_PARAMETERS)] } { 124 ReadToolParameters 10 125 } 126 99 127 set loadobjs {} 100 128 foreach runfile $params(-load) { … … 163 191 set installdir [file normalize [file dirname $params(-tool)]] 164 192 $xmlobj put tool.version.application.directory(tool) $installdir 165 166 193 set tool [Rappture::Tool ::#auto $xmlobj $installdir] 167 194 -
trunk/gui/scripts/numberentry.tcl
r5659 r6021 25 25 public method label {} 26 26 public method tooltip {} 27 28 27 protected method _newValue {} 29 28 … … 43 42 # ---------------------------------------------------------------------- 44 43 itcl::body Rappture::NumberEntry::constructor {owner path args} { 44 set varname [lindex [split $path ()] end-1] 45 45 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 46 46 error "bad object \"$owner\": should be Rappture::ControlOwner" … … 68 68 } 69 69 70 # check for number UQ flag 71 set use_uq [$_owner xml get $path.uq] 72 if {$use_uq == ""} { 73 # check for global UQ flag 74 set use_uq [[$_owner tool] xml get tool.uq] 75 } 76 77 if {$use_uq == ""} { 78 set use_uq no 79 } else { 80 set use_uq [string trim $use_uq] 81 } 82 70 83 # 71 84 # Create the widget and configure it properly based on other … … 73 86 # 74 87 itk_component add gauge { 75 $class $itk_interior.gauge -units $units -presets $presets -log $path 88 $class $itk_interior.gauge -uq $use_uq -units $units -presets $presets \ 89 -log $path -varname $varname -label [label] 76 90 } 77 91 pack $itk_component(gauge) -expand yes -fill both -
trunk/gui/scripts/probdisteditor.tcl
r5120 r6021 50 50 # CONSTRUCTOR 51 51 # ---------------------------------------------------------------------- 52 itcl::body Rappture::ProbDistEditor::constructor {min max } {52 itcl::body Rappture::ProbDistEditor::constructor {min max units default} { 53 53 # create a dispatcher for events 54 puts "PDE::constructor $min $max"54 #puts "PDE::constructor $min $max $default" 55 55 56 56 # These are the tool min and max values. May be empty. 57 57 set _umin $min 58 58 set _umax $max 59 set _units [Rappture::Units::Search::for $_umin] 59 set _units $units 60 set _uvalue(central) $default 60 61 61 62 Rappture::dispatcher _dispatcher … … 199 200 # ---------------------------------------------------------------------- 200 201 itcl::body Rappture::ProbDistEditor::value {{newval ""}} { 201 puts "PDE::value $newval"202 # puts "PDE::value $newval" 202 203 203 204 #FIXME: _value has numerical values _uvalue has value with units … … 243 244 if {"" != $_umin} { 244 245 if {"" != $units} { 245 set tmp(min) [Rappture::Units::convert $_umin -to $units - units off]246 set tmp(min) [Rappture::Units::convert $_umin -to $units -context $units -units off] 246 247 } else { 247 248 set tmp(min) $_umin … … 250 251 if {"" != $_umax} { 251 252 if {"" != $units} { 252 set tmp(max) [Rappture::Units::convert $_umax -to $units - units off]253 set tmp(max) [Rappture::Units::convert $_umax -to $units -context $units -units off] 253 254 } else { 254 255 set tmp(max) $_umax … … 285 286 # ---------------------------------------------------------------------- 286 287 itcl::body Rappture::ProbDistEditor::mode {{newval ""}} { 287 puts "PDE::mode mode=$newval min=$_umin max=$_umax units=$_units"288 # puts "PDE::mode mode=$newval min=$_umin max=$_umax units=$_units" 288 289 289 290 set modes {exact uniform gaussian custom} … … 291 292 return $modes 292 293 } 294 295 set check 0 296 if {$newval == "check"} { 297 set newval $_mode 298 set check 1 299 } 300 293 301 if {[lsearch $modes $newval] < 0} { 294 302 error "bad value \"$newval\": should be [join $modes {, }]" … … 303 311 set min "" 304 312 } else { 305 set min [Rappture::Units::convert $_umin - units off]313 set min [Rappture::Units::convert $_umin -context $_units -units off] 306 314 } 307 315 if {$_umax == ""} { 308 316 set max "" 309 317 } else { 310 set max [Rappture::Units::convert $_umax - units off]318 set max [Rappture::Units::convert $_umax -context $_units -units off] 311 319 } 312 320 } … … 326 334 uniform { 327 335 if {![info exists _value(min)] || ![info exists _value(max)]} { 328 # puts "UNIFORM min=$min max=$max" 329 if {$min != "" && $max != ""} { 330 set _value(min) $min 331 set _value(max) $max 332 } elseif {$min != ""} { 333 set _value(min) $min 334 set _value(max) [expr $min + 1] 335 } elseif {$max != ""} { 336 set _value(max) $max 337 set _value(min) [expr $max - 1] 336 set _value(max) [expr $_value(central) * 1.1] 337 set _value(min) [expr $_value(central) * 0.9] 338 if {$_value(central) == 0.0} { 339 set _value(max) 1.0 340 } 341 if {$min != ""} { 342 if {$_value(min) < $min} { 343 set $_value(min) $min 344 } 345 } 346 if {$max != ""} { 347 if {$_value(max) > $max} { 348 set $_value(max) $max 349 } 338 350 } 339 351 set _uvalue(min) $_value(min)$_units … … 342 354 } 343 355 gaussian { 344 # 356 #puts "GAUSSIAN min=$min max=$max" 345 357 if {![info exists _value(central)]} { 346 358 if {[info exists _value(min)] && [info exists _value(max)]} { … … 350 362 } 351 363 } 352 # 364 #puts "central=$_value(central)" 353 365 if {![info exists _value(stddev)]} { 354 if {[info exists _value(min)] && [info exists _value(max)]} { 355 set _value(stddev) [expr {0.3*($_value(max) - $_value(min))}] 356 } elseif {$min != "" && $max != ""} { 357 set _value(stddev) [expr {0.3*($max - $min)}] 358 } else { 359 set _value(stddev) [expr $_value(central) * 0.10] 360 } 366 set _value(stddev) [expr $_value(central) * 0.10] 361 367 } 362 368 if {$_value(stddev) <= 0} { 363 369 set _value(stddev) 1.0 364 370 } 365 # 371 #puts "stddev=$_value(stddev)" 366 372 # lower bound is -3 deviations or tool min 367 373 set trunc [expr {$_value(central) - 3*$_value(stddev)}] … … 387 393 } 388 394 395 if {$check == 1} { 396 return 397 } 389 398 # pop up the panel of editing options for this mode 390 399 foreach w [pack slaves $itk_component(vals)] { … … 452 461 # ---------------------------------------------------------------------- 453 462 itcl::body Rappture::ProbDistEditor::_redraw {} { 463 #puts "PDE::_redraw" 464 454 465 set g $itk_component(graph) 455 466 eval $g element delete [$g element names] … … 486 497 } 487 498 gaussian { 499 #puts "min=$_value(min) max=$_value(max)" 500 #puts "mean=$_value(central) dev=$_value(stddev)" 501 488 502 set min $_value(min) 489 503 set max $_value(max) … … 592 606 # ---------------------------------------------------------------------- 593 607 itcl::body Rappture::ProbDistEditor::_apply {op {widget ""}} { 594 puts "_apply $op $widget"608 #puts "PDE::_apply $op $widget" 595 609 if {$op != "bindings"} { 596 610 # need this for value/finalize … … 640 654 set newval [Rappture::Units::convert [$widget get] -context $_units] 641 655 } 642 puts "widget=$widget"643 656 set itk $itk_component(gaussianvals).stddev 644 puts "itk=$itk"645 657 if {$widget != $itk && [catch {Rappture::Units::mcheck_range $newval $_umin $_umax $_units} err]} { 646 658 # oops! value is bad -- edit again … … 658 670 set $uvar $newval 659 671 672 #if {$widget == $itk_component(gaussianvals).mean} { 673 # need new min and max 674 #set $_uvalue(min) 675 #set $_uvalue(max) ... 676 #} 677 660 678 if {[catch {Rappture::Units::convert $newval -units off} nvar]} { 661 679 set nvar $newval … … 663 681 set $var $nvar 664 682 683 mode check 665 684 $_dispatcher event -idle !redraw 666 685 } -
trunk/gui/scripts/responseviewer.tcl
r5849 r6021 167 167 168 168 if {$var1 == $var2} { 169 set path "output.curve(scatter)" 170 set _dobj [Rappture::Curve ::#auto $xmlobj $path] 171 Rappture::XyResult $w 172 $w add $_dobj {-color red} 173 169 174 set path "output.curve(response)" 170 175 set _dobj [Rappture::Curve ::#auto $xmlobj $path] 171 Rappture::XyResult $w 176 172 177 } else { 173 178 set path "output.field(f2d)" -
trunk/gui/scripts/resultviewer.tcl
r5659 r6021 26 26 27 27 constructor {args} { 28 28 # defined below 29 29 } 30 30 destructor { 31 31 # defined below 32 32 } 33 public method add {index xmlobj path }33 public method add {index xmlobj path label {uq_part ""}} 34 34 public method clear {{index ""}} 35 35 public method value {xmlobj} … … 40 40 protected method _plotAdd {xmlobj {settings ""}} 41 41 protected method _fixScale {args} 42 protected method _xml2data {xmlobj path }42 protected method _xml2data {xmlobj path label {uq_part ""}} 43 43 protected method _cleanIndex {index} 44 44 … … 58 58 # ---------------------------------------------------------------------- 59 59 itcl::body Rappture::ResultViewer::constructor {args} { 60 #puts "Creating RV $args" 60 61 # create a dispatcher for events 61 62 Rappture::dispatcher _dispatcher … … 84 85 # Data is taken from the <xmlobj> object at the <path>. 85 86 # ---------------------------------------------------------------------- 86 itcl::body Rappture::ResultViewer::add {index xmlobj path} { 87 itcl::body Rappture::ResultViewer::add {index xmlobj path label {uq_part ""}} { 88 #puts "RV add index=$index path=$path label=$label uq_part=$uq_part" 87 89 set index [_cleanIndex $index] 88 set dobj [_xml2data $xmlobj $path ]90 set dobj [_xml2data $xmlobj $path $label $uq_part] 89 91 90 92 # … … 95 97 lappend _dataslots "" 96 98 } 99 97 100 set slot [lindex $_dataslots $index] 98 lappend slot $dobj 99 set _dataslots [lreplace $_dataslots $index $index $slot] 100 101 $_dispatcher event -idle !scale 101 102 # only add dobj if it isn't already there. 103 if {[lsearch -exact $slot $dobj] < 0} { 104 lappend slot $dobj 105 #puts "slot=$slot" 106 set _dataslots [lreplace $_dataslots $index $index $slot] 107 $_dispatcher event -idle !scale 108 } 102 109 } 103 110 … … 112 119 # ---------------------------------------------------------------------- 113 120 itcl::body Rappture::ResultViewer::clear {{index ""}} { 121 #puts "RV::clear $index" 114 122 if {$index ne ""} { 115 123 # clear one result … … 191 199 # ---------------------------------------------------------------------- 192 200 itcl::body Rappture::ResultViewer::plot {option args} { 201 #puts "RV plot option=$option args=$args" 193 202 switch -- $option { 194 203 add { … … 250 259 # ---------------------------------------------------------------------- 251 260 itcl::body Rappture::ResultViewer::_plotAdd {dataobj {settings ""}} { 261 #puts "RV _plotAdd $dataobj : [$dataobj info class] : $settings" 252 262 switch -- [$dataobj info class] { 263 ::Rappture::UqInfo { 264 set mode "uq" 265 if {![info exists _mode2widget($mode)]} { 266 set w $itk_interior.uq 267 Rappture::UqNotebook $w 268 set _mode2widget($mode) $w 269 } 270 } 253 271 ::Rappture::DataTable { 254 272 set mode "datatable" … … 411 429 } 412 430 413 if {$mode != $_mode && $_mode != ""} {414 set nactive [llength [$_mode2widget($_mode) get]]415 if {$nactive > 0} {416 return ;# mixing data that doesn't mix -- ignore it!417 }418 }419 431 # Are we plotting in a new mode? then change widgets 420 432 if {$_mode2widget($mode) != [pack slaves $itk_interior]} { … … 442 454 if {"" != $_mode} { 443 455 set dlist "" 456 set objclass "" 444 457 foreach slot $_dataslots { 445 458 foreach dobj $slot { 459 if {$objclass == ""} { 460 set objclass [$dobj info class] 461 } else { 462 if {$objclass != [$dobj info class]} { 463 # If some of the objects are different classes 464 # then we cannot use the same scale, so give up. 465 return 466 } 467 } 446 468 lappend dlist $dobj 447 469 } … … 474 496 # specified <path> in the <xmlobj>. 475 497 # ---------------------------------------------------------------------- 476 itcl::body Rappture::ResultViewer::_xml2data {xmlobj path} { 477 if {[info exists _xml2data($xmlobj-$path)]} { 498 itcl::body Rappture::ResultViewer::_xml2data {xmlobj path label {uq_part ""}} { 499 #puts "RV:_xml2data $path ([$xmlobj element -as type $path]) label=$label uq_part=$uq_part" 500 501 if {$uq_part != ""} { 502 if {[info exists _xml2data($xmlobj-$label)]} { 503 $_xml2data($xmlobj-$label) add $xmlobj $path $uq_part 504 return $_xml2data($xmlobj-$label) 505 } 506 } elseif {[info exists _xml2data($xmlobj-$path]} { 478 507 return $_xml2data($xmlobj-$path) 479 508 } 480 509 481 set type [$xmlobj element -as type $path] 510 if {$uq_part != ""} { 511 set type "UQ" 512 } else { 513 set type [$xmlobj element -as type $path] 514 } 515 482 516 switch -- $type { 517 UQ { 518 set dobj [Rappture::UqInfo ::#auto $xmlobj $path $uq_part] 519 set path $label 520 } 483 521 curve { 484 522 set dobj [Rappture::Curve ::#auto $xmlobj $path] -
trunk/gui/scripts/spectrum.tcl
r5659 r6021 199 199 200 200 set value [lindex $args 0] 201 if {$units != ""} { 202 set value [Rappture::Units::convert $value \ 203 -context $units -to $units -units off] 201 202 switch -- [lindex $value 0] { 203 gaussian { 204 set value [lindex $value 1] 205 if {$units != ""} { 206 set value [Rappture::Units::convert $value \ 207 -context $units -to $units -units off] 208 } 209 } 210 uniform { 211 set min [lindex $value 1] 212 set max [lindex $value 2] 213 if {$units != ""} { 214 set min [Rappture::Units::convert $min \ 215 -context $units -to $units -units off] 216 set max [Rappture::Units::convert $max \ 217 -context $units -to $units -units off] 218 } 219 set value [expr {0.5 * ($min + $max)}] 220 } 221 default { 222 if {$units != ""} { 223 set value [Rappture::Units::convert $value \ 224 -context $units -to $units -units off] 225 } 226 } 204 227 } 205 228 -
trunk/gui/scripts/tempgauge.tcl
r5659 r6021 26 26 inherit Rappture::Gauge 27 27 28 constructor {args} { # defined below } 29 28 constructor {args} { 29 array set attrs $args 30 Rappture::Gauge::constructor -uq $attrs(-uq) 31 } { 32 eval itk_initialize -spectrum $_spectrum -units K $args 33 } 30 34 protected method _redraw {} 31 35 protected method _resize {} … … 40 44 41 45 itk::usual TemperatureGauge { 42 }43 44 # ----------------------------------------------------------------------45 # CONSTRUCTOR46 # ----------------------------------------------------------------------47 itcl::body Rappture::TemperatureGauge::constructor {args} {48 eval itk_initialize -spectrum $_spectrum -units K $args49 46 } 50 47 -
trunk/gui/scripts/tool.tcl
r5659 r6021 28 28 public method installdir {} { 29 29 return [$_task installdir] 30 } 31 public method get_uq {args} { 32 sync ;# sync all widget values to XML 33 return [eval $_task get_uq $args] 30 34 } 31 35 public method run {args} { -
trunk/gui/scripts/units.tcl
r5659 r6021 61 61 } 62 62 63 64 # ---------------------------------------------------------------------- 65 # USAGE: mcheck_range value {min ""} {max ""} 66 # 67 # Checks a value or PDF to determine if is is in a required range. 68 # Automatically does unit conversion if necessary. 69 # Returns value if OK. Error if out-of-range 70 # Examples: 71 # [mcheck_range "gaussian 0C 1C" 200K 500K] returns 1 72 # [mcheck_range "uniform 100 200" 150 250] returns 0 73 # [mcheck_range 100 0 200] returns 1 74 # ---------------------------------------------------------------------- 75 76 proc Rappture::Units::_check_range {value min max units} { 77 # puts "_check_range $value min=$min max=$max units=$units" 78 # make sure the value has units 79 if {$units != ""} { 80 set value [Rappture::Units::convert $value -context $units] 81 # for comparisons, remove units 82 set nv [Rappture::Units::convert $value -context $units -units off] 83 # get the units for the value 84 set newunits [Rappture::Units::Search::for $value] 85 } else { 86 set nv $value 87 } 88 89 if {"" != $min} { 90 if {"" != $units} { 91 # compute the minimum in the new units 92 set minv [Rappture::Units::convert $min -to $newunits -context $units -units off] 93 # same, but include units for printing 94 set convMinVal [Rappture::Units::convert $min -to $newunits -context $units] 95 } else { 96 set minv $min 97 set convMinVal $min 98 } 99 if {$nv < $minv} { 100 error "Minimum value allowed here is $convMinVal" 101 } 102 } 103 if {"" != $max} { 104 if {"" != $units} { 105 # compute the maximum in the new units 106 set maxv [Rappture::Units::convert $max -to $newunits -context $units -units off] 107 # same, but include units for printing 108 set convMaxVal [Rappture::Units::convert $max -to $newunits -context $units ] 109 } else { 110 set maxv $max 111 set convMaxVal $max 112 } 113 if {$nv > $maxv} { 114 error "Maximum value allowed here is $convMaxVal" 115 } 116 } 117 return $value 118 } 119 120 proc Rappture::Units::mcheck_range {value {min ""} {max ""} {units ""}} { 121 # puts "mcheck_range $value min=$min max=$max units=$units" 122 123 switch -- [lindex $value 0] { 124 normal - 125 gaussian { 126 # get the mean 127 set mean [_check_range [lindex $value 1] $min $max $units] 128 if {$units == ""} { 129 set dev [lindex $value 2] 130 set ndev $dev 131 } else { 132 set dev [Rappture::Units::convert [lindex $value 2] -context $units] 133 set ndev [Rappture::Units::convert $dev -units off] 134 } 135 if {$ndev <= 0} { 136 error "Deviation must be positive." 137 } 138 return [list gaussian $mean $dev] 139 } 140 uniform { 141 set min [_check_range [lindex $value 1] $min $max $units] 142 set max [_check_range [lindex $value 2] $min $max $units] 143 return [list uniform $min $max] 144 } 145 exact { 146 return [_check_range [lindex $value 1] $min $max $units] 147 } 148 default { 149 return [_check_range [lindex $value 0] $min $max $units] 150 } 151 } 152 } 153 154 # ---------------------------------------------------------------------- 155 # USAGE: mconvert value ?-context units? ?-to units? ?-units on/off? 156 # 157 # This version of convert() converts multiple values. Used when the 158 # value could be a range or probability density function (PDF). 159 # Examples: 160 # gaussian 100k 1k 161 # uniform 0eV 10eV 162 # 42 163 # exact 42 164 # ---------------------------------------------------------------------- 165 166 proc Rappture::Units::mconvert {value args} { 167 # puts "mconvert $value : $args" 168 array set opts { 169 -context "" 170 -to "" 171 -units "on" 172 } 173 174 set value [split $value] 175 176 switch -- [lindex $value 0] { 177 normal - gaussian { 178 set valtype gaussian 179 set vals [lrange $value 1 2] 180 set convtype {0 1} 181 } 182 uniform { 183 set valtype uniform 184 set vals [lrange $value 1 2] 185 set convtype {0 0} 186 } 187 exact { 188 set valtype "" 189 set vals [lindex $value 1] 190 set convtype {0} 191 } 192 default { 193 set valtype "" 194 set vals $value 195 set convtype {0} 196 } 197 } 198 199 foreach {key val} $args { 200 if {![info exists opts($key)]} { 201 error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]" 202 } 203 set opts($key) $val 204 } 205 206 set newval $valtype 207 foreach val $vals ctype $convtype { 208 if {$ctype == 1} { 209 # This code handles unit conversion for deltas (changes). 210 # For example, if we want a standard deviation of 10C converted 211 # to Kelvin, that is 10K, NOT a standard deviation of 283.15K. 212 set units [Rappture::Units::Search::for $val] 213 set base [eval Rappture::Units::convert 0$units $args -units off] 214 set new [eval Rappture::Units::convert $val $args -units off] 215 set delta [expr $new - $base] 216 set val $delta$opts(-to) 217 } 218 # tcl 8.5 allows us to do this: 219 # lappend newval [Rappture::Units::convert $val {*}$args] 220 # but we are using tcl8.4 so we use eval :^( 221 lappend newval [eval Rappture::Units::convert $val $args] 222 } 223 return $newval 224 } 225 63 226 # ---------------------------------------------------------------------- 64 227 # USAGE: convert value ?-context units? ?-to units? ?-units on/off? … … 70 233 # current system. 71 234 # ---------------------------------------------------------------------- 72 proc Rappture::Units::convert {value args} { 73 array set opts { 74 -context "" 75 -to "" 76 -units "on" 77 } 78 foreach {key val} $args { 79 if {![info exists opts($key)]} { 80 error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]" 81 } 82 set opts($key) $val 83 } 84 85 # 86 # Parse the value into the number part and the units part. 87 # 88 set value [string trim $value] 89 if {![regexp {^([-+]?[0-9]+\.?([0-9]+)?([eEdD][-+]?[0-9]+)?) *(/?[a-zA-Z]+[0-9]*)?$} $value match number dummy1 dummy2 units]} { 90 set mesg "bad value \"$value\": should be real number with units" 91 if {$opts(-context) != ""} { 92 append mesg " of [Rappture::Units::description $opts(-context)]" 93 } 94 error $mesg 95 } 96 if {$units == ""} { 97 set units $opts(-context) 98 } 99 100 # 101 # Try to find the object representing the current system of units. 102 # 103 set units [Rappture::Units::System::regularize $units] 104 set oldsys [Rappture::Units::System::for $units] 105 if {$oldsys == ""} { 106 set mesg "value \"$value\" has unrecognized units" 107 if {$opts(-context) != ""} { 108 append mesg ".\nShould be units of [Rappture::Units::description $opts(-context)]" 109 } 110 error $mesg 111 } 112 113 # 114 # Convert the number to the new system of units. 115 # 116 if {$opts(-to) == ""} { 117 # no units -- return the number as is 118 return "$number$units" 119 } 120 return [$oldsys convert "$number$units" $opts(-to) $opts(-units)] 121 } 235 # proc Rappture::Units::convert {value args} {} 236 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 237 122 238 123 239 # ---------------------------------------------------------------------- … … 128 244 # along with a list of all compatible systems. 129 245 # ---------------------------------------------------------------------- 130 proc Rappture::Units::description {units} { 131 set sys [Rappture::Units::System::for $units] 132 if {$sys == ""} { 133 return "" 134 } 135 set mesg [$sys cget -type] 136 set ulist [Rappture::Units::System::all $units] 137 if {"" != $ulist} { 138 append mesg " ([join $ulist {, }])" 139 } 140 return $mesg 141 } 246 # proc Rappture::Units::description {units} {} 247 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 248 142 249 143 250 # ---------------------------------------------------------------------- … … 154 261 private variable _system "" ;# this system of units 155 262 156 public proc for {units} 157 public proc all {units} 263 # These are in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 264 # public proc for {units} 265 # public proc all {units} 266 158 267 public proc regularize {units} 159 268 … … 361 470 # if there is no system that matches the units string. 362 471 # ---------------------------------------------------------------------- 363 itcl::body Rappture::Units::System::for {units} { 364 # 365 # See if the units are a recognized system. If not, then try to 366 # extract any metric prefix and see if what's left is a recognized 367 # system. If all else fails, see if we can find a system without 368 # the exact capitalization. The user might say "25c" instead of 369 # "25C". Try to allow that. 370 # 371 if {[info exists _base($units)]} { 372 return $_base($units) 373 } else { 374 set orig $units 375 if {[regexp {^(/?)[cCmMuUnNpPfFaAkKgGtT](.+)$} $units match slash tail]} { 376 set base "$slash$tail" 377 if {[info exists _base($base)]} { 378 set sys $_base($base) 379 if {[$sys cget -metric]} { 380 return $sys 381 } 382 } 383 384 # check the base part for improper capitalization below... 385 set units $base 386 } 387 388 set matching "" 389 foreach u [array names _base] { 390 if {[string equal -nocase $u $units]} { 391 lappend matching $_base($u) 392 } 393 } 394 if {[llength $matching] == 1} { 395 set sys [lindex $matching 0] 396 # 397 # If we got rid of a metric prefix above, make sure 398 # that the system is metric. If not, then we don't 399 # have a match. 400 # 401 if {[string equal $units $orig] || [$sys cget -metric]} { 402 return $sys 403 } 404 } 405 } 406 return "" 407 } 472 # itcl::body Rappture::Units::System::for {units} {} 473 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 474 408 475 409 476 # ---------------------------------------------------------------------- … … 414 481 # relationships that lead to the same base system. 415 482 # ---------------------------------------------------------------------- 416 itcl::body Rappture::Units::System::all {units} { 417 set sys [Rappture::Units::System::for $units] 418 if {$sys == ""} { 419 return "" 420 } 421 422 if {"" != [$sys cget -basis]} { 423 set basis [lindex [$sys cget -basis] 0] 424 } else { 425 set basis $units 426 } 427 428 set ulist $basis 429 foreach u [array names _base] { 430 set obj $_base($u) 431 set b [lindex [$obj cget -basis] 0] 432 if {$b == $basis} { 433 lappend ulist $u 434 } 435 } 436 return $ulist 437 } 483 # itcl::body Rappture::Units::System::all {units} {} 484 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 485 438 486 439 487 # ---------------------------------------------------------------------- -
trunk/gui/scripts/uq.tcl
r5120 r6021 4 4 itcl::class Rappture::UQ { 5 5 6 constructor {varlist type uqargs} {7 puts "Rappture::UQ constructor $varlist:$type:$uqargs"6 constructor {varlist num type uqargs} { 7 #puts "Rappture::UQ constructor $varlist:$type:$uqargs" 8 8 set _varlist $varlist 9 9 set _type $type 10 10 set _args $uqargs 11 set _num $num 11 12 } 12 13 … … 30 31 private variable _num_pts {} 31 32 private variable _go "" 33 private variable _num 0 32 34 } 33 35 … … 64 66 label $fr.text 65 67 66 67 68 # bind $_val <<Value>> [itcl::code $this _change_param_type $inner] 68 69 69 70 button $fr.cancel -text Cancel -command [itcl::code $this _setWaitVariable 0] 70 71 set _go $fr.go 71 button $_go -text Continue-command [itcl::code $this _setWaitVariable 1]72 button $_go -text "Launch Jobs" -command [itcl::code $this _setWaitVariable 1] 72 73 _set_text $inner 73 74 … … 119 120 120 121 itcl::body Rappture::UQ::num_runs {} { 121 set numvars [llength $_varlist] 122 puts "UQ num_runs $numvars $_type $_args" 122 #puts "varlist=$_varlist" 123 set numvars $_num 124 #puts "UQ num_runs $numvars $_type $_args" 123 125 if {![array exists _num_pts]} { _init_num_pts_array } 124 126 switch $_type { -
trunk/gui/scripts/xyresult.tcl
r5659 r6021 249 249 } 250 250 if { $color == "auto" || $color == "autoreset" } { 251 #if { $color == "autoreset" } {252 #set _nextColorIndex 0253 #}251 if { $color == "autoreset" } { 252 set _nextColorIndex 0 253 } 254 254 set color [lindex $itk_option(-autocolors) $_nextColorIndex] 255 255 if { "" == $color} { -
trunk/lang/tcl/scripts/library.tcl
r4181 r6021 70 70 } 71 71 set fname [file join $Rappture::installdir lib library.xml] 72 73 set fid [::open $fname r] 74 set info [read $fid] 75 close $fid 76 72 if { [catch { 73 set fid [::open $fname r] 74 set info [read $fid] 75 close $fid 76 } errs] != 0 } { 77 puts stderr "can't open \"$fname\": errs=$errs errorInfo=$errorInfo" 78 } 77 79 set stdlib [Rappture::LibraryObj ::#auto $info] 78 80 return $stdlib … … 83 85 } else { 84 86 # otherwise, try to open the file and create its LibraryObj 85 set fid [::open $fname r] 86 set info [read $fid] 87 close $fid 87 if { [catch { 88 set fid [::open $fname r] 89 set info [read $fid] 90 close $fid 91 } errs] != 0 } { 92 puts stderr "can't open \"$fname\": errs=$errs errorInfo=$errorInfo" 93 } 88 94 } 89 95 … … 215 221 public method remove {{path ""}} 216 222 public method xml {{path ""}} 223 public method uq_get_vars {{tfile ""}} 217 224 218 225 public method diff {libobj} … … 228 235 private variable _root 0 ;# non-zero => this obj owns document 229 236 private variable _document "" ;# XML DOM tree 230 private variable _node "" ;# node within 237 private variable _node "" ;# node within 231 238 } 232 239 … … 696 703 set otherv [Rappture::entities $libobj input] 697 704 705 # add UQ checking 706 lappend thisv uq.type uq.args 707 lappend otherv uq.type uq.args 708 698 709 # scan through values for this object, and compare against other one 699 710 foreach path $thisv { … … 717 728 lappend rlist + $path "" $oraw 718 729 } 730 719 731 return $rlist 720 732 } … … 771 783 set units [$libobj get $path.units] 772 784 if {"" != $units} { 773 set val [Rappture::Units:: convert $val \785 set val [Rappture::Units::mconvert $val \ 774 786 -context $units -to $units -units off] 775 787 } … … 1038 1050 return $rlist 1039 1051 } 1052 1053 # ---------------------------------------------------------------------- 1054 # USAGE: uq_get_vars [$tfile] 1055 # 1056 # Scans number nodes in the input section for UQ parameters. 1057 # 1058 # Returns a string in JSON so it can easily be passed to PUQ. Strips units 1059 # because PUQ does not need or recognize them. 1060 # 1061 # For example, 2 parameters, one gaussian and one uniform might return: 1062 # [["height","m",["gaussian",100,10,{"min":0}]],["velocity","m/s",["uniform",80,90]]] 1063 # 1064 # Returns "" if there are no UQ parameters. 1065 # 1066 # If tfile is specified, write a template file out. 1067 # ---------------------------------------------------------------------- 1068 itcl::body Rappture::LibraryObj::uq_get_vars {{tfile ""}} { 1069 set varout \[ 1070 set varlist [] 1071 1072 if {$tfile == ""} { 1073 set node $_node 1074 } else { 1075 set fid [::open $tfile r] 1076 set doc [dom parse [read $fid]] 1077 set node [$doc documentElement] 1078 close $fid 1079 } 1080 1081 set count 0 1082 set n [$node selectNodes /run/input//number] 1083 foreach _n $n { 1084 set x [$_n selectNodes current/text()] 1085 set val [$x nodeValue] 1086 if {[string equal -length 8 $val "uniform "] || 1087 [string equal -length 9 $val "gaussian "]} { 1088 1089 set vname [$_n getAttribute id] 1090 if {[lsearch $varlist $vname] >= 0} { 1091 continue 1092 } else { 1093 lappend varlist $vname 1094 } 1095 1096 if {$count > 0} { 1097 append varout , 1098 } 1099 incr count 1100 1101 set units "" 1102 set unode [$_n selectNodes units/text()] 1103 if {"" != $unode} { 1104 set units [$unode nodeValue] 1105 set val [Rappture::Units::mconvert $val \ 1106 -context $units -to $units -units off] 1107 } 1108 1109 set v \[\"$vname\",\"$units\", 1110 set fmt "\[\"%s\",%.16g,%.16g" 1111 set val [format $fmt [lindex $val 0] [lindex $val 1] [lindex $val 2]] 1112 append v $val 1113 1114 if {[string equal -length 9 [$x nodeValue] "gaussian "]} { 1115 set minv "" 1116 set min_node [$_n selectNodes min/text()] 1117 if {"" != $min_node} { 1118 set minv [$min_node nodeValue] 1119 if {$units != ""} { 1120 set minv [Rappture::Units::convert $minv -context $units -units off] 1121 } 1122 } 1123 1124 set maxv "" 1125 set max_node [$_n selectNodes max/text()] 1126 if {"" != $max_node} { 1127 set maxv [$max_node nodeValue] 1128 if {$units != ""} { 1129 set maxv [Rappture::Units::convert $maxv -context $units -units off] 1130 } 1131 } 1132 1133 if {$minv != "" || $maxv != ""} { 1134 append v ",{" 1135 if {$minv != ""} { 1136 append v "\"min\":$minv" 1137 if {$maxv != ""} {append v ,} 1138 } 1139 if {$maxv != ""} { 1140 append v "\"max\":$maxv" 1141 } 1142 append v "}" 1143 } 1144 } 1145 1146 if {$tfile != ""} { 1147 $x nodeValue @@[$_n getAttribute id] 1148 } 1149 append varout $v\]\] 1150 } 1151 } 1152 append varout \] 1153 1154 if {$tfile != ""} { 1155 set fid [open $tfile w] 1156 puts $fid "<?xml version=\"1.0\"?>" 1157 puts $fid [$node asXML] 1158 close $fid 1159 $doc delete 1160 } 1161 if {$varout == "\[\]"} {set varout ""} 1162 #puts "uq_get_vars returning $varout" 1163 return [list $varout $count] 1164 } -
trunk/lang/tcl/scripts/task.tcl
r4970 r6021 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: task - represents the executable part of a tool … … 29 29 30 30 public method run {args} 31 public method get_uq {args} 31 32 public method abort {} 32 33 public method reset {} … … 37 38 protected method _output {data} 38 39 protected method _log {args} 40 protected method _build_submit_cmd {cmd tfile params_file} 41 protected method _get_params {varlist uq_type uq_args} 39 42 40 43 private variable _xmlobj "" ;# XML object with inputs/outputs … … 114 117 } 115 118 return "" 119 } 120 121 itcl::body Rappture::Task::get_uq {args} { 122 foreach {path val} $args { 123 if {$path == "-uq_type"} { 124 set uq_type $val 125 } elseif {$path == "-uq_args"} { 126 set uq_args $val 127 } 128 } 129 #set varlist [$_xmlobj uq_get_vars] 130 foreach {varlist num} [$_xmlobj uq_get_vars] break 131 return [Rappture::UQ ::#auto $varlist $num $uq_type $uq_args] 116 132 } 117 133 … … 156 172 # if there are any args, use them to override parameters 157 173 set _outputcb "" 174 set uq_type "" 158 175 foreach {path val} $args { 159 176 if {$path == "-output"} { 160 177 set _outputcb $val 178 } elseif {$path == "-uq_type"} { 179 set uq_type $val 180 } elseif {$path == "-uq_args"} { 181 set uq_args $val 161 182 } else { 162 183 $_xmlobj put $path.current $val … … 165 186 166 187 foreach item {control output error} { set job($item) "" } 167 168 # write out the driver.xml file for the tool169 set file "driver[pid].xml"170 set status [catch {171 set fid [open $file w]172 puts $fid "<?xml version=\"1.0\"?>"173 puts $fid [$_xmlobj xml]174 close $fid175 } result]176 188 177 189 # Set limits for cpu time … … 187 199 set limit 10; # lower bound is 10 seconds. 188 200 } 189 } 190 Rappture::rlimit set cputime $limit 201 } 202 Rappture::rlimit set cputime $limit 203 204 # write out the driver.xml file for the tool 205 set file "driver[pid].xml" 206 set status [catch { 207 set fid [open $file w] 208 puts $fid "<?xml version=\"1.0\"?>" 209 puts $fid [$_xmlobj xml] 210 close $fid 211 } result] 212 213 if {$uq_type != ""} { 214 # Copy xml into a new file 215 set tfile "template[pid].xml" 216 set fid [open $tfile w] 217 puts $fid "<?xml version=\"1.0\"?>" 218 puts $fid [$_xmlobj xml] 219 close $fid 220 221 # Return a list of the UQ variables and their PDFs. 222 # Also turns $tfile into a template file. 223 set uq_varlist [lindex [$_xmlobj uq_get_vars $tfile] 0] 224 } 225 226 191 227 # execute the tool using the path from the tool description 192 228 if {$status == 0} { 193 229 set cmd [$_xmlobj get tool.command] 194 230 regsub -all @tool $cmd $_installdir cmd 195 regsub -all @driver $cmd $file cmd196 regsub -all {\\} $cmd {\\\\} cmd197 231 set cmd [string trimleft $cmd " "] 198 if { $cmd == "" } { 199 puts stderr "cmd is empty" 200 return [list 1 "Command is empty.\n\nThere is no command specified by\n\n <command>\n </command>\n\nin the tool.xml file."] 201 } 202 203 switch -glob -- [resources -jobprotocol] { 204 "submit*" { 205 # if job_protocol is "submit", then use use submit command 206 set cmd "submit --local $cmd" 207 } 208 "mx" { 209 # metachory submission 210 set cmd "mx $cmd" 211 } 212 "exec" { 213 # default -- nothing special 214 } 215 } 216 $_xmlobj put tool.execute $cmd 232 233 if { $cmd == "" } { 234 puts stderr "cmd is empty" 235 return [list 1 "Command is empty.\n\nThere is no command specified by\n\n <command>\n </command>\n\nin the tool.xml file."] 236 } 237 238 if {$uq_type == ""} { 239 regsub -all @driver $cmd $file cmd 240 241 switch -glob -- [resources -jobprotocol] { 242 "submit*" { 243 # if job_protocol is "submit", then use use submit command 244 set cmd "submit --local $cmd" 245 } 246 "mx" { 247 # metachory submission 248 set cmd "mx $cmd" 249 } 250 "exec" { 251 # default -- nothing special 252 } 253 } 254 } else { 255 set params_file [_get_params $uq_varlist $uq_type $uq_args] 256 set cmd [_build_submit_cmd $cmd $tfile $params_file] 257 file delete -force puq 258 } 259 260 $_xmlobj put tool.execute $cmd 217 261 218 262 # starting job... … … 223 267 if {0 == [string compare -nocase -length 5 $cmd "ECHO "] } { 224 268 set status 0; 225 set job(output) [string range $cmd 5 end] 269 set job(output) [string range $cmd 5 end] 226 270 } else { 227 271 set status [catch { 228 229 230 231 232 233 234 235 236 237 272 set ::Rappture::Task::job(control) "" 273 eval blt::bgexec \ 274 ::Rappture::Task::job(control) \ 275 -keepnewline yes \ 276 -killsignal SIGTERM \ 277 -onoutput [list [itcl::code $this _output]] \ 278 -output ::Rappture::Task::job(output) \ 279 -error ::Rappture::Task::job(error) \ 280 $cmd 281 } result] 238 282 239 283 if { $status != 0 } { 240 # We're here because the exec-ed program failed 241 242 243 244 245 246 247 248 249 250 251 252 253 284 # We're here because the exec-ed program failed 285 set logmesg $result 286 if { $::Rappture::Task::job(control) ne "" } { 287 foreach { token pid code mesg } \ 288 $::Rappture::Task::job(control) break 289 if { $token == "EXITED" } { 290 # This means that the program exited normally but 291 # returned a non-zero exitcode. Consider this an 292 # invalid result from the program. Append the stderr 293 # from the program to the message. 294 set logmesg "Program finished: exit code is $code" 295 set result "$logmesg\n\n$::Rappture::Task::job(error)" 296 } elseif { $token == "abort" } { 297 # The user pressed the abort button. 254 298 set logmesg "Program terminated by user." 255 256 257 258 259 260 261 299 set result "$logmesg\n\n$::Rappture::Task::job(output)" 300 } else { 301 # Abnormal termination 302 set logmesg "Abnormal program termination: $mesg" 303 set result "$logmesg\n\n$::Rappture::Task::job(output)" 304 } 305 } 262 306 _log run failed [list $logmesg] 263 307 return [list $status $result] 264 308 } 265 309 } … … 279 323 if {[string length $jobstats] > 0} { 280 324 uplevel #0 $jobstats [list job [incr jobnum] \ 281 282 283 325 event $simulation start $times(start) \ 326 walltime $times(walltime) cputime $times(cputime) \ 327 status $status] 284 328 } 285 329 … … 340 384 } 341 385 if {$status == 0} { 342 file delete -force -- $file386 # file delete -force -- $file 343 387 } 344 388 … … 353 397 # a reference to the run.xml file containing results. 354 398 # 399 355 400 if {$status == 0} { 356 401 set result [string trim $job(output)] 402 403 if {$uq_type != ""} { 404 # UQ. Collect data from all jobs and put it in one xml run file. 405 file delete -force -- run_uq.xml 406 if {[catch {exec puq_analyze.py puq_[pid].hdf5} res]} { 407 set fp [open "uq_debug.err" r] 408 set rdata [read $fp] 409 close $fp 410 puts "PUQ analysis failed: $res\n$rdata" 411 error "UQ analysis failed: $res\n$rdata" 412 } else { 413 append result "\n" $res 414 } 415 } 357 416 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 358 417 set _lastrun $file … … 389 448 390 449 return [list $status $result] 450 } 451 452 # ---------------------------------------------------------------------- 453 # Turn the command string from tool.xml into the proper syntax to use 454 # with a submit parameter sweep with a temlate file. Proper quoting 455 # of the template file is necessary to prevent submit from being too smart 456 # and converting it to a full pathname. 457 # ---------------------------------------------------------------------- 458 itcl::body Rappture::Task::_build_submit_cmd {cmd tfile params_file} { 459 set quote_next 0 460 set newcmd "submit --progress submit --runName=puq -l -i @:$tfile -d $params_file" 461 set cmds [split $cmd " "] 462 for {set i 0} {$i < [llength $cmds]} {incr i} { 463 set arg [lindex $cmds $i] 464 if {$quote_next == 1} { 465 set nc [string range $arg 0 0] 466 if {$nc != "\""} { 467 set arg "\"\\\"$arg\\\"\"" 468 } 469 } 470 if {$arg == "--eval"} { 471 set quote_next 1 472 } else { 473 set quote_next 0 474 } 475 if {$arg == "@driver"} { 476 set arg "\"\\\"$tfile\\\"\"" 477 } 478 append newcmd " " $arg 479 } 480 regsub -all @driver $newcmd $tfile newcmd 481 return $newcmd 391 482 } 392 483 … … 550 641 puts stderr $line 551 642 } 643 644 645 # 646 # Send the list of parameters to a python program so it can call PUQ 647 # and get a CSV file containing the parameter values to use for the runs. 648 itcl::body Rappture::Task::_get_params {varlist uq_type uq_args} { 649 set pid [pid] 650 # puts "get_params.py $pid $varlist $uq_type $uq_args" 651 if {[catch {exec get_params.py $pid $varlist $uq_type $uq_args}]} { 652 set fp [open "uq_debug.err" r] 653 set rdata [read $fp] 654 close $fp 655 puts "get_params.py failed: $rdata" 656 error "get_params.py: $rdata" 657 } 658 return params[pid].csv 659 } -
trunk/lang/tcl/scripts/units.tcl
r3362 r6021 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 2 # ---------------------------------------------------------------------- 2 3 # COMPONENT: units - mechanism for converting numbers with units … … 60 61 } 61 62 63 64 # ---------------------------------------------------------------------- 65 # USAGE: mcheck_range value {min ""} {max ""} 66 # 67 # Checks a value or PDF to determine if is is in a required range. 68 # Automatically does unit conversion if necessary. 69 # Returns value if OK. Error if out-of-range 70 # Examples: 71 # [mcheck_range "gaussian 0C 1C" 200K 500K] returns 1 72 # [mcheck_range "uniform 100 200" 150 250] returns 0 73 # [mcheck_range 100 0 200] returns 1 74 # ---------------------------------------------------------------------- 75 76 proc Rappture::Units::_check_range {value min max units} { 77 # puts "_check_range $value min=$min max=$max units=$units" 78 # make sure the value has units 79 if {$units != ""} { 80 set value [Rappture::Units::convert $value -context $units] 81 # for comparisons, remove units 82 set nv [Rappture::Units::convert $value -context $units -units off] 83 # get the units for the value 84 set newunits [Rappture::Units::Search::for $value] 85 } else { 86 set nv $value 87 } 88 89 if {"" != $min} { 90 if {"" != $units} { 91 # compute the minimum in the new units 92 set minv [Rappture::Units::convert $min -to $newunits -context $units -units off] 93 # same, but include units for printing 94 set convMinVal [Rappture::Units::convert $min -to $newunits -context $units] 95 } else { 96 set minv $min 97 set convMinVal $min 98 } 99 if {$nv < $minv} { 100 error "Minimum value allowed here is $convMinVal" 101 } 102 } 103 if {"" != $max} { 104 if {"" != $units} { 105 # compute the maximum in the new units 106 set maxv [Rappture::Units::convert $max -to $newunits -context $units -units off] 107 # same, but include units for printing 108 set convMaxVal [Rappture::Units::convert $max -to $newunits -context $units ] 109 } else { 110 set maxv $max 111 set convMaxVal $max 112 } 113 if {$nv > $maxv} { 114 error "Maximum value allowed here is $convMaxVal" 115 } 116 } 117 return $value 118 } 119 120 proc Rappture::Units::mcheck_range {value {min ""} {max ""} {units ""}} { 121 # puts "mcheck_range $value min=$min max=$max units=$units" 122 123 switch -- [lindex $value 0] { 124 normal - gaussian { 125 # get the mean 126 set mean [_check_range [lindex $value 1] $min $max $units] 127 if {$units == ""} { 128 set dev [lindex $value 2] 129 set ndev $dev 130 } else { 131 set dev [Rappture::Units::convert [lindex $value 2] -context $units] 132 set ndev [Rappture::Units::convert $dev -units off] 133 } 134 if {$ndev <= 0} { 135 error "Deviation must be positive." 136 } 137 return [list gaussian $mean $dev] 138 } 139 uniform { 140 set min [_check_range [lindex $value 1] $min $max $units] 141 set max [_check_range [lindex $value 2] $min $max $units] 142 return [list uniform $min $max] 143 } 144 exact { 145 return [_check_range [lindex $value 1] $min $max $units] 146 } 147 default { 148 return [_check_range [lindex $value 0] $min $max $units] 149 } 150 } 151 } 152 153 # ---------------------------------------------------------------------- 154 # USAGE: mconvert value ?-context units? ?-to units? ?-units on/off? 155 # 156 # This version of convert() converts multiple values. Used when the 157 # value could be a range or probability density function (PDF). 158 # Examples: 159 # gaussian 100k 1k 160 # uniform 0eV 10eV 161 # 42 162 # exact 42 163 # ---------------------------------------------------------------------- 164 165 proc Rappture::Units::mconvert {value args} { 166 # puts "mconvert $value : $args" 167 array set opts { 168 -context "" 169 -to "" 170 -units "on" 171 } 172 173 set value [split $value] 174 175 switch -- [lindex $value 0] { 176 normal - gaussian { 177 set valtype gaussian 178 set vals [lrange $value 1 2] 179 set convtype {0 1} 180 } 181 uniform { 182 set valtype uniform 183 set vals [lrange $value 1 2] 184 set convtype {0 0} 185 } 186 exact { 187 set valtype "" 188 set vals [lindex $value 1] 189 set convtype {0} 190 } 191 default { 192 set valtype "" 193 set vals $value 194 set convtype {0} 195 } 196 } 197 198 foreach {key val} $args { 199 if {![info exists opts($key)]} { 200 error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]" 201 } 202 set opts($key) $val 203 } 204 205 set newval $valtype 206 foreach val $vals ctype $convtype { 207 if {$ctype == 1} { 208 # This code handles unit conversion for deltas (changes). 209 # For example, if we want a standard deviation of 10C converted 210 # to Kelvin, that is 10K, NOT a standard deviation of 283.15K. 211 set units [Rappture::Units::Search::for $val] 212 set base [eval Rappture::Units::convert 0$units $args -units off] 213 set new [eval Rappture::Units::convert $val $args -units off] 214 set delta [expr $new - $base] 215 set val $delta$opts(-to) 216 } 217 # tcl 8.5 allows us to do this: 218 # lappend newval [Rappture::Units::convert $val {*}$args] 219 # but we are using tcl8.4 so we use eval :^( 220 lappend newval [eval Rappture::Units::convert $val $args] 221 } 222 return $newval 223 } 224 62 225 # ---------------------------------------------------------------------- 63 226 # USAGE: convert value ?-context units? ?-to units? ?-units on/off? … … 69 232 # current system. 70 233 # ---------------------------------------------------------------------- 71 proc Rappture::Units::convert {value args} { 72 array set opts { 73 -context "" 74 -to "" 75 -units "on" 76 } 77 foreach {key val} $args { 78 if {![info exists opts($key)]} { 79 error "bad option \"$key\": should be [join [lsort [array names opts]] {, }]" 80 } 81 set opts($key) $val 82 } 83 84 # 85 # Parse the value into the number part and the units part. 86 # 87 set value [string trim $value] 88 if {![regexp {^([-+]?[0-9]+\.?([0-9]+)?([eEdD][-+]?[0-9]+)?) *(/?[a-zA-Z]+[0-9]*)?$} $value match number dummy1 dummy2 units]} { 89 set mesg "bad value \"$value\": should be real number with units" 90 if {$opts(-context) != ""} { 91 append mesg " of [Rappture::Units::description $opts(-context)]" 92 } 93 error $mesg 94 } 95 if {$units == ""} { 96 set units $opts(-context) 97 } 98 99 # 100 # Try to find the object representing the current system of units. 101 # 102 set units [Rappture::Units::System::regularize $units] 103 set oldsys [Rappture::Units::System::for $units] 104 if {$oldsys == ""} { 105 set mesg "value \"$value\" has unrecognized units" 106 if {$opts(-context) != ""} { 107 append mesg ".\nShould be units of [Rappture::Units::description $opts(-context)]" 108 } 109 error $mesg 110 } 111 112 # 113 # Convert the number to the new system of units. 114 # 115 if {$opts(-to) == ""} { 116 # no units -- return the number as is 117 return "$number$units" 118 } 119 return [$oldsys convert "$number$units" $opts(-to) $opts(-units)] 120 } 234 # proc Rappture::Units::convert {value args} {} 235 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 236 121 237 122 238 # ---------------------------------------------------------------------- … … 127 243 # along with a list of all compatible systems. 128 244 # ---------------------------------------------------------------------- 129 proc Rappture::Units::description {units} { 130 set sys [Rappture::Units::System::for $units] 131 if {$sys == ""} { 132 return "" 133 } 134 set mesg [$sys cget -type] 135 set ulist [Rappture::Units::System::all $units] 136 if {"" != $ulist} { 137 append mesg " ([join $ulist {, }])" 138 } 139 return $mesg 140 } 245 # proc Rappture::Units::description {units} {} 246 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 247 141 248 142 249 # ---------------------------------------------------------------------- … … 153 260 private variable _system "" ;# this system of units 154 261 155 public proc for {units} 156 public proc all {units} 262 # These are in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 263 # public proc for {units} 264 # public proc all {units} 265 157 266 public proc regularize {units} 158 267 … … 360 469 # if there is no system that matches the units string. 361 470 # ---------------------------------------------------------------------- 362 itcl::body Rappture::Units::System::for {units} { 363 # 364 # See if the units are a recognized system. If not, then try to 365 # extract any metric prefix and see if what's left is a recognized 366 # system. If all else fails, see if we can find a system without 367 # the exact capitalization. The user might say "25c" instead of 368 # "25C". Try to allow that. 369 # 370 if {[info exists _base($units)]} { 371 return $_base($units) 372 } else { 373 set orig $units 374 if {[regexp {^(/?)[cCmMuUnNpPfFaAkKgGtT](.+)$} $units match slash tail]} { 375 set base "$slash$tail" 376 if {[info exists _base($base)]} { 377 set sys $_base($base) 378 if {[$sys cget -metric]} { 379 return $sys 380 } 381 } 382 383 # check the base part for improper capitalization below... 384 set units $base 385 } 386 387 set matching "" 388 foreach u [array names _base] { 389 if {[string equal -nocase $u $units]} { 390 lappend matching $_base($u) 391 } 392 } 393 if {[llength $matching] == 1} { 394 set sys [lindex $matching 0] 395 # 396 # If we got rid of a metric prefix above, make sure 397 # that the system is metric. If not, then we don't 398 # have a match. 399 # 400 if {[string equal $units $orig] || [$sys cget -metric]} { 401 return $sys 402 } 403 } 404 } 405 return "" 406 } 471 # itcl::body Rappture::Units::System::for {units} {} 472 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 473 407 474 408 475 # ---------------------------------------------------------------------- … … 413 480 # relationships that lead to the same base system. 414 481 # ---------------------------------------------------------------------- 415 itcl::body Rappture::Units::System::all {units} { 416 set sys [Rappture::Units::System::for $units] 417 if {$sys == ""} { 418 return "" 419 } 420 421 if {"" != [$sys cget -basis]} { 422 set basis [lindex [$sys cget -basis] 0] 423 } else { 424 set basis $units 425 } 426 427 set ulist $basis 428 foreach u [array names _base] { 429 set obj $_base($u) 430 set b [lindex [$obj cget -basis] 0] 431 if {$b == $basis} { 432 lappend ulist $u 433 } 434 } 435 return $ulist 436 } 482 # itcl::body Rappture::Units::System::all {units} {} 483 # Actual implementation is in rappture/lang/tcl/src/RpUnitsTclInterface.cc. 484 437 485 438 486 # ---------------------------------------------------------------------- -
trunk/puq/Makefile.in
r5030 r6021 22 22 SCRIPTS = $(srcdir)/get_params.py \ 23 23 $(srcdir)/puq_analyze.py \ 24 $(srcdir)/ uq.py24 $(srcdir)/get_response.py 25 25 26 26 .PHONY: all install clean distclean -
trunk/puq/get_params.py
r5029 r6021 1 1 #!/usr/bin/env python 2 from puq import * 3 import csv, sys, os 2 """ 3 This script takes some uq parameters from the command line 4 and starts up a PUQ session using them. The RapptureHost() 5 class will not actually execute any jobs. Job parameters 6 are instead saved to a CSV file named params[pid].csv. 7 PUQ status is saved into an hdf5 file, as usual. 8 """ 9 10 from __future__ import print_function 11 import sys 12 import os 13 from puq import NormalParameter, UniformParameter, Sweep, RapptureHost, Smolyak 4 14 import numpy as np 5 15 from puq.jpickle import unpickle 6 16 7 dfile, pid, varlist, uq_type, args = sys.argv[1:] 17 # Redirect stdout and stderr to files for debugging. 18 sys.stdout = open("uq_debug.out", 'w') 19 sys.stderr = open("uq_debug.err", 'w') 20 21 print(sys.argv) 22 pid, varlist, uq_type, args = sys.argv[1:] 23 24 dfile = "driver%s.xml" % pid 8 25 cvsname = "params%s.csv" % pid 9 26 hname = "puq_%s.hdf5" % pid 10 27 11 12 sys.stdout = open("gp.log", 'w')13 sys.stderr = open("gp.err", 'w')14 15 print sys.argv[1:]16 28 varlist = unpickle(varlist) 17 print "varlist=", varlist 18 print type(varlist) 29 print("varlist=", varlist) 19 30 20 31 v = {} 32 units = {} 21 33 for p in varlist: 22 name, dist = p34 name, _units, dist = p 23 35 name = str(name) 24 print "name=", name 25 print "dist=", dist 36 units[name] = str(_units) 26 37 if dist[0] == u'gaussian': 27 v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2]) 38 try: 39 kwargs = dist[3] 40 except: 41 kwargs = {} 42 v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2], **kwargs) 43 print(v[name]) 28 44 elif dist[0] == u'uniform': 29 45 v[name] = UniformParameter(name, name, min=dist[1], max=dist[2]) 30 46 else: 31 print "ERROR: Unknown distribution type: %s" % dist[0]47 print("ERROR: Unknown distribution type: %s" % dist[0]) 32 48 sys.exit(1) 33 49 if uq_type == "smolyak": 34 50 uq = Smolyak(v.values(), args) 35 51 else: 36 print "ERROR: Unknown UQ type: %s" % uq_type52 print("ERROR: Unknown UQ type: %s" % uq_type) 37 53 os.chdir('..') 38 54 sys.exit(1) 39 55 40 vals = np.column_stack([p.values for p in uq.params]) 41 names = ['@@'+str(p.name) for p in uq.params] 42 np.savetxt(cvsname, vals, delimiter=',', header=','.join(names), comments='') 56 # save parameter values to CSV file 57 with open(cvsname, 'w') as f: 58 print(','.join(['@@'+str(p.name) for p in uq.params]), file=f) 59 for i in range(len(uq.params[0].values)): 60 print(','.join(['%.16g%s' % (p.values[i], units[p.name]) for p in uq.params]), file=f) 43 61 44 sw = Sweep(uq, RapptureHost('puq', dfile), 'test/vel_add.py') 62 # This just saves PUQ state into HDF5 file, so later we can have PUQ analyze 63 # the results and it knows about the input parameters, UQ method, etc. 64 host = RapptureHost('puq', dfile) 65 sw = Sweep(uq, host, None) 66 host.psweep = sw.psweep 45 67 sw.run(hname, overwrite=True) 68 69 print("Finished with get_params.py\n") -
trunk/puq/get_response.py
r5849 r6021 40 40 resp = unpickle(resp) 41 41 var = None 42 42 43 for index, p in enumerate(resp.params): 43 44 if p.name == name: … … 50 51 51 52 data = resp.data 52 print ("vars=", resp.vars) 53 print("data=", data) 54 print("my data=", data.T[index]) 55 print("my data=", data[:, index]) 53 print('data=', repr(data)) 54 for ind, p in enumerate(resp.params): 55 if ind == index: 56 continue 57 m = p.pdf.mean 58 means = np.isclose(m, data[:, ind], rtol=1e-6, atol=1e-12) 59 data = data[means] 60 61 print("vars=", resp.vars) 62 print("data=", repr(data)) 56 63 57 64 curve = xml.SubElement(dout, 'curve', {'id': 'response'}) … … 74 81 else: 75 82 allpts[:, i] = np.mean(v.pdf.mean) 76 print("allpts=", allpts) 83 77 84 pts = resp.evala(allpts) 78 print("pts=", pts)79 85 xy = '\n'.join([' '.join(map(repr, a)) for a in zip(x, pts)]) 80 86 comp = xml.SubElement(curve, 'component') … … 82 88 83 89 # scatter plot sampled data on response surface 84 # curve = io['output.curve(response-%s-scatter)' % name] 85 # curve['about.label'] = 'Data Points' 86 # curve['about.group'] = title 87 # curve['about.type'] = 'scatter' 88 # curve['xaxis.label'] = varlist[0] 89 # curve['yaxis.label'] = tname 90 # curve['component.xy'] = (xdata, ydata) 90 curve = xml.SubElement(dout, 'curve', {'id': 'scatter'}) 91 about = xml.SubElement(curve, 'about') 92 xml.SubElement(about, 'label').text = 'Data Points' 93 xml.SubElement(about, 'group').text = rlabel 94 xml.SubElement(about, 'type').text = 'scatter' 95 comp = xml.SubElement(curve, 'component') 96 xy = '\n'.join([' '.join(map(repr, a)) for a in zip(data[:, index], data[:, -1])]) 97 xml.SubElement(comp, 'xy').text = xy 91 98 92 99 -
trunk/puq/puq_analyze.py
r5103 r6021 1 1 #!/usr/bin/env python 2 """ 3 Once submit has finished with the jobs, this function is called to have PUQ 4 process the results. 5 """ 6 from __future__ import print_function 2 7 import sys 3 sys.stdout = open("analyze.out", 'w') 4 sys.stderr = open("analyze.err", 'w') 5 8 import os 9 import numpy as np 10 import h5py 11 import re 6 12 import puq 7 import csv8 import numpy as np9 import os, h5py10 13 from puq.jpickle import unpickle 11 import xml.etree.ElementTree as xml 12 13 14 import Rappture 15 import StringIO 16 from scipy.spatial import ConvexHull 17 # geometry library 18 from shapely.geometry import Polygon 19 from shapely.ops import unary_union 20 21 # Redirect stdout and stderr to files for debugging. 22 # Append to the files created in get_params.py 23 sys.stdout = open("uq_debug.out", 'a') 24 sys.stderr = open("uq_debug.err", 'a') 25 26 27 # Restore the state of a PUQ session from a HDF5 file. 14 28 def load_from_hdf5(name): 15 29 h5 = h5py.File(name, 'r+') … … 24 38 return sw 25 39 26 sw = load_from_hdf5(sys.argv[1]) 27 sw.analyze() 28 29 h5 = h5py.File(sys.argv[1], 'r+') 30 31 32 dtree = xml.parse('run_uq.xml') 33 droot = dtree.getroot() 34 dout = droot.find('output') 35 36 uqtype = h5.attrs['UQtype'] 37 for v in h5[uqtype]: 38 print 'PDF', v 39 rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value) 40 pdf = rs.pdf(fit=False) 41 42 id = '%s PDF' % v 43 elem = xml.SubElement(dout, 'curve', {'id': id}) 44 about = xml.SubElement(elem, 'about') 45 label = xml.SubElement(about, 'label') 46 label.text = id 47 desc = xml.SubElement(about, 'description') 48 desc.text = "PDF for %s" % id 49 yaxis = xml.SubElement(elem, 'yaxis') 50 label = xml.SubElement(yaxis, 'label') 51 label.text = 'Probability' 52 53 component = xml.SubElement(elem, 'component') 54 xy = xml.SubElement(component, 'xy') 40 41 # Plots probability curves 42 def plot_pdf_curve(io, h5, xvals, vname, percent): 43 print('plot_pdf_curve %s %s' % (vname, percent)) 44 # compute upper and lower percentiles 45 pm = (100 - percent)/200.0 46 pp = 1 - pm 47 48 label = None 49 50 # collect data into an array 51 xarr = np.empty(len(xvals[vname])) 52 yp = np.empty(len(xvals[vname])) 53 ym = np.empty(len(xvals[vname])) 54 55 for vindex in sorted(xvals[vname].keys()): 56 if label is None: 57 label = h5['/output/data/%s[%d]' % (vname, vindex)].attrs['label'] 58 xarr[vindex] = xvals[vname][vindex] 59 yp[vindex] = pcurves[vname][vindex].ppf(pp) 60 ym[vindex] = pcurves[vname][vindex].ppf(pm) 61 62 curve = io['output.curve(curve_pdf-%s-%s)' % (vname, percent)] 63 if percent == 0: 64 curve['about.label'] = "mean" 65 else: 66 curve['about.label'] = "middle %s%%" % percent 67 curve['about.group'] = label 68 curve['about.uqtype'] = 'Probability' 69 70 pts = "" 71 for x, y in zip(xarr, yp): 72 pts += "%s %s " % (x, y) 73 if percent == 0: 74 pts += '\n' 75 else: 76 for x, y in reversed(zip(xarr, ym)): 77 pts += "%s %s " % (x, y) 78 pts += "%s %s\n" % (xarr[0], yp[0]) 79 80 curve['component.xy'] = pts 81 82 83 def add_pts(f1, percent): 84 # compute upper and lower percentiles 85 pm = (100 - percent) / 200.0 86 pp = 1 - pm 87 prob = np.linspace(pm, pp, 31) 88 x, y = f1.eval(prob) 89 return np.array(zip(x, y)) 90 91 92 def plot_pdf_acurve(io, h5, acurves, vname, percent): 93 """ 94 This function plots the probability curves for parametric 95 PDFs. 96 """ 97 print('plot_pdf_acurve %s %s' % (vname, percent)) 98 99 label = None 100 prev_pts = None # last set of points 101 102 poly = [] 103 for vindex in sorted(acurves[vname].keys()): 104 if label is None: 105 label = h5['/output/data/%s[%d]' % (vname, vindex)].attrs['label'] 106 f1 = unpickle(h5['/output/data/%s[%d]' % (vname, vindex)].attrs['curve']) 107 bpts = add_pts(f1, percent) 108 109 # first data set? Just remember it. 110 if prev_pts is None: 111 prev_pts = bpts 112 continue 113 114 pts = np.array((prev_pts, bpts)).ravel().reshape(-1, 2) 115 hull = ConvexHull(pts, qhull_options='Pp') 116 p1 = Polygon([hull.points[v] for v in hull.vertices]) 117 poly.append(p1) 118 prev_pts = bpts 119 120 u = unary_union(poly) 121 122 curve = io['output.curve(curve_pdf-%s-%s)' % (vname, percent)] 123 if percent == 0: 124 curve['about.label'] = "mean" 125 else: 126 curve['about.label'] = "middle %s%%" % percent 127 curve['about.group'] = label 128 curve['about.uqtype'] = 'Probability' 129 curve['component.xy'] = np.array(u.exterior.xy) 130 131 132 def plot_pdf(io, v, pdf, desc): 133 print("plot_pdf %s desc=%s" % (v, desc)) 134 p = io['output.curve(pdf-%s)' % v] 135 p['about.label'] = desc 136 p['about.uqtype'] = "PDF" 137 p['yaxis.label'] = 'Probability' 138 55 139 pts = "%s 0\n" % pdf.x[0] 56 140 for x, y in zip(pdf.x, pdf.y): 57 141 pts += "%s %s\n" % (x, y) 58 142 pts += "%s 0\n" % pdf.x[-1] 59 xy.text = pts 60 61 with open('run_uq.xml', 'w') as f: 62 f.write("<?xml version=\"1.0\"?>\n") 63 dtree.write(f) 64 65 143 p['component.xy'] = pts 144 145 146 def write_responses(io, h5): 147 uqtype = h5.attrs['UQtype'] 148 for v in h5[uqtype]: 149 print("write_responses", v) 150 if '[' in v: 151 # It is a curve. Ignore. 152 continue 153 try: 154 desc = h5['%s/%s' % (uqtype, v)].attrs['description'] 155 except: 156 desc = '' 157 try: 158 label = h5['%s/%s' % (uqtype, v)].attrs['label'] 159 except: 160 label = '' 161 162 rsp = h5['/%s/%s/response' % (uqtype, v)].value 163 rout = io['output.response(%s)' % v] 164 rout['value'] = rsp 165 rout['about.description'] = desc 166 rout['about.label'] = label 167 rout['about.uqtype'] = 'Response' 168 169 rs = unpickle(rsp) 170 rout['variables'] = ' '.join([str(p.name) for p in rs.params]) 171 labels = ' '.join([repr(str(p.label)) for p in rs.params]) 172 rout['labels'] = labels.replace("'", '"') 173 174 if type(rs) == puq.response.ResponseFunc: 175 rout['equation'] = rs.eqn 176 rout['rmse'] = "{:6.3g}".format(rs.rmse()[1]) 177 178 rout['data'] = rs.data 179 180 181 def write_params(h5, out): 182 params = map(str, h5['/input/params'].keys()) 183 print('#' * 80, file=out) 184 print('INPUT PARAMETERS', file=out) 185 186 for pname in params: 187 print('-' * 80, file=out) 188 p = puq.unpickle(h5['/input/params/' + pname].value) 189 cname = p.__class__.__name__[:-9] 190 pdf_str = '%s [%s - %s] mean=%s dev=%s mode=%s' % (cname, p.pdf.range[0], p.pdf.range[1], p.pdf.mean, p.pdf.dev, p.pdf.mode) 191 192 print("Name:", p.name, file=out) 193 try: 194 print("Label:", p.label, file=out) 195 except: 196 pass 197 print("Desc:", p.description, file=out) 198 print('Value:', pdf_str, file=out) 199 print('#' * 80, file=out) 200 print(file=out) 201 202 203 def write_summary(io, h5): 204 outstr = StringIO.StringIO() 205 write_params(h5, outstr) 206 uqtype = h5.attrs['UQtype'] 207 for v in h5[uqtype]: 208 if '[' in v: 209 # It is a curve. Ignore. 210 continue 211 desc = h5['%s/%s' % (uqtype, v)].attrs['description'] 212 print("QoI: %s (%s)" % (v, desc), file=outstr) 213 rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value) 214 if type(rs) == puq.response.ResponseFunc: 215 print("\nv=%s\n" % rs.eqn, file=outstr) 216 print("SURROGATE MODEL ERROR:{:6.3g}%".format(rs.rmse()[1]), file=outstr) 217 sens = puq.unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value) 218 max_name_len = max(map(len, [p[0] for p in sens])) 219 print("\nSENSITIVITY:", file=outstr) 220 print("Var%s u* dev" % (' '*(max_name_len)), file=outstr) 221 print('-'*(28+max_name_len), file=outstr) 222 for item in sens: 223 pad = ' '*(max_name_len - len(item[0])) 224 print("{}{} {:10.4g} {:10.4g}".format(pad, item[0], 225 item[1]['ustar'], item[1]['std']), file=outstr) 226 print('-'*(28+max_name_len), file=outstr) 227 print(file=outstr) 228 iostr = io['output.string(UQ Summary)'] 229 iostr['about.label'] = 'UQ Summary' 230 iostr['current'] = outstr.getvalue() 231 outstr.close() 232 233 234 def write_sensitivity(io, h5): 235 # If more than one variable, display sensitivity. 236 # Curves have indexed variables, so skip them. 237 if len(h5['/input/params']) > 1 and ['[' in x for x in h5[uqtype]].count(False): 238 for v in h5[uqtype]: 239 if '[' in v: 240 # curve. skip it. 241 continue 242 desc = h5['/output/data/%s' % v].attrs['label'] 243 sens = unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value) 244 245 hist = io['output.histogram(sens-%s)' % v] 246 hist['about.label'] = desc 247 hist['about.uqtype'] = 'Sensitivity' 248 hist['about.type'] = 'scatter' 249 hist['xaxis.label'] = 'Parameters' 250 hist['yaxis.label'] = 'Sensitivity' 251 pts = '' 252 for name in sens: 253 n = name[0] 254 try: 255 n = h5['/input/params/%s' % n].attrs['label'] 256 except: 257 pass 258 pts += "\"%s\" %s\n" % (n, name[1]['ustar']) 259 hist['component.xy'] = pts 260 261 sw = load_from_hdf5(sys.argv[1]) 262 sw.analyze() 263 264 h5 = h5py.File(sys.argv[1], 'r+') 265 io = Rappture.PyXml('run_uq.xml') 266 267 # curves built from pdfs 268 pcurves = {} 269 xvals = {} 270 acurves = {} 271 272 reg1 = re.compile('([ \da-zA-Z_]+)\[([ \d]+)\]') 273 274 uqtype = h5.attrs['UQtype'] 275 for v in h5[uqtype]: 276 print('v=', v) 277 rsp = h5['/%s/%s/response' % (uqtype, v)].value 278 rs = unpickle(rsp) 279 pdf = rs.pdf(fit=False) 280 odata = h5['/output/data/%s' % v] 281 282 # For curves built from pdfs, just put them in a dict for now 283 if 'x' in odata.attrs: 284 matches = reg1.findall(v) 285 vname, vindex = matches[0] 286 print('CURVE: vname=%s vindex=%s' % (vname, vindex)) 287 vindex = int(vindex) 288 if vname not in pcurves: 289 pcurves[vname] = {} 290 xvals[vname] = {} 291 xvals[vname][vindex] = odata.attrs['x'] 292 pcurves[vname][vindex] = pdf 293 elif 'curve' in odata.attrs: 294 matches = reg1.findall(v) 295 vname, vindex = matches[0] 296 print('ACURVE: %s - %s' % (vname, vindex)) 297 if vname not in acurves: 298 acurves[vname] = {} 299 acurves[vname][int(vindex)] = pdf 300 else: 301 desc = h5['/output/data/%s' % v].attrs['label'] 302 plot_pdf(io, v, pdf, desc) 303 304 # now do probability curves 305 for vname in xvals: 306 plot_pdf_curve(io, h5, xvals, vname, 95) 307 plot_pdf_curve(io, h5, xvals, vname, 50) 308 309 for vname in acurves: 310 try: 311 plot_pdf_acurve(io, h5, acurves, vname, 95) 312 except: 313 pass 314 try: 315 plot_pdf_acurve(io, h5, acurves, vname, 50) 316 except: 317 pass 318 319 write_sensitivity(io, h5) 320 write_responses(io, h5) 321 write_summary(io, h5) 322 323 io.close() 66 324 h5.close()
Note: See TracChangeset
for help on using the changeset viewer.