예제 #1
0
    def _on_about(self, evt):

        info = wx.adv.AboutDialogInfo()
        info.SetIcon(gui.icon)
        info.Name = gui.name
        info.Version = odemis.__version__
        info.Description = odemis.__fullname__
        info.Copyright = odemis.__copyright__
        info.WebSite = ("http://delmic.com", "delmic.com")
        info.License = odemis.__licensetxt__
        info.Developers = odemis.__authors__
        # info.DocWriters = ['???']
        # info.Artists = ['???']
        # info.Translators = ['???']

        if DyeDatabase:
            info.Developers += [
                "",
                "Dye database from Fluorophores.org http://fluorophores.org"
            ]
            info.License += DYE_LICENCE

        # Show the plugins
        app = wx.GetApp()
        if app.plugins:
            # Add a flag so it appears in big that some plugins are loaded
            info.Description += " (+ plugins)"
            info.Developers += ["", "Plugins:"]
            for p in app.plugins:
                info.Developers += [
                    u"%s by %s under %s license" %
                    (p, p.__author__, p.__license__)
                ]

        try:
            mem_usage = driver.readMemoryUsage() / 2**20  # MiB
            info.Description += "\n(%0.2f MiB memory used)" % mem_usage
        except NotImplementedError:
            pass

        wx.adv.AboutBox(info)
예제 #2
0
    def _on_about(self, evt):

        info = wx.AboutDialogInfo()
        info.SetIcon(gui.icon)
        info.Name = gui.name
        info.Version = odemis.__version__
        info.Description = odemis.__fullname__
        info.Copyright = odemis.__copyright__
        info.WebSite = ("http://delmic.com", "delmic.com")
        info.License = odemis.__licensetxt__
        info.Developers = odemis.__authors__
        # info.DocWriters = ['???']
        # info.Artists = ['???']
        # info.Translators = ['???']

        if DyeDatabase:
            info.Developers += ["", "Dye database from http://fluorophores.org"]
            info.License += DYE_LICENCE

        # Show the plugins
        app = wx.GetApp()
        if app.plugins:
            # Add a flag so it appears in big that some plugins are loaded
            info.Description += " (+ plugins)"
            info.Developers += ["", "Plugins:"]
            for p in app.plugins:
                info.Developers += [u"%s by %s under %s license" %
                                    (p, p.__author__, p.__license__)]

        try:
            mem_usage = driver.readMemoryUsage() / 2 ** 20  # MiB
            info.Description += "\n(%0.2f MiB memory used)" % mem_usage
        except NotImplementedError:
            pass

        wx.AboutBox(info)
예제 #3
0
 def test_memoryUsage(self):
     m = readMemoryUsage()
     self.assertGreater(m, 1)
