Exemple #1
0
    def _record_view_factory(self, ai, progress=None, **kw):

        iso = IsotopeRecordView(**kw)
        iso.create(ai)
        if progress:
            progress.change_message('Loading {}'.format(iso.record_id))

        return iso
    def _get_find_parameters(self):
        f = FindAssociatedParametersDialog()

        ais = self.active_editor.analyses
        if ais:
            unks = ais
        elif self.analysis_table.selected:
            ans = self.analysis_table.selected
            unks = ans[:]
        elif self.selected_samples:
            ans = self.analysis_table.analyses
            unks = ans[:]
        elif self.selected_projects:
            with self.manager.db.session_ctx():
                ans = self._get_projects_analyzed_analyses(
                    self.selected_projects)
                unks = [IsotopeRecordView(ai) for ai in ans]
        else:
            self.information_dialog(
                'Select a list of projects, samples or analyses')
            return

        ts = [get_datetime(ai.timestamp) for ai in unks]
        lpost, hpost = min(ts), max(ts)
        f.model.nominal_lpost_date = lpost.date()
        f.model.nominal_hpost_date = hpost.date()

        f.model.nominal_lpost_time = lpost.time()
        f.model.nominal_hpost_time = hpost.time()

        ms = list(set([ai.mass_spectrometer for ai in unks]))
        f.model.available_mass_spectrometers = ms
        f.model.mass_spectrometers = ms

        info = f.edit_traits(kind='livemodal')
        if info.result:
            return f.model
 def func(xi, prog, i, n):
     if prog:
         prog.change_message('Loading {}'.format(xi.record_id))
     return IsotopeRecordView(xi)
 def func(a):
     # print a, a.plateau_step
     ir = IsotopeRecordView(is_plateau_step=a.plateau_step)
     ir.create(a.analysis)
     return ir
