def set_isotope_detector(self, det, add=False): det, name = det.name, det.isotope # print 'setting isotope detector {} {}'.format(name, det) # print self.pairs() # name = None # if iso: # name = iso # if not isinstance(det, str): # name, det = det.isotope, det.name # # name = '{}{}'.format(det.isotope, det.name) if name in self.isotopes: iso = self.isotopes.pop(name) if add: if iso.detector != det: nn = '{}{}'.format(iso.name, iso.detector) self.isotopes[nn] = iso iso = Isotope(name, det) name = '{}{}'.format(name, det) self.isotopes[name] = iso else: self.isotopes[name] = iso else: iso = Isotope(name, det) self.isotopes[name] = iso iso.detector = det iso.ic_factor = self.get_ic_factor(det)
class IsotopeTestCase(unittest.TestCase): def setUp(self): self.iso = Isotope() xs = linspace(10, 410, 400) c = 1000.0 b = -2.0 a = 0.0 ys = a * xs * xs + b * xs + c self.iso.trait_set(xs=xs, ys=ys) self.iso.fit = 'parabolic' def test_value(self): v = self.iso.value self.assertEqual(v, 999.999999999995) def test_filtered_value(self): self.iso.ys[[1, 2, 3]] = [0, 1, 1] d = {'filter_outliers': True, 'filter_outliers_iteration': 1, 'filter_outliers_std_dev': 2} self.iso.set_filtering(d) v = self.iso.value self.assertEqual(v, 999.99999999997499)
class IsotopeTestCase(unittest.TestCase): def setUp(self): self.iso = Isotope() xs = linspace(10, 410, 400) c = 1000.0 b = -2.0 a = 0.0 ys = a * xs * xs + b * xs + c self.iso.trait_set(xs=xs, ys=ys) self.iso.fit = 'parabolic' def test_value(self): v = self.iso.value self.assertEqual(v, 999.999999999995) def test_filtered_value(self): self.iso.ys[[1, 2, 3]] = [0, 1, 1] d = { 'filter_outliers': True, 'filter_outliers_iteration': 1, 'filter_outliers_std_dev': 2 } self.iso.set_filtering(d) v = self.iso.value self.assertEqual(v, 999.99999999997499)
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 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
def _get_isotope(self, f, name, ncnts): iso = Isotope(name, 'Detector1') iso.name = name rs = (f.next() for i in xrange(ncnts)) xs, ys = zip(*((float(r[0]), float(r[1])) for r in rs)) iso.xs = xs iso.ys = ys return iso
def generate_test_data(nslope, nintercept, nnoise, dslope, dintercept, dnoise): random.seed(123456789) xs, ys = gen_data(nintercept, nslope, nnoise) a40 = Isotope(name='Ar40', xs=xs, ys=ys) xs, ys = gen_data(dintercept, dslope, dnoise) a39 = Isotope(name='Ar39', xs=xs, ys=ys) return dict(Ar40=a40, Ar39=a39)
def factory(name, detector, v): i = Isotope(name, detector) i.set_units(v.get('units', 'fA')) i.set_time_zero(time_zero_offset) i.set_detector_serial_id(v.get('serial_id', '')) i.correct_for_blank = cb return i
def set_isotope(self, iso, v, **kw): if not self.isotopes.has_key(iso): niso = Isotope(name=iso) self.isotopes[iso] = niso else: niso = self.isotopes[iso] niso.set_uvalue(v) niso.trait_set(**kw) return niso
def _get_isotope(self, f, name, ncnts, bk): iso = Isotope(name, 'Detector1') iso.set_ublank(bk) iso.name = name iso.set_fit('linear') iso.set_fit_error_type('SEM') rs = (next(f) for i in range(ncnts)) ys, xs = list(zip(*((float(r[0]), float(r[1])) for r in rs))) iso.xs = array(xs) iso.ys = array(ys) return iso
def set_isotope(self, iso, det, v, **kw): if iso not in self.isotopes: niso = Isotope(iso, det) self.isotopes[iso] = niso else: niso = self.isotopes[iso] niso.set_uvalue(v) for k, v in kw.items(): setattr(niso, k, v) return niso
def setUp(self): self.iso = Isotope() xs = linspace(10, 410, 400) c = 1000.0 b = -2.0 a = 0.0 ys = a * xs * xs + b * xs + c self.iso.trait_set(xs=xs, ys=ys) self.iso.fit = 'parabolic'
def set_isotope(self, iso, det, v, **kw): # print 'set isotope', iso, v if iso not in self.isotopes: niso = Isotope(iso, det) self.isotopes[iso] = niso else: niso = self.isotopes[iso] niso.set_uvalue(v) for k, v in kw.iteritems(): setattr(niso, k, v) # niso.trait_set(**kw) return niso
def set_isotope(self, iso, det, v, **kw): # print 'set isotope', iso, v if iso not in self.isotopes: niso = Isotope(iso, det) self.isotopes[iso] = niso else: niso = self.isotopes[iso] niso.set_uvalue(v) for k, v in kw.items(): setattr(niso, k, v) # niso.trait_set(**kw) return niso
def set_isotope_detector(self, det, iso=None): if iso: name = iso if not isinstance(det, str): name, det = det.isotope, det.name if name in self.isotopes: iso = self.isotopes[name] else: iso = Isotope(name=name) self.isotopes[name] = iso iso.detector = det iso.ic_factor = self.get_ic_factor(det)
def setUp(self): self.arun = Arun() xs = linspace(0, 100) ys = 2 * xs + 4 ar40 = Isotope(name='Ar40', xs=xs, ys=ys) ar40.baseline.value = 0.25 ar40.blank.value = 0.75 ys = 2 * xs + 1 ar39 = Isotope(name='Ar39', xs=xs, ys=ys) # ar39.baseline.value = 0.25 # ar39.blank.value = 0.75 self.arun.isotope_group.isotopes = {'Ar40': ar40, 'Ar39': ar39} self.arun.isotope_group.age = 10
def get_isotope(self, name=None, detector=None, kind=None): if name is None and detector is None: raise NotImplementedError('name or detector required') iso = None if name: try: iso = self.isotopes[name] if detector: if iso.detector != detector: iso = next( (i for i in self.itervalues() if i.name == name and i.detector == detector), None) if not iso: return except KeyError: if detector: try: iso = self.isotopes['{}{}'.format(name, detector)] except KeyError: self.isotopes[name] = iso = Isotope(name, detector) else: iso = next( (iso for iso in self.itervalues() if iso.detector == detector), None) if iso: if kind == 'sniff': iso = iso.sniff elif kind == 'baseline': iso = iso.baseline return iso
def _set_isotopes(self, jd): isos = jd.get('isotopes') if not isos: return isos = {k: Isotope(k, v['detector']) for k, v in isos.iteritems()} self.isotopes = isos
def test_save_persister(): paths.build('_dev') dvc = DVC(bind=False) dvc.db.connect() per = DVCPersister(dvc=dvc) run_spec = AutomatedRunSpec() run_spec.labnumber = '10001' run_spec.project = 'Test' arar = ArArAge() arar.isotopes['Ar40'] = Isotope(xs=[1, 2, 3], ys=[1, 2, 3], name='Ar40', detector='H1') sd = {} dd = {'H1': 100} gd = {'H1': 1.021} per_spec = PersistenceSpec(run_spec=run_spec, arar_age=arar, spec_dict=sd, defl_dict=dd, gains=gd, positions=[1, ], experiment_queue_name='testexp.txt', measurement_name='jan_unknown.py', extraction_name='foo.py') per.per_spec_save(per_spec)
def set_blank(self, iso, detector, v): if iso not in self.isotopes: niso = Isotope(iso, detector) self.isotopes[iso] = niso self.debug('setting {} blank {}'.format(iso, v)) self.isotopes[iso].blank.set_uvalue(v)
def set_blank(self, iso, v): if not self.isotopes.has_key(iso): niso = Isotope(name=iso) self.isotopes[iso] = niso self.debug('setting {} blank {}'.format(iso, v)) self.isotopes[iso].blank.set_uvalue(v)
def _get_signals(self, meas_analysis, dbisos, unpack, selected_histories): d = self.isotopes default_fit = self._default_fit_factory('linear', 'SEM') for iso in dbisos: mw = iso.molecular_weight # print iso.kind, iso.detector if not iso.kind == 'signal' or not mw: continue if not iso.detector: continue det = iso.detector.name isoname = mw.name key = isoname if isoname in d: key = '{}{}'.format(isoname, det) result = None # todo: this needs to be fixed to handle data_reduction_tag # if analysis has a dr tag then get its associated select_histories entry # the get the select_fits then the associated results if selected_histories is None: try: result = iso.results[-1] except IndexError: result = None # r = Isotope(mass=mw.mass, # dbrecord=iso, # dbresult=result, # name=isoname, # detector=det, # unpack=unpack) r = Isotope(isoname, det) if unpack: r.unpack_data(iso.signal.data) r.mass = mw.mass if result: r.value = result.signal_ r.error = result.signal_err if r.unpack_error: self.warning('Bad isotope {} {}. error: {}'.format( self.record_id, key, r.unpack_error)) self.temp_status = 1 else: fit = self.get_db_fit(meas_analysis, isoname, 'signal', selected_histories) if fit is None: fit = default_fit() r.set_fit(fit, notify=False) d[key] = r
def testAr40Fit(self): iso = Isotope() fits = dict([f.split(':') for f in self.fits]) iso.set_fit_blocks(fits['Ar41']) self.assertEqual(iso.get_fit(0), 'average') self.assertEqual(iso.get_fit(-1), 'cubic') self.assertEqual(iso.get_fit(100), 'cubic')
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
def _get_signals(self, meas_analysis, dbisos, unpack, selected_histories): d = self.isotopes default_fit = self._default_fit_factory('linear', 'SEM') for iso in dbisos: mw = iso.molecular_weight if not iso.kind == 'signal' or not mw: continue if not iso.detector: continue det = iso.detector.name isoname = mw.name key=isoname if isoname in d: key='{}{}'.format(isoname, det) # todo: this needs to be fixed to handle data_reduction_tag # if analysis has a dr tag then get its associated select_histories entry # the get the select_fits then the associated results if selected_histories is None: try: result = iso.results[-1] except IndexError: result = None r = Isotope(mass=mw.mass, dbrecord=iso, dbresult=result, name=isoname, detector=det, unpack=unpack) if r.unpack_error: self.warning('Bad isotope {} {}. error: {}'.format(self.record_id, key, r.unpack_error)) self.temp_status = 1 else: fit = self.get_db_fit(meas_analysis, isoname, 'signal', selected_histories) if fit is None: fit = default_fit() r.set_fit(fit, notify=False) d[key] = r
def _get_signals(self, isodict, meas_analysis, unpack): for iso in meas_analysis.isotopes: if not iso.kind == 'signal' or not iso.molecular_weight: continue name = iso.molecular_weight.name if name in isodict: continue if not iso.detector: continue det = iso.detector.name result = None if iso.results: result = iso.results[-1] r = Isotope(mass=iso.molecular_weight.mass, dbrecord=iso, dbresult=result, name=name, detector=det, unpack=unpack) if r.unpack_error: self.warning('Bad isotope {} {}. error: {}'.format( self.record_id, name, r.unpack_error)) self.temp_status = 1 else: fit = self.get_db_fit(meas_analysis, name, 'signal') if fit is None: fit = Fit(fit='linear', error_type='SD', filter_outliers=False, filter_outlier_iterations=1, filter_outlier_std_devs=2) r.set_fit(fit) isodict[name] = r
def _get_signals(self, isodict, meas_analysis, unpack): for iso in meas_analysis.isotopes: if not iso.kind == 'signal' or not iso.molecular_weight: continue name = iso.molecular_weight.name if name in isodict: continue if not iso.detector: continue det = iso.detector.name result = None if iso.results: result = iso.results[-1] r = Isotope(mass=iso.molecular_weight.mass, dbrecord=iso, dbresult=result, name=name, detector=det, unpack=unpack) if r.unpack_error: self.warning('Bad isotope {} {}. error: {}'.format(self.record_id, name, r.unpack_error)) self.temp_status = 1 else: fit = self.get_db_fit(meas_analysis, name, 'signal') if fit is None: fit = Fit(fit='linear', error_type='SD', filter_outliers=False, filter_outlier_iterations=1, filter_outlier_std_devs=2) r.set_fit(fit) isodict[name] = r
def setUp(self): self.arun = Arun() xs = linspace(0, 100) ys = 2 * xs + 4 # ar40 = Isotope(name='Ar40', xs=xs, ys=ys) ar40 = Isotope('Ar40', 'H1') ar40.xs = xs ar40.ys = ys ar40.fit = 'parabolic' ar40.baseline.value = 0.25 ar40.blank.value = 0.75 ys = 2 * xs + 1 ar39 = Isotope('Ar39', 'AX') ar39.fit = 'parabolic' ar39.xs = xs ar39.ys = ys # ar39.baseline.value = 0.25 # ar39.blank.value = 0.75 self.arun.isotope_group.isotopes = {'Ar40': ar40, 'Ar39': ar39} self.arun.isotope_group.age = 10
def _set_isotopes(self, jd): isos = jd.get('isotopes') if not isos: return isos = {k: Isotope(k, v['detector']) for k, v in isos.iteritems()} self.isotopes = isos # set mass path = os.path.join(paths.meta_root, 'molecular_weights.json') masses = dvc_load(path) for k, v in isos.items(): v.mass = masses.get(k, 0)
def testAr41Fit(self): iso=Isotope() fits = dict([f.split(':') for f in self.fits]) iso.set_fit_blocks(fits['Ar41']) self.assertEqual(iso.get_fit(0), 'avherage') self.assertEqual(iso.get_fit(-1), 'cubic') self.assertEqual(iso.get_fit(100), 'cubic')
def _sync_isotopes(self, yd): isos = {} for iso in yd['isotopes']: io = Isotope(name=iso['name']) for attr in ('value', 'error', 'detector', 'fit'): setattr(io, attr, iso[attr]) baseline, blank = io.baseline, io.blank baseline.value = iso['baseline'] baseline.error = iso['baseline_err'] blank.value = iso['blank'] blank.error = iso['blank_err'] isos[iso['name']] = io self.isotopes = isos
def setUpClass(cls): # xs=[0,1,2,3,4,5,6,7,8,9,10] # ys=[0,1,2,3,4,5,6,7,8,9,10] m = 1 b = 1 xs = np.linspace(0, 10, 10) ys = xs * m + b ys[5] = 0 cls.iso = Isotope(xs=xs, ys=ys) # cls.iso.filter_outliers_dict=fod cls.intercept = b cls.slope = m cls.reg = OLSRegressor(xs=xs, ys=ys, fit='linear')
def _sync_isotopes(self, yd, meas_analysis, unpack): """ load isotopes from file """ isos = {} # print yd['isotopes'] for iso in yd['isotopes']: ii = Isotope(name=iso['name'], detector=iso['detector'], ic_factor=self._to_ufloat(iso, 'ic_factor'), discrimination=self._to_ufloat(iso, 'discrimination')) ii.trait_set(_value=iso['value'], _error=iso['error']) ii.set_blank(iso['blank'], iso['blank_err']) ii.set_baseline(iso['baseline'], iso['baseline_err']) isos[iso['name']] = ii self.isotopes = isos
def set_isotope_detector(self, det, add=False): det, name = det.name, det.isotope if name in self.isotopes: iso = self.isotopes.pop(name) if add: if iso.detector != det: nn = '{}{}'.format(iso.name, iso.detector) self.isotopes[nn] = iso iso = Isotope(name, det) name = '{}{}'.format(name, det) self.isotopes[name] = iso else: self.isotopes[name] = iso else: iso = Isotope(name, det) self.isotopes[name] = iso iso.detector = det iso.ic_factor = self.get_ic_factor(det)
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
def factory(name, detector, v): i = Isotope(name, detector) i.set_units(v.get('units', 'fA')) i.set_time_zero(time_zero_offset) return i
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
def get_analysis_import_spec(self, delimiter=None): f = self.file_gen(delimiter) pspec = self.new_persistence_spec() ident = os.path.splitext(os.path.basename(self.path))[0] pspec.run_spec.uuid = ident # labnumber = '100000' # irradiation_level = 'A' # irradiation_position = 1 aliquot = int(ident[-4:]) # pspec.run_spec.labnumber = labnumber pspec.run_spec.aliquot = aliquot # pspec.run_spec.irradiation_level = irradiation_level # pspec.run_spec.irradiation_position = irradiation_position version = next(f) ncycles = next(f) total_analysis_time = get_int(f, 1) start = next(f) end = next(f) nzeros = next(f) nanalysis_cycles = next(f) toffset = next(f) pspec.timestamp = datetime.strptime(get_next(f, 1), '#%Y-%m-%d %H:%M:%S#') collector_gains = next(f) print('casd', collector_gains) # int_posts = [next(f) for i in range(41)] # print(int_posts) while 1: i = next(f) if i[0] == '"Number of peaks centred"': npeakscentered = i[1] break print('fff', npeakscentered) ndeflectors = next(f)[1] source_ht = next(f) half_plate_v = next(f) trap = next(f) trap_voltage = next(f) repeller = next(f) filament_v = next(f) delta_hp = next(f) z_lens = next(f) delta_z = next(f) max_current = next(f) quad_1 = next(f) cubic_1 = next(f) lin_1 = next(f) q18_cor = next(f) q19_cor = next(f) quad_2 = next(f) cubic_2 = next(f) lin_2 = next(f) q28_cor = next(f) q29_cor = next(f) suppressor = next(f) Deflect_IC1 = next(f) Filter_IC0 = next(f) Deflect_IC0 = next(f) Deflect_IC2 = next(f) Filter_IC3 = next(f) Deflect_IC3 = next(f) mdfpath = next(f) analysis_type_info = next(f) # trim off quotes ati = analysis_type_info[1:-1] ati = ati.split(' ') if ati[0] == 'Blank': pspec.run_spec.labnumber = 'ba-01' pspec.run_spec.irradiation = 'NoIrradiation' pspec.run_spec.irradiation_level = 'A' pspec.run_spec.irradiation_position = 1 elif ati[0] == 'Air': a = int(ati[1]) pspec.run_spec.labnumber = 'a-{:02n}'.format(a) pspec.run_spec.irradiation = 'NoIrradiation' pspec.run_spec.irradiation_level = 'A' pspec.run_spec.irradiation_position = a + 1 ics = next(f) discs = next(f) [_ for _ in range(9)] signals = [] for _ in range(total_analysis_time): line = next(f) _type = int(line[-1]) if _type: signals.append([float(li) for li in line]) signals = array(signals) with open(self.nice_path, 'r') as nice: isotopes = {} parser = NiceParser(signals) for line in nice: try: lhs, rhs = list(map(str.strip, line.split('='))) except ValueError: continue if lhs.startswith('Result'): break parser.set_tokens(rhs.split(' ')) ret, det_idx = parser.exp() iso = Isotope(lhs, 'IC{}'.format(det_idx)) iso.name = lhs iso.xs = ret.xs iso.ys = ret.ys isotopes[lhs] = iso pspec.isotope_group = IsotopeGroup(isotopes=isotopes) return pspec
def _sync(self, obj): self.j = ufloat(0, 0) self.age = 0 self.age_err = 0 self.age_err_wo_j = 0 self.rad40_percent = 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.rad40_percent = 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) self.kca = ufloat(arar.CaOverK, arar.CaOverKEr) ** -1 self.kcl = ufloat(arar.ClOverK, arar.ClOverKEr) ** -1 prefs = obj.changeable.preferences_set fo, fi, fs = 0, 0, 0 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.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 blank = self._blank(r) if blank: iso.blank.set_uvalue(blank) self.isotopes[key] = iso
return '\n'.join(lines) class BlankResult(AutomatedRunResult): def _make_summary(self): s = self._air_ratio() return s if __name__ == '__main__': from pychron.core.ui.text_editor import myTextEditor from pychron.processing.isotope import Isotope from traitsui.api import View, UItem ig = IsotopeGroup() a40 = Isotope('Ar40', 'H1') a40.set_uvalue((50000.12345, 0.4123412341)) a36 = Isotope('Ar36', 'CDD') a36.set_uvalue((51230.12345 / 295.5, 0.132142341)) a38 = Isotope('Ar38', 'L1') a38.set_uvalue((51230.12345 / 1590.5, 0.132142341)) ig.isotopes = dict(Ar40=a40, Ar36=a36, Ar38=a38) ig.age = 1.143 a = AirResult(runid='1234123-01A', isotope_group=ig) a.tripped_conditional = AutomatedRunConditional('age>10') v = View(UItem('summary', style='custom', editor=myTextEditor(editable=False, fontsize=14)),
def _make_per_spec(self, lt): run_spec = AutomatedRunSpec() per_spec = PersistenceSpec() arar_age = ArArAge() # populate per_spec per_spec.run_spec = run_spec per_spec.arar_age = arar_age # popluate run_spec run_spec.identifier = lt.labnumber run_spec.aliquot = lt.aliquot run_spec.step = lt.step run_spec.username = '******' run_spec.uuid = lt.uuid cp = lt.collection_path man = H5DataManager() man.open_file(cp) # add signal/isotopes group = man.get_group('signal') for grp in man.get_groups(group): isok = grp._v_name iso = Isotope(name=isok, fit='linear') # only handle one detector per isotope tbl = man.get_tables(grp)[0] iso.detector = tbl._v_name xs = array([x['time'] for x in tbl.iterrows()]) ys = array([x['value'] for x in tbl.iterrows()]) iso.xs = xs iso.ys = ys arar_age.isotopes[isok] = iso # add sniffs group = man.get_group('sniff') for k, iso in arar_age.isotopes.iteritems(): grp = man.get_group(k, group) tbl = man.get_tables(grp)[0] iso.sniff.detector = tbl._v_name xs = array([x['time'] for x in tbl.iterrows()]) ys = array([x['value'] for x in tbl.iterrows()]) iso.sniff.xs = xs iso.sniff.ys = ys # add baselines group = man.get_group('baseline') for dettbl in man.get_tables(group): detname = dettbl._v_name xs = array([x['time'] for x in dettbl.iterrows()]) ys = array([x['value'] for x in dettbl.iterrows()]) for iso in arar_age.isotopes.itervalues(): if iso.detector == detname: iso.baseline.xs = xs iso.baseline.ys = ys iso.baseline.fit = 'average' return per_spec