コード例 #1
0
 def _dm_factory(self, p):
     dm = XLSDataManager()
     dm.open(p)
     return dm
コード例 #2
0
class XLSIrradiationSource:
    def __init__(self, p):
        self._dm = XLSDataManager()
        self._dm.open(p)

    def connect(self):
        return True

    def get_irradiation_names(self):
        dm = self._dm
        sheet = dm.get_sheet(('Irradiations', 0))
        nameidx = dm.get_column_idx(NAME, sheet)
        return list({r[nameidx].value for r in dm.iterrows(sheet, start=1)})

    def get_import_spec(self, name):

        spec = ImportSpec()

        i = Irradiation()
        i.name = name

        spec.irradiation = i

        i.doses = self._get_doses(name)

        nlevels = []

        dm = self._dm
        sheet = dm.get_sheet(('Irradiations', 0))
        nameidx = dm.get_column_idx(NAME, sheet)
        levelidx = dm.get_column_idx(LEVEL, sheet)
        pridx = dm.get_column_idx(PR, sheet)
        holderidx = dm.get_column_idx(HOLDER, sheet)
        zidx = dm.get_column_idx(Z, sheet)
        noteidx = dm.get_column_idx(NOTE, sheet)

        z = 0
        for row in dm.iterrows(sheet, start=1):
            if row[nameidx].value == name:
                level = Level()
                level.name = row[levelidx].value
                level.z = row[zidx].value or z
                z = level.z + 1
                level.note = row[noteidx].value

                prod = Production()
                prod.name = row[pridx].value
                level.production = prod
                level.holder = row[holderidx].value

                pos = self._get_positions(name, level.name)
                level.positions = pos
                nlevels.append(level)

        i.levels = nlevels
        return spec

    def _get_doses(self, name):
        dm = self._dm
        sheet = dm.get_sheet(('Chronologies', 1))
        doses = []

        nameidx = dm.get_column_idx(NAME, sheet)
        poweridx = dm.get_column_idx(('Power',), sheet)
        startidx = dm.get_column_idx(('Start',), sheet)
        endidx = dm.get_column_idx(('End',), sheet)

        for row in dm.iterrows(sheet, start=1):
            if row[nameidx].value == name:
                p = row[poweridx].value
                s = row[startidx].value
                e = row[endidx].value

                doses.append((p, s, e))

        return doses

    def _get_positions(self, name, level):
        dm = self._dm
        sheet = dm.get_sheet(('Positions', 2))
        nameidx = dm.get_column_idx(NAME, sheet)
        levelidx = dm.get_column_idx(LEVEL, sheet)
        positionidx = dm.get_column_idx(POSITION, sheet)
        sampleidx = dm.get_column_idx(SAMPLE, sheet)
        materialidx = dm.get_column_idx(MATERIAL, sheet)
        projectidx = dm.get_column_idx(PROJECT, sheet)
        piidx = dm.get_column_idx(PI, sheet)
        noteidx = dm.get_column_idx(NOTE, sheet)
        weightidx = dm.get_column_idx(WEIGHT, sheet)

        ps = []
        for row in dm.iterrows(sheet, start=1):
            if row[nameidx].value == name and row[levelidx].value == level:
                pos = Position()

                pos.position = row[positionidx].value

                sample = Sample()
                sample.name = row[sampleidx].value
                sample.material = row[materialidx].value

                project = Project()
                project.name = row[projectidx].value
                project.principal_investigator = row[piidx].value
                sample.project = project
                pos.sample = sample

                pos.note = row[noteidx].value or ''
                pos.weight = row[weightidx].value or 0

                ps.append(pos)
        return ps
コード例 #3
0
    def _load_level_from_file(self, p, positions, irradiation, level):
        """
            use an xls file to enter irradiation positions

            looks for sheet named "IrradiationLoading"
                if not present use 0th sheet
        """

        dm = XLSDataManager()
        dm.open(p)

        header_offset = 1
        sheet = dm.get_sheet(('IrradiationLoading', 0))
        idxs = self._get_idxs(dm, sheet)

        if not idxs:
            return

        rows = [ri for ri in range(sheet.nrows - header_offset)
                if sheet.cell_value(ri + header_offset, idxs['level']) == level]

        prog = self.progress
        if prog:
            prog.max = len(rows) - 1

        for ri in rows:
            ri += header_offset

            project, material = None, None
            sample = sheet.cell_value(ri, idxs['sample'])
            if sample.lower() == 'monitor':
                sample = self.monitor_name

            if sample:
                #is this a sample in the database
                dbsam = self.db.get_sample(sample)
                if dbsam:
                    if dbsam.project:
                        project = dbsam.project.name
                    if dbsam.material:
                        material = dbsam.material.name

            if project is None:
                project = sheet.cell_value(ri, idxs['project'])
            if material is None:
                material = sheet.cell_value(ri, idxs['material'])

            pos = sheet.cell_value(ri, idxs['position'])

            weight = sheet.cell_value(ri, idxs['weight'])
            note = sheet.cell_value(ri, idxs['note'])

            if prog:
                prog.change_message('Importing {}'.format(pos))
                prog.increment()

            ir_pos, canvas_pos = self._get_position(pos, positions)
            if ir_pos:
                ir_pos.trait_set(weight=weight,
                                 project=project,
                                 material=material,
                                 sample=sample,
                                 note=note,
                )
                if sample:
                    canvas_pos.fill = True
            else:
                msg = 'Invalid position for this tray {}'.format(ir_pos)
                #self.warning_dialog()
                self.warning(msg)
コード例 #4
0
    def _load_level_from_file(self, p, positions, irradiation, level):
        """
            use an xls file to enter irradiation positions

            looks for sheet named "IrradiationLoading"
                if not present use 0th sheet
        """

        dm = XLSDataManager()
        dm.open(p)

        header_offset = 1
        sheet = dm.get_sheet(('IrradiationLoading', 0))
        idxs = self._get_idxs(dm, sheet)

        if not idxs:
            return

        rows = [
            ri for ri in range(sheet.nrows - header_offset)
            if sheet.cell_value(ri + header_offset, idxs['level']) == level
        ]

        prog = self.progress
        if prog:
            prog.max = len(rows) - 1

        for ri in rows:
            ri += header_offset

            project, material = None, None
            sample = sheet.cell_value(ri, idxs['sample'])
            if sample.lower() == 'monitor':
                sample = self.monitor_name

            if sample:
                #is this a sample in the database
                dbsam = self.db.get_sample(sample)
                if dbsam:
                    if dbsam.project:
                        project = dbsam.project.name
                    if dbsam.material:
                        material = dbsam.material.name

            if project is None:
                project = sheet.cell_value(ri, idxs['project'])
            if material is None:
                material = sheet.cell_value(ri, idxs['material'])

            pos = sheet.cell_value(ri, idxs['position'])

            weight = sheet.cell_value(ri, idxs['weight'])
            note = sheet.cell_value(ri, idxs['note'])

            if prog:
                prog.change_message('Importing {}'.format(pos))
                prog.increment()

            ir_pos, canvas_pos = self._get_position(pos, positions)
            if ir_pos:
                ir_pos.trait_set(
                    weight=weight,
                    project=project,
                    material=material,
                    sample=sample,
                    note=note,
                )
                if sample:
                    canvas_pos.fill = True
            else:
                msg = 'Invalid position for this tray {}'.format(ir_pos)
                #self.warning_dialog()
                self.warning(msg)
コード例 #5
0
class XLSIrradiationSource:
    def __init__(self, p):
        self._dm = XLSDataManager()
        self._dm.open(p)

    def connect(self):
        return True

    def get_irradiation_names(self):
        dm = self._dm
        sheet = dm.get_sheet(('Irradiations', 0))
        nameidx = dm.get_column_idx(NAME, sheet)
        return list({r[nameidx].value for r in dm.iterrows(sheet, start=1)})

    def get_import_spec(self, name):

        spec = ImportSpec()

        i = Irradiation()
        i.name = name

        spec.irradiation = i

        i.doses = self._get_doses(name)

        nlevels = []

        dm = self._dm
        sheet = dm.get_sheet(('Irradiations', 0))
        nameidx = dm.get_column_idx(NAME, sheet)
        levelidx = dm.get_column_idx(LEVEL, sheet)
        pridx = dm.get_column_idx(PR, sheet)
        holderidx = dm.get_column_idx(HOLDER, sheet)
        zidx = dm.get_column_idx(Z, sheet)
        noteidx = dm.get_column_idx(NOTE, sheet)

        z = 0
        for row in dm.iterrows(sheet, start=1):
            if row[nameidx].value == name:
                level = Level()
                level.name = row[levelidx].value
                level.z = row[zidx].value or z
                z = level.z + 1
                level.note = row[noteidx].value

                prod = Production()
                prod.name = row[pridx].value
                level.production = prod
                level.holder = row[holderidx].value

                pos = self._get_positions(name, level.name)
                level.positions = pos
                nlevels.append(level)

        i.levels = nlevels
        return spec

    def _get_doses(self, name):
        dm = self._dm
        sheet = dm.get_sheet(('Chronologies', 1))
        doses = []

        nameidx = dm.get_column_idx(NAME, sheet)
        poweridx = dm.get_column_idx(('Power', ), sheet)
        startidx = dm.get_column_idx(('Start', ), sheet)
        endidx = dm.get_column_idx(('End', ), sheet)

        for row in dm.iterrows(sheet, start=1):
            if row[nameidx].value == name:
                p = row[poweridx].value
                s = row[startidx].value
                e = row[endidx].value

                doses.append((p, s, e))

        return doses

    def _get_positions(self, name, level):
        dm = self._dm
        sheet = dm.get_sheet(('Positions', 2))
        nameidx = dm.get_column_idx(NAME, sheet)
        levelidx = dm.get_column_idx(LEVEL, sheet)
        positionidx = dm.get_column_idx(POSITION, sheet)
        sampleidx = dm.get_column_idx(SAMPLE, sheet)
        materialidx = dm.get_column_idx(MATERIAL, sheet)
        projectidx = dm.get_column_idx(PROJECT, sheet)
        piidx = dm.get_column_idx(PI, sheet)
        noteidx = dm.get_column_idx(NOTE, sheet)
        weightidx = dm.get_column_idx(WEIGHT, sheet)

        ps = []
        for row in dm.iterrows(sheet, start=1):
            if row[nameidx].value == name and row[levelidx].value == level:
                pos = Position()

                pos.position = row[positionidx].value

                sample = Sample()
                sample.name = row[sampleidx].value
                sample.material = row[materialidx].value

                project = Project()
                project.name = row[projectidx].value
                project.principal_investigator = row[piidx].value
                sample.project = project
                pos.sample = sample

                pos.note = row[noteidx].value or ''
                pos.weight = row[weightidx].value or 0

                ps.append(pos)
        return ps
