示例#1
0
    def _get_baselines(self, isotopes, meas_analysis, unpack):
        for dbiso in meas_analysis.isotopes:
            if not dbiso.molecular_weight:
                continue

            name = dbiso.molecular_weight.name
            if not name in isotopes:
                continue

            det = dbiso.detector.name

            iso = isotopes[name]

            kw = dict(dbrecord=dbiso, name=name, detector=det, unpack=unpack)

            if dbiso.kind == 'baseline':
                result = None
                if dbiso.results:
                    result = dbiso.results[-1]
                r = Baseline(dbresult=result, **kw)
                fit = self.get_db_fit(meas_analysis, name, 'baseline')
                if fit is None:
                    fit = Fit(fit='average',
                              error_type='SEM',
                              filter_outliers=False,
                              filter_outlier_iterations=0,
                              filter_outlier_std_devs=0)

                r.set_fit(fit)
                iso.baseline = r

            elif dbiso.kind == 'sniff':
                r = Sniff(**kw)
                iso.sniff = r
示例#2
0
    def _get_baselines(self, meas_analysis, dbisos, unpack, selected_histories):
        isotopes = self.isotopes
        default_fit = self._default_fit_factory('average', 'SEM')
        for dbiso in dbisos:
            mw = dbiso.molecular_weight
            if not mw:
                continue

            name = mw.name
            det = dbiso.detector.name
            try:
                iso = isotopes['{}{}'.format(name, det)]
            except KeyError:
                iso = isotopes[name]

            # kw = dict(dbrecord=dbiso,
            #           name=name,
            #           detector=det,
            #           unpack=unpack)

            kind = dbiso.kind
            if kind == 'baseline':
                result = None
                if selected_histories is None:
                    # todo: this needs to be fixed to handle data_reduction_tag
                    try:
                        result = dbiso.results[-1]
                    except IndexError:
                        result = None

                # kw['name'] = '{} bs'.format(name)
                # r = Baseline(dbresult=result, **kw)
                r = Baseline('{} bs'.format(name), det)
                if result:
                    r.value = result.signal_
                    r.error = result.signal_err
                if unpack:
                    r.unpack_data(dbiso.signal.data)
                fit = self.get_db_fit(meas_analysis, name, 'baseline', selected_histories)
                if fit is None:
                    fit = default_fit()

                r.set_fit(fit, notify=False)
                iso.baseline = r
            elif kind == 'sniff' and unpack:
                # r = Sniff(**kw)
                r = Sniff(name, det)
                if unpack:
                    r.unpack_data(dbiso.signal.data)
                iso.sniff = r
示例#3
0
    def get_baseline(self, attr):
        if attr.endswith('bs'):
            attr = attr[:-2]

        if attr in self.isotopes:
            return self.isotopes[attr].baseline
        else:
            return Baseline()
示例#4
0
    def _get_baselines(self, meas_analysis, dbisos, unpack,
                       selected_histories):
        isotopes = self.isotopes
        default_fit = self._default_fit_factory('average', 'SEM')
        for dbiso in dbisos:
            mw = dbiso.molecular_weight
            if not mw:
                continue

            name = mw.name
            det = dbiso.detector.name
            try:
                iso = isotopes['{}{}'.format(name, det)]
            except KeyError:
                iso = isotopes[name]

            kw = dict(dbrecord=dbiso, name=name, detector=det, unpack=unpack)

            kind = dbiso.kind
            if kind == 'baseline':
                result = None
                if selected_histories is None:
                    # todo: this needs to be fixed to handle data_reduction_tag
                    try:
                        result = dbiso.results[-1]
                    except IndexError:
                        result = None

                kw['name'] = '{} bs'.format(name)
                r = Baseline(dbresult=result, **kw)
                fit = self.get_db_fit(meas_analysis, name, 'baseline',
                                      selected_histories)
                if fit is None:
                    fit = default_fit()

                r.set_fit(fit, notify=False)
                iso.baseline = r
            elif kind == 'sniff' and unpack:
                r = Sniff(**kw)
                iso.sniff = r
