Esempio n. 1
0
    def _get_mswd(self):
        self.valid_mswd=False
        if self._degree==1:
            # a = self.intercept
            # b = self.slope
            coeffs=self._calculate_coefficients()
            if not len(coeffs):
                self.calculate()
                coeffs = self._calculate_coefficients()

            if len(coeffs):
                x = self.xs
                y = self.ys

                sx = self.xserr
                sy = self.yserr

                if not len(sx):
                    sx=zeros(self.n)
                if not len(sy):
                    sy=zeros(self.n)

                x=self._clean_array(x)
                y=self._clean_array(y)
                sx=self._clean_array(sx)
                sy=self._clean_array(sy)

                m=calculate_mswd2(x, y, sx, sy, coeffs[1], coeffs[0])
                self.valid_mswd=validate_mswd(m, len(ys), k=2)
                return m
            else:
                return 0
        else:
            return super(OLSRegressor, self)._get_mswd()
Esempio n. 2
0
    def _add_info(self, plot, reg, label=None, text_color='black'):
        intercept = reg.predict(0)
        err = reg.get_intercept_error()
        mswd = reg.mswd
        n = reg.n

        try:
            inv_intercept = intercept ** -1
            p = calc_percent_error(intercept, err, scale=1)

            err = inv_intercept * p
            mse = err * mswd ** 0.5
            v, e, p, mse = floatfmt(inv_intercept, s=3), floatfmt(err, s=3), floatfmt(p * 100, n=2), floatfmt(mse, s=3)
        except ZeroDivisionError:
            v, e, p, mse = 'NaN', 'NaN', 'NaN', 'NaN'

        ratio_line = u'Ar40/Ar36= {} {}{} ({}%) mse= {}'.format(v, PLUSMINUS, e, p, mse)

        u = self._ref_age_units

        age = self.analysis_group.isochron_age

        v = age.nominal_value
        e = age.std_dev
        p = format_percent_error(v, e)

        mse_age = e * mswd ** 0.5

        valid = validate_mswd(mswd, n)
        mswd = '{:0.2f}'.format(mswd)
        if not valid:
            mswd = '*{}'.format(mswd)
            # n = len([ai for ai in self.analyses if ai.temp_status == 0])
        # mswd = 'NaN'
        age_line = u'Age= {} {}{} ({}%) {}. mse= {}'.format(floatfmt(v, n=3),
                                                            PLUSMINUS,
                                                            floatfmt(e, n=4, s=3), p, u,
                                                            floatfmt(mse_age, s=3))
        mswd_line = 'N= {} mswd= {}'.format(n, mswd)
        if label is None:
            th = 0
            for overlay in plot.overlays:
                if isinstance(overlay, OffsetPlotLabel):
                    w, h = overlay.get_preferred_size()
                    th += h + 2

            label = OffsetPlotLabel(
                offset=(1, th),
                component=plot,
                overlay_position='inside bottom',
                hjustify='left',
                bgcolor='white',

                color=text_color)
            plot.overlays.append(label)
            self._plot_label = label

        lines = u'\n'.join((ratio_line, age_line, mswd_line))
        label.text = u'{}'.format(lines)
        label.request_redraw()
Esempio n. 3
0
    def _get_mswd(self):
        self.valid_mswd = False
        if self._degree == 1:
            # a = self.intercept
            # b = self.slope
            coeffs = self._calculate_coefficients()
            if not len(coeffs):
                self.calculate()
                coeffs = self._calculate_coefficients()

            if len(coeffs):
                x = self.xs
                y = self.ys

                sx = self.xserr
                sy = self.yserr

                if not len(sx):
                    sx = zeros(self.n)
                if not len(sy):
                    sy = zeros(self.n)

                x = self._clean_array(x)
                y = self._clean_array(y)
                sx = self._clean_array(sx)
                sy = self._clean_array(sy)

                m = calculate_mswd2(x, y, sx, sy, coeffs[1], coeffs[0])
                self.valid_mswd = validate_mswd(m, len(ys), k=2)
                return m
            else:
                return 0
        else:
            return super(OLSRegressor, self)._get_mswd()
Esempio n. 4
0
    def set_mean_j(self, use_weights):

        ans = [a for a in self.analyses if not a.is_omitted()]
        if ans:
            j, mswd = mean_j(ans, use_weights, self.error_kind,
                             self.monitor_age, self.lambda_k)
            self.mean_j = nominal_value(j)
            self.mean_jerr = std_dev(j)
            self.mean_j_mswd = mswd
            self.mean_j_valid_mswd = validate_mswd(mswd, len(ans))

        self.n = len(ans)
Esempio n. 5
0
    def _validate_mswd(self, kind, unks, attr):
        if attr == 'age':
            xs = [u.age for u in unks]
            es = [u.age_err_wo_j for u in unks]
        elif attr == 'kca':
            vs = [u.kca for u in unks]
            xs = [nominal_value(v) for v in vs]
            es = [std_dev(v) for v in vs]

        mswd = calculate_mswd(xs, es)
        if kind == 'mahon':
            v = validate_mswd(mswd, len(xs))
        elif kind == 'threshold':
            v = mswd < self.mswd_threshold
        else:
            v = abs(mswd -
                    self._prev_mswd) / mswd * 100 < self.plateau_threshold
            self._prev_mswd = mswd

        return v
