Example #1
0
    def load_measurement(self, an, ar):

        j = self._get_j(an)
        jf = 'NaN'
        if j is not None:
            jj = floatfmt(j.nominal_value, n=3, s=3)
            jf = u'{} \u00b1{:0.2e}'.format(jj, j.std_dev)

        a39 = ar.ar39decayfactor
        a37 = ar.ar37decayfactor
        #print ar, a39
        ms = [
            MeasurementValue(name='AnalysisID', value=self.analysis_id),
            MeasurementValue(name='Spectrometer', value=an.mass_spectrometer),
            MeasurementValue(name='Run Date',
                             value=an.rundate.strftime('%Y-%m-%d %H:%M:%S')),
            MeasurementValue(name='Irradiation',
                             value=self._get_irradiation(an)),
            MeasurementValue(name='J', value=jf),
            MeasurementValue(name='Project', value=an.project),
            MeasurementValue(name='Sample', value=an.sample),
            MeasurementValue(name='Material', value=an.material),
            MeasurementValue(name='Comment', value=an.comment),
            MeasurementValue(name='Ar39Decay', value=floatfmt(a39)),
            MeasurementValue(name='Ar37Decay', value=floatfmt(a37)),
        ]
        self.measurement_values = ms
Example #2
0
    def _build_label_text(self, x, we, mswd, valid_mswd, n,
                          percent_error=False,
                          sig_figs=3):
        display_n = True
        display_mswd = n >= 2
        if display_n:
            n = 'n= {}'.format(n)
        else:
            n = ''

        if display_mswd:
            vd = '' if valid_mswd else '*'
            mswd = '{}mswd= {:0.2f}'.format(vd, mswd)
        else:
            mswd = ''

        sx = floatfmt(x, sig_figs)
        swe = floatfmt(we, sig_figs)

        if self.options.index_attr in ('uF', 'Ar40/Ar36'):
            me = '{} +/-{}'.format(sx, swe)
        else:
            age_units = self._get_age_units()
            pe = ''
            if percent_error:
                pe = '({})'.format(format_percent_error(x, we, include_percent_sign=True))

            me = '{} +/-{}{} {}'.format(sx, swe, pe, age_units)

        return u'{} {} {}'.format(me, mswd, n)
Example #3
0
    def test_hundreths(self):
        x = 0.01
        fx = floatfmt(x)
        self.assertEqual(fx, '0.0100')

        fx = floatfmt(x, n=2)
        self.assertEqual(fx, '0.01')
Example #4
0
    def _load_air_computed(self, an, new_list):
        if self.experiment_type == AR_AR:
            if new_list:
                c = an.arar_constants
                ratios = [('40Ar/36Ar', 'Ar40/Ar36', nominal_value(c.atm4036)),
                          ('40Ar/38Ar', 'Ar40/Ar38', nominal_value(c.atm4038))]
                cv = self._make_ratios(ratios)
                self.computed_values = cv

            self._update_ratios()

            try:
                niso, diso = self._get_ratio('Ar40/Ar36')
                if niso and diso:
                    noncorrected = self._get_non_corrected_ratio(niso, diso)
                    v, e = nominal_value(noncorrected), std_dev(noncorrected)
                    ref = 295.5
                    self.summary_str = u'Ar40/Ar36={} {}{}({}%) IC={:0.5f}'.format(
                        floatfmt(v), PLUSMINUS, floatfmt(e),
                        format_percent_error(v, e),
                        nominal_value(noncorrected / ref))
            except:
                pass
        else:
            # todo add ratios for other isotopes. e.g Ne
            pass
Example #5
0
    def _make_tables(self, record):
        age = record.age.nominal_value
        age_error = record.age.std_dev
        age_perror = calc_percent_error(age, age_error, n=3)
        woj_age_error = record.age_error_wo_j
        woj_age_perror = calc_percent_error(age, woj_age_error, n=3)

        ar40_39 = record.Ar40_39.nominal_value
        ar40_39_error = record.Ar40_39.std_dev
        ar40_39_perror = calc_percent_error(ar40_39, ar40_39_error, n=3)

        tt = TextTable(
            HeaderRow(TextCell(''), TextCell('Value'),
                      TextCell(u'{}1{}'.format(PLUSMINUS, SIGMA)),
                      TextCell('% error')),
            TextRow(
                BoldCell('Age ({}):'.format(record.arar_constants.age_units)),
                TextCell(floatfmt(age)), TextCell(floatfmt(age_error)),
                TextCell(age_perror, n=2)),
            TextRow(BoldCell('w/o J err:'), TextCell(''),
                    TextCell(floatfmt(woj_age_error)),
                    TextCell(woj_age_perror)),
            TextRow(
                BoldCell('40Ar*/39Ar:'),
                TextCell(floatfmt(record.Ar40_39.nominal_value)),
                TextCell(floatfmt(record.Ar40_39.std_dev)),
                TextCell(ar40_39_perror),
                #                                HtmlCell('<sup>40</sup>Ar*/<sup>39</sup>Ar',
                #                                         bold=True)
            ),
            border=True)
        return [tt]
