Пример #1
0
 def doReadArray(self, quality):
     # read data via CARESS and transform it
     res = self._caress_guard(self._readblock)
     if not res:
         return None
     # first 3 values are sizes of dimensions
     # evaluate shape return correctly reshaped numpy array
     if (res[1], res[2]) in [(1, 1), (0, 1), (1, 0), (0, 0)]:  # 1D array
         self.arraydesc = ArrayDesc('data', shape=(res[0], ), dtype='<u4')
         data = numpy.fromiter(res[3:], '<u4', res[0])
         self.readresult = [data.sum()]
         return data
     if res[2] in [0, 1]:  # 2D array
         self.arraydesc = ArrayDesc('data',
                                    shape=(res[0], res[1]),
                                    dtype='<u4')
         data = numpy.fromiter(res[3:], '<u4', res[0] * res[1])
         self.readresult = [data.sum()]
         return data.reshape((res[0], res[1]),
                             order='C' if not self.transpose else 'F')
     # 3D array
     self.arraydesc = ArrayDesc('data',
                                shape=(res[0], res[1], res[2]),
                                dtype='<u4')
     data = numpy.fromiter(res[3:], '<u4', res[0] * res[1] * res[3])
     self.readresult = [data.sum()]
     return data.reshape((res[0], res[1], res[2]), order='C')
Пример #2
0
 def doReadArray(self, quality):
     # read data via taco and transform it
     res = self._taco_guard(self._dev.read)
     # first 3 values are sizes of dimensions
     # evaluate shape return correctly reshaped numpy array
     if (res[1], res[2]) in [(1, 1), (0, 1), (1, 0), (0, 0)]:  # 1D array
         self.arraydesc = ArrayDesc('data', shape=(res[0], ), dtype='<u4')
         data = np.fromiter(res[3:], '<u4', res[0])
         self.readresult = [data.sum()]
     elif res[2] in [0, 1]:  # 2D array
         self.arraydesc = ArrayDesc('data',
                                    shape=(res[0], res[1]),
                                    dtype='<u4')
         data = np.fromiter(res[3:], '<u4', res[0] * res[1])
         self.readresult = [data.sum()]
         data = data.reshape((res[0], res[1]), order='C')
     else:  # 3D array
         self.arraydesc = ArrayDesc('data',
                                    shape=(res[0], res[1], res[2]),
                                    dtype='<u4')
         data = np.fromiter(res[3:], '<u4', res[0] * res[1] * res[3])
         self.readresult = [data.sum()]
         data = data.reshape((res[0], res[1], res[2]), order='C')
     for axis in self.flipaxes:
         data = np.flip(data, axis)
     return data