示例#5
0
    def _get_baselines(self, isotopes, meas_analysis, unpack):
        for dbiso in meas_analysis.isotopes:
            if not dbiso.molecular_weight:
                continue

            name = dbiso.molecular_weight.name
            if not name in isotopes:
                continue

            det = dbiso.detector.name

            iso = isotopes[name]

            kw = dict(dbrecord=dbiso,
                      name=name,
                      detector=det,
                      unpack=unpack)

            if dbiso.kind == 'baseline':
                result = None
                if dbiso.results:
                    result = dbiso.results[-1]
                r = Baseline(dbresult=result, **kw)
                fit = self.get_db_fit(meas_analysis, name, 'baseline')
                if fit is None:
                    fit = Fit(fit='average',
                              error_type='SEM',
                              filter_outliers=False,
                              filter_outlier_iterations=0,
                              filter_outlier_std_devs=0)

                r.set_fit(fit)
                iso.baseline = r

            elif dbiso.kind == 'sniff':
                r = Sniff(**kw)
                iso.sniff = r
示例#6
0
    def _sync(self, obj):
        for dbiso in obj.isotopes:
            r = dbiso.results[-1]
            uv = r.Iso
            ee = r.IsoEr

            bv = r.Bkgd
            be = r.BkgdEr

            key = dbiso.Label
            iso = Isotope(name=key, value=uv, error=ee)

            iso.baseline = Baseline(name=key,
                                    reverse_unpack=True,
                                    dbrecord=dbiso.baseline,
                                    unpacker=lambda x: x.PeakTimeBlob,
                                    fit='average_SEM')

            iso.blank = Blank(name=key, value=bv, error=be)
            self.isotopes[key] = iso
示例#7
0
    def _sync(self, obj):

        arar = obj.araranalyses[-1]
        if arar:
            self.j = ufloat(arar.JVal, arar.JEr)
            self.age = arar.Age
            self.age_err = arar.ErrAge
            self.age_err_wo_j = arar.ErrAgeWOErInJ
            self.rad40_percent = ufloat(arar.PctRad, arar.PctRadEr)

        for dbiso in obj.isotopes:
            r = dbiso.results[-1]
            uv = r.Iso
            ee = r.IsoEr

            bv = r.Bkgd
            be = r.BkgdEr

            key = dbiso.Label
            n = dbiso.NumCnts
            iso = Isotope(name=key, value=uv, error=ee, n=n)
            det =dbiso.detector
            iso.ic_factor=ufloat(det.ICFactor, det.ICFactorEr)
            iso.fit = r.fit.Label.lower()

            iso.baseline = Baseline(name=key,
                                    reverse_unpack=True,
                                    dbrecord=dbiso.baseline,
                                    unpack=True,
                                    unpacker=lambda x: x.PeakTimeBlob,
                                    error_type='SEM',
                                    fit='average')
            iso.baseline.set_filter_outliers_dict()

            iso.blank = Blank(name=key, value=bv, error=be)
            self.isotopes[key] = iso