Example #6
0
    def load_measurement(self, an, ar):

        j = self._get_j(an)
        jf = 'NaN'
        if j is not None:
            jj = floatfmt(j.nominal_value, n=7, s=5)
            pe = format_percent_error(j.nominal_value,
                                      j.std_dev,
                                      include_percent_sign=True)
            jf = u'{} \u00b1{:0.2e}({})'.format(jj, j.std_dev, pe)

        a39 = ar.ar39decayfactor
        a37 = ar.ar37decayfactor
        ms = [
            MeasurementValue(name='DR Version', value=an.data_reduction_tag),
            MeasurementValue(name='DAQ Version', value=an.collection_version),
            MeasurementValue(name='AnalysisID', value=self.analysis_id),
            MeasurementValue(name='Spectrometer', value=an.mass_spectrometer),
            MeasurementValue(name='Run Date',
                             value=an.rundate.strftime('%Y-%m-%d %H:%M:%S')),
            MeasurementValue(name='Irradiation',
                             value=self._get_irradiation(an)),
            MeasurementValue(name='J', value=jf),
            MeasurementValue(name='Project', value=an.project),
            MeasurementValue(name='Sample', value=an.sample),
            MeasurementValue(name='Material', value=an.material),
            MeasurementValue(name='Comment', value=an.comment),
            MeasurementValue(name='Ar39Decay', value=floatfmt(a39)),
            MeasurementValue(name='Ar37Decay', value=floatfmt(a37)),
            MeasurementValue(name='Sens.', value=floatfmt(an.sensitivity))
        ]

        self.measurement_values = ms
Example #7
0
 def af(i, x, y, analysis):
     v, e = self._get_interpolated_value(po, analysis)
     return (u'Interpolated: {}{}{}'.format(floatfmt(v), PLUSMINUS,
                                            floatfmt(e)),
             'Run Date: {}'.format(
                 analysis.rundate.strftime('%m-%d-%Y %H:%M')),
             'Rel. Time: {:0.4f}'.format(x))
Example #8
0
 def func(ai):
     uv = ai.get_value(i_attr)
     v = nominal_value(uv)
     e = std_dev(uv)
     pe = format_percent_error(v, e)
     return '{}= {}+/-{}({}%)'.format(fi_attr, floatfmt(v), floatfmt(e),
                                      pe)
Example #9
0
    def _build_label_text(self, x, we, n, total_n=None, mswd_args=None, percent_error=False, sig_figs=3):

        display_n = True
        display_mswd = n >= 2

        if display_n:
            if total_n and n != total_n:
                n = "n= {}/{}".format(n, total_n)
            else:
                n = "n= {}".format(n)
        else:
            n = ""

        if mswd_args and display_mswd:
            mswd, valid_mswd, _ = mswd_args
            vd = "" if valid_mswd else "*"
            mswd = "{}mswd= {:0.2f}".format(vd, mswd)
        else:
            mswd = ""

        sx = floatfmt(x, sig_figs)
        swe = floatfmt(we, sig_figs)

        if self.options.index_attr in ("uF", "Ar40/Ar36"):
            me = u"{} {}{}".format(sx, PLUSMINUS, swe)
        else:
            age_units = self._get_age_units()
            pe = ""
            if percent_error:
                pe = "({})".format(format_percent_error(x, we, include_percent_sign=True))

            me = u"{} {}{}{} {}".format(sx, PLUSMINUS, swe, pe, age_units)

        return u"{} {} {}".format(me, mswd, n)
Example #10
0
    def assemble_lines(self):
        if self._cached_lines is None:
            idx = self.current_position
            comp = self.component

            idx2 = idx * 2
            e = comp.errors[idx2]
            ys = comp.value.get_data()[::2]
            v = ys[idx]

            low_c = self.cumulative39s[idx2]
            high_c = self.cumulative39s[idx2 + 1]

            an = self.analyses[idx]
            lines = [
                'RunID={}'.format(an.record_id), 'Tag={}'.format(an.tag),
                'Status={}'.format(an.status_text),
                u'{}={} {}{} (1{})'.format(comp.container.y_axis.title,
                                           floatfmt(v), PLUSMINUS, floatfmt(e),
                                           SIGMA),
                'Cumulative. Ar39={}-{}'.format(floatfmt(low_c),
                                                floatfmt(high_c))
            ]

            self._cached_lines = lines

        return self._cached_lines
Example #11
0
    def test_hundreths(self):
        x = 0.01
        fx = floatfmt(x)
        self.assertEqual(fx, '0.0100')

        fx = floatfmt(x, n=2)
        self.assertEqual(fx, '0.01')
Example #12
0
    def _get_discrimination_text(self):
        ic = self.item.discrimination
        if ic is None:
            v, e = 1.0, 0
        else:
            v, e = nominal_value(ic), std_dev(ic)

        return '{}+/-{}'.format(floatfmt(v, n=4), floatfmt(e, n=4))
Example #13
0
    def _get_discrimination_text(self):
        ic = self.item.discrimination
        if ic is None:
            v, e = 1.0, 0
        else:
            v, e = nominal_value(ic), std_dev(ic)

        return '{}+/-{}'.format(floatfmt(v, n=4), floatfmt(e, n=4))
