def is_conflict(self, spec): """ return str listing the differences if databases are in conflict """ self._new_step = -1 self._new_aliquot = 1 self.debug('check for conflicts') if check_massspec_database_save(spec.identifier): self.store_connect('massspec') # self.secondary_connect() self.debug('connected to massspec') self.store_connect('isotopedb') if spec.is_step_heat(): k = 'Stepheat' self.debug('get greatest steps') ps, ns, vs = self._get_greatest_steps(spec.identifier, spec.aliquot) mv = max(vs) + 1 step = make_step(mv) # print ps, ns, vs, spec.identifier self._new_runid = make_aliquot_step(spec.aliquot, step) self._new_step = mv self._new_aliquot = spec.aliquot else: k = 'Fusion' self.debug('get greatest aliquots for {}'.format(spec.identifier)) try: ps, ns, vs = self._get_greatest_aliquots(spec.identifier) self.debug( 'greatest aliquots. Sources: {}, Precedences: {}, Aliquots: {}' .format(ns, ps, vs)) mv = max(vs) self._new_runid = make_aliquot_step(mv + 1, '') self._new_aliquot = mv + 1 except MissingAliquotPychronException: self.warning('secondary db analyses missing aliquot_pychron') return 'secondary db analyses missing aliquot_pychron' self.debug( '{} conflict args. precedence={}, names={}, values={}'.format( k, ps, ns, vs)) if not check_list(list(vs)): hn, hv = ns[0], vs[0] txt = [] for ln, lv in zip(ns[1:], vs[1:]): if lv != hv: txt.append('{}!={} {}!={}'.format(hn, ln, hv, lv)) err = ', '.join(txt) self.warning('Datastore conflicts. {}'.format(err)) return err
def is_conflict(self, spec): """ return str listing the differences if databases are in conflict """ self._new_step = -1 self._new_aliquot = 1 self.debug('check for conflicts') if check_massspec_database_save(spec.identifier): self.store_connect('massspec') # self.secondary_connect() self.debug('connected to massspec') self.store_connect('isotopedb') if spec.is_step_heat(): k = 'Stepheat' self.debug('get greatest steps') ps, ns, vs = self._get_greatest_steps(spec.identifier, spec.aliquot) mv = max(vs) + 1 step = make_step(mv) # print ps, ns, vs, spec.identifier self._new_runid = make_aliquot_step(spec.aliquot, step) self._new_step = mv self._new_aliquot = spec.aliquot else: k = 'Fusion' self.debug('get greatest aliquots for {}'.format(spec.identifier)) try: ps, ns, vs = self._get_greatest_aliquots(spec.identifier) self.debug('greatest aliquots. Sources: {}, Precedences: {}, Aliquots: {}'.format(ns, ps, vs)) mv = max(vs) self._new_runid = make_aliquot_step(mv + 1, '') self._new_aliquot = mv + 1 except MissingAliquotPychronException: self.warning('secondary db analyses missing aliquot_pychron') return 'secondary db analyses missing aliquot_pychron' self.debug('{} conflict args. precedence={}, names={}, values={}'.format(k, ps, ns, vs)) if not check_list(list(vs)): hn, hv = ns[0], vs[0] txt = [] for ln, lv in zip(ns[1:], vs[1:]): if lv != hv: txt.append('{}!={} {}!={}'.format(hn, ln, hv, lv)) err = ', '.join(txt) self.warning('Datastore conflicts. {}'.format(err)) return err
def _get_aliquot_text(self): al = '' it = self.item if it.aliquot != 0: al = make_aliquot_step(it.aliquot, it.step) return al
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)
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'])
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)
def _get_aliquot_text(self): return make_aliquot_step(self.item.aliquot, self.item.step)
def sync(self, obj, **kw): self._sync(obj, **kw) self.aliquot_step_str = make_aliquot_step(self.aliquot, self.step)