writeemc.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Dragonfly 作者: duaneloh 项目源码 文件源码
def write_frame(self, frame, fraction=1.):
        """Write given frame to the file
        Using temporary files, the sparsified version of the input is written.

        Arguments:
            frame (int array) - 1D dense array with photon counts in each pixel
            fraction (float, optional) - What fraction of photons to write
        If fraction is less than 1, then each photon is written randomly with
        the probability = fraction. by default, all photons are written. This
        option is useful for performing tests with lower photons/frame.
        """
        if len(frame.shape) != 1 or not np.issubdtype(frame.dtype, np.integer):
            raise ValueError('write_frame needs 1D array of integers: '+str(frame.shape)+' '+str(frame.dtype))

        place_ones = np.where(frame == 1)[0]
        place_multi = np.where(frame > 1)[0]
        count_multi = frame[place_multi]

        if fraction < 1.:
            sel = (np.random.random(len(place_ones)) < fraction)
            place_ones = place_ones[sel]
            sel = (np.random.random(count_multi.sum()) < fraction)
            count_multi = np.array([a.sum() for a in np.split(sel, count_multi.cumsum())])[:-1]
            place_multi = place_multi[count_multi>0]
            count_multi = count_multi[count_multi>0]
        self.num_data += 1
        self.mean_count += len(place_ones) + count_multi.sum()
        self.ones.append(len(place_ones))
        self.multi.append(len(place_multi))

        place_ones.astype(np.int32).tofile(self.f[0])
        place_multi.astype(np.int32).tofile(self.f[1])
        count_multi.astype(np.int32).tofile(self.f[2])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号