Example #14
0
    def _load_unknown_computed(self, an, new_list):
        attrs = (('Age', 'uage_w_j_err'),
                 # ('Age', 'age', None, None, 'age_err'),
                 ('w/o J', 'wo_j', '', 'uage', 'age_err_wo_j'),
                 ('K/Ca', 'kca'),
                 ('K/Cl', 'kcl'),
                 ('40Ar*', 'rad40_percent'),
                 ('F', 'uF'),
                 ('w/o Irrad', 'wo_irrad', '', 'uF', 'F_err_wo_irrad'))

        if new_list:
            def comp_factory(n, a, value=None, value_tag=None, error_tag=None):
                if value is None:
                    value = getattr(an, a)

                display_value = True
                if value_tag:
                    value = getattr(an, value_tag)
                    display_value = False

                if error_tag:
                    e = getattr(an, error_tag)
                else:
                    e = std_dev(value)

                return ComputedValue(name=n,
                                     tag=a,
                                     value=nominal_value(value) or 0,
                                     value_tag=value_tag or '',
                                     display_value=display_value,
                                     error=e or 0)

            cv = [comp_factory(*args)
                  for args in attrs]

            self.computed_values = cv
        else:
            age = an.uage
            nage, sage = nominal_value(age), std_dev(age)
            try:
                self.summary_str = u'Age={} {}{}({}%)'.format(floatfmt(nage), PLUSMINUS,
                                                              floatfmt(sage), format_percent_error(nage, sage))
            except:
                pass

            for ci in self.computed_values:
                attr = ci.tag
                if attr == 'wo_j':
                    ci.error = an.age_err_wo_j or 0
                    ci.value = nominal_value(getattr(an, ci.value_tag))
                elif attr == 'wo_irrad':
                    ci.error = an.F_err_wo_irrad or 0
                    ci.value = nominal_value(getattr(an, ci.value_tag))
                else:
                    v = getattr(an, attr)
                    if v is not None:
                        ci.value = nominal_value(v)
                        ci.error = std_dev(v)
Example #15
0
    def _load_unknown_computed(self, an, new_list):
        attrs = (('Age', 'uage_w_j_err'), ('w/o J', 'wo_j', '', 'uage',
                                           'age_err_wo_j'), ('K/Ca', 'kca'),
                 ('K/Cl', 'kcl'), ('40Ar*', 'radiogenic_yield'), ('F', 'uF'),
                 ('w/o Irrad', 'wo_irrad', '', 'uF', 'F_err_wo_irrad'))

        if new_list:

            def comp_factory(n, a, value=None, value_tag=None, error_tag=None):
                if value is None:
                    value = getattr(an, a)

                display_value = True
                if value_tag:
                    value = getattr(an, value_tag)
                    display_value = False

                if error_tag:
                    e = getattr(an, error_tag)
                else:
                    e = std_dev(value)

                return self._computed_value_factory(
                    name=n,
                    tag=a,
                    value=nominal_value(value) or 0,
                    value_tag=value_tag or '',
                    display_value=display_value,
                    error=e or 0)

            cv = [comp_factory(*args) for args in attrs]

            self.computed_values = cv
        else:
            age = an.uage
            nage, sage = nominal_value(age), std_dev(age)
            try:
                self.summary_str = u'Age={} {}{}({}%)'.format(
                    floatfmt(nage), PLUSMINUS, floatfmt(sage),
                    format_percent_error(nage, sage))
            except:
                pass

            for ci in self.computed_values:
                ci.sig_figs = self.sig_figs
                attr = ci.tag
                if attr == 'wo_j':
                    ci.error = an.age_err_wo_j or 0
                    ci.value = nominal_value(getattr(an, ci.value_tag))
                elif attr == 'wo_irrad':
                    ci.error = an.F_err_wo_irrad or 0
                    ci.value = nominal_value(getattr(an, ci.value_tag))
                else:
                    v = getattr(an, attr)
                    if v is not None:
                        ci.value = nominal_value(v)
                        ci.error = std_dev(v)
Example #16
0
    def _make_flux_row(self, ans):

        mR = sum(ai.R for ai in ans) / len(ans)
        j, e = calculate_flux(mR, 1, self.monitor_age)
        r = Row(fontsize=8)
        r.add_item(value='<b>J</b>', span=5)
        r.add_item(value='<b>{}</b>'.format(floatfmt(j)))
        r.add_item(value='<b>{}</b>'.format(floatfmt(e)))

        return r
Example #17
0
    def _make_flux_row(self, ans):

        mR = sum(ai.R for ai in ans) / len(ans)
        j, e = calculate_flux(mR, 1, self.monitor_age)
        r = Row(fontsize=8)
        r.add_item(value='<b>J</b>', span=5)
        r.add_item(value='<b>{}</b>'.format(floatfmt(j)))
        r.add_item(value='<b>{}</b>'.format(floatfmt(e)))

        return r
Example #18
0
    def test_convert_to_scientific(self):
        x = 0.001
        fx = floatfmt(x, n=2)
        self.assertEqual(fx, '1.00E-03')

        fx = floatfmt(x, n=2, s=1)
        self.assertEqual(fx, '1.0E-03')

        x = 0.001
        fx = floatfmt(x)
        self.assertEqual(fx, '0.0010')
Example #19
0
    def calculate_width(self, txt):
        if self.calculated_width is None:
            self.calculated_width = self._calculate_label_width()

        if isinstance(txt, float):
            if self.nsigfigs:
                txt = floatfmt(txt, self.nsigfigs, use_scientific=self.use_scientific)
            else:
                txt = floatfmt(txt)

        self.calculated_width = max(self.calculated_width, len(str(txt))+5)
Example #20
0
    def _irradiation_changed(self):
        if self.irradiation:
            self.level = ''

            chron = self.dvc.meta_repo.get_chronology(self.irradiation)
            j = chron.duration * self.j_multiplier
            self._estimated_j_value = j
            self.estimated_j_value = u'{} {}{}'.format(floatfmt(j), PLUSMINUS,
                                                       floatfmt(j * 0.001))
            items = [NeutronDose(*args) for args in chron.get_doses()]
            self.chronology_items = items
