[5709] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
| 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: ResponseViewer - Response Surface (surogate Model) Viewer |
---|
| 4 | # |
---|
| 5 | # Gets response data from PUQ and displayes it using vtk. |
---|
| 6 | # ====================================================================== |
---|
| 7 | # Copyright (c) 2004-2014 HUBzero Foundation, LLC |
---|
| 8 | # |
---|
| 9 | # See the file "license.terms" for information on usage and |
---|
| 10 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 11 | # ====================================================================== |
---|
| 12 | package require Itk |
---|
| 13 | package require BLT |
---|
| 14 | |
---|
| 15 | option add *ResponseViewer.width 4i widgetDefault |
---|
| 16 | option add *ResponseViewer*cursor crosshair widgetDefault |
---|
| 17 | option add *ResponseViewer.height 4i widgetDefault |
---|
| 18 | option add *ResponseViewer.foreground black widgetDefault |
---|
| 19 | option add *ResponseViewer.controlBackground gray widgetDefault |
---|
| 20 | option add *ResponseViewer.controlDarkBackground #999999 widgetDefault |
---|
| 21 | option add *ResponseViewer.plotBackground black widgetDefault |
---|
| 22 | option add *ResponseViewer.plotForeground white widgetDefault |
---|
| 23 | option add *ResponseViewer.font \ |
---|
| 24 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | itcl::class Rappture::ResponseViewer { |
---|
| 28 | inherit itk::Widget |
---|
| 29 | |
---|
| 30 | itk_option define -plotforeground plotForeground Foreground "" |
---|
| 31 | itk_option define -plotbackground plotBackground Background "" |
---|
| 32 | |
---|
| 33 | constructor {args} { |
---|
| 34 | # defined below |
---|
| 35 | } |
---|
| 36 | destructor { |
---|
| 37 | # defined below |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | public method add {dataobj {settings ""}} |
---|
| 41 | public method delete {args} |
---|
[5720] | 42 | public method download {option args} |
---|
[5709] | 43 | |
---|
| 44 | private variable _response |
---|
| 45 | private variable _settings |
---|
| 46 | private variable _label |
---|
| 47 | private variable _dobj "" |
---|
| 48 | private method _combobox_cb {} |
---|
| 49 | private method _plot_response {var1 var2} |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | itk::usual ResponseViewer { |
---|
| 53 | keep -background -foreground -cursor -font |
---|
| 54 | keep -plotbackground -plotforeground |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | # ---------------------------------------------------------------------- |
---|
| 58 | # CONSTRUCTOR |
---|
| 59 | # ---------------------------------------------------------------------- |
---|
| 60 | itcl::body Rappture::ResponseViewer::constructor {args} { |
---|
| 61 | option add hull.width hull.height |
---|
| 62 | pack propagate $itk_component(hull) yes |
---|
| 63 | |
---|
| 64 | itk_component add frame { |
---|
| 65 | frame $itk_interior.frame |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | itk_component add frame2 { |
---|
| 69 | frame $itk_interior.frame2 |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | # ---------------------------------------------------------------------- |
---|
| 74 | # DESTRUCTOR |
---|
| 75 | # ---------------------------------------------------------------------- |
---|
| 76 | itcl::body Rappture::ResponseViewer::destructor {} { |
---|
| 77 | |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | # ---------------------------------------------------------------------- |
---|
| 81 | # USAGE: add <dataobj> ?<settings>? |
---|
| 82 | # |
---|
| 83 | # Clients use this to add a dataobj to the plot. |
---|
| 84 | # ---------------------------------------------------------------------- |
---|
| 85 | itcl::body Rappture::ResponseViewer::add {uqobj {settings ""}} { |
---|
[5833] | 86 | #puts "ResponseViewer ADD $uqobj ($settings)" |
---|
[5709] | 87 | set _response [$uqobj response] |
---|
| 88 | set vars [$uqobj variables] |
---|
| 89 | set labs [$uqobj vlabels] |
---|
| 90 | set _settings $settings |
---|
| 91 | set _label [$uqobj label] |
---|
[5743] | 92 | |
---|
[5709] | 93 | if {[llength $vars] > 1} { |
---|
| 94 | set cb1 [Rappture::Combobox $itk_interior.frame2.cb1 -width 10 -editable no] |
---|
| 95 | set cb2 [Rappture::Combobox $itk_interior.frame2.cb2 -width 10 -editable no] |
---|
| 96 | |
---|
| 97 | foreach v $vars l $labs { |
---|
| 98 | $cb1 choices insert end $v $l |
---|
| 99 | $cb2 choices insert end $v $l |
---|
| 100 | } |
---|
| 101 | $cb1 value [$cb1 label [lindex $vars 0]] |
---|
| 102 | $cb2 value [$cb2 label [lindex $vars 1]] |
---|
| 103 | bind $cb1 <<Value>> [itcl::code $this _combobox_cb] |
---|
| 104 | bind $cb2 <<Value>> [itcl::code $this _combobox_cb] |
---|
| 105 | |
---|
| 106 | set vs [label $itk_interior.frame2.desc -text "vs"] |
---|
| 107 | grid $cb1 $vs $cb2 |
---|
| 108 | } else { |
---|
| 109 | set label [lindex $labs 0] |
---|
| 110 | set lab [label $itk_interior.frame2.desc -text "Response for $label"] |
---|
| 111 | grid $lab |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | set rmsep [$uqobj rmse] |
---|
| 115 | if {$rmsep > 10} { |
---|
| 116 | set color red |
---|
| 117 | } elseif {$rmsep > 5} { |
---|
| 118 | set color orange |
---|
| 119 | } elseif {$rmsep > 2} { |
---|
| 120 | set color yellow |
---|
| 121 | } else { |
---|
| 122 | set color black |
---|
| 123 | } |
---|
| 124 | set rmse [label $itk_interior.frame2.rmse -text "RMSE: $rmsep%" -foreground $color] |
---|
| 125 | |
---|
| 126 | grid $rmse -row 0 -column 4 -sticky e |
---|
| 127 | grid $itk_component(frame) -row 0 -column 0 -sticky nsew |
---|
| 128 | grid $itk_component(frame2) -row 1 -column 0 -sticky nsew |
---|
| 129 | grid columnconfigure $itk_component(frame) 0 -weight 1 |
---|
| 130 | grid columnconfigure $itk_component(frame2) 3 -weight 1 |
---|
| 131 | grid rowconfigure $itk_component(frame) 0 -weight 1 |
---|
| 132 | grid columnconfigure $itk_component(hull) 0 -weight 1 |
---|
| 133 | grid rowconfigure $itk_component(hull) 0 -weight 1 |
---|
| 134 | |
---|
| 135 | if {[llength $vars] > 1} { |
---|
| 136 | _combobox_cb |
---|
| 137 | } else { |
---|
| 138 | if {$_dobj != ""} { |
---|
| 139 | destroy $itk_component(frame).field |
---|
| 140 | destroy _dobj |
---|
| 141 | set _dobj "" |
---|
| 142 | } |
---|
| 143 | set vname [lindex $vars 0] |
---|
| 144 | after idle [itcl::code $this _plot_response $vname $vname] |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | itcl::body Rappture::ResponseViewer::_plot_response {var1 var2} { |
---|
[5833] | 149 | #puts "plotting $var1 vs $var2" |
---|
[5709] | 150 | |
---|
| 151 | set fname response_result.xml |
---|
| 152 | |
---|
| 153 | set rs $_response |
---|
| 154 | if {[catch {exec get_response.py $fname $rs $var1 $var2 $_label} res]} { |
---|
| 155 | set fp [open "response.err" r] |
---|
| 156 | set rdata [read $fp] |
---|
| 157 | close $fp |
---|
| 158 | puts "Surrogate Model failed: $res\n$rdata" |
---|
| 159 | error "Sampling of Surrogate Model failed: $res\n$rdata" |
---|
| 160 | # FIXME: Maybe put in text box instead of error()? |
---|
| 161 | return |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | set xmlobj [Rappture::library $fname] |
---|
[5833] | 165 | #puts "xmlobj=$xmlobj" |
---|
[5709] | 166 | set w $itk_component(frame).field |
---|
| 167 | |
---|
| 168 | if {$var1 == $var2} { |
---|
| 169 | set path "output.curve(response)" |
---|
| 170 | set _dobj [Rappture::Curve ::#auto $xmlobj $path] |
---|
| 171 | Rappture::XyResult $w |
---|
| 172 | } else { |
---|
| 173 | set path "output.field(f2d)" |
---|
| 174 | set _dobj [Rappture::Field ::#auto $xmlobj $path] |
---|
| 175 | Rappture::FieldResult $w -mode heightmap |
---|
| 176 | } |
---|
| 177 | $w add $_dobj $_settings |
---|
| 178 | $w scale $_dobj |
---|
[5833] | 179 | #puts "added _dobj" |
---|
| 180 | #puts "w=$w" |
---|
[5709] | 181 | pack $w -expand yes -fill both |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | itcl::body Rappture::ResponseViewer::_combobox_cb {} { |
---|
| 185 | if {$_dobj != ""} { |
---|
| 186 | destroy $itk_component(frame).field |
---|
| 187 | destroy _dobj |
---|
| 188 | set _dobj "" |
---|
| 189 | } |
---|
| 190 | set var1 [$itk_component(frame2).cb1 current] |
---|
| 191 | set var2 [$itk_component(frame2).cb2 current] |
---|
| 192 | _plot_response $var1 $var2 |
---|
| 193 | } |
---|
[5720] | 194 | |
---|
| 195 | |
---|
| 196 | itcl::body Rappture::ResponseViewer::download {option args} { |
---|
| 197 | $itk_component(frame).field download $option $args |
---|
| 198 | } |
---|