Esempio n. 6
0
    def _add_info(self, plot, reg, label=None, text_color='black'):
        intercept = reg.predict(0)
        err = reg.get_intercept_error()
        mswd = reg.mswd
        n = reg.n

        try:
            inv_intercept = intercept ** -1
            p = calc_percent_error(inv_intercept, err)

            v = floatfmt(inv_intercept, s=3)
            e = floatfmt(err, s=3)

            mse = err * mswd ** 0.5
            mse = floatfmt(mse, s=3)
            #v = '{:0.2f}'.format(inv_intercept)
            #e = '{:0.3f}'.format(err)

        except ZeroDivisionError:
            v, e, p, mse = 'NaN', 'NaN', 'NaN', 'NaN'

        ratio_line = 'Ar40/Ar36= {} +/-{} ({}%) mse= {}'.format(v, e, p, mse)

        j = self._ref_j
        u = self._ref_age_units

        #xint = ufloat(reg.x_intercept, reg.x_intercept_error)
        #try:
        #    R = xint ** -1
        #except ZeroDivisionError:
        #    R = 0
        #
        #v, e, mse_age = 0, 0, 0
        #if R > 0:
        #    age = age_equation(j, R, arar_constants=self._ref_constants)

        age = self._age
        v = age.nominal_value
        e = age.std_dev
        mse_age = e * mswd ** 0.5

        valid = validate_mswd(mswd, n)
        mswd = '{:0.2f}'.format(mswd)
        if not valid:
            mswd = '*{}'.format(mswd)
            #n = len([ai for ai in self.analyses if ai.temp_status == 0])
        #mswd = 'NaN'
        age_line = 'Age= {} +/-{} ({}%) {}. mse= {}'.format(floatfmt(v, n=3),
                                                            floatfmt(e, n=4, s=3), p, u,
                                                            floatfmt(mse_age, s=3))
        mswd_line = 'N= {} mswd= {}'.format(n, mswd)
        if label is None:
            label = OffsetPlotLabel(
                offset=(0, 50 * self.group_id),
                component=plot,
                overlay_position='inside bottom',
                hjustify='left',
                color=text_color)
            plot.overlays.append(label)
            self._plot_label = label

        lines = '\n'.join((ratio_line, age_line, mswd_line))
        label.text = '{}'.format(lines)
        label.request_redraw()
Esempio n. 7
0
    def _add_info(self, plot, reg, label=None, text_color='black'):
        intercept = reg.predict(0)
        err = reg.get_intercept_error()
        mswd = reg.mswd
        n = reg.n

        try:
            inv_intercept = intercept**-1
            p = calc_percent_error(inv_intercept, err)

            v = floatfmt(inv_intercept, s=3)
            e = floatfmt(err, s=3)

            mse = err * mswd**0.5
            mse = floatfmt(mse, s=3)
            #v = '{:0.2f}'.format(inv_intercept)
            #e = '{:0.3f}'.format(err)

        except ZeroDivisionError:
            v, e, p, mse = 'NaN', 'NaN', 'NaN', 'NaN'

        ratio_line = 'Ar40/Ar36= {} +/-{} ({}%) mse= {}'.format(v, e, p, mse)

        j = self._ref_j
        u = self._ref_age_units

        #xint = ufloat(reg.x_intercept, reg.x_intercept_error)
        #try:
        #    R = xint ** -1
        #except ZeroDivisionError:
        #    R = 0
        #
        #v, e, mse_age = 0, 0, 0
        #if R > 0:
        #    age = age_equation(j, R, arar_constants=self._ref_constants)

        age = self._age
        v = age.nominal_value
        e = age.std_dev
        mse_age = e * mswd**0.5

        valid = validate_mswd(mswd, n)
        mswd = '{:0.2f}'.format(mswd)
        if not valid:
            mswd = '*{}'.format(mswd)
            #n = len([ai for ai in self.analyses if ai.temp_status == 0])
        #mswd = 'NaN'
        age_line = 'Age= {} +/-{} ({}%) {}. mse= {}'.format(
            floatfmt(v, n=3), floatfmt(e, n=4, s=3), p, u,
            floatfmt(mse_age, s=3))
        mswd_line = 'N= {} mswd= {}'.format(n, mswd)
        if label is None:
            label = OffsetPlotLabel(offset=(0, 50 * self.group_id),
                                    component=plot,
                                    overlay_position='inside bottom',
                                    hjustify='left',
                                    color=text_color)
            plot.overlays.append(label)
            self._plot_label = label

        lines = '\n'.join((ratio_line, age_line, mswd_line))
        label.text = '{}'.format(lines)
        label.request_redraw()