Example #21
0
    def _update_ratios(self, an):
        for ci in self.computed_values:
            nd = ci.detectors
            r = self._get_non_corrected_ratio(nd)
            rr, ic = self._get_corrected_ratio(nd)

            ci.trait_set(value=floatfmt(rr.nominal_value),
                         error=floatfmt(rr.std_dev),
                         noncorrected_value=r.nominal_value,
                         noncorrected_error=r.std_dev,
                         ic_factor=nominal_value(ic))
Example #22
0
    def _update_ratios(self, an):
        for ci in self.computed_values:
            nd = ci.detectors
            r = self._get_non_corrected_ratio(nd)
            rr, ic = self._get_corrected_ratio(nd)

            ci.trait_set(value=floatfmt(rr.nominal_value),
                         error=floatfmt(rr.std_dev),
                         noncorrected_value=r.nominal_value,
                         noncorrected_error=r.std_dev,
                         ic_factor=nominal_value(ic))
Example #23
0
    def _irradiation_changed(self):
        if self.irradiation:
            self.level = ''

            chron = self.dvc.meta_repo.get_chronology(self.irradiation)
            j = chron.duration * self.j_multiplier
            self._estimated_j_value = j
            self.estimated_j_value = u'{} {}{}'.format(floatfmt(j),
                                                       PLUSMINUS,
                                                       floatfmt(j * 0.001))
            items = [NeutronDose(*args) for args in chron.get_doses()]
            self.chronology_items = items
Example #24
0
    def traits_view(self):
        def column(klass=ObjectColumn, editable=False, **kw):
            return klass(text_font='arial 10', editable=editable, **kw)

        cols = [
            column(klass=CheckboxColumn,
                   name='use',
                   label='Use',
                   editable=True,
                   width=30),
            column(name='hole_id', label='Hole'),
            column(name='identifier', label='Identifier'),
            column(name='sample', label='Sample', width=115),
            column(name='x', label='X', format='%0.3f', width=50),
            column(name='y', label='Y', format='%0.3f', width=50),
            column(name='theta', label=u'\u03b8', format='%0.3f', width=50),
            column(name='j',
                   label='J',
                   format_func=lambda x: floatfmt(x, n=7, s=3),
                   width=75),
            column(name='jerr',
                   format_func=lambda x: floatfmt(x, n=8, s=3),
                   label=u'\u00b1\u03c3',
                   width=75),
            column(name='dev', label='dev', format='%0.2f', width=70),
            column(klass=CheckboxColumn,
                   name='save',
                   label='Save',
                   editable=True,
                   width=30)
        ]

        editor = TableEditor(columns=cols, sortable=False, reorderable=False)

        v = View(
            VSplit(
                UItem('graph',
                      style='custom',
                      editor=InstanceEditor(),
                      height=0.72),
                VGroup(
                    HGroup(
                        spring,
                        icon_button_editor(
                            'save_unknowns_button',
                            'dialog-ok-5',
                            tooltip='Toggle "save" for unknown positions'),
                        icon_button_editor(
                            'save_all_button',
                            'dialog-ok-apply-5',
                            tooltip='Toggle "save" for all positions')),
                    UItem('positions', editor=editor, height=0.28))))
        return v
Example #25
0
    def _permutate(self, ai, record_id, e, ici, prog, i, n):
        if prog:
            prog.change_message("Setting ic_factor to {}, {}".format(ici, e))

        ai.set_ic_factor("CDD", ici, e)

        ai.calculate_age(force=True)
        r = PermutationRecord()
        r.age = ai.uage
        r.info_str = "{} (ic={},{})".format(record_id, floatfmt(ici), floatfmt(e))
        r.identifier = ai.identifier
        return r
Example #26
0
    def _permutate(self, ai, record_id, e, ici, prog, i, n):
        if prog:
            prog.change_message('Setting ic_factor to {}, {}'.format(ici, e))

        ai.set_ic_factor('CDD', ici, e)

        ai.calculate_age(force=True)
        r = PermutationRecord()
        r.age = ai.uage
        r.info_str = '{} (ic={},{})'.format(record_id, floatfmt(ici), floatfmt(e))
        r.identifier = ai.identifier
        return r
Example #27
0
 def value_string(self, t):
     if t == 'uF':
         a, e = self.F, self.F_err
     elif t == 'uage':
         a, e = self.uage.nominal_value, self.uage.std_dev
     else:
         v = self.get_value(t)
         if isinstance(v, Isotope):
             v = v.get_intensity()
         a, e = v.nominal_value, v.std_dev
     pe = format_percent_error(a, e)
     return u'{} {}{} ({}%)'.format(floatfmt(a), PLUSMINUS, floatfmt(e), pe)
Example #28
0
 def value_string(self, t):
     if t == 'uF':
         a, e = self.F, self.F_err
     elif t == 'uage':
         a, e = self.uage.nominal_value, self.uage.std_dev
     else:
         v = self.get_value(t)
         if isinstance(v, Isotope):
             v = v.get_intensity()
         a, e = v.nominal_value, v.std_dev
     pe = format_percent_error(a, e)
     return u'{} {}{} ({}%)'.format(floatfmt(a), PLUSMINUS, floatfmt(e), pe)
