writeNiftiArray: Write NiftiArray Object

Description Usage Arguments Value Examples

View source: R/writeNiftiArray.R

Description

A function for writing NIfTI objects on disk to a specifically formatted HDF5 file. The HDF5 file will include a group for the NIfTI image or array and the NIfTI header.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
writeNiftiArray(
  x,
  filepath = tempfile(fileext = ".h5"),
  name = "image",
  header_name = "hdr",
  chunkdim = NULL,
  level = NULL,
  verbose = FALSE,
  header = NULL,
  overwrite = FALSE,
  extendible = FALSE
)

Arguments

x

A niftiImage object loaded into R or a file path to a NIfTI file.

filepath

The file path (single character string) of where to save the HDF5 file converted from the NIfTI input as x. By default creates a temporary file on disk.

name

The name of the group for the NIfTI image in the HDF5 file. Default is set to "image". Unless you have to other "image" groups in the HDF5 file there is no need to change default settings.

header_name

The name of the group for the NIfTI header in the HDF5 file. Default is set to "header". Unless you have to other "header" groups in the HDF5 file there is no need to change default settings.

chunkdim

The dimensions of the chunks to use for writing the data to disk. Passed to HDF5Array::writeHDF5Array.

level

The compression level, passed to HDF5Array::writeHDF5Array.

verbose

Display progress, passed to HDF5Array::writeHDF5Array.

header

List of header information; overrides call of nifti_header.

overwrite

FALSE by default. In the event that an HDF5 file already exists for filepath input then do not overwrite it. If set to TRUE then the name and header_name group objects in the HDF5 file location will overwrite.

extendible

Should a single empty dimension be added to the array? Currently necessary for easy reshaping.

Value

A NiftiArray object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
nii_fname = system.file("extdata", "example.nii.gz", package = "RNifti")
res = writeNiftiArray(nii_fname)
filepath = tempfile(fileext = ".h5")
res = writeNiftiArray(nii_fname, filepath = filepath)
testthat::expect_error(
   writeNiftiArray(nii_fname, filepath = filepath),
   regexp = "already exist",
)
res = writeNiftiArray(nii_fname, filepath = filepath, overwrite = TRUE)
img = RNifti::readNifti(nii_fname)
writeNiftiArray(c(img), header = nifti_header(img))

neuroconductor/NiftiArray documentation built on May 23, 2021, 8:40 a.m.