def _graph_grid(self, x, y, z, ze, r, reg, refresh): self.min_j = min(z) self.max_j = max(z) g = self.graph layout = FigureLayout(fixed='filled_grid') nrows, ncols = layout.calculate(len(x)) if not isinstance(g, Graph): g = RegressionGraph(container_dict={ 'bgcolor': 'gray', 'kind': 'g', 'shape': (nrows, ncols) }) self.graph = g def get_ip(xi, yi): return next((ip for ip in self.monitor_positions if ((ip.x - xi)**2 + (ip.y - yi)**2)**0.5 < 0.01), None) opt = self.plotter_options monage = opt.monitor_age * 1e6 lk = opt.lambda_k ans = self._analyses[0] scale = opt.flux_scalar for r in range(nrows): for c in range(ncols): idx = c + ncols * r if refresh: try: yy = z[idx] * scale ye = ze[idx] * scale except IndexError: continue # if hasattr(g, 'rules'): # if idx in g.rules: # l1, l2, l3 = g.rules[idx] # l1.value = yy # l2.value = yy + ye # l3.value = yy - ye else: plot = g.new_plot(padding_left=65, padding_right=5, padding_top=30, padding_bottom=5) try: ip = get_ip(x[idx], y[idx]) except IndexError: continue add_axes_tools(g, plot) yy = z[idx] * scale ye = ze[idx] * scale plot.title = 'Identifier={} Position={}'.format( ip.identifier, ip.hole_id) plot.x_axis.visible = False if c == 0 and r == nrows // 2: plot.y_axis.title = 'J x{}'.format(scale) if not ip.use: continue # get ip via x,y ais = [ a for a in ans if a.irradiation_position == ip.hole_id ] n = len(ais) # plot mean value # l1 = g.add_horizontal_rule(yy, color='black', line_style='solid', plotid=idx) # l2 = g.add_horizontal_rule(yy + ye, plotid=idx) # l3 = g.add_horizontal_rule(yy - ye, plotid=idx) # rs = (l1, l2, l3) # d = {idx: rs} # if hasattr(g, 'rules'): # g.rules.update(d) # else: # g.rules = d # plot individual analyses fs = [a.model_j(monage, lk) * scale for a in ais] fs = sorted(fs) iys = array([nominal_value(fi) for fi in fs]) ies = array([std_dev(fi) for fi in fs]) if self.plotter_options.use_weighted_fit: fit = 'weighted mean' else: fit = 'average' ek = self.plotter_options.error_kind if ek == MSEM: ek = 'msem' fit = '{}_{}'.format(fit, ek) p_, s, l_ = g.new_series(linspace(0, n - 1, n), iys, yerror=ies, type='scatter', fit=fit, add_point_inspector=False, add_inspector=False, marker='circle', marker_size=3) g.set_x_limits(0, n - 1, pad='0.1', plotid=idx) g.set_y_limits(min(iys - ies), max(iys + ies), pad='0.1', plotid=idx) g.add_statistics(plotid=idx) ebo = ErrorBarOverlay(component=s, orientation='y') s.underlays.append(ebo) s.error_bars = ebo add_analysis_inspector(s, ais) s.index.on_trait_change( self._grid_update_graph_metadata(ais), 'metadata_changed') self.suppress_metadata_change = True sel = [i for i, a in enumerate(ais) if a.is_omitted()] s.index.metadata['selections'] = sel self.suppress_metadata_change = False g.refresh()
def _graph_linear_j(self, x, y, r, reg, refresh): g = self.graph if not isinstance(g, RegressionGraph): g = RegressionGraph( container_dict={'bgcolor': self.plotter_options.bgcolor}) self.graph = g po = self.plotter_options g.clear() plot = g.new_plot(padding=po.get_paddings()) if po.model_kind == WEIGHTED_MEAN_1D: fit = 'weighted mean' else: fit = po.least_squares_fit _, scatter, line = g.new_series(x=reg.xs, y=reg.ys, yerror=reg.yserr, fit=fit) ebo = ErrorBarOverlay(component=scatter, orientation='y') scatter.underlays.append(ebo) scatter.error_bars = ebo add_inspector(scatter, self._additional_info) add_axes_tools(g, plot) g.set_x_title(po.one_d_axis) g.set_y_title('J') g.add_statistics() miy = 100 may = -1 if self._individual_analyses_enabled: sel = [ i for i, (a, x, y, e) in enumerate(zip(*self._analyses)) if a.is_omitted() ] # plot the individual analyses iscatter, iys = self._graph_individual_analyses(fit=None, add_tools=False) miy = min(iys) may = max(iys) # set metadata last because it will trigger a refresh self.suppress_metadata_change = True iscatter.index.metadata['selections'] = sel self.suppress_metadata_change = False g.set_y_limits(min_=miy, max_=may, pad='0.1') g.set_x_limits(pad='0.1') g.refresh() fys = line.value.get_data() self.max_j = fys.max() self.min_j = fys.min()