def _calculate_probability_curve(self, ages, errors, calculate_limits=False, limits=None): xmi, xma = None, None if limits: xmi, xma = limits if not xmi and not xma: xmi, xma = self.graph.get_x_limits() if xmi == -Inf or xma == Inf: xmi, xma = self.xmi, self.xma opt = self.options if opt.probability_curve_kind == 'kernel': return kernel_density(ages, errors, xmi, xma, n=N) else: if opt.use_asymptotic_limits and calculate_limits: cfunc = lambda x1, x2: cumulative_probability(ages, errors, x1, x2, n=N) # bins,probs=cfunc(xmi,xma) # wa = self.analysis_group.weighted_age # m, e = nominal_value(wa), std_dev(wa) # xmi, xma = m - e, m + e bins, probs, x1, x2 = self._calculate_asymptotic_limits(cfunc, tol=(opt.asymptotic_height_percent or 10)) self.trait_setq(xmi=x1, xma=x2) return bins, probs else: return cumulative_probability(ages, errors, xmi, xma, n=N)
def _calculate_probability_curve(self, ages, errors, calculate_limits=False, limits=None): xmi, xma = None, None if limits: xmi, xma = limits if not xmi and not xma: xmi, xma = self.graph.get_x_limits() if xmi == -Inf or xma == Inf: xmi, xma = self.xmi, self.xma opt = self.options if opt.probability_curve_kind == 'kernel': return kernel_density(ages, errors, xmi, xma, n=N) else: if opt.use_asymptotic_limits and calculate_limits: cfunc = lambda x1, x2: cumulative_probability( ages, errors, x1, x2, n=N) # bins,probs=cfunc(xmi,xma) # wa = self.analysis_group.weighted_age # m, e = nominal_value(wa), std_dev(wa) # xmi, xma = m - e, m + e bins, probs, x1, x2 = self._calculate_asymptotic_limits( cfunc, tol=(opt.asymptotic_height_percent or 10)) self.trait_setq(xmi=x1, xma=x2) return bins, probs else: return cumulative_probability(ages, errors, xmi, xma, n=N)
def _calculate_probability_curve(self, ages, errors, calculate_limits=False, limits=None): xmi, xma = None, None if limits: xmi, xma = limits if not xmi and not xma: xmi, xma = self.graph.get_x_limits() if xmi == -Inf or xma == Inf: xmi, xma = self.xmi, self.xma opt = self.options if opt.probability_curve_kind == 'kernel': return kernel_density(ages, errors, xmi, xma, n=N) else: if opt.use_asymptotic_limits and calculate_limits: def cfunc(x1, x2): return cumulative_probability(ages, errors, x1, x2, n=N) bins, probs, x1, x2 = self._calculate_asymptotic_limits( cfunc, tol=(opt.asymptotic_height_percent or 10)) self.trait_setq(xmi=x1, xma=x2) return bins, probs else: return cumulative_probability(ages, errors, xmi, xma, n=N)
def _plot_relative_probability(self, po, plot, pid): graph = self.graph bins, probs = self._calculate_probability_curve(self.xs, self.xes, calculate_limits=True) ogid = self.group_id gid = ogid + 1 sgid = ogid * 2 plotkw = self.options.get_plot_dict(ogid) line, _ = graph.new_series(x=bins, y=probs, plotid=pid, **plotkw) if self.options.label_all_peaks: self._add_peak_labels(line, self.xs, self.xes) graph.set_series_label('Current-{}'.format(gid), series=sgid, plotid=pid) # add the dashed original line graph.new_series(x=bins, y=probs, plotid=pid, visible=False, color=line.color, line_style='dash') graph.set_series_label('Original-{}'.format(gid), series=sgid + 1, plotid=pid) self._add_info(graph, plot) self._add_mean_indicator(graph, line, po, bins, probs, pid) mi, ma = min(probs), max(probs) # if not po.has_ylimits(): self._set_y_limits(mi, ma, min_=0, pad='0.025') d = lambda a, b, c, d: self.update_index_mapper(a, b, c, d) plot.index_mapper.on_trait_change(d, 'updated') if self.options.display_inset: xs = self.xs n = xs.shape[0] startidx = 1 if self.group_id > 0: for ov in plot.overlays: if isinstance(ov, IdeogramPointsInset): print 'ideogram point inset', self.group_id, startidx, ov.value.get_bounds()[1] + 1 startidx = max(startidx, ov.value.get_bounds()[1] + 1) else: startidx = 1 if self.options.analysis_number_sorting == 'Oldest @Top': ys = arange(startidx, startidx + n) else: ys = arange(startidx + n - 1, startidx - 1, -1) yma2 = max(ys) + 1 h = self.options.inset_height / 2.0 if self.group_id == 0: # bgcolor = self.options.get_formatting_value('plot_bgcolor') bgcolor = self.options.plot_bgcolor else: bgcolor = 'transparent' d = self.options.get_plot_dict(ogid) o = IdeogramPointsInset(self.xs, ys, color=d['color'], outline_color=d['color'], bgcolor=bgcolor, width=self.options.inset_width, height=h, visible_axes=False, xerror=ArrayDataSource(self.xes), location=self.options.inset_location) # o.x_axis.visible = False plot.overlays.append(o) cfunc = lambda x1, x2: cumulative_probability(self.xs, self.xes, x1, x2, n=N) xs, ys, xmi, xma = self._calculate_asymptotic_limits(cfunc, # asymptotic_width=10, tol=self.options.asymptotic_height_percent) oo = IdeogramInset(xs, ys, color=d['color'], bgcolor=bgcolor, yoffset=h, visible_axes=self.group_id == 0, width=self.options.inset_width, height=self.options.inset_height, location=self.options.inset_location) yma = max(ys) if self.group_id > 0: for ov in plot.overlays: if isinstance(ov, IdeogramInset): mi, ma = ov.get_x_limits() xmi = min(mi, xmi) xma = max(ma, xma) _, ma = ov.get_y_limits() yma = max(ma, yma) plot.overlays.append(oo) for ov in plot.overlays: if isinstance(ov, IdeogramInset): ov.set_x_limits(xmi, xma) ov.set_y_limits(0, yma * 1.1) elif isinstance(ov, IdeogramPointsInset): ov.set_x_limits(xmi, xma) ov.set_y_limits(0, yma2)
def setUp(self): xs = [10, 10, 10, 20, 20, 20] es = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1] self.xs, self.ys = cumulative_probability(xs, es, 5, 25)
def _plot_relative_probability(self, po, plot, pid): graph = self.graph bins, probs = self._calculate_probability_curve(self.xs, self.xes, calculate_limits=True) ogid = self.group_id gid = ogid + 1 sgid = ogid * 2 plotkw = self.options.get_plot_dict(ogid) line, _ = graph.new_series(x=bins, y=probs, plotid=pid, **plotkw) if self.options.label_all_peaks: self._add_peak_labels(line, self.xs, self.xes) graph.set_series_label('Current-{}'.format(gid), series=sgid, plotid=pid) # add the dashed original line graph.new_series(x=bins, y=probs, plotid=pid, visible=False, color=line.color, line_style='dash') graph.set_series_label('Original-{}'.format(gid), series=sgid + 1, plotid=pid) self._add_info(graph, plot) self._add_mean_indicator(graph, line, po, bins, probs, pid) mi, ma = min(probs), max(probs) # if not po.has_ylimits(): self._set_y_limits(mi, ma, min_=0, pad='0.025') d = lambda a, b, c, d: self.update_index_mapper(a, b, c, d) plot.index_mapper.on_trait_change(d, 'updated') if self.options.display_inset: xs = self.xs n = xs.shape[0] startidx = 1 if self.group_id > 0: for ov in plot.overlays: if isinstance(ov, IdeogramPointsInset): print 'ideogram point inset', self.group_id, startidx, ov.value.get_bounds( )[1] + 1 startidx = max(startidx, ov.value.get_bounds()[1] + 1) else: startidx = 1 if self.options.analysis_number_sorting == 'Oldest @Top': ys = arange(startidx, startidx + n) else: ys = arange(startidx + n - 1, startidx - 1, -1) yma2 = max(ys) + 1 h = self.options.inset_height / 2.0 if self.group_id == 0: # bgcolor = self.options.get_formatting_value('plot_bgcolor') bgcolor = self.options.plot_bgcolor else: bgcolor = 'transparent' d = self.options.get_plot_dict(ogid) o = IdeogramPointsInset(self.xs, ys, color=d['color'], outline_color=d['color'], bgcolor=bgcolor, width=self.options.inset_width, height=h, visible_axes=False, xerror=ArrayDataSource(self.xes), location=self.options.inset_location) # o.x_axis.visible = False plot.overlays.append(o) cfunc = lambda x1, x2: cumulative_probability( self.xs, self.xes, x1, x2, n=N) xs, ys, xmi, xma = self._calculate_asymptotic_limits( cfunc, # asymptotic_width=10, tol=self.options.asymptotic_height_percent) oo = IdeogramInset(xs, ys, color=d['color'], bgcolor=bgcolor, yoffset=h, visible_axes=self.group_id == 0, width=self.options.inset_width, height=self.options.inset_height, location=self.options.inset_location) yma = max(ys) if self.group_id > 0: for ov in plot.overlays: if isinstance(ov, IdeogramInset): mi, ma = ov.get_x_limits() xmi = min(mi, xmi) xma = max(ma, xma) _, ma = ov.get_y_limits() yma = max(ma, yma) plot.overlays.append(oo) for ov in plot.overlays: if isinstance(ov, IdeogramInset): ov.set_x_limits(xmi, xma) ov.set_y_limits(0, yma * 1.1) elif isinstance(ov, IdeogramPointsInset): ov.set_x_limits(xmi, xma) ov.set_y_limits(0, yma2)
def cfunc(x1, x2): return cumulative_probability(ages, errors, x1, x2, n=N)
def cfunc(x1, x2): return cumulative_probability(self.xs, self.xes, x1, x2, n=N)