Example #29
0
    def _make_weighted_mean_row(self, ans):
        r = Row(fontsize=8)

        ages, errors = zip(*[(ai.age.nominal_value, ai.age.std_dev)
                            for ai in ans])

        wm, we = calculate_weighted_mean(ages, errors)
        r.add_item(value='<b>weighted mean</b>', span=2)
        r.add_blank_item(3)
        r.add_item(value='<b>{}</b>'.format(floatfmt(wm)))
        r.add_item(value=u'<b>\u00b1{}</b>'.format(floatfmt(we)))

        return r
Example #30
0
    def _make_weighted_mean_row(self, ans):
        r = Row(fontsize=8)

        ages, errors = zip(*[(ai.age.nominal_value, ai.age.std_dev)
                             for ai in ans])

        wm, we = calculate_weighted_mean(ages, errors)
        r.add_item(value='<b>weighted mean</b>', span=2)
        r.add_blank_item(3)
        r.add_item(value='<b>{}</b>'.format(floatfmt(wm)))
        r.add_item(value=u'<b>\u00b1{}</b>'.format(floatfmt(we)))

        return r
Example #31
0
    def calculate_width(self, txt):
        if self.calculated_width is None:
            self.calculated_width = self._calculate_label_width()

        if isinstance(txt, float):
            if self.nsigfigs:
                txt = floatfmt(txt,
                               self.nsigfigs,
                               use_scientific=self.use_scientific)
            else:
                txt = floatfmt(txt)

        self.calculated_width = max(self.calculated_width, len(str(txt)) + 5)
Example #32
0
            def comp_factory(n, a, value=None, error_tag=None):
                if value is None:
                    aa = getattr(an, a)
                    value = floatfmt(nominal_value(aa))
                if error_tag:
                    e = getattr(an, error_tag)
                else:
                    e = std_dev(aa)

                return ComputedValue(name=n,
                                     tag=a,
                                     value=value,
                                     error=floatfmt(e))
Example #33
0
    def _air_ratio(self):
        a4038 = self.isotope_group.get_ratio('Ar40/Ar38', non_ic_corr=True)
        a4036 = self.isotope_group.get_ratio('Ar40/Ar36', non_ic_corr=True)
        # e4038 = uformat_percent_error(a4038, include_percent_sign=True)
        # e4036 = uformat_percent_error(a4036, include_percent_sign=True)

        lines = [self._make_header('Ratios'),
                 'Ar40/Ar36= {} {}'.format(floatfmt(nominal_value(a4036)), errorfmt(nominal_value(a4036),
                                                                                    std_dev(a4036))),
                 'Ar40/Ar38= {} {}'.format(floatfmt(nominal_value(a4038)), errorfmt(nominal_value(a4038),
                                                                                    std_dev(a4038)))]

        return self._make_lines(lines)
Example #34
0
    def _get_value(self, attr, n=3, **kw):
        v = ''
        item = self.item
        if hasattr(item, attr):
            v = getattr(self.item, attr)
            if v:
                v = floatfmt(nominal_value(v), n=n, **kw)
        elif hasattr(item, 'isotopes'):
            if attr in item.isotopes:
                v = item.isotopes[attr].get_intensity()
                v = floatfmt(nominal_value(v), n=n, **kw)

        return v
Example #35
0
    def _get_value(self, attr, n=3, **kw):
        v = ""
        item = self.item
        if hasattr(item, attr):
            v = getattr(self.item, attr)
            if v:
                v = floatfmt(nominal_value(v), n=n, **kw)
        elif hasattr(item, "isotopes"):
            if attr in item.isotopes:
                v = item.isotopes[attr].get_intensity()
                v = floatfmt(nominal_value(v), n=n, **kw)

        return v
Example #36
0
            def comp_factory(n, a, value=None, error_tag=None):
                if value is None:
                    aa = getattr(an, a)
                    value = floatfmt(nominal_value(aa))
                if error_tag:
                    e = getattr(an, error_tag)
                else:
                    e = std_dev(aa)

                return ComputedValue(name=n,
                                     tag=a,
                                     value=value,
                                     error=floatfmt(e))
Example #37
0
        def ad(i, x, y, ai):
            a = ai.isotopes['Ar39'].get_interference_corrected_value()
            b = ai.isotopes['Ar40'].get_interference_corrected_value()
            r = a / b
            v = r.nominal_value
            e = r.std_dev

            try:
                pe = '({:0.2f}%)'.format(e / v * 100)
            except ZeroDivisionError:
                pe = '(Inf%)'

            return u'39Ar/40Ar = {} {}{} {}'.format(floatfmt(v, n=6), PLUSMINUS, floatfmt(e, n=7), pe)
Example #38
0
    def _irradiation_changed(self):
        super(LabnumberEntry, self)._irradiation_changed()
        if self.irradiation:
            db = self.db
            with db.session_ctx():
                irrad = db.get_irradiation(self.irradiation)

                j = irrad.chronology.duration
                j *= self.j_multiplier
                self.estimated_j_value = u'{} {}{}'.format(floatfmt(j),
                                                          PLUSMINUS,
                                                          floatfmt(j*0.001))
                items = [NeutronDose(*args) for args in irrad.chronology.get_doses()]
                self.chronology_items = items
