write.fs.morph.cifti: Write morphometry data to a CIFTI-2 '.dscalar' file.

View source: R/write_cifti_fs.R

write.fs.morph.ciftiR Documentation

Write morphometry data to a CIFTI-2 .dscalar file.

Description

Write a per-vertex data vector (or several of them, as the maps of the file) to a CIFTI-2 dense scalar file. This is the inverse of read.fs.morph.cifti: the data are given for the complete surface, and the vertices that the file contains are selected with the mapping of a template file (which is what a grayordinates file needs, since it leaves out the medial wall).

Usage

write.fs.morph.cifti(
  filepath,
  data,
  template = NULL,
  structure = NULL,
  map_names = NULL,
  metadata = NULL
)

Arguments

filepath

character string, the path of the file to write. The name should end with .dscalar.nii.

data

numeric vector or matrix or named list, the per-vertex data:

  • a vector: one value per vertex of the complete surface of one structure,

  • a matrix: one row per vertex of the complete surface, one column per map,

  • a named list (e.g. list(lh = ..., rh = ...)): a vector or matrix as above per structure.

The vertex order is the order of the surface mesh, which is also the order in which read.fs.morph.cifti returns the data.

template

character string (the path of a CIFTI-2 file), an fs.cifti or an fs.cifti.data object, or NULL. The grayordinate mapping of this file is used, so pass the file the data comes from (e.g. an HCP file of the same subject): the mapping of such a file cannot be invented. Without a template, the file covers all vertices of the surfaces, and structure has to be given.

structure

character string or NULL, the brain structure the data belongs to (e.g. 'lh'), needed if data is not a named list and there is no template to take the structures from.

map_names

character vector or NULL, the names of the maps. The number of names has to match the number of maps in the data. Without this, the map names of the template file are kept if it has as many maps as the data.

metadata

named character vector or NULL, the matrix metadata, see write.cifti. The default keeps the metadata of the template file.

Value

the axes that were written, invisibly.

See Also

Other cifti functions: cifti.axis.brain.models(), cifti.axis.from.template(), cifti.axis.labels(), cifti.axis.parcels(), cifti.axis.parcels.from.annot(), cifti.axis.scalars(), cifti.axis.series(), cifti.brain.model.surface(), cifti.brain.model.volume(), cifti.dim.labels(), cifti.file.type.for.axes(), cifti.grayordinates(), cifti.header.from.axes(), cifti.label.table(), cifti.parcel(), cifti.parcels(), cifti.series.info(), cifti.structure.data(), cifti.structures(), cifti.volume(), print.fs.cifti(), print.fs.cifti.data(), print.fs.connectome(), read.cifti(), read.cifti.header(), read.cifti.rows(), read.fs.connectome.cifti(), write.cifti(), write.fs.connectome.cifti(), write.fs.parcellated.cifti(), write.fs.parcellation.cifti(), write.fs.series.cifti()

Examples

template <- system.file("extdata", "cifti", "tiny.dscalar.nii", package = "freesurferformats")
out_file <- file.path(tempdir(), "written.dscalar.nii")
data <- read.fs.morph.cifti(template, "lh")
data[2] <- 555 # change one value
write.fs.morph.cifti(out_file, data, template = template, structure = "lh")
read.fs.morph.cifti(out_file, "lh")[1:3]



freesurferformats documentation built on Sept. 25, 2026, 1:07 a.m.