Skip to content

Add example code for removing data from imaging files while retaining headers #517

Description

@tsalo

This seems more useful to me than having 0B files.

@effigies showed me how to do this for NIfTIs (see Python code below) but we should have documentation on how to do it for a range of common imaging filetypes in the CONTRIBUTING file.

import io
import gzip
from pathlib import Path

import nibabel as nb

path = Path('/path/to/example/dset').resolve()
for file in path.rglob('*.nii.gz'):
    img = nb.load(file)
    bio = io.BytesIO()
    img.header.write_to(bio)
    header = bio.getvalue()
    # Write gzipped header for .nii.gz files
    with gzip.open(file, 'wb') as f:
        f.write(header)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions