コード例 #1
0
 def connect(self):
     self._xmap = MultiXMAP(self.prefix, nmca=self.nmca)
     self._xmap.PV('ElapsedReal', callback=self.onRealTime)
     self._xmap.PV('DeadTime')
     time.sleep(0.001)
     self.mcas = self._xmap.mcas
     self.connected = True
     # self._xmap.SpectraMode()
     self.rois = self._xmap.mcas[0].get_rois()
コード例 #2
0
ファイル: xrf_detectors.py プロジェクト: xraypy/xraylarch
 def connect(self):
     self._xmap = MultiXMAP(self.prefix, nmca=self.nmca)
     self._xmap.PV('ElapsedReal', callback=self.onRealTime)
     self._xmap.PV('DeadTime')
     time.sleep(0.001)
     self.mcas = self._xmap.mcas
     self.connected = True
     # self._xmap.SpectraMode()
     self.rois = self._xmap.mcas[0].get_rois()
コード例 #3
0
ファイル: xrf_detectors.py プロジェクト: xraypy/xraylarch
class Epics_MultiXMAP(object):
    """multi-element MCA detector using XIA xMAP electronics
    and epics dxp 3.x series of software

    mcas    list of MCA objects

    connect()
    set_dwelltime(dtime=0)
    start()
    stop()
    erase()
    add_roi(roiname, lo, hi)
    del_roi(roiname)
    clear_rois()
    save_ascii(filename)
    get_energy(mca=1)
    get_array(mca=1)
    """
    def __init__(self, prefix=None, nmca=4, **kws):
        self.nmca = nmca
        self.prefix = prefix
        self.mcas = []
        self.energies = []
        self.connected = False
        self.elapsed_real = None
        self.elapsed_textwidget = None
        self.needs_refresh = False
        self.frametime = 1.0
        self.nframes = 1
        if self.prefix is not None:
            self.connect()

    # @EpicsFunction
    def connect(self):
        self._xmap = MultiXMAP(self.prefix, nmca=self.nmca)
        self._xmap.PV('ElapsedReal', callback=self.onRealTime)
        self._xmap.PV('DeadTime')
        time.sleep(0.001)
        self.mcas = self._xmap.mcas
        self.connected = True
        # self._xmap.SpectraMode()
        self.rois = self._xmap.mcas[0].get_rois()

    @EpicsFunction
    def connect_displays(self, status=None, elapsed=None, deadtime=None):
        pvs = self._xmap._pvs
        if elapsed is not None:
            self.elapsed_textwidget = elapsed
        for wid, attr in ((status, 'Acquiring'),(deadtime, 'DeadTime')):
            if wid is not None:
                pvs[attr].add_callback(partial(self.update_widget, wid=wid))

    @DelayedEpicsCallback
    def update_widget(self, pvname, char_value=None,  wid=None, **kws):
        if wid is not None:
            wid.SetLabel(char_value)

    @DelayedEpicsCallback
    def onRealTime(self, pvname, value=None, char_value=None, **kws):
        self.elapsed_real = value
        self.needs_refresh = True
        self.frametime = value
        if self.elapsed_textwidget is not None:
            self.elapsed_textwidget.SetLabel(" %8.2f" % value)

    def get_deadtime(self, mca=1):
        """return deadtime info"""
        return self._xmap.get("DeadTime")

    def set_dwelltime(self, dtime=0):
        if dtime <= 0.1:
            self._xmap.PresetMode = 0
        else:
            self._xmap.PresetMode = 1
            self._xmap.PresetReal = dtime

    def start(self):
        return self._xmap.start()

    def stop(self):
        return self._xmap.stop()

    def erase(self):
        self._xmap.put('EraseAll', 1)

    def get_array(self, mca=1):
        out = 1.0*self._xmap.mcas[mca-1].get('VAL')
        out[np.where(out<0.91)]= 0.91
        return out

    def get_energy(self, mca=1):
        return self._xmap.mcas[mca-1].get_energy()

    def get_mca(self, mca=1, with_rois=True):
        """return an MCA object """
        emca = self._xmap.mcas[mca-1]
        if with_rois:
            emca.get_rois()
        counts = self.get_array(mca=mca)
        if max(counts) < 1.0:
            counts    = 0.5*np.ones(len(counts))
            counts[0] = 2.0

        thismca = MCA(counts=counts, offset=emca.CALO, slope=emca.CALS)
        thismca.energy = emca.get_energy()
        thismca.counts = counts
        thismca.real_time = emca.ERTM
        thismca.live_time = emca.ELTM
        thismca.rois = []
        if with_rois:
            for eroi in emca.rois:
                thismca.rois.append(ROI(name=eroi.NM, address=eroi.address,
                                        left=eroi.LO, right=eroi.HI))
        return thismca

    def clear_rois(self):
        for mca in self._xmap.mcas:
            mca.clear_rois()
        self.rois = self._xmap.mcas[0].get_rois()

    @EpicsFunction
    def del_roi(self, roiname):
        for mca in self._xmap.mcas:
            mca.del_roi(roiname)
        self.rois = self._xmap.mcas[0].get_rois()

    def add_roi(self, roiname, lo=-1, hi=-1):
        calib = self._xmap.mcas[0].get_calib()
        for mca in self._xmap.mcas:
            mca.add_roi(roiname, lo=lo, hi=hi, calib=calib)
        self.rois = self._xmap.mcas[0].get_rois()

    @EpicsFunction
    def rename_roi(self, i, newname):
        roi = self._xmap.mcas[0].rois[i]
        roi.NM = newname
        rootname = roi._prefix
        for imca in range(1, len(self._xmap.mcas)):
            pvname = rootname.replace('mca1', 'mca%i'  % (1+imca))
            epics.caput(pvname+'NM', newname)

    def restore_rois(self, roifile):
        self._xmap.restore_rois(roifile)
        self.rois = self._xmap.mcas[0].get_rois()

    def save_rois(self, roifile):
        buff = self._xmap.roi_calib_info()
        with open(roifile, 'w') as fout:
            fout.write("%s\n" % "\n".join(buff))

    def save_mca(self, fname):
        buff = self._xmap

    def save_mcafile(self, filename, environ=None):
        """write MultiChannel MCA file

        Parameters:
        -----------
        * filename: output file name
        """
        nelem = len(self.mcas)
        rois = self._xmap.get_rois()
        mcas = [self.get_mca(mca=i+1, with_rois=False) for i in range(nelem)]


        save_gsemcafile(filename, mcas, rois, environ=environ)