Example #39
0
    def _update_ratios(self, an):
        for ci in self.computed_values:
            nd = ci.detectors
            n, d = nd.split('/')
            niso, diso = self._get_isotope(n), self._get_isotope(d)

            noncorrected = self._get_non_corrected_ratio(niso, diso)
            corrected, ic = self._get_corrected_ratio(niso, diso)

            ci.trait_set(value=floatfmt(nominal_value(corrected)),
                         error=floatfmt(std_dev(corrected)),
                         noncorrected_value=nominal_value(noncorrected),
                         noncorrected_error=std_dev(noncorrected),
                         ic_factor=nominal_value(ic))
Example #40
0
    def load_measurement(self, an, ar):

        # j = self._get_j(an)
        j = ar.j
        jf = 'NaN'
        if j is not None:
            jj = floatfmt(nominal_value(j), n=7, s=5)
            pe = format_percent_error(nominal_value(j), std_dev(j), include_percent_sign=True)
            jf = u'{} \u00b1{:0.2e}({})'.format(jj, std_dev(j), pe)

        a39 = ar.ar39decayfactor
        a37 = ar.ar37decayfactor
        ms = [MeasurementValue(name='Branch',
                               value=an.branch),
              MeasurementValue(name='DAQ Version',
                               value=an.collection_version),
              MeasurementValue(name='UUID',
                               value=an.uuid),
              MeasurementValue(name='RepositoryID',
                               value=an.repository_identifier),
              MeasurementValue(name='Spectrometer',
                               value=an.mass_spectrometer),
              MeasurementValue(name='Run Date',
                               value=an.rundate.strftime('%Y-%m-%d %H:%M:%S')),
              MeasurementValue(name='Irradiation',
                               value=self._get_irradiation(an)),
              MeasurementValue(name='J',
                               value=jf),
              MeasurementValue(name='Position Error',
                               value=floatfmt(an.position_jerr, use_scientific=True)),
              MeasurementValue(name='Lambda K',
                               value=nominal_value(ar.arar_constants.lambda_k),
                               units='1/a'),
              MeasurementValue(name='Project',
                               value=an.project),
              MeasurementValue(name='Sample',
                               value=an.sample),
              MeasurementValue(name='Material',
                               value=an.material),
              MeasurementValue(name='Comment',
                               value=an.comment),
              MeasurementValue(name='Ar39Decay',
                               value=floatfmt(a39)),
              MeasurementValue(name='Ar37Decay',
                               value=floatfmt(a37)),
              MeasurementValue(name='Sens.',
                               value=floatfmt(an.sensitivity, use_scientific=True),
                               units=an.sensitivity_units)]

        self.measurement_values = ms
Example #41
0
    def _update_ratios(self, an):
        for ci in self.computed_values:
            nd = ci.detectors
            n, d = nd.split('/')
            niso, diso = self._get_isotope(n), self._get_isotope(d)

            noncorrected = self._get_non_corrected_ratio(niso, diso)
            corrected, ic = self._get_corrected_ratio(niso, diso)

            ci.trait_set(value=floatfmt(nominal_value(corrected)),
                         error=floatfmt(std_dev(corrected)),
                         noncorrected_value=nominal_value(noncorrected),
                         noncorrected_error=std_dev(noncorrected),
                         ic_factor=nominal_value(ic))
Example #42
0
    def assemble_lines(self):
        pt = self.current_position
        if pt:
            # x, y = self.component.map_data(pt)

            comp = self.component
            inds = self.get_selected_index()
            lines = []
            convert_index = self.convert_index
            if inds is not None and len(inds):
                he = hasattr(self.component, 'yerror')
                ys = comp.value.get_data()[inds]
                xs = comp.index.get_data()[inds]

                for i, x, y in zip(inds, xs, ys):
                    if he:
                        ye = comp.yerror.get_data()[i]
                        pe = self.percent_error(y, ye)

                        ye = floatfmt(ye, n=6, s=3)
                        sy = u'{} {}{} ({})'.format(y, PLUSMINUS, ye, pe)
                    else:
                        sy = floatfmt(y, n=6, s=3)

                    if convert_index:
                        x = convert_index(x)
                    else:
                        x = '{:0.5f}'.format(x)

                    lines.extend(
                        [u'pt={:03d}, x= {}, y= {}'.format(i + 1, x, sy)])
                    if hasattr(comp, 'display_index'):
                        x = comp.display_index.get_data()[i]
                        lines.append('{}'.format(x))

                    if self.additional_info is not None:
                        try:
                            ad = self.additional_info(i, self.id)
                        except BaseException:
                            ad = self.additional_info(i)
                        if isinstance(ad, (list, tuple)):
                            lines.extend(ad)
                        else:
                            lines.append(ad)

            return lines
            # delim_n = max([len(li) for li in lines])
            # return intersperse(lines, '-' * delim_n)
        else:
            return []
