示例#1
0
def load_npz(filename):
    """
    Load an .npz Image, this .npz file must have at least two arrays

    * data: the data array
    * dimnames: the dimension names of the corresponding grid
    * affine: the affine transformation of grid

    The remaining arrays of .npz file are stored as the 'extra' attribute of the Image.
    """
    npzobj = np.load(filename)
    
    im = Image(npzobj['data'], CoordinateMap.from_affine(Affine(npzobj['affine']),
                                                        list(npzobj['dimnames']),
                                                        npzobj['data'].shape))
    im.extra = {}
    for f in npzobj.files:
        if f not in ['affine', 'dimnames', 'data']:
            im.extra[f] = npzobj[f]

    return im