コード例 #4
0
class Epics_MultiXMAP(object):
    """multi-element MCA detector using XIA xMAP electronics
    and epics dxp 3.x series of software

    mcas    list of MCA objects

    connect()
    set_dwelltime(dtime=0)
    start()
    stop()
    erase()
    add_roi(roiname, lo, hi)
    del_roi(roiname)
    clear_rois()
    save_ascii(filename)
    get_energy(mca=1)
    get_array(mca=1)
    """
    def __init__(self, prefix=None, nmca=4, **kws):
        self.nmca = nmca
        self.prefix = prefix
        self.mcas = []
        self.energies = []
        self.connected = False
        self.elapsed_real = None
        self.elapsed_textwidget = None
        self.needs_refresh = False
        if self.prefix is not None:
            self.connect()

    # @EpicsFunction
    def connect(self):
        self._xmap = MultiXMAP(self.prefix, nmca=self.nmca)
        self._xmap.PV('ElapsedReal', callback=self.onRealTime)
        self._xmap.PV('DeadTime')
        time.sleep(0.001)
        self.mcas = self._xmap.mcas
        self.connected = True
        # self._xmap.SpectraMode()
        self.rois = self._xmap.mcas[0].get_rois()

    @EpicsFunction
    def connect_displays(self, status=None, elapsed=None, deadtime=None):
        pvs = self._xmap._pvs
        if elapsed is not None:
            self.elapsed_textwidget = elapsed
        for wid, attr in ((status, 'Acquiring'), (deadtime, 'DeadTime')):
            if wid is not None:
                pvs[attr].add_callback(partial(self.update_widget, wid=wid))

    @DelayedEpicsCallback
    def update_widget(self, pvname, char_value=None, wid=None, **kws):
        if wid is not None:
            wid.SetLabel(char_value)

    @DelayedEpicsCallback
    def onRealTime(self, pvname, value=None, char_value=None, **kws):
        self.elapsed_real = value
        self.needs_refresh = True
        if self.elapsed_textwidget is not None:
            self.elapsed_textwidget.SetLabel(" %8.2f" % value)

    def get_deadtime(self, mca=1):
        """return deadtime info"""
        return self._xmap.get("Deadtime")

    def set_dwelltime(self, dtime=0):
        if dtime <= 0.1:
            self._xmap.PresetMode = 0
        else:
            self._xmap.PresetMode = 1
            self._xmap.PresetReal = dtime

    def start(self):
        return self._xmap.start()

    def stop(self):
        return self._xmap.stop()

    def erase(self):
        self._xmap.put('EraseAll', 1)

    def get_array(self, mca=1):
        out = 1.0 * self._xmap.mcas[mca - 1].get('VAL')
        out[np.where(out < 0.91)] = 0.91
        return out

    def get_energy(self, mca=1):
        return self._xmap.mcas[mca - 1].get_energy()

    def get_mca(self, mca=1, with_rois=True):
        """return an MCA object """
        emca = self._xmap.mcas[mca - 1]
        if with_rois:
            emca.get_rois()
        counts = self.get_array(mca=mca)
        if max(counts) < 1.0:
            counts = 0.5 * np.ones(len(counts))
            counts[0] = 2.0

        thismca = MCA(counts=counts, offset=emca.CALO, slope=emca.CALS)
        thismca.energy = emca.get_energy()
        thismca.counts = counts
        thismca.real_time = emca.ERTM
        thismca.live_time = emca.ELTM
        thismca.rois = []
        if with_rois:
            for eroi in emca.rois:
                thismca.rois.append(
                    ROI(name=eroi.NM,
                        address=eroi.address,
                        left=eroi.LO,
                        right=eroi.HI))
        return thismca

    def clear_rois(self):
        for mca in self._xmap.mcas:
            mca.clear_rois()
        self.rois = self._xmap.mcas[0].get_rois()

    @EpicsFunction
    def del_roi(self, roiname):
        for mca in self._xmap.mcas:
            mca.del_roi(roiname)
        self.rois = self._xmap.mcas[0].get_rois()

    def add_roi(self, roiname, lo=-1, hi=-1):
        calib = self._xmap.mcas[0].get_calib()
        for mca in self._xmap.mcas:
            mca.add_roi(roiname, lo=lo, hi=hi, calib=calib)
        self.rois = self._xmap.mcas[0].get_rois()

    @EpicsFunction
    def rename_roi(self, i, newname):
        roi = self._xmap.mcas[0].rois[i]
        roi.NM = newname
        rootname = roi._prefix
        for imca in range(1, len(self._xmap.mcas)):
            pvname = rootname.replace('mca1', 'mca%i' % (1 + imca))
            epics.caput(pvname + 'NM', newname)

    def restore_rois(self, roifile):
        self._xmap.restore_rois(roifile)
        self.rois = self._xmap.mcas[0].get_rois()

    def save_rois(self, roifile):
        buff = self._xmap.roi_calib_info()
        with open(roifile, 'w') as fout:
            fout.write("%s\n" % "\n".join(buff))

    def save_mca(self, fname):
        buff = self._xmap

    def save_mcafile(self, filename, environ=None):
        """write MultiChannel MCA file

        Parameters:
        -----------
        * filename: output file name
        """
        nelem = len(self.mcas)
        rois = self._xmap.get_rois()
        mcas = [self.get_mca(mca=i + 1, with_rois=False) for i in range(nelem)]

        save_gsemcafile(filename, mcas, rois, environ=environ)