コード例 #6
0
    def _dm_factory(self, p):
        dm = XLSDataManager()
        dm.open(p)
        return dm

        # ============= EOF =============================================
        # def get_nlevels(self, irradname):
        # dm =self.dm
        # if not dm:
        # raise AttributeError
        #
        # sheet = self.dm.get_sheet(('Irradiations',0))
        # idx = dm.get_column_idx('Name', sheet=sheet)
        # lidx = dm.get_column_idx('Levels', sheet=sheet)
        # for ri, ni in enumerate(sheet.col(idx)):
        # if ni.value==irradname:
        # level_str = sheet.cell(ri, lidx)
        # ps = parse_level_str(level_str.value)
        # return len(ps) if ps else 0
        # def iterate_irradiations2(self):
        # dm = self.dm
        #         sheet = dm.get_sheet(('Irradiations', 0))
        #
        #         irrads=[]
        #         rows = []
        #         for ri in dm.iterrows(sheet):
        #             # for ji in dm.iterrows(sheet):
        #             if ctype_text[ri[1].ctype]=='empty':
        #                 irrads.append(rows)
        #                 rows=[]
        #             else:
        #                 rows.append(ri)
        #
        #         if rows:
        #             irrads.append(rows)
        #         return irrads
        #
        #

        # def _load_level_from_file(self, p, positions, irradiation, level):
        #         """
        #             use an xls file to enter irradiation positions
        #
        #             looks for sheet named "IrradiationLoading"
        #                 if not present use 0th sheet
        #         """
        #
        #         # dm = XLSDataManager()
        #         # dm.open(p)
        #         dm = self._dm_factory(p)
        #
        #         header_offset = 1
        #         sheet = dm.get_sheet(('IrradiationLoading', 0))
        #         idxs = self._get_idxs(dm, sheet)
        #
        #         if not idxs:
        #             return
        #
        #         rows = [ri for ri in range(sheet.nrows - header_offset)
        #                 if sheet.cell_value(ri + header_offset, idxs['level']) == level]
        #
        #         prog = self.progress
        #         if prog:
        #             prog.max = len(rows) - 1
        #
        #         for ri in rows:
        #             ri += header_offset
        #
        #             project, material = None, None
        #             sample = sheet.cell_value(ri, idxs['sample'])
        #             if sample.lower() == 'monitor':
        #                 sample = self.monitor_name
        #
        #             if sample:
        #                 #is this a sample in the database
        #                 dbsam = self.db.get_sample(sample)
        #                 if dbsam:
        #                     if dbsam.project:
        #                         project = dbsam.project.name
        #                     if dbsam.material:
        #                         material = dbsam.material.name
        #
        #             if project is None:
        #                 project = sheet.cell_value(ri, idxs['project'])
        #             if material is None:
        #                 material = sheet.cell_value(ri, idxs['material'])
        #
        #             pos = sheet.cell_value(ri, idxs['position'])
        #
        #             weight = sheet.cell_value(ri, idxs['weight'])
        #             note = sheet.cell_value(ri, idxs['note'])
        #
        #             if prog:
        #                 prog.change_message('Importing {}'.format(pos))
        #                 prog.increment()
        #
        #             ir_pos, canvas_pos = self._get_position(pos, positions)
        #             if ir_pos:
        #                 ir_pos.trait_set(weight=weight,
        #                                  project=project,
        #                                  material=material,
        #                                  sample=sample,
        #                                  note=note)
        #                 if sample:
        #                     canvas_pos.fill = True
        #             else:
        #                 msg = 'Invalid position for this tray {}'.format(ir_pos)
        #                 #self.warning_dialog()
        #                 self.warning(msg)