def get_timestamps(src, sql, tol_hrs):
    with src.session_ctx() as sess:
        result = sess.execute(sql)
        ts = array([make_timef(ri[0]) for ri in result.fetchall()])

        idxs = bin_timestamps(ts, tol_hrs=tol_hrs)
        return ts, idxs
def get_timestamps(src, sql, tol_hrs):
    with src.session_ctx() as sess:
        result = sess.execute(sql)
        ts = array([make_timef(ri[0]) for ri in result.fetchall()])

        idxs = bin_timestamps(ts, tol_hrs=tol_hrs)
        return ts, idxs
Exemple #3
0
    def load_meta(self, jd):
        self.measurement_script_name = jd.get('measurement', NULL_STR)
        self.extraction_script_name = jd.get('extraction', NULL_STR)

        src = jd.get('source')
        if src:
            self.filament_parameters = src

        for attr in META_ATTRS:
            v = jd.get(attr)
            # print 'attr={},{}'.format(attr, v)
            if v is not None:
                setattr(self, attr, v)

        if self.increment is not None:
            self.step = make_step(self.increment)

        ts = jd['timestamp']
        for fmt in ('%Y-%m-%dT%H:%M:%S', '%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'):
            try:
                self.rundate = datetime.datetime.strptime(ts, fmt)
                break
            except ValueError:
                continue

        self.timestamp = self.timestampf = make_timef(self.rundate)
        self.aliquot_step_str = make_aliquot_step(self.aliquot, self.step)

        # self.collection_version = jd['collection_version']
        self._set_isotopes(jd)

        if self.analysis_type.lower() == 'sample':
            self.analysis_type = 'unknown'
        self.arar_mapping = jd.get('arar_mapping', ARAR_MAPPING)
Exemple #4
0
    def load_meta(self, jd):
        self.measurement_script_name = jd.get('measurement', NULL_STR)
        self.extraction_script_name = jd.get('extraction', NULL_STR)

        src = jd.get('source')
        if src:
            self.filament_parameters = src

        for attr in META_ATTRS:
            v = jd.get(attr)
            # print 'attr={},{}'.format(attr, v)
            if v is not None:
                setattr(self, attr, v)

        if self.increment is not None:
            self.step = make_step(self.increment)

        ts = jd['timestamp']
        for fmt in ('%Y-%m-%dT%H:%M:%S', '%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%d %H:%M:%S'):
            try:
                self.rundate = datetime.datetime.strptime(ts, fmt)
                break
            except ValueError:
                continue

        self.timestamp = self.timestampf = make_timef(self.rundate)
        self.aliquot_step_str = make_aliquot_step(self.aliquot, self.step)

        # self.collection_version = jd['collection_version']
        self._set_isotopes(jd)

        if self.analysis_type.lower() == 'sample' or not self.analysis_type:
            self.analysis_type = 'unknown'
        self.arar_mapping = jd.get('arar_mapping', ARAR_MAPPING)
    def __init__(self, record_id, repository_identifier, *args, **kw):
        super(DVCAnalysis, self).__init__(*args, **kw)
        self.record_id = record_id
        path = analysis_path(record_id, repository_identifier)
        self.repository_identifier = repository_identifier
        self.rundate = datetime.datetime.now()
        root = os.path.dirname(path)
        bname = os.path.basename(path)
        head, ext = os.path.splitext(bname)

        jd = dvc_load(os.path.join(root, 'extraction', '{}.extr{}'.format(head, ext)))
        for attr in EXTRACTION_ATTRS:
            tag = attr
            if attr == 'cleanup_duration':
                if attr not in jd:
                    tag = 'cleanup'
            elif attr == 'extract_duration':
                if attr not in jd:
                    tag = 'duration'

            v = jd.get(tag)
            if v is not None:
                setattr(self, attr, v)

        pd = jd.get('positions')
        if pd:
            ps = sorted(pd, key=lambda x: x['position'])
            self.position = ','.join([str(pp['position']) for pp in ps])

            self.xyz_position = ';'.join([','.join(map(str, (pp['x'], pp['y'], pp['z']))) for pp in ps if pp['x'] is
                                          not None])

        if not self.extract_units:
            self.extract_units = 'W'

        jd = dvc_load(path)
        for attr in META_ATTRS:
            v = jd.get(attr)
            self.debug('{}={}'.format(attr, v))
            if v is not None:
                setattr(self, attr, v)

        if self.increment is not None:
            self.step = make_step(self.increment)

        ts = jd['timestamp']
        try:
            self.rundate = datetime.datetime.strptime(ts, '%Y-%m-%dT%H:%M:%S')
        except ValueError:
            self.rundate = datetime.datetime.strptime(ts, '%Y-%m-%dT%H:%M:%S.%f')

        self.collection_version = jd['collection_version']
        self._set_isotopes(jd)

        self.timestamp = make_timef(self.rundate)
        self.aliquot_step_str = make_aliquot_step(self.aliquot, self.step)

        self.load_paths()
        self.load_spectrometer_parameters(jd['spec_sha'])
Exemple #6
0
    def __init__(self, record_id, experiment_id, *args, **kw):
        super(DVCAnalysis, self).__init__(*args, **kw)
        self.record_id = record_id
        path = analysis_path(record_id, experiment_id)
        self.experiment_identifier = experiment_id
        self.rundate = datetime.datetime.now()
        root = os.path.dirname(path)
        bname = os.path.basename(path)
        head, ext = os.path.splitext(bname)
        with open(os.path.join(root, 'extraction', '{}.extr{}'.format(head, ext))) as rfile:
            jd = json.load(rfile)
            for attr in EXTRACTION_ATTRS:
                tag = attr
                if attr == 'cleanup_duration':
                    if attr not in jd:
                        tag = 'cleanup'
                elif attr == 'extract_duration':
                    if attr not in jd:
                        tag = 'duration'

                v = jd.get(tag)
                if v is not None:
                    setattr(self, attr, v)

        with open(path, 'r') as rfile:
            jd = json.load(rfile)
            for attr in META_ATTRS:
                v = jd.get(attr)
                if v is not None:
                    setattr(self, attr, v)

            try:
                self.rundate = datetime.datetime.strptime(jd['timestamp'], '%Y-%m-%dT%H:%M:%S')
            except ValueError:
                self.rundate = datetime.datetime.strptime(jd['timestamp'], '%Y-%m-%dT%H:%M:%S.%f')

            self.collection_version = jd['collection_version']
            self._set_isotopes(jd)

        self.timestamp = make_timef(self.rundate)

        for tag in ('intercepts', 'baselines', 'blanks', 'icfactors'):
            # print tag
            with open(self._analysis_path(modifier=tag), 'r') as rfile:
                jd = json.load(rfile)
                func = getattr(self, '_load_{}'.format(tag))
                func(jd)

        self.aliquot_step_str = make_aliquot_step(self.aliquot, self.step)
Exemple #7
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 timestampf(self):
     return make_timef(self.timestamp)
Exemple #9
0
 def timestampf(self):
     return make_timef(self.timestamp)