Пример #3
0
class DLSCard(BaseImageChannel):
    attached_devices = {
        'wheels': Attach('The filter wheel positions', Readable,
                         multiple=True, optional=True),
    }

    parameters = {
        'angles': Param('Scattering angles of the detector',
                        type=tupleof(float, float), mandatory=True,
                        settable=True),
        'mode':   Param('Measure mode', type=oneof(*MODES),
                        default='cross_cross', settable=True),
    }

    def _get_filters(self):
        return ' '.join('%d' % wh.read() for wh in self._attached_wheels)

    def setMode(self):
        self._dev.readoutMode = self.mode

    def readAbscissa(self):
        return self._dev.abscissa

    def readIntensity(self):
        data = self._dev.intensity
        return data.reshape((len(data) // 3, 3))

    abscissa_arraydesc = ArrayDesc('data', shape=(264,), dtype='<f8')
    intensity_arraydesc = ArrayDesc('data', shape=(100, 3), dtype='<f8')
Пример #4
0
 def doReadArray(self, quality):
     arr = np.array(self._taco_guard(self._dev.read))
     ndata = np.reshape(arr[2:], (arr[1], arr[0]))
     self.arraydesc = ArrayDesc(self.name, ndata.shape, np.uint32)
     self.readresult = [ndata[2:self.monitorchannel].sum() +
                        ndata[self.monitorchannel + 1:].sum()]
     return ndata
Пример #5
0
 def __init__(self, name, dtype, dims):
     shape = []
     dimnames = []
     dimunits = []
     dimbins = []
     for dim in dims:
         if not isinstance(dim, HistogramDimDesc):
             raise ConfigurationError('%s should be of type '
                                      'HistogramDimDesc' % dim)
         shape.append(dim.length)
         dimnames.append(dim.label)
         dimunits.append(dim.unit)
         dimbins.append(dim.bins)
     ArrayDesc.__init__(self, name, shape, dtype, dimnames)
     self.dimunits = dimunits
     self.dimbins = dimbins
     self.dimbins = dimbins
Пример #6
0
 def doInit(self, mode):
     # Determine image type
     if mode == SIMULATION:
         iwstr, ihstr = '2000', '1598'
     else:
         try:
             data = self._communicate('GetSize')
             iwstr, ihstr = data.split(';')
         except OSError:
             self.log.warning('Error during init', exc=1)
             iwstr, ihstr = '2000', '1598'
     self._setROParam('imagewidth', int(iwstr))
     self._setROParam('imageheight', int(ihstr))
     shape = (self.imagewidth, self.imageheight)
     self.arraydesc = ArrayDesc('data', shape, np.uint16)
Пример #7
0
    def doReadArray(self, quality):
        if not self._sim_intercept:
            (shape, data) = self._communicate('GetImage')
            mode = self._communicate('GetMode')
        else:
            shape = (self.imagewidth, self.imageheight)
            data = b'0' * self.imagewidth * self.imageheight
        self._setROParam('imagewidth', shape[0])
        self._setROParam('imageheight', shape[1])
        # default for detector 'I:16' mode
        self.arraydesc = ArrayDesc('data', shape, self._modemap[mode])
        na = np.frombuffer(bytearray(data), self._modemap[mode])

        na = np.flipud(na.reshape(shape))
        # as flipud creates a view, we need to copy first
        return np.require(na, None, ['C', 'O'])
Пример #8
0
 def _set_resosteps(self, value):
     # TODO: shape should be (y, x) not (x, y)
     shape = (value * self.numinputs, 256)
     self._step_size = self.range / value
     if not self._arraydesc:
         self._arraydesc = ArrayDesc('data', shape=shape, dtype='<u4')
         self._array_data = np.zeros(shape, dtype='<u4', order='F')
     else:
         self._arraydesc.shape = shape
         self._array_data = np.resize(self._array_data,
                                      shape).astype('<u4', order='F')
         self._array_data.fill(0)
     if self._mode != SIMULATION:
         self._cache.put(self, 'fmtstr', self._fmtstr(value))
     self.log.debug('%r', self._arraydesc)
     self.log.debug('stepsize: %f', self._step_size)
Пример #9
0
    def _set_resosteps(self, value):
        # TODO: shape should be (y, x) not (x, y)
        image = self._attached_detector._attached_images[0]
        if hasattr(image, 'size'):
            height = image.size[1]
        elif hasattr(image, 'sizes'):
            height = image.sizes[1]
        else:
            height = 256
        shape = (value * self.numinputs, height)

        self._step_size = self.range / value
        if not self._arraydesc:
            self._arraydesc = ArrayDesc('data', shape=shape, dtype='<u4')
            self._array_data = np.zeros(shape, dtype='<u4', order='F')
        else:
            self._arraydesc.shape = shape
            self._array_data = np.resize(self._array_data,
                                         shape).astype('<u4', order='F')
            self._array_data.fill(0)
        if self._mode != SIMULATION:
            self._cache.put(self, 'fmtstr', self._fmtstr(value))
        self.log.debug('%r', self._arraydesc)
        self.log.debug('stepsize: %f', self._step_size)
Пример #10
0
 def doInit(self, mode):
     self._clear()
     self.arraydesc = ArrayDesc('data', (1, 16384), np.uint32)
Пример #11
0
 def arraydesc(self):
     return ArrayDesc('data', self._datashape, '<u4')
Пример #12
0
 def doReadArray(self, quality):
     self.arraydesc = ArrayDesc(
         'data', shape=self._shape, dtype='<u4')
     return self._dev.value.reshape(self.arraydesc.shape)
Пример #13
0
 def doInit(self, mode):
     if mode != SIMULATION:
         shape = self._shape
     else:
         shape = (256, 256)  # select some arbitrary shape
     self.arraydesc = ArrayDesc('data', shape=shape, dtype='<u4')
Пример #14
0
 def doInit(self, mode):
     self.arraydesc = ArrayDesc(self.name, self.sizes, '<u4')
Пример #15
0
 def doPreinit(self, mode):
     TacoDevice.doPreinit(self, mode)
     self.arraydesc = ArrayDesc('data', (self.numinputs, self.timechannels),
                                np.uint32)
     self._fix_state(mode)
Пример #16
0
 def get_array_description(cls, num_bins, det_width, det_height):
     return ArrayDesc('data',
                      shape=(det_width, det_height),
                      dtype=np.float64)
Пример #17
0
 def doPrepare(self):
     shape = self._get_pv('size_x'), self._get_pv('size_y')
     data_type = data_type_t[self._get_pv('data_type', as_string=True)]
     self.arraydesc = ArrayDesc('data', shape=shape, dtype=data_type)
Пример #18
0
 def doInit(self, mode):
     # Determine image type
     self.arraydesc = ArrayDesc('data', self._width_height[::-1],
                                self._getImageType())
Пример #19
0
class Image(ImageChannelMixin, PassiveChannel):
    """Channel that returns the image, histogram, or spectrogram."""

    # initial array description, will be updated upon readImage
    arraydesc = ArrayDesc('data', (128, 128), '<u4')

    parameters = {
        'listmodefile':
        Param(
            'List mode data file name (if it is empty, no '
            'file will be written)',
            type=str,
            settable=True,
            default='',
            category='instrument',
        ),
        'histogramfile':
        Param(
            'Histogram data file name (if it is empty, no '
            'file will be written)',
            type=str,
            settable=True,
            default='',
            category='instrument',
        ),
        'configfile':
        Param(
            'Used detector configuration file',
            type=str,
            settable=False,
            volatile=True,
            category='instrument',
        ),
        'calibrationfile':
        Param(
            'Used detector calibration file',
            type=str,
            settable=False,
            volatile=True,
            category='instrument',
        ),
        'listmode':
        Param('Should the Detector write list mode data files',
              type=bool,
              default=False,
              chatty=False,
              prefercache=False,
              settable=True),
        'histogram':
        Param('Should the Detector write histogram data files',
              type=bool,
              default=False,
              chatty=False,
              prefercache=False,
              settable=True),
    }

    def valueInfo(self):
        return Value('%s.sum' % self,
                     type='counter',
                     errors='sqrt',
                     unit='cts',
                     fmtstr='%d'),

    def doReadCalibrationfile(self):
        return NotImplementedError('Implement "doReadCalibrationfile"')

    def doReadConfigfile(self):
        return NotImplementedError('Implement "doReadConfigfile"')
Пример #20
0
 def doInit(self, mode):
     self.arraydesc = ArrayDesc(self.name, self.size, '<u4')
     self._workdir = os.getcwd()
Пример #21
0
 def arrayInfo(self):
     return (ArrayDesc('data', shape=(self.num_bins, ), dtype=np.float64), )