def update_global_tolerances(self):
     controller = self.controller 
     case = self.case
     pvals = self.pvals
     if pvals is None:
         self.tolerances_table.children = []
         return
     if case.is_valid(p_bounds=pvals) is False:
         self.tolerances_table.children = []
         return            
     table = HTML()
     html_str = '<div><table>\n<caption>Global tolerances determined for Case ' + case.case_number + ' (' + case.signature + ') showing fold-difference to a large qualitative change{0}. </caption>\n'.format(' in log-coordinates' if self.log_coordinates is True else '') 
     html_str += '<tr ><th align=center  rowspan=2 style="padding:0 15px 0 15px;"> Parameters </th><th colspan=2> Tolerance </th></tr>'
     html_str += '<tr><td style="padding:0 15px 0 15px;"><b> Lower bound</b></td><td style="padding:0 15px 0 15px;"><b> Upper bound</b></td></tr>'
     tolerances = case.measure_tolerance(pvals, log_out=self.log_coordinates)
     for xi in sorted(pvals.keys()):
         lower_th = 1e-15 if self.log_coordinates is False else -15
         upper_th = 1e15 if self.log_coordinates is False else 15
         lower, upper = tolerances[xi]
         html_str += '<tr><td style="padding:0 15px 0 15px;"><b>{0}</b></td><td style="padding:0 15px 0 15px;">{1}</td><td style="padding:0 15px 0 15px;">{2}</td></tr>'.format(
                      xi,
                      lower if lower > lower_th else '-&infin;',
                      upper if upper < upper_th else '&infin;')
     html_str += '</table><caption>'
     html_str += 'Note: Global tolerance calculated based on the following values for the parameters: ' 
     html_str += '; '.join([i + ' = ' + str(pvals[i]) for i in sorted(pvals.keys())]) + '.'
     html_str += '</caption></div>'
     table.value = html_str
     save_button = Button(description='Save Global Tolerance Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     self.tolerances_table.children = [HTML(value='<br>'),
                                       save_button,
                                       table]
     return
 def update_bounding_box(self):
     controller = self.controller 
     case = self.case
     pvals = self.pvals
     if case.is_valid(p_bounds=pvals) is False:
         self.bounding_box_table.children = []
         return
     if case.is_cyclical is True:
         self.bounding_box_table.children = []
         return            
     table = HTML()
     html_str = '<div><table>\n<caption>Bounding box determined for Case ' + case.case_number + ' (' + case.signature + '){0}. </caption>\n'.format(' in log-coordinates' if self.log_coordinates is True else '') 
     html_str += '<tr ><th align=center  rowspan=2 style="padding:0 15px 0 15px;"> Parameters </th><th colspan=2> Tolerance </th></tr>'
     html_str += '<tr><td style="padding:0 15px 0 15px;"><b> Lower bound</b></td><td style="padding:0 15px 0 15px;"><b> Upper bound</b></td></tr>'
     tolerances = case.bounding_box(log_out=self.log_coordinates)
     for xi in sorted(tolerances.keys()):
         lower_th = 1e-15 if self.log_coordinates is False else -15
         upper_th = 1e15 if self.log_coordinates is False else 15
         lower, upper = tolerances[xi]
         html_str += '<tr><td style="padding:0 15px 0 15px;"><b>{0}</b></td><td style="padding:0 15px 0 15px;">{1}</td><td style="padding:0 15px 0 15px;">{2}</td></tr>'.format(
                      xi,
                      lower if lower > lower_th else '-&infin;',
                      upper if upper < upper_th else '&infin;')
     html_str += '</table></div>'
     table.value = html_str
     save_button = Button(description='Save Bounding Box Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     self.bounding_box_table.children = [HTML(value='<br>'),
                                         save_button,
                                         table]
     return
 def update_parameter_table(self):
     controller = self.controller 
     case = self.case
     pvals = self.pvals
     if pvals is None:
         self.parameter_table.children = []
         return
     if case.is_valid(p_bounds=pvals) is False:
         self.parameter_table.children = []
         return
     make_nominal = Button(description='Make Nominal Parameter Set')
     make_nominal.on_click(self.save_parameters)
     table = HTML()
     html_str = '<div><table>\n<caption>Value for the parameters automatically determined for Case ' + case.case_number + ' (' + case.signature + '). </caption>\n'
     html_str += '<tr ><th align=center  style="padding:0 15px 0 15px;"> Parameters </th><th> Value </th>'
     for xi in sorted(pvals.keys()):
             html_str += '<tr><td><b>{0}</b></td><td>{1}</td></tr>'.format(
                          xi,
                          pvals[xi])
     html_str += '</table></div>'
     table.value = html_str
     save_button = Button(description='Save Parameter Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     self.parameter_table.children = [HTML(value='<br>'),
                                      save_button,
                                      table,
                                      make_nominal
                                      ]
     return
 def update_log_gains(self):
     controller = self.controller 
     case = self.case
     if case.ssystem.solution is None:
         self.log_gains.children = []
         return
     table = HTML()
     html_str = '<div><table>\n<caption>Logarithmic gains and parameter sensitivities for Case ' + case.case_number + ' (' + case.signature + '). </caption>\n'
     html_str += '<tr ><th rowspan="2" align=center  style="padding:0 15px 0 15px;"> Dependent<br> Variables </th>'
     html_str += '<th colspan="' + str(len(case.independent_variables)) + '" align=center  style="padding:0 15px 0 15px;"> Independent Variables and Parameters</th></tr><tr align=center>'
     for xi in case.independent_variables:
             html_str += '<td><b>{0}</b></td>'.format(xi)
     html_str += '</tr>\n'
     for xd in case.dependent_variables:
         html_str += '<tr><td align=center  style="padding:0 15px 0 15px;"><b>{0}</b></td>'.format(xd)
         for xi in case.independent_variables:
             html_str += '<td align=center  style="padding:0 15px 0 15px;">{0}</td>'.format(str(case.ssystem.log_gain(xd, xi)))
         html_str += '</tr>\n'
     html_str += '</table></div><br>'
     save_button = Button(description='Save Log-Gain Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     table.value = html_str
     self.log_gains.children = [HTML(value='<br>'),
                                save_button, 
                                table]
     return
 def update_info(self):
     
     title = HTML(value='<b> Cases to Co-localize </b>')
     buttons = []
     html_str = '<div><b>Is Valid: {0}</b></div>'.format(self.ci.is_valid())
     if self.ci.is_valid() is False:
         self.make_plot.disabled = True
     else:
         self.make_plot.disabled = False
     valid = HTML(value = html_str)
     html_str = '<table><caption> Auxiliary variables for ' + self.name 
     html_str += ' with ' + ', '.join(self.slice_variables) 
     html_str += ' as the slice variable{0}.</caption>'.format('s' if len(self.slice_variables) > 1 else '')
     html_str += '<tr ><th rowspan="2" align=center  style="padding:0 15px 0 15px;"> Slice<br> Variables </th>'
     html_str += '<th colspan="' + str(len(self.cases)) + '" align=center  style="padding:0 15px 0 15px;"> Cases </th></tr><tr align=center>'
     for c in self.cases:
             html_str += '<td style="padding:0 15px 0 15px;"><b>  {0}  </b></td>'.format(c.case_number)
     html_str += '</tr>\n'
     pset = self.ci.valid_interior_parameter_set()
     for i in self.cases:
         key = i.case_number
         case_button = Button(description='Case ' + key)
         buttons.append(case_button)
         case_button.pvals = pset[key] if key in pset else None
         case_button.on_click(self.open_case)
     for j, xj in enumerate(self.slice_variables):
         html_str += '<tr align=center><td>{0}</td>'.format(xj)
         for i, c in enumerate(self.cases):
             html_str += '<td>${0}_{1}</td>'.format(xj, i)
         html_str += '</tr>'  
     html_str += '</table>'
     html_str += '<caption>Case co-localization assumes that the slice variables '
     html_str += 'for one case are independent from the slice variables for the other cases in the co-localization.'
     html_str += 'Each auxiliary variable corresponds to a slice variable for one cases.</caption>'
     save_table = Button(description='Save variable table')
     save_table.on_click(self.save_table)
     save_table.table_data = html_str
     variables = HTML(value=html_str)
     self.info.children = [title] + buttons + [valid, save_table, variables]