def _find_peaks(self): if self.graph.plots: #clear peaks self.graph.remove_rulers() data = self.graph.plots[0].data xs = data.get_data('x0') ys = data.get_data('y0') if len(xs) and len(ys): lookahead = max(1, int(self.min_peak_separation / self.fstep_dac)) mxp, mip = find_peaks(ys, xs, lookahead=lookahead, delta=self.delta) pks = [] isos = self.spectrometer.molecular_weights.keys() isos = sort_isotopes(isos) for dac, v in mxp: if v > self.min_peak_height: l = self.graph.add_vertical_rule(dac) pks.append(CalibrationPeak(dac=dac, isotopes=isos, ruler=l)) self.calibration_peaks = pks self._redraw()
def _find_peaks(self): if self.graph.plots: # clear peaks self.graph.remove_rulers() data = self.graph.plots[0].data xs = data.get_data('x0') ys = data.get_data('y0') if len(xs) and len(ys): lookahead = max(1, int(self.min_peak_separation / self.fstep_dac)) mxp, mip = find_peaks(ys, xs, lookahead=lookahead, delta=self.delta) pks = [] isos = list(self.spectrometer.molecular_weights.keys()) isos = sort_isotopes(isos) for dac, v in mxp: if v > self.min_peak_height: l = self.graph.add_vertical_rule(dac) pks.append( CalibrationPeak(dac=dac, isotopes=isos, ruler=l)) self.calibration_peaks = pks self._redraw()
def _calculate_stats(self, ages, errors, xs, ys): mswd, valid_mswd, n =self.analysis_group.get_mswd_tuple() if self.options.mean_calculation_kind == 'kernel': wm, we = 0, 0 delta = 1 maxs, _mins = find_peaks(ys, xs, delta=delta, lookahead=1) wm = max(maxs, axis=1)[0] else: wm, we = calculate_weighted_mean(ages, errors) we = self._calc_error(we, mswd) return wm, we, mswd, valid_mswd
def _calculate_stats(self, ages, errors, xs, ys): mswd, valid_mswd, n = self.analysis_group.get_mswd_tuple() if self.options.mean_calculation_kind == 'kernel': wm, we = 0, 0 delta = 1 maxs, _mins = find_peaks(ys, xs, delta=delta, lookahead=1) wm = max(maxs, axis=1)[0] else: wm, we = calculate_weighted_mean(ages, errors) we = self._calc_error(we, mswd) return wm, we, mswd, valid_mswd
def _calculate_stats(self, xs, ys): ag = self.analysis_group ag.attribute = self.options.index_attr ag.weighted_age_error_kind = self.options.error_calc_method ag.include_j_error_in_mean = self.options.include_j_error_in_mean ag.include_j_error_in_individual_analyses = self.options.include_j_error mswd, valid_mswd, n = self.analysis_group.get_mswd_tuple() if self.options.mean_calculation_kind == 'kernel': wm, we = 0, 0 delta = 1 maxs, _mins = find_peaks(ys, xs, delta=delta, lookahead=1) wm = np_max(maxs, axis=1)[0] else: wage = self.analysis_group.weighted_age wm, we = wage.nominal_value, wage.std_dev return wm, we, mswd, valid_mswd
def _calculate_stats(self, xs, ys): ag = self.analysis_group ag.attribute = self.options.index_attr ag.weighted_age_error_kind = self.options.error_calc_method ag.include_j_error_in_mean = self.options.include_j_error_in_mean ag.include_j_error_in_individual_analyses = self.options.include_j_error mswd, valid_mswd, n = self.analysis_group.get_mswd_tuple() if self.options.mean_calculation_kind == 'kernel': wm, we = 0, 0 delta = 1 maxs, _mins = find_peaks(ys, xs, delta=delta, lookahead=1) wm = np_max(maxs, axis=1)[0] else: wage = self.analysis_group.weighted_age wm, we = wage.nominal_value, wage.std_dev return wm, we, mswd, valid_mswd # def _calc_error(self, we, mswd): # ec = self.options.error_calc_method # n = self.options.nsigma # if ec == 'SEM': # a = 1 # elif ec == 'SEM, but if MSWD>1 use SEM * sqrt(MSWD)': # a = 1 # if mswd > 1: # a = mswd ** 0.5 # return we * a * n # ============= EOF ============================================= # def _add_mean_indicator2(self, g, scatter, bins, probs, pid): # offset = 0 # percentH = 1 - 0.954 # 2sigma # # maxp = max(probs) # wm, we, mswd, valid_mswd = self._calculate_stats(self.xs, self.xes, # bins, probs) # #ym = maxp * percentH + offset # #set ym in screen space # #convert to data space # ogid = self.group_id # gid = ogid + 1 # sgid = ogid * 3 # # ym = maxp * 0.1 * gid # # s, p = g.new_series( # [wm], [ym], # type='scatter', # marker='circle', # #selection_marker_size=3, # marker_size=3, # #selection_marker='circle', # #selection_color=scatter.color, # #selection_outline_color=scatter.color, # color=scatter.color, # plotid=0 # ) # # g.set_series_label('Mean-{}'.format(gid), series=sgid + 2, plotid=pid) # # self._add_error_bars(s, [we], 'x', self.options.nsigma) # # display_mean_indicator = self._get_plot_option(self.options, # 'display_mean_indicator', default=True) # if not self.options.display_mean_indicator: # s.visible = False # # label = None # # display_mean = self._get_plot_option(self.options, 'display_mean_text', default=True) # if self.options.display_mean: # text = self._build_label_text(wm, we, mswd, valid_mswd, len(self.xs)) # # font = self._get_plot_option(self.options, 'data_label_font', default='modern 12') # self._add_data_label(s, text, (wm, ym), # # font=font # ) # # add a tool to move the mean age point # s.tools.append(PointMoveTool(component=s, # label=label, # constrain='y'))
def test_max_peak_x2(self): maxp, minp = find_peaks(self.ys, self.xs, lookahead=1) self.assertAlmostEqual(maxp[1][0], 20.0, 0)
def test_find_max_peaks(self): maxp, minp = find_peaks(self.ys, self.xs, lookahead=1) self.assertEqual(len(maxp), 2)