def strip_extension(path):
    """Strip classical image extensions (.nii.gz, .nii, .mgz, .npz) from a filename."""
    path = path.replace('.nii.gz', '')
    path = path.replace('.nii', '')
    path = path.replace('.mgz', '')
    path = path.replace('.npz', '')
    return path