Exemplo n.º 1
0
    def load_data(self, ch=None):
        if ch is None: ch = self.ch
        #outmeta = {'ch':ch}
        outmeta = dict(ch=ch, timestamp=self.timestamps[0])
        outmeta['axes'] = lib.alist_to_scale([(self.dz, 'um'),
                                              (self.dx, 'um')])
        var_names = self.img_names
        nchannels = self.nchannels

        if ch is None or ch == 'all':
            ## TODO: use smth like np.concatenate(map(lambda m:\
            ## m.reshape(m.shape+(1,)), (x1,x2,x3)), 3)
            sh = tuple(self.base_shape) + (max(3, nchannels),)
            #print 'Shape', sh, self.base_shape, nchannels
            recs = self._get_recs(var_names)
            stream = lib.clip_and_rescale(np.array([recs[n] for n in var_names]))
            data = np.zeros(sh)
            framecount = 0
            #print 'Shape2:', stream[0].shape
            for k in xrange(0, self.nframes//nchannels,nchannels):
                for j in xrange(nchannels):
                    data[framecount,...,j] = stream[k+j]
                framecount += 1
        else:
            if isinstance(ch,int) :
                var_names = var_names[ch::nchannels]
            elif isinstance(ch,basestring) :
                var_names = [n for n,c in zip(var_names,self.channels) if ch.lower() in c]
            recs = self._get_recs(var_names)
            data = np.array([recs[n] for n in var_names])
        return data, outmeta
Exemplo n.º 2
0
 def load_data(self,ch=None):
     if ch == None: ch = self.ch
     outmeta = dict(ch=ch, timestamp=self.timestamps[0])
     outmeta['axes'] = lib.alist_to_scale([(self.dt,'s'), (self.dx, 'um')])
     nframes, nlines, line_len = self.nframes, self.nlines, self.line_length
     base_shape = (nframes-1, nlines, line_len)
     streams = self._load_streams(ch=ch)
     if len(streams) == 1:
         data = np.zeros(base_shape, dtype=streams[0].dtype)
         for k,f in enumerate(self._reshape_frames(streams[0])):
             data[k] = f
     else:
         #streams = [lib.clip_and_rescale(s) for s in streams]
         reshape_iter = itt.izip(*map(self._reshape_frames, streams))
         sh = base_shape + (max(3, len(streams)),)
         data = np.zeros(sh, dtype=streams[0].dtype)
         for k, a in enumerate(reshape_iter):
             for j, f in enumerate(a):
                 data[k,...,j] = f
     self.data = data
     self.outmeta = outmeta
     return  data, outmeta