示例#8
0
    def get_analysis_import_spec(self, delimiter=None):

        pspec = self.new_persistence_spec()
        rspec = pspec.run_spec

        f = self.file_gen(delimiter)
        row = next(f)

        rspec.identifier = row[0][:-1]
        rspec.aliquot = 1
        rspec.step = row[0][-1]

        rspec.extract_device = make_ed(row[0])

        rspec.irradiation = row[1]

        rspec.irradiation_position = get_int(f, 1)
        rspec.irradiation_level = 'A'

        for attr in ('sample', 'material', 'project'):
            setattr(rspec, attr, get_next(f, 1))

        for attr in ('j', 'j_err'):
            setattr(pspec, attr, get_float(f, 1))

        d = get_next(f, 1)
        t = get_next(f, 1)
        pspec.timestamp = datetime.strptime('{} {}'.format(d, t),
                                            '%m/%d/%Y %H:%M:%S')

        abundance_sens = get_float(f)
        abundance_sens_err = get_float(f)

        air = get_float(f)
        disc = 295.5 / air

        pspec.discrimination = disc

        row = next(f)  # MD errpr
        row = next(f)  # peakhop cycles

        n40 = get_int(f)
        n39 = get_int(f)
        n38 = get_int(f)
        n37 = get_int(f)
        n36 = get_int(f)
        n41 = get_int(f)
        n355 = get_int(f)
        _spare = next(f)

        int40 = next(f)
        int39 = next(f)
        int38 = next(f)
        int37 = next(f)
        int36 = next(f)
        int41 = next(f)
        int355 = next(f)

        bk40 = get_ufloat(f)
        bk39 = get_ufloat(f)
        bk38 = get_ufloat(f)
        bk37 = get_ufloat(f)
        bk36 = get_ufloat(f)
        bk41 = get_ufloat(f)

        bk40 += get_ufloat(f)
        bk39 += get_ufloat(f)
        bk38 += get_ufloat(f)
        bk37 += get_ufloat(f)
        bk36 += get_ufloat(f)
        bk41 += get_ufloat(f)

        bk40 += get_ufloat(f)
        bk39 += get_ufloat(f)
        bk38 += get_ufloat(f)
        bk37 += get_ufloat(f)
        bk36 += get_ufloat(f)
        bk41 += get_ufloat(f)

        isotopes = {
            'Ar40': self._get_isotope(f, 'Ar40', n40, bk40),
            'Ar39': self._get_isotope(f, 'Ar39', n39, bk39),
            'Ar38': self._get_isotope(f, 'Ar38', n38, bk38),
            'Ar37': self._get_isotope(f, 'Ar37', n37, bk37),
            'Ar36': self._get_isotope(f, 'Ar36', n36, bk36),
            'Ar41': self._get_isotope(f, 'Ar41', n41, bk41)
        }

        xs, ys = self._get_baseline(f, n355)
        for iso in isotopes.values():
            bs = Baseline(iso.name, iso.detector)
            bs.set_fit('average')
            bs.set_fit_error_type('SEM')
            bs.xs = xs
            bs.ys = ys
            iso.baseline = bs

        try:
            next(f)
            self.warning('Extra data in file')
        except StopIteration:
            pass

        pspec.isotope_group = IsotopeGroup(isotopes=isotopes)
        return pspec
示例#9
0
    def _sync(self, obj):

        self.j = ufloat(0, 0)
        self.age = 0
        self.age_err = 0
        self.age_err_wo_j = 0
        self.radiogenic_yield = ufloat(0, 0)
        self.rad4039 = ufloat(0, 0)

        arar = None
        if obj.araranalyses:
            arar = obj.araranalyses[-1]
            if arar:
                self.j = ufloat(arar.JVal, arar.JEr)
                self.age = arar.Age
                self.age_err = arar.ErrAge
                self.age_err_wo_j = arar.ErrAgeWOErInJ
                self.radiogenic_yield = ufloat(arar.PctRad, arar.PctRadEr)
                self.rad4039 = ufloat(arar.Rad4039, arar.Rad4039Er)
                self.r3739 = ufloat(arar.R3739Cor, arar.ErR3739Cor)
                self.Cl3839 = ufloat(arar.Cl3839, 0)
                try:
                    self.kca = ufloat(arar.CaOverK, arar.CaOverKEr)**-1
                except ZeroDivisionError:
                    self.kca = 0

                try:
                    self.kcl = ufloat(arar.ClOverK, arar.ClOverKEr)**-1
                except ZeroDivisionError:
                    self.kcl = 0

        changeable = obj.changeable
        fo, fi, fs = 0, 0, 0
        if changeable:
            self.comment = changeable.Comment
            self.tag = STATUS_MAP.get(changeable.StatusLevel)
            prefs = changeable.preferences_set
            if prefs:
                fo = prefs.DelOutliersAfterFit == 'true'
                fi = int(prefs.NFilterIter)
                fs = int(prefs.OutlierSigmaFactor)
                self.lambda_k = prefs.Lambda40Kepsilon + prefs.Lambda40KBeta
                self.lambda_Ar37 = prefs.LambdaAr37
                self.lambda_Ar39 = prefs.LambdaAr39
                self.lambda_Cl36 = prefs.LambdaCl36

        for dbiso in obj.isotopes:
            r = dbiso.results[-1]
            uv, ee = self._intercept_value(r)
            key = dbiso.Label
            n = dbiso.NumCnts
            det = dbiso.detector
            iso = Isotope(key, det.detector_type.Label)
            iso.baseline_corrected = ufloat(uv, ee)
            tv, te = 0, 0
            if arar:
                try:
                    k = key[2:]
                    tv, te = getattr(arar, 'Tot{}'.format(k)), getattr(
                        arar, 'Tot{}Er'.format(k))
                except AttributeError:
                    pass

            iso.set_filter_outliers_dict(filter_outliers=fo,
                                         iterations=fi,
                                         std_devs=fs)
            iso.total_value = ufloat(tv, te)
            # iso.set_uvalue((uv, ee))
            iso.n = n

            iso.ic_factor = ufloat(det.ICFactor, det.ICFactorEr)

            iso.fit = r.fit.Label.lower() if r.fit else ''

            iso.baseline = Baseline(key, det.detector_type.Label)

            iso.baseline.fit = 'average'
            iso.baseline.set_filter_outliers_dict(filter_outliers=fo,
                                                  iterations=fi,
                                                  std_devs=fs)

            iso.baseline.n = dbiso.baseline.NumCnts

            # uv = iso.baseline_corrected + iso.baseline.uvalue
            # print('asdf',key, uv, iso.baseline_corrected, iso.baseline.uvalue)
            # iso.value = nominal_value(uv)
            # iso.error = std_dev(uv)
            # iso.set_uvalue()
            blank = self._blank(r)
            if blank:
                iso.blank.set_uvalue(blank)

            self.isotopes[key] = iso