Example #43
0
    def assemble_lines(self):
        pt = self.current_position
        if pt:
            # x, y = self.component.map_data(pt)

            comp = self.component
            inds = self.get_selected_index()
            lines = []
            convert_index = self.convert_index
            if inds is not None and len(inds):
                he = hasattr(self.component, 'yerror')
                ys = comp.value.get_data()[inds]
                xs = comp.index.get_data()[inds]

                for i, x, y in zip(inds, xs, ys):
                    if he:
                        ye = comp.yerror.get_data()[i]
                        pe = self.percent_error(y, ye)

                        ye = floatfmt(ye, n=6, s=3)
                        sy = u'{} {}{} ({})'.format(y, PLUSMINUS, ye, pe)
                    else:
                        sy = floatfmt(y, n=6, s=3)

                    if convert_index:
                        x = convert_index(x)
                    else:
                        x = '{:0.5f}'.format(x)

                    lines.extend([u'pt={:03d}, x= {}, y= {}'.format(i + 1, x, sy)])
                    if hasattr(comp, 'display_index'):
                        x = comp.display_index.get_data()[i]
                        lines.append('{}'.format(x))

                    if self.additional_info is not None:
                        try:
                            ad = self.additional_info(i, self.id)
                        except BaseException:
                            ad = self.additional_info(i)
                        if isinstance(ad, (list, tuple)):
                            lines.extend(ad)
                        else:
                            lines.append(ad)

            return lines
            # delim_n = max([len(li) for li in lines])
            # return intersperse(lines, '-' * delim_n)
        else:
            return []
Example #44
0
 def traits_view(self):
     return View(HGroup(Item('age_kind',
                             style='readonly', show_label=False),
                        Item('display_age', format_func=lambda x: floatfmt(x, 3),
                             label='Age',
                             style='readonly'),
                        Item('display_age_err',
                             label=u'\u00b11\u03c3',
                             format_func=lambda x: floatfmt(x, 4),
                             style='readonly'),
                        Item('display_age_units',
                             style='readonly', show_label=False),
                        Item('mswd',
                             format_func=lambda x: floatfmt(x, 2),
                             style='readonly', label='MSWD')))
Example #45
0
    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):

        tool = self.tool
        y, y2 = other_component.y, other_component.y2
        x, x2 = other_component.x, other_component.x2

        if tool.ruler_pos:
            a, b = tool.ruler_pos
            if tool.orientation == 'x':
                x, x2 = a, a
                self.label.sx = x
                self.label.sy = b + 10
            else:
                y, y2 = b, b
                self.label.sx = a + 20
                self.label.sy = y

            with gc:
                gc.set_stroke_color(self.color_)
                gc.set_line_width(2)
                gc.lines([(x, y), (x2, y2)])
                gc.stroke_path()

            if tool.entered_value:
                self.label.bgcolor = self.label_manual_color
                v = tool.entered_value
            else:
                self.label.bgcolor = self.label_bgcolor
                v = floatfmt(tool.ruler_data_pos)

            self.label.text = '{}: {}'.format(tool.orientation.upper(), v)
            self.label.overlay(other_component, gc, view_bounds=None, mode="normal")
Example #46
0
def make_items(isotopes):
    items = []
    for det in DETECTOR_ORDER:
        ai = next((ai for ai in isotopes.values() if ai.detector.upper() == det), None)
        if ai:
            rv = ai.get_non_detector_corrected_value()
            r = RatioItem(name=ai.detector,
                          refvalue=rv,
                          intensity=floatfmt(nominal_value(rv)),
                          intensity_err=floatfmt(std_dev(rv)))
            r.add_ratio(ai)
            for bi in isotopes.values():
                r.add_ratio(bi)

            items.append(r)
    return items
Example #47
0
    def run(self):
        self._alive = True
        st = self._start_time
        p = self.period
        rd = self.response_device
        rds = self.response_device_secondary
        od = self.output_device
        dm = self.data_manager

        odata = self.output_data
        rdata = self.response_data
        while self._alive:
            to = time.time()
            t = to - st
            out = od.get_output()
            odata = vstack((odata, (t, out)))

            r = rd.get_response(force=True)
            rdata = vstack((rdata, (t, r)))

            r2 = rds.get_response(force=True)

            datum = (t, out, r, r2)
            datum = map(lambda x: floatfmt(x, n=3), datum)
            dm.write_to_frame(datum)
            et = time.time() - to
            slt = p - et - 0.001
            if slt > 0:
                time.sleep(slt)

        self.output_data = odata
        self.response_data = rdata
Example #48
0
    def _air_ratio(self):
        a4038 = self.isotope_group.get_ratio('Ar40/Ar38', non_ic_corr=True)
        a4036 = self.isotope_group.get_ratio('Ar40/Ar36', non_ic_corr=True)
        # e4038 = uformat_percent_error(a4038, include_percent_sign=True)
        # e4036 = uformat_percent_error(a4036, include_percent_sign=True)

        lines = [
            self._make_header('Ratios'), 'Ar40/Ar36= {} {}'.format(
                floatfmt(nominal_value(a4036)),
                errorfmt(nominal_value(a4036), std_dev(a4036))),
            'Ar40/Ar38= {} {}'.format(
                floatfmt(nominal_value(a4038)),
                errorfmt(nominal_value(a4038), std_dev(a4038)))
        ]

        return self._make_lines(lines)
Example #49
0
    def _add_peak_labels(self, line):
        opt = self.options

        xs = line.index.get_data()
        ys = line.value.get_data()
        if xs.shape[0]:
            xp, yp = fast_find_peaks(ys, xs)

            self.peaks = xp

            if opt.label_all_peaks:
                border = opt.peak_label_border
                border_color = opt.peak_label_border_color

                bgcolor = opt.peak_label_bgcolor if opt.peak_label_bgcolor_enabled else 'transparent'

                for xi, yi in zip(xp, yp):
                    label = PeakLabel(line,
                                      data_point=(xi, yi),
                                      label_text=floatfmt(
                                          xi, n=opt.peak_label_sigfigs),
                                      border_visible=bool(border),
                                      border_width=border,
                                      border_color=border_color,
                                      bgcolor=bgcolor)
                    line.overlays.append(label)