Exemple #5
0
    def record_view(self):
        iv = self._record_view
        if not iv:

            iv = IsotopeRecordView()
            iv.extract_script_name = self.extractionName
            iv.meas_script_name = self.measurementName

            irradpos = self.irradiation_position
            iv.identifier = irradpos.identifier
            iv.irradiation = irradpos.level.irradiation.name
            iv.irradiation_level = irradpos.level.name
            iv.irradiation_position_position = irradpos.position

            iv.labnumber = iv.identifier
            iv.experiment_ids = es = [e.experimentName for e in self.experiment_associations]
            if len(es) == 1:
                iv.experiment_identifier = es[0]

            for tag in ('aliquot', 'increment', 'uuid',
                        'extract_value', 'cleanup', 'duration',
                        'mass_spectrometer',
                        'extract_device',
                        'rundate',
                        'analysis_type'):
                setattr(iv, tag, getattr(self, tag))

            if irradpos.sample:
                iv.sample = irradpos.sample.name
                if irradpos.sample.project:
                    iv.project = irradpos.sample.project.name

            iv.timestampf = make_timef(self.timestamp)
            tag = self.change.tag_item
            iv.tag = tag.name
            iv.tag_dict = {k: getattr(tag, k) for k in ('name',) + OMIT_KEYS}
            self._record_view = iv

        return iv
    def _transfer_analysis(self,
                           rec,
                           exp,
                           overwrite=True,
                           monitor_mapping=None):
        dest = self.dvc.db
        proc = self.processor
        src = proc.db

        # args = rec.split('-')
        # idn = '-'.join(args[:-1])
        # t = args[-1]
        # try:
        #     aliquot = int(t)
        #     step = None
        # except ValueError:
        #     aliquot = int(t[:-1])
        #     step = t[-1]
        m = IDENTIFIER_REGEX.match(rec)
        if not m:
            m = SPECIAL_IDENTIFIER_REGEX.match(rec)

        if not m:
            self.warning('invalid runid {}'.format(rec))
            return
        else:
            idn = m.group('identifier')
            aliquot = m.group('aliquot')
            try:
                step = m.group('step') or None
            except IndexError:
                step = None

        if idn == '4359':
            idn = 'c-01-j'
        elif idn == '4358':
            idn = 'c-01-o'

        # check if analysis already exists. skip if it does
        if dest.get_analysis_runid(idn, aliquot, step):
            self.warning('{} already exists'.format(
                make_runid(idn, aliquot, step)))
            return

        dban = src.get_analysis_runid(idn, aliquot, step)
        iv = IsotopeRecordView()
        iv.uuid = dban.uuid

        self.debug('make analysis idn:{}, aliquot:{} step:{}'.format(
            idn, aliquot, step))
        # try:
        an = proc.make_analysis(iv,
                                unpack=True,
                                use_cache=False,
                                use_progress=False)
        # except BaseException as e:
        #     self.warning('Failed to make {}'.format(make_runid(idn, aliquot, step)))
        #     self.warning('exception: {}'.format(e))
        #     return

        self._transfer_meta(dest, dban, monitor_mapping)
        # return

        dblab = dban.labnumber

        if dblab.irradiation_position:
            irrad = dblab.irradiation_position.level.irradiation.name
            level = dblab.irradiation_position.level.name
            irradpos = dblab.irradiation_position.position
        else:
            irrad = 'NoIrradiation'
            level = 'A'
            irradpos = self._get_irradpos(dest, irrad, level, dblab.identifier)
            # irrad, level, irradpos = '', '', 0

        extraction = dban.extraction
        ms = dban.measurement.mass_spectrometer.name
        if not dest.get_mass_spectrometer(ms):
            self.debug('adding mass spectrometer {}'.format(ms))
            dest.add_mass_spectrometer(ms)
            dest.commit()

        ed = extraction.extraction_device.name if extraction.extraction_device else None
        if not ed:
            ed = 'No Extract Device'

        if not dest.get_extraction_device(ed):
            self.debug('adding extract device {}'.format(ed))
            dest.add_extraction_device(ed)
            dest.commit()

        if step is None:
            inc = -1
        else:
            inc = alpha_to_int(step)

        username = ''
        if dban.user:
            username = dban.user.name
            if not dest.get_user(username):
                self.debug('adding user. username:{}'.format(username))
                dest.add_user(username)
                dest.commit()

        if monitor_mapping:
            sample_name, material_name, project_name = monitor_mapping
        else:
            dbsam = dblab.sample
            sample_name = dbsam.name
            material_name = dbsam.material.name
            project_name = format_repository_identifier(dbsam.project.name)

        rs = AutomatedRunSpec(labnumber=idn,
                              username=username,
                              material=material_name,
                              project=project_name,
                              sample=sample_name,
                              irradiation=irrad,
                              irradiation_level=level,
                              irradiation_position=irradpos,
                              repository_identifier=exp,
                              mass_spectrometer=ms,
                              uuid=dban.uuid,
                              _step=inc,
                              comment=dban.comment.decode('utf-8') or '',
                              aliquot=int(aliquot),
                              extract_device=ed,
                              duration=extraction.extract_duration,
                              cleanup=extraction.cleanup_duration,
                              beam_diameter=extraction.beam_diameter,
                              extract_units=extraction.extract_units or '',
                              extract_value=extraction.extract_value,
                              pattern=extraction.pattern or '',
                              weight=extraction.weight,
                              ramp_duration=extraction.ramp_duration or 0,
                              ramp_rate=extraction.ramp_rate or 0,
                              collection_version='0.1:0.1',
                              queue_conditionals_name='',
                              tray='')

        meas = dban.measurement
        # get spectrometer parameters
        # gains
        gains = {}
        gain_history = dban.gain_history
        if gain_history:
            gains = {d.detector.name: d.value for d in gain_history.gains}

        # deflections
        deflections = {d.detector.name: d.deflection for d in meas.deflections}

        # source
        src = {
            k: getattr(meas.spectrometer_parameters, k)
            for k in QTEGRA_SOURCE_KEYS
        }

        ps = PersistenceSpec(
            run_spec=rs,
            tag=an.tag.name,
            isotope_group=an,
            timestamp=dban.analysis_timestamp,
            defl_dict=deflections,
            gains=gains,
            spec_dict=src,
            use_repository_association=True,
            positions=[p.position for p in extraction.positions])

        self.debug('transfer analysis with persister')
        self.persister.per_spec_save(ps,
                                     commit=False,
                                     commit_tag='Database Transfer')
        return True
Exemple #7
0
    db = man.db
    db.trait_set(name='pychrondata',
                 kind='mysql',
                 host='129.138.12.160',
                 username='******',
                 password='******',
                 echo=False)
    db.connect()

    with db.session_ctx():
        # for si in sams:
        _ans, n = db.get_labnumber_analyses([
            # '57493',
            '62118'
        ])
        ts = [xi.analysis_timestamp for xi in _ans]
        lpost, hpost = min(ts), max(ts)
        _ans = db.get_analyses_date_range(lpost, hpost, order='asc')
        # _ans = db.get_date_range_analyses(lpost, hpost, ordering='asc')
        _ans = [IsotopeRecordView(xi) for xi in _ans]
        # _ans = sorted(_ans, key=lambda x: x.timestamp)

    d = Demo(analyses=_ans)
    d.configure_traits()
    # print info.result
    # if info.result:
    # s = g.get_selection()
    # for si in s:
    # print si, si.analysis_type
