mrc.py 文件源码

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

项目:pyem 作者: asarnow 项目源码 文件源码
def append(fname, data):
    with open(fname, 'r+b') as f:
        nx, ny, nz = np.fromfile(f, dtype=np.int32, count=3)  # First 12 bytes of stack.
        f.seek(36)  # First byte of zlen.
        zlen = np.fromfile(f, dtype=np.float32, count=1)
        if data.shape[0] != nx or data.shape[1] != ny:
            raise Exception
        f.seek(0, os.SEEK_END)
        np.require(np.reshape(data, (-1,), order='F'), dtype=np.float32).tofile(f)
        # Update header after new data is written.
        apix = zlen / nz
        nz += data.shape[2]
        zlen += apix * data.shape[2]
        f.seek(8)
        nz.tofile(f)
        f.seek(36)
        zlen.tofile(f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号