Example #50
0
 def _format_number(self, attr, **kw):
     if self.item.record_id:
         v = getattr(self.item, attr)
         r = floatfmt(v, **kw)
     else:
         r = ''
     return r
Example #51
0
    def _irradiation_changed(self):
        super(LabnumberEntry, self)._irradiation_changed()
        if self.irradiation:
            db = self.db
            with db.session_ctx():
                irrad = db.get_irradiation(self.irradiation)

                j = irrad.chronology.duration
                j *= self.j_multiplier
                self.estimated_j_value = u'{} {}{}'.format(
                    floatfmt(j), PLUSMINUS, floatfmt(j * 0.001))
                items = [
                    NeutronDose(*args)
                    for args in irrad.chronology.get_doses()
                ]
                self.chronology_items = items
Example #52
0
    def assemble_lines(self):
        idx = self.current_position
        comp = self.component

        e = comp.errors[idx]
        ys = comp.value.get_data()[::2]
        v = ys[idx]

        low_c = 0 if idx == 0 else self.cumulative39s[idx - 1]

        return ['Step={}'.format(ALPHAS[idx]),
                '{}={} +/- {} (1s)'.format(comp.container.y_axis.title, floatfmt(v),
                                           floatfmt(e)
                ),
                'Cumulative. Ar39={}-{}'.format(floatfmt(low_c),
                                                floatfmt(self.cumulative39s[idx]))]
Example #53
0
    def _rebuild_hole_vs_j(self, x, y, r, reg):
        g = Graph()
        self.graph = g

        p = g.new_plot(xtitle='Hole (Theta)',
                       ytitle='J',
                       padding=[90, 5, 5, 40])

        p.y_axis.tick_label_formatter = lambda x: floatfmt(x, n=2, s=3)

        xs = arctan2(x, y)
        ys = reg.ys
        yserr = reg.yserr

        scatter, _ = g.new_series(xs, ys,
                                  yerror=yserr,
                                  type='scatter', marker='circle')

        ebo = ErrorBarOverlay(component=scatter,
                              orientation='y')
        scatter.overlays.append(ebo)
        self._add_inspector(scatter)

        a = max((abs(min(xs)), abs(max(xs))))

        fxs = linspace(-a, a)

        a = r * sin(fxs)
        b = r * cos(fxs)
        pts = vstack((a, b)).T

        fys = reg.predict(pts)

        g.new_series(fxs, fys)
        g.set_x_limits(-3.2, 3.2)
Example #54
0
 def _format_number(self, attr, **kw):
     if self.item.record_id:
         v = getattr(self.item, attr)
         r = floatfmt(v, **kw)
     else:
         r = ''
     return r
Example #55
0
    def run(self):
        self._alive = True
        st = self._start_time
        p = self.period
        rd = self.response_device
        rds = self.response_device_secondary
        od = self.output_device
        dm = self.data_manager

        odata = self.output_data
        rdata = self.response_data
        while self._alive:
            to = time.time()
            t = to - st
            out = od.get_output()
            odata = vstack((odata, (t, out)))

            r = rd.get_response(force=True)
            rdata = vstack((rdata, (t, r)))

            r2 = rds.get_response(force=True)

            datum = (t, out, r, r2)
            datum = map(lambda x: floatfmt(x, n=3), datum)
            dm.write_to_frame(datum)
            et = time.time() - to
            slt = p - et - 0.001
            if slt > 0:
                time.sleep(slt)

        self.output_data = odata
        self.response_data = rdata
Example #56
0
    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):

        tool = self.tool
        y, y2 = other_component.y, other_component.y2
        x, x2 = other_component.x, other_component.x2

        if tool.ruler_pos:
            a, b = tool.ruler_pos
            if tool.orientation == 'x':
                x, x2 = a, a
                self.label.sx = x
                self.label.sy = b + 10
            else:
                y, y2 = b, b
                self.label.sx = a + 20
                self.label.sy = y

            with gc:
                gc.set_stroke_color(self.color_)
                gc.set_line_width(2)
                gc.lines([(x, y), (x2, y2)])
                gc.stroke_path()

            if tool.entered_value:
                self.label.bgcolor = self.label_manual_color
                v = tool.entered_value
            else:
                self.label.bgcolor = self.label_bgcolor
                v = floatfmt(tool.ruler_data_pos)

            self.label.text = '{}: {}'.format(tool.orientation.upper(), v)
            self.label.overlay(other_component, gc, view_bounds=None, mode="normal")
    def assemble_lines(self):
        reg = self.component.regressor

        v, e = reg.predict(0), reg.predict_error(0)
        lines = [reg.make_equation(),
                 'x=0, y={} +/-{}({}%)'.format(floatfmt(v, n=5),
                                               floatfmt(e, n=5),
                                               format_percent_error(v, e))]

        if not reg.mswd in ('NaN', None):
            valid = '' if reg.valid_mswd else '*'
            lines.append('MSWD= {}{}, n={}'.format(valid,
                                                   floatfmt(reg.mswd, n=3), reg.n))

        lines.extend(map(unicode.strip, map(unicode, reg.tostring().split(','))))

        return lines
Example #58
0
    def _get_diff_text(self):
        v = self.item.diff
        if isinstance(v, float):
            v = floatfmt(v, n=8, use_scientific=True)
        elif isinstance(v, bool):
            v = '---' if v else ''

        return v