Esempio n. 8
0
    def _add_results_info(self, plot, label=None, text_color='black'):

        ag = self.analysis_group

        age = ag.isochron_age
        a = ag.isochron_4036

        n = ag.nanalyses
        mswd = ag.isochron_regressor.mswd

        intercept, err = nominal_value(a), std_dev(a)

        try:
            inv_intercept = intercept ** -1
            p = calc_percent_error(intercept, err, scale=1)
            err = inv_intercept * p * self.options.nsigma
            mse = err * mswd ** 0.5
            v, e, p, mse = floatfmt(inv_intercept, s=3), floatfmt(err, s=3), floatfmt(p * 100, n=2), floatfmt(mse, s=3)
        except ZeroDivisionError:
            v, e, p, mse = 'NaN', 'NaN', 'NaN', 'NaN'

        sample_line = u'{}({})'.format(ag.identifier, ag.sample)
        ratio_line = u'Ar40/Ar36= {} {}{} ({}%) mse= {}'.format(v, PLUSMINUS, e, p, mse)

        v = nominal_value(age)
        e = std_dev(age) * self.options.nsigma

        p = format_percent_error(v, e)

        mse_age = e * mswd ** 0.5

        valid = validate_mswd(mswd, n)
        mswd = '{:0.2f}'.format(mswd)
        if not valid:
            mswd = '*{}'.format(mswd)

        age_line = u'Age= {} {}{} ({}%) {}. mse= {}'.format(floatfmt(v, n=3),
                                                            PLUSMINUS,
                                                            floatfmt(e, n=4, s=3), p, ag.age_units,
                                                            floatfmt(mse_age, s=3))
        mswd_line = 'N= {} mswd= {}'.format(n, mswd)
        if label is None:
            th = 0
            for overlay in plot.overlays:
                if isinstance(overlay, OffsetPlotLabel):
                    w, h = overlay.get_preferred_size()
                    th += h + self.options.results_info_spacing

            label = OffsetPlotLabel(
                offset=(1, th),
                component=plot,
                overlay_position='inside bottom',
                hjustify='left',
                bgcolor='white',
                font=self.options.results_font,
                color=text_color)
            plot.overlays.append(label)
            self._plot_label = label

        lines = u'\n'.join((sample_line, ratio_line, age_line, mswd_line))
        label.text = u'{}'.format(lines)
        label.bgcolor = plot.bgcolor
        label.request_redraw()
Esempio n. 9
0
    def _add_results_info(self, plot, label=None, text_color='black'):

        ag = self.analysis_group

        age = ag.isochron_age
        a = ag.isochron_3640

        n = ag.nanalyses
        mswd = ag.isochron_regressor.mswd

        intercept, err = nominal_value(a), std_dev(a)

        try:
            inv_intercept = intercept ** -1
            p = calc_percent_error(intercept, err, scale=1)
            err = inv_intercept * p * self.options.nsigma
            mse = err * mswd ** 0.5
            sf = self.options.yintercept_sig_figs
            v, e, p, mse = floatfmt(inv_intercept, n=sf, s=3), floatfmt(err, n=sf, s=3), \
                           floatfmt(p * 100, n=2), floatfmt(mse, s=3)
        except ZeroDivisionError:
            v, e, p, mse = 'NaN', 'NaN', 'NaN', 'NaN'

        sample_line = u'{}({})'.format(ag.identifier, ag.sample)
        mse_text = ''
        if self.options.include_4036_mse:
            mse_text = ' MSE= {}'.format(mse)

        ptext = ''
        if self.options.include_percent_error:
            ptext = ' ({}%)'.format(p)

        ratio_line = '<sup>40</sup>Ar/<sup>36</sup>Ar= {} {}{}{}{}'.format(v, PLUSMINUS, e, ptext, mse_text)

        v = nominal_value(age)
        e = std_dev(age) * self.options.nsigma

        p = format_percent_error(v, e)

        mse_age = e * mswd ** 0.5

        valid = validate_mswd(mswd, n)
        mswd = '{:0.2f}'.format(mswd)
        if not valid:
            mswd = '*{}'.format(mswd)

        af = self.options.age_sig_figs

        mse_text = ''
        if self.options.include_age_mse:
            mse_text = ' MSE= {}'.format(floatfmt(mse_age, s=3))

        age_line = u'Age= {} {}{} ({}%) {}{}'.format(floatfmt(v, n=af),
                                                     PLUSMINUS,
                                                     floatfmt(e, n=af, s=3), p, ag.age_units, mse_text)
        mswd_line = 'N= {} MSWD= {}'.format(n, mswd)
        if label is None:
            th = 0
            for overlay in plot.overlays:
                if isinstance(overlay, OffsetPlotLabel):
                    w, h = overlay.get_preferred_size()
                    th += h + self.options.results_info_spacing

            label = OffsetPlotLabel(
                offset=(1, th),
                component=plot,
                overlay_position='inside bottom',
                hjustify='left',
                bgcolor='white',
                font=self.options.results_font,
                color=text_color)
            plot.overlays.append(label)
            self._plot_label = label

        lines = u'\n'.join((sample_line, ratio_line, age_line, mswd_line))
        label.text = u'{}'.format(lines)
        label.bgcolor = plot.bgcolor
        label.request_redraw()