Exemplo n.º 1
0
def _load_tray_map(db, p, name):
    from pychron.stage.maps.laser_stage_map import LaserStageMap

    sm = LaserStageMap(file_path=p)

    r = sm.g_dimension
    # blob = ''.join([struct.pack('>fff', si.x, si.y, r)
    #                 for si in sm.sample_holes])
    # from pychron.canvas.utils import make_geom

    blob = make_geom(((si.x, si.y, r) for si in sm.sample_holes))

    db.add_load_holder(name, geometry=blob)
Exemplo n.º 2
0
def _load_tray_map(db, p, name):
    from pychron.stage.maps.laser_stage_map import LaserStageMap

    sm = LaserStageMap(file_path=p)

    r = sm.g_dimension
    # blob = ''.join([struct.pack('>fff', si.x, si.y, r)
    #                 for si in sm.sample_holes])
    # from pychron.canvas.utils import make_geom

    blob = make_geom(((si.x, si.y, r) for si in sm.sample_holes))

    db.add_load_holder(name, geometry=blob)
Exemplo n.º 3
0
def load_irradiation_map(db, p, name, overwrite_geometry=False):
    holes = parse_irradiation_tray_map(p)
    if holes is not None:
        try:
            # blob = ''.join([struct.pack('>fff', x, y, r) for x, y, r in holes])
            blob = make_geom(holes)
            name, _ = os.path.splitext(name)

            h = db.add_irradiation_holder(name)
            if overwrite_geometry or not h.geometry:
                h.geometry = blob
        except Exception as e:
            print('load irradiation map', p, name, e)
            db.session.rollback()
Exemplo n.º 4
0
def load_irradiation_map(db, p, name, overwrite_geometry=False):
    holes = parse_irradiation_tray_map(p)
    if holes is not None:
        try:
            # blob = ''.join([struct.pack('>fff', x, y, r) for x, y, r in holes])
            blob = make_geom(holes)
            name, _ = os.path.splitext(name)

            h = db.add_irradiation_holder(name)
            if overwrite_geometry or not h.geometry:
                h.geometry = blob
        except Exception, e:
            print 'load irradiation map', p, name, e
            db.sess.rollback()
Exemplo n.º 5
0
    def _transfer_meta(self, dest, dban, monitor_mapping):
        self.debug('transfer meta {}'.format(monitor_mapping))

        dblab = dban.labnumber
        if monitor_mapping is None:
            dbsam = dblab.sample
            project = dbsam.project.name
            project_name = project.replace('/', '_').replace('\\', '_')
            sample_name = dbsam.name
            material_name = dbsam.material.name
        else:
            sample_name, material, project = monitor_mapping

        sam = dest.get_sample(sample_name, project_name, material_name)
        if not sam:
            if not dest.get_material(material_name):
                self.debug('add material {}'.format(material_name))
                dest.add_material(material_name)
                dest.flush()

            if not dest.get_project(project_name):
                self.debug('add project {}'.format(project_name))
                dest.add_project(project_name)
                dest.flush()

            self.debug('add sample {}'.format(sample_name))
            sam = dest.add_sample(sample_name, project_name, material_name)
            dest.flush()

        dbirradpos = dblab.irradiation_position
        if not dbirradpos:
            irradname = 'NoIrradiation'
            levelname = 'A'
            holder = 'Grid'
            pos = None
            identifier = dblab.identifier
            doses = []
            prod = None
            prodname = 'NoIrradiation'

            geom = make_geom([(0, 0, 0.0175),
                              (1, 0, 0.0175),
                              (2, 0, 0.0175),
                              (3, 0, 0.0175),
                              (4, 0, 0.0175),

                              (0, 1, 0.0175),
                              (1, 1, 0.0175),
                              (2, 1, 0.0175),
                              (3, 1, 0.0175),
                              (4, 1, 0.0175),

                              (0, 2, 0.0175),
                              (1, 2, 0.0175),
                              (2, 2, 0.0175),
                              (3, 2, 0.0175),
                              (4, 2, 0.0175),

                              (0, 3, 0.0175),
                              (1, 3, 0.0175),
                              (2, 3, 0.0175),
                              (3, 3, 0.0175),
                              (4, 3, 0.0175),

                              (0, 4, 0.0175),
                              (1, 4, 0.0175),
                              (2, 4, 0.0175),
                              (3, 4, 0.0175),
                              (4, 4, 0.0175)
                              ])
        else:
            dblevel = dbirradpos.level
            dbirrad = dblevel.irradiation
            dbchron = dbirrad.chronology

            irradname = dbirrad.name
            levelname = dblevel.name

            holder = dblevel.holder.name if dblevel.holder else ''
            geom = dblevel.holder.geometry if dblevel.holder else ''
            prodname = dblevel.production.name if dblevel.production else ''
            prodname = prodname.replace(' ', '_')
            pos = dbirradpos.position
            doses = dbchron.get_doses()

        meta_repo = self.dvc.meta_repo
        # save db irradiation
        if not dest.get_irradiation(irradname):
            self.debug('Add irradiation {}'.format(irradname))

            self.dvc.add_irradiation(irradname, doses)
            dest.flush()
            # meta_repo.add_irradiation(irradname)
            # meta_repo.add_chronology(irradname, doses, add=False)
            # meta_repo.commit('added irradiation {}'.format(irradname))

        # save production name to db
        if not dest.get_production(prodname):
            self.debug('Add production {}'.format(prodname))
            dest.add_production(prodname)
            dest.flush()

            # meta_repo.add_production(irradname, prodname, prod, add=False)
            # meta_repo.commit('added production {}'.format(prodname))

        # save db level
        if not dest.get_irradiation_level(irradname, levelname):
            self.debug('Add level irrad:{} level:{}'.format(irradname, levelname))
            dest.add_irradiation_level(levelname, irradname, holder, prodname)
            dest.flush()

            meta_repo.add_irradiation_holder(holder, geom, add=False)
            meta_repo.add_level(irradname, levelname, add=False)
            meta_repo.update_level_production(irradname, levelname, prodname)

            # meta_repo.commit('added empty level {}{}'.format(irradname, levelname))

        if pos is None:
            pos = self._get_irradpos(dest, irradname, levelname, identifier)

        # save db irradiation position
        if not dest.get_irradiation_position(irradname, levelname, pos):
            self.debug('Add position irrad:{} level:{} pos:{}'.format(irradname, levelname, pos))
            p = meta_repo.get_level_path(irradname, levelname)
            with open(p, 'r') as rfile:
                yd = json.load(rfile)

            dd = dest.add_irradiation_position(irradname, levelname, pos)
            dd.identifier = dblab.identifier
            dd.sample = sam
            dest.flush()
            try:
                f = dban.labnumber.selected_flux_history.flux
                j, e = f.j, f.j_err
            except AttributeError:
                j, e = 0, 0

            yd.append({'j': j, 'j_err': e, 'position': pos, 'decay_constants': {}})
            dvc_dump(yd, p)

        dest.commit()