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
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
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
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