# ============= EOF =============================================
Exemple #8
0
    def _transfer_analysis(self, rec, exp, overwrite=True, monitor_mapping=None):
        dest = self.dvc.db
        proc = self.processor
        src = proc.db

        # args = rec.split('-')
        # idn = '-'.join(args[:-1])
        # t = args[-1]
        # try:
        #     aliquot = int(t)
        #     step = None
        # except ValueError:
        #     aliquot = int(t[:-1])
        #     step = t[-1]
        m = IDENTIFIER_REGEX.match(rec)
        if not m:
            m = SPECIAL_IDENTIFIER_REGEX.match(rec)

        if not m:
            self.warning('invalid runid {}'.format(rec))
            return
        else:
            idn = m.group('identifier')
            aliquot = m.group('aliquot')
            try:
                step = m.group('step') or None
            except IndexError:
                step = None

        if idn == '4359':
            idn = 'c-01-j'
        elif idn == '4358':
            idn = 'c-01-o'

        # check if analysis already exists. skip if it does
        if dest.get_analysis_runid(idn, aliquot, step):
            self.warning('{} already exists'.format(make_runid(idn, aliquot, step)))
            return

        dban = src.get_analysis_runid(idn, aliquot, step)
        iv = IsotopeRecordView()
        iv.uuid = dban.uuid

        self.debug('make analysis idn:{}, aliquot:{} step:{}'.format(idn, aliquot, step))
        try:
            an = proc.make_analysis(iv, unpack=True, use_cache=False, use_progress=False)
        except:
            self.warning('Failed to make {}'.format(make_runid(idn, aliquot, step)))
            return

        self._transfer_meta(dest, dban, monitor_mapping)
        # return

        dblab = dban.labnumber

        if dblab.irradiation_position:
            irrad = dblab.irradiation_position.level.irradiation.name
            level = dblab.irradiation_position.level.name
            irradpos = dblab.irradiation_position.position
        else:
            irrad = 'NoIrradiation'
            level = 'A'
            irradpos = self._get_irradpos(dest, irrad, level, dblab.identifier)
            # irrad, level, irradpos = '', '', 0

        extraction = dban.extraction
        ms = dban.measurement.mass_spectrometer.name
        if not dest.get_mass_spectrometer(ms):
            self.debug('adding mass spectrometer {}'.format(ms))
            dest.add_mass_spectrometer(ms)
            dest.commit()

        ed = extraction.extraction_device.name if extraction.extraction_device else None
        if not ed:
            ed = 'No Extract Device'

        if not dest.get_extraction_device(ed):
            self.debug('adding extract device {}'.format(ed))
            dest.add_extraction_device(ed)
            dest.commit()

        if step is None:
            inc = -1
        else:
            inc = ALPHAS.index(step)

        username = ''
        if dban.user:
            username = dban.user.name
            if not dest.get_user(username):
                self.debug('adding user. username:{}'.format(username))
                dest.add_user(username)
                dest.commit()

        if monitor_mapping:
            sample_name, material_name, project_name = monitor_mapping
        else:
            dbsam = dblab.sample
            sample_name = dbsam.name
            material_name = dbsam.material.name
            project_name = format_repository_identifier(dbsam.project.name)

        rs = AutomatedRunSpec(labnumber=idn,
                              username=username,
                              material=material_name,
                              project=project_name,
                              sample=sample_name,
                              irradiation=irrad,
                              irradiation_level=level,
                              irradiation_position=irradpos,
                              repository_identifier=exp,
                              mass_spectrometer=ms,
                              uuid=dban.uuid,
                              _step=inc,
                              comment=dban.comment or '',
                              aliquot=int(aliquot),
                              extract_device=ed,
                              duration=extraction.extract_duration,
                              cleanup=extraction.cleanup_duration,
                              beam_diameter=extraction.beam_diameter,
                              extract_units=extraction.extract_units or '',
                              extract_value=extraction.extract_value,
                              pattern=extraction.pattern or '',
                              weight=extraction.weight,
                              ramp_duration=extraction.ramp_duration or 0,
                              ramp_rate=extraction.ramp_rate or 0,

                              collection_version='0.1:0.1',
                              queue_conditionals_name='',
                              tray='')

        meas = dban.measurement
        # get spectrometer parameters
        # gains
        gains = {}
        gain_history = dban.gain_history
        if gain_history:
            gains = {d.detector.name: d.value for d in gain_history.gains}

        # deflections
        deflections = {d.detector.name: d.deflection for d in meas.deflections}

        # source
        src = {k: getattr(meas.spectrometer_parameters, k) for k in QTEGRA_SOURCE_KEYS}

        ps = PersistenceSpec(run_spec=rs,
                             tag=an.tag.name,
                             arar_age=an,
                             timestamp=dban.analysis_timestamp,
                             defl_dict=deflections,
                             gains=gains,
                             spec_dict=src,
                             use_repository_association=True,
                             positions=[p.position for p in extraction.positions])

        self.debug('transfer analysis with persister')
        self.persister.per_spec_save(ps, commit=False, msg_prefix='Database Transfer')
        return True