示例#10
0
    def get_analysis_import_spec(self, delimiter=None):

        pspec = self.new_persistence_spec()
        rspec = pspec.run_spec

        f = self.file_gen(delimiter)
        row = next(f)

        rspec.identifier = row[0][:-1]
        rspec.aliquot = 1
        rspec.step = row[0][-1]

        rspec.extract_device = make_ed(row[0])

        rspec.irradiation = row[1]

        rspec.irradiation_position = get_int(f, 1)
        rspec.irradiation_level = 'A'

        for attr in ('sample', 'material', 'project'):
            setattr(rspec, attr, get_next(f, 1))

        for attr in ('j', 'j_err'):
            setattr(pspec, attr, get_float(f, 1))

        d = get_next(f, 1)
        t = get_next(f, 1)
        pspec.timestamp = datetime.strptime('{} {}'.format(d, t), '%m/%d/%Y %H:%M:%S')

        abundance_sens = get_float(f)
        abundance_sens_err = get_float(f)

        air = get_float(f)
        disc = 295.5 / air

        pspec.discrimination = disc

        row = next(f)  # MD errpr
        row = next(f)  # peakhop cycles

        n40 = get_int(f)
        n39 = get_int(f)
        n38 = get_int(f)
        n37 = get_int(f)
        n36 = get_int(f)
        n41 = get_int(f)
        n355 = get_int(f)
        _spare = next(f)

        int40 = next(f)
        int39 = next(f)
        int38 = next(f)
        int37 = next(f)
        int36 = next(f)
        int41 = next(f)
        int355 = next(f)

        bk40 = get_ufloat(f)
        bk39 = get_ufloat(f)
        bk38 = get_ufloat(f)
        bk37 = get_ufloat(f)
        bk36 = get_ufloat(f)
        bk41 = get_ufloat(f)

        bk40 += get_ufloat(f)
        bk39 += get_ufloat(f)
        bk38 += get_ufloat(f)
        bk37 += get_ufloat(f)
        bk36 += get_ufloat(f)
        bk41 += get_ufloat(f)

        bk40 += get_ufloat(f)
        bk39 += get_ufloat(f)
        bk38 += get_ufloat(f)
        bk37 += get_ufloat(f)
        bk36 += get_ufloat(f)
        bk41 += get_ufloat(f)

        isotopes = {'Ar40': self._get_isotope(f, 'Ar40', n40, bk40),
                    'Ar39': self._get_isotope(f, 'Ar39', n39, bk39),
                    'Ar38': self._get_isotope(f, 'Ar38', n38, bk38),
                    'Ar37': self._get_isotope(f, 'Ar37', n37, bk37),
                    'Ar36': self._get_isotope(f, 'Ar36', n36, bk36),
                    'Ar41': self._get_isotope(f, 'Ar41', n41, bk41)}

        xs, ys = self._get_baseline(f, n355)
        for iso in isotopes.values():
            bs = Baseline(iso.name, iso.detector)
            bs.set_fit('average')
            bs.set_fit_error_type('SEM')
            bs.xs = xs
            bs.ys = ys
            iso.baseline = bs

        try:
            next(f)
            self.warning('Extra data in file')
        except StopIteration:
            pass

        pspec.isotope_group = IsotopeGroup(isotopes=isotopes)
        return pspec