예제 #4
0
    def _runAcquisition(self, future):

        self._detector.pixelDuration.value = self.pixelDuration.value
        logging.debug("Syncoffset used %s", self.syncOffset.value)
        logging.debug("SyncDiv used %s", self.syncDiv.value)

        # number of drift corrections per pixel
        nDC = self.nDC.value
        # semfov, physwidth = self._get_sem_fov()
        #xyps, stepsize = self._calc_xy_pos()
        xres, yres = self.get_scan_res()
        xyps = self.calc_xy_pos(self.roi.value, self.stepsize.value)
        logging.debug("Will scan on X/Y positions %s", xyps)

        #phys_rect = convert_roi_ratio_to_phys(escan,roi)
        measurement_n = 0
        cordata = []
        sedata = []
        NPOS = len(xyps)  # = xres * yres

        self._save_hw_settings()

        # a list (instead of a tuple) for the summation to work on each element independently
        tot_dc_vect = [0, 0]

        #check whether a drift region is defined
        if self.dcRegion.value != UNDEFINED_ROI:
            drift_est = drift.AnchoredEstimator(self._emitter, self._sed,
                                                self.dcRegion.value,
                                                self.dcDwellTime.value)
            drift_est.acquire()
        else:
            drift_est = None

        try:
            if drift_est:
                self._start_spot(nDC)
                # re-adjust dwell time for number of drift corrections
                self._detector.dwellTime.value = self.dwellTime.value / nDC
                self._emitter.dwellTime.value = self.dwellTime.value / nDC

                for x, y in xyps:
                    sedatapix = []
                    cordatapix = []

                    for ll in range(self.nDC.value):
                        # add total drift vector at this point
                        xc = x - tot_dc_vect[0]
                        yc = y - tot_dc_vect[1]

                        # check if drift correction leads to an x,y position outside of scan region
                        cx, cy = self._emitter.translation.clip((xc, yc))
                        if (cx, cy) != (xc, yc):
                            logging.error(
                                "Drift of %s px caused acquisition region out "
                                "of bounds: needed to scan spot at %s.",
                                tot_dc_vect, (xc, yc))
                        xc, yc = (cx, cy)
                        xm, ym = self._convert_xy_pos_to_m(xc, yc)
                        logging.info(
                            "Acquiring scan number %d at position (%g, %g), with drift correction of %s",
                            ll + 1, xm, ym, tot_dc_vect)
                        startt = time.time()
                        cordat, sedat = self._acquire_correlator(
                            xc, yc, self.dwellTime.value / nDC, future)
                        endt = time.time()
                        logging.debug("Took %g s (expected = %g s)",
                                      endt - startt,
                                      self.dwellTime.value / nDC)
                        cordatapix.append(cordat)
                        sedatapix.append(sedat)
                        logging.debug("Memory used = %d bytes",
                                      udriver.readMemoryUsage())
                        drift_est.acquire()
                        # drift correction vectors
                        dc_vect = drift_est.estimate()
                        tot_dc_vect[0] += dc_vect[0]
                        tot_dc_vect[1] += dc_vect[1]

                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n,
                                 NPOS)

                    # Perform addition of measurements here which keeps other
                    # acquisitions the same and reduces memory required.
                    cordatam = numpy.sum(cordatapix, 0, dtype=numpy.float64)
                    # checks whether datavalue exceeds data-type range.
                    # Note: this works for integers only. For floats there is a separate numpy function
                    idt = numpy.iinfo(cordatapix[0].dtype)
                    # we can choose different things here. For now we just force to clip the signal
                    cordatam = numpy.clip(cordatam, idt.min, idt.max)
                    # convert back to right datatype and (re)add metadata
                    cordatam = model.DataArray(
                        cordatam.astype(cordatapix[0].dtype),
                        cordatapix[0].metadata)
                    cordata.append(cordatam)

                    # For SE data just use mean because absolute scale is not relevant
                    sedatam = numpy.mean(sedatapix).astype(sedatapix[0].dtype)
                    # The brackets are required to give enough dimensions to make the rest happy
                    sedatam = model.DataArray([[[[sedatam]]]],
                                              sedatapix[0].metadata)
                    sedata.append(sedatam)

            else:
                self._start_spot(1)
                for x, y in xyps:
                    self._detector.dwellTime.value = self.dwellTime.value
                    xm, ym = self._convert_xy_pos_to_m(x, y)
                    logging.info("Acquiring at position (%g, %g)", xm, ym)
                    startt = time.time()
                    # dwelltime is used as input for the acquisition because it is different for with drift and without
                    cordat, sedat = self._acquire_correlator(
                        x, y, self.dwellTime.value, future)
                    endt = time.time()
                    logging.debug("Took %g s (expected = %g s)", endt - startt,
                                  self.dwellTime.value)
                    cordata.append(cordat)
                    sedata.append(sedat)
                    logging.debug("Memory used = %d bytes",
                                  udriver.readMemoryUsage())
                    # number of scans that have been done. Could be printed to show progress
                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n,
                                 NPOS)

            self._stop_spot()
            stepsize = (self.stepsize.value, self.stepsize.value)
            cordata[0].metadata[model.MD_POS] = sedata[0].metadata[
                model.MD_POS]
            full_cordata = self._assemble_correlator_data(
                cordata, (xres, yres), self.roi.value, stepsize)
            full_sedata = self._assemble_sed_data(sedata, (xres, yres),
                                                  self.roi.value, stepsize)

            if future._acq_state == CANCELLED:
                raise CancelledError()
            das = [full_cordata, full_sedata]
            if drift_est:
                das.append(self._assembleAnchorData(drift_est.raw))

            return das

        except CancelledError:
            logging.info("Time correlator stream cancelled")
            with future._acq_lock:
                self._acq_state = FINISHED
            raise  # Just don't log the exception
        except Exception:
            logging.exception("Failure during Correlator acquisition")
            raise
        finally:
            logging.debug("TC acquisition finished")
            # Make sure all detectors are stopped
            self._stop_spot()
            self._detector.data.unsubscribe(self._receive_tc_data)
            future._acq_done.set()
            self._resume_hw_settings()
예제 #5
0
    def _runAcquisition(self, future):
        # number of drift corrections per pixel
        nDC = self.nDC.value
        # Initialize spectrograph
        CENTERWL = self.centerWavelength.value
        SLIT_WIDTH = self.slitWidth.value
        # move to appropriate center wavelength
        self._sgr.moveAbs({"wavelength": CENTERWL}).result()
        # set slit width
        self._sgr.moveAbs({"slit-in": SLIT_WIDTH}).result()

        dt = self.dwellTime.value
        self._emitter.dwellTime.value = dt
        #exposure time and dwell time should be the same in this case
        bins = (self.binninghorz.value, self.binningvert.value)
        self._detector.binning.value = bins
        specresx = self._detector.shape[0] // bins[0]
        specresy = self._detector.shape[1] // bins[1]
        self._detector.resolution.value = (specresx, specresy)
        # semfov, physwidth = self._get_sem_fov()
        #xyps, stepsize = self._calc_xy_pos()
        xres, yres = self.get_scan_res()
        xyps = self.calc_xy_pos(self.roi.value, self.stepsize.value)
        logging.debug("Will scan on X/Y positions %s", xyps)

        #phys_rect = convert_roi_ratio_to_phys(escan,roi)
        measurement_n = 0
        ARdata = []
        sedata = []
        NPOS = len(xyps)  # = xres * yres
        self._save_hw_settings()

        # drift correction vectors
        dc_vect = (0, 0)
        # list instead of tuple, to allow changing just one item at a time
        tot_dc_vect = [0, 0]

        if self.dcRegion.value != UNDEFINED_ROI:
            drift_est = drift.AnchoredEstimator(self._emitter, self._sed,
                                                self.dcRegion.value,
                                                self.dcDwellTime.value)
            drift_est.acquire()
        else:
            drift_est = None

        try:
            if drift_est:
                self._start_spot(nDC)
                # re-adjust dwell time for number of drift corrections
                self._detector.exposureTime.value = dt / nDC
                self._emitter.dwellTime.value = dt / nDC

                for x, y in xyps:
                    sedatapix = []
                    sedatam = []
                    ARdatapix = []
                    ARdatam = []

                    for ll in range(self.nDC.value):
                        # add total drift vector at this point
                        xc = x - tot_dc_vect[0]
                        yc = y - tot_dc_vect[1]

                        # check if drift correction leads to an x,y position outside of scan region
                        cx, cy = self._emitter.translation.clip((xc, yc))
                        if (cx, cy) != (xc, yc):
                            logging.error(
                                "Drift of %s px caused acquisition region out "
                                "of bounds: needed to scan spot at %s.",
                                tot_dc_vect, (xc, yc))
                        xc, yc = (cx, cy)
                        xm, ym = self._convert_xy_pos_to_m(xc, yc)
                        logging.info(
                            "Acquiring scan number %d at position (%g, %g), with drift correction of %s",
                            ll + 1, xm, ym, tot_dc_vect)
                        startt = time.time()
                        ARdat, sedat = self._acquire_ARspec(
                            x, y, dt / nDC, future)
                        endt = time.time()
                        logging.debug("Took %g s (expected = %g s)",
                                      endt - startt, dt / nDC)
                        ARdatapix.append(ARdat)
                        sedatapix.append(sedat)
                        logging.debug("Memory used = %d bytes",
                                      udriver.readMemoryUsage())
                        drift_est.acquire()
                        dc_vect = drift_est.estimate()
                        tot_dc_vect[0] += dc_vect[0]
                        tot_dc_vect[1] += dc_vect[1]

                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n,
                                 NPOS)

                    # Perform addition of measurements here which keeps other
                    # acquisitions the same and reduces memory required. We use 32 bits in this case as the data is 16 bits.
                    ARdatam = numpy.sum(ARdatapix, 0, dtype=numpy.float32)
                    # checks whether datavalue exceeds data-type range.
                    # Note: this works for integers only. For floats there is a separate numpy function
                    idt = numpy.iinfo(ARdatapix[0].dtype)
                    # we can choose different things here. For now we just force to clip the signal
                    ARdatam = numpy.clip(ARdatam, idt.min, idt.max)
                    # convert back to right datatype and (re)add metadata
                    ARdatam = model.DataArray(
                        ARdatam.astype(ARdatapix[0].dtype),
                        ARdatapix[0].metadata)
                    ARdata.append(ARdatam)

                    # For SE data just use mean because absolute scale is not relevant
                    sedatam = numpy.mean(sedatapix).astype(sedatapix[0].dtype)
                    # The brackets are required to give enough dimensions to make the rest happy
                    sedatam = model.DataArray([[[[sedatam]]]],
                                              sedatapix[0].metadata)
                    sedata.append(sedatam)

            else:
                self._start_spot(1)
                for x, y in xyps:
                    self._detector.exposureTime.value = dt
                    xm, ym = self._convert_xy_pos_to_m(x, y)
                    logging.info("Acquiring at position (%g, %g)", xm, ym)
                    startt = time.time()
                    # dwelltime is used as input for the acquisition because it is different for with drift and without
                    ARdat, sedat = self._acquire_ARspec(
                        x, y, self.dwellTime.value, future)
                    endt = time.time()
                    logging.debug("Took %g s (expected = %g s)", endt - startt,
                                  self.dwellTime.value)
                    ARdata.append(ARdat)
                    sedata.append(sedat)
                    logging.debug("Memory used = %d bytes",
                                  udriver.readMemoryUsage())
                    # number of scans that have been done. Could be printed to show progress
                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n,
                                 NPOS)

            self._stop_spot()
            stepsize = (self.stepsize.value, self.stepsize.value)
            ARdata[0].metadata[model.MD_POS] = sedata[0].metadata[model.MD_POS]
            full_ARdata = self._assemble_ARspectral_data(
                ARdata, (xres, yres), self.roi.value, stepsize, bins, specresx)
            full_sedata = self._assemble_sed_data(sedata, (xres, yres),
                                                  self.roi.value, stepsize)

            if future._acq_state == CANCELLED:
                raise CancelledError()
            das = [full_ARdata, full_sedata]
            if drift_est:
                das.append(self._assembleAnchorData(drift_est.raw))

            return das

        except CancelledError:
            logging.info("AR spectral stream cancelled")
            self._stop_spot()
            with future._acq_lock:
                self._acq_state = FINISHED
            raise  # Just don't log the exception
        except Exception:
            logging.exception("Failure during AR spectral acquisition")
            raise
        finally:
            logging.debug("AR spectral acquisition finished")
            self._sed.data.unsubscribe(self._receive_sem_data)
            future._acq_done.set()
            self._resume_hw_settings()
예제 #6
0
 def test_memoryUsage(self):
     m = readMemoryUsage()
     self.assertGreater(m, 1)
예제 #7
0
    def _runAcquisition(self, future):

        self._detector.pixelDuration.value = self.pixelDuration.value
        logging.debug("Syncoffset used %s", self.syncOffset.value)
        logging.debug("SyncDiv used %s", self.syncDiv.value)

        # number of drift corrections per pixel
        nDC = self.nDC.value
        # semfov, physwidth = self._get_sem_fov()
        #xyps, stepsize = self._calc_xy_pos()
        xres, yres = self.get_scan_res()
        xyps = self.calc_xy_pos(self.roi.value, self.stepsize.value)
        logging.debug("Will scan on X/Y positions %s", xyps)

        #phys_rect = convert_roi_ratio_to_phys(escan,roi)
        measurement_n = 0
        cordata = []
        sedata = []
        NPOS = len(xyps)  # = xres * yres

        self._save_hw_settings()

        # drift correction vectors
        dc_vect = (0, 0)
        # a list (instead of a tuple) for the summation to work on each element independently
        tot_dc_vect = [0, 0]

        #check whether a drift region is defined
        if self.dcRegion.value != UNDEFINED_ROI:
            drift_est = drift.AnchoredEstimator(self._emitter, self._sed,
                                                self.dcRegion.value,
                                                self.dcDwellTime.value)
            drift_est.acquire()
        else:
            drift_est = None

        try:
            if drift_est:
                self._start_spot(nDC)
                # re-adjust dwell time for number of drift corrections
                self._detector.dwellTime.value = self.dwellTime.value / nDC
                self._emitter.dwellTime.value = self.dwellTime.value / nDC

                for x, y in xyps:
                    sedatapix = []
                    sedatam = []
                    cordatapix = []
                    cordatam = []

                    for ll in range(self.nDC.value):
                        # add total drift vector at this point
                        xc = x - tot_dc_vect[0]
                        yc = y - tot_dc_vect[1]

                        # check if drift correction leads to an x,y position outside of scan region
                        cx, cy = self._emitter.translation.clip((xc, yc))
                        if (cx, cy) != (xc, yc):
                            logging.error("Drift of %s px caused acquisition region out "
                                          "of bounds: needed to scan spot at %s.",
                                          tot_dc_vect, (xc, yc))
                        xc, yc = (cx, cy)
                        xm, ym = self._convert_xy_pos_to_m(xc, yc)
                        logging.info("Acquiring scan number %d at position (%g, %g), with drift correction of %s",
                                     ll + 1, xm, ym, tot_dc_vect)
                        startt = time.time()
                        cordat, sedat = self._acquire_correlator(xc, yc, self.dwellTime.value/nDC, future)
                        endt = time.time()
                        logging.debug("Took %g s (expected = %g s)", endt - startt, self.dwellTime.value/nDC)
                        cordatapix.append(cordat)
                        sedatapix.append(sedat)
                        logging.debug("Memory used = %d bytes", udriver.readMemoryUsage())
                        drift_est.acquire()
                        dc_vect = drift_est.estimate()
                        tot_dc_vect[0] += dc_vect[0]
                        tot_dc_vect[1] += dc_vect[1]

                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n, NPOS)

                    # Perform addition of measurements here which keeps other
                    # acquisitions the same and reduces memory required.
                    cordatam = numpy.sum(cordatapix, 0, dtype=numpy.float64)
                    # checks whether datavalue exceeds data-type range.
                    # Note: this works for integers only. For floats there is a separate numpy function
                    idt = numpy.iinfo(cordatapix[0].dtype)
                    # we can choose different things here. For now we just force to clip the signal
                    cordatam = numpy.clip(cordatam, idt.min, idt.max)
                    # convert back to right datatype and (re)add metadata
                    cordatam = model.DataArray(cordatam.astype(cordatapix[0].dtype), cordatapix[0].metadata)
                    cordata.append(cordatam)

                    # For SE data just use mean because absolute scale is not relevant
                    sedatam = numpy.mean(sedatapix).astype(sedatapix[0].dtype)
                    # The brackets are required to give enough dimensions to make the rest happy
                    sedatam = model.DataArray([[[[sedatam]]]], sedatapix[0].metadata)
                    sedata.append(sedatam)

            else:
                self._start_spot(1)
                for x, y in xyps:
                    self._detector.dwellTime.value = self.dwellTime.value
                    xm, ym = self._convert_xy_pos_to_m(x, y)
                    logging.info("Acquiring at position (%g, %g)", xm, ym)
                    startt = time.time()
                    # dwelltime is used as input for the acquisition because it is different for with drift and without
                    cordat, sedat = self._acquire_correlator(x, y, self.dwellTime.value, future)
                    endt = time.time()
                    logging.debug("Took %g s (expected = %g s)", endt - startt, self.dwellTime.value)
                    cordata.append(cordat)
                    sedata.append(sedat)
                    logging.debug("Memory used = %d bytes", udriver.readMemoryUsage())
                    # number of scans that have been done. Could be printed to show progress
                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n, NPOS)

            self._stop_spot()
            stepsize = (self.stepsize.value, self.stepsize.value)
            cordata[0].metadata[model.MD_POS] = sedata[0].metadata[model.MD_POS]
            full_cordata = self._assemble_correlator_data(cordata, (xres, yres), self.roi.value, stepsize)
            full_sedata = self._assemble_sed_data(sedata, (xres, yres), self.roi.value, stepsize)

            if future._acq_state == CANCELLED:
                raise CancelledError()
            das = [full_cordata, full_sedata]
            if drift_est:
                das.append(self._assembleAnchorData(drift_est.raw))

            return das

        except CancelledError:
            logging.info("Time correlator stream cancelled")
            with future._acq_lock:
                self._acq_state = FINISHED
            raise  # Just don't log the exception
        except Exception:
            logging.exception("Failure during Correlator acquisition")
            raise
        finally:
            logging.debug("TC acquisition finished")
            # Make sure all detectors are stopped
            self._stop_spot()
            self._detector.data.unsubscribe(self._receive_tc_data)
            future._acq_done.set()
            self._resume_hw_settings()
예제 #8
0
    def _runAcquisition(self, future):
        # number of drift corrections per pixel
        nDC = self.nDC.value
        # Initialize spectrograph
        CENTERWL = self.centerWavelength.value
        SLIT_WIDTH = self.slitWidth.value
        # move to appropriate center wavelength
        self._sgr.moveAbs({"wavelength": CENTERWL}).result()
        # set slit width
        self._sgr.moveAbs({"slit-in": SLIT_WIDTH}).result()

        dt = self.dwellTime.value
        self._emitter.dwellTime.value = dt
        #exposure time and dwell time should be the same in this case
        bins = (self.binninghorz.value,self.binningvert.value)
        self._detector.binning.value = bins
        #check if this is correct syntax
        specresx = self._detector.shape[0] // bins[0]
        specresy = self._detector.shape[1] // bins[1]
        self._detector.resolution.value = (specresx,specresy)
        # semfov, physwidth = self._get_sem_fov()
        #xyps, stepsize = self._calc_xy_pos()
        xres, yres = self.get_scan_res()
        xyps = self.calc_xy_pos(self.roi.value, self.stepsize.value)
        logging.debug("Will scan on X/Y positions %s", xyps)

        #phys_rect = convert_roi_ratio_to_phys(escan,roi)
        measurement_n = 0
        ARdata = []
        sedata = []
        NPOS = len(xyps)  # = xres * yres
        self._save_hw_settings()

        # drift correction vectors
        dc_vect = (0, 0)
        # list instead of tuple, to allow changing just one item at a time
        tot_dc_vect = [0, 0]

        if self.dcRegion.value != UNDEFINED_ROI:
            drift_est = drift.AnchoredEstimator(self._emitter, self._sed,
                                                self.dcRegion.value,
                                                self.dcDwellTime.value)
            drift_est.acquire()
        else:
            drift_est = None

        try:
            if drift_est:
                self._start_spot(nDC)
                # re-adjust dwell time for number of drift corrections
                self._detector.exposureTime.value = dt / nDC
                self._emitter.dwellTime.value = dt / nDC

                for x, y in xyps:
                    sedatapix = []
                    sedatam = []
                    ARdatapix = []
                    ARdatam = []

                    for ll in range(self.nDC.value):
                        # add total drift vector at this point
                        xc = x - tot_dc_vect[0]
                        yc = y - tot_dc_vect[1]

                        # check if drift correction leads to an x,y position outside of scan region
                        cx, cy = self._emitter.translation.clip((xc, yc))
                        if (cx, cy) != (xc, yc):
                            logging.error("Drift of %s px caused acquisition region out "
                                          "of bounds: needed to scan spot at %s.",
                                          tot_dc_vect, (xc, yc))
                        xc, yc = (cx, cy)
                        xm, ym = self._convert_xy_pos_to_m(xc, yc)
                        logging.info("Acquiring scan number %d at position (%g, %g), with drift correction of %s",
                                     ll + 1, xm, ym, tot_dc_vect)
                        startt = time.time()
                        ARdat, sedat = self._acquire_ARspec(x, y, dt/nDC, future)
                        endt = time.time()
                        logging.debug("Took %g s (expected = %g s)", endt - startt, dt/nDC)
                        ARdatapix.append(ARdat)
                        sedatapix.append(sedat)
                        logging.debug("Memory used = %d bytes", udriver.readMemoryUsage())
                        drift_est.acquire()
                        dc_vect = drift_est.estimate()
                        tot_dc_vect[0] += dc_vect[0]
                        tot_dc_vect[1] += dc_vect[1]

                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n, NPOS)

                    # Perform addition of measurements here which keeps other
                    # acquisitions the same and reduces memory required. We use 32 bits in this case as the data is 16 bits.
                    ARdatam = numpy.sum(ARdatapix, 0, dtype=numpy.float32)
                    # checks whether datavalue exceeds data-type range.
                    # Note: this works for integers only. For floats there is a separate numpy function
                    idt = numpy.iinfo(ARdatapix[0].dtype)
                    # we can choose different things here. For now we just force to clip the signal
                    ARdatam = numpy.clip(ARdatam, idt.min, idt.max)
                    # convert back to right datatype and (re)add metadata
                    ARdatam = model.DataArray(ARdatam.astype(ARdatapix[0].dtype), ARdatapix[0].metadata)
                    ARdata.append(ARdatam)

                    # For SE data just use mean because absolute scale is not relevant
                    sedatam = numpy.mean(sedatapix).astype(sedatapix[0].dtype)
                    # The brackets are required to give enough dimensions to make the rest happy
                    sedatam = model.DataArray([[[[sedatam]]]], sedatapix[0].metadata)
                    sedata.append(sedatam)

            else:
                self._start_spot(1)
                for x, y in xyps:
                    self._detector.exposureTime.value = dt
                    xm, ym = self._convert_xy_pos_to_m(x, y)
                    logging.info("Acquiring at position (%g, %g)", xm, ym)
                    startt = time.time()
                    # dwelltime is used as input for the acquisition because it is different for with drift and without
                    ARdat, sedat = self._acquire_ARspec(x, y, self.dwellTime.value, future)
                    endt = time.time()
                    logging.debug("Took %g s (expected = %g s)", endt - startt, self.dwellTime.value)
                    ARdata.append(ARdat)
                    sedata.append(sedat)
                    logging.debug("Memory used = %d bytes", udriver.readMemoryUsage())
                    # number of scans that have been done. Could be printed to show progress
                    measurement_n += 1
                    # TODO: update the future progress
                    logging.info("Acquired %d out of %d pixels", measurement_n, NPOS)

            self._stop_spot()
            stepsize = (self.stepsize.value, self.stepsize.value)
            ARdata[0].metadata[model.MD_POS] = sedata[0].metadata[model.MD_POS]
            full_ARdata = self._assemble_ARspectral_data(ARdata,(xres,yres),self.roi.value,stepsize,bins,specresx)
            full_sedata = self._assemble_sed_data(sedata,(xres,yres),self.roi.value,stepsize)

            if future._acq_state == CANCELLED:
                raise CancelledError()
            das = [full_ARdata, full_sedata]
            if drift_est:
                das.append(self._assembleAnchorData(drift_est.raw))

            return das

        except CancelledError:
            logging.info("AR spectral stream cancelled")
            self._stop_spot()
            with future._acq_lock:
                self._acq_state = FINISHED
            raise  # Just don't log the exception
        except Exception:
            logging.exception("Failure during AR spectral acquisition")
            raise
        finally:
            logging.debug("AR spectral acquisition finished")
            self._sed.data.unsubscribe(self._discard_data)
            future._acq_done.set()
            self._resume_hw_settings()