Title: | Reads in 'Neuroimaging' 'GIFTI' Files with Geometry Information |
---|---|
Description: | Functions to read in the geometry format under the 'Neuroimaging' 'Informatics' Technology Initiative ('NIfTI'), called 'GIFTI' <https://www.nitrc.org/projects/gifti/>. These files contain surfaces of brain imaging data. |
Authors: | John Muschelli |
Maintainer: | John Muschelli <[email protected]> |
License: | GPL-2 |
Version: | 0.8.2 |
Built: | 2024-10-29 05:33:32 UTC |
Source: | https://github.com/muschellij2/gifti |
Converts a data type to the size and what
for
readBin
, necessary for Base64Binary
and
GZipBase64Binary
formats
convert_binary_datatype( datatype = c("NIFTI_TYPE_UINT8", "NIFTI_TYPE_INT32", "NIFTI_TYPE_UINT32", "NIFTI_TYPE_FLOAT32") )
convert_binary_datatype( datatype = c("NIFTI_TYPE_UINT8", "NIFTI_TYPE_INT32", "NIFTI_TYPE_UINT32", "NIFTI_TYPE_FLOAT32") )
datatype |
data type from GIFTI image |
List of length 2: with elements of size and what
convert_binary_datatype() convert_binary_datatype('NIFTI_TYPE_INT32') testthat::expect_error(convert_binary_datatype('NIFTI_TYPE_BLAH'))
convert_binary_datatype() convert_binary_datatype('NIFTI_TYPE_INT32') testthat::expect_error(convert_binary_datatype('NIFTI_TYPE_BLAH'))
Converts Endian format from GIFTI
convert_endian(endian)
convert_endian(endian)
endian |
character passed from GIFTI XML |
Character string
Converts the intent
field from a GIFTI image
to a more standard naming
convert_intent(intent)
convert_intent(intent)
intent |
(character) string of intent type |
A character string
Create Data Matrix with ordering respected
create_data_matrix( data, dims, ordering = c("RowMajorOrder", "ColumnMajorOrder") )
create_data_matrix( data, dims, ordering = c("RowMajorOrder", "ColumnMajorOrder") )
data |
Data output from |
dims |
Dimensions of output |
ordering |
Ordering of the data |
Matrix of Values
Parses a list of XML data to get the attributes
data_array_attributes(darray)
data_array_attributes(darray)
darray |
List of |
data.frame
of attributes
Decodes values from a GIFTI image
data_decoder( values, encoding = c("ASCII", "Base64Binary", "GZipBase64Binary", "ExternalFileBinary"), datatype = NULL, endian = c("little", "big", "LittleEndian", "BigEndian"), ext_filename = NULL, n = NULL )
data_decoder( values, encoding = c("ASCII", "Base64Binary", "GZipBase64Binary", "ExternalFileBinary"), datatype = NULL, endian = c("little", "big", "LittleEndian", "BigEndian"), ext_filename = NULL, n = NULL )
values |
text from XML of GIFTI image |
encoding |
encoding of GIFTI values |
datatype |
Passed to |
endian |
Endian to pass in |
ext_filename |
if |
n |
number of values to read. Relevant if
|
Vector of values
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) L = gifti_list(gii_files[1]) orig = L$DataArray$Data[[1]] encoding = attributes(L$DataArray)$Encoding datatype = attributes(L$DataArray)$DataType endian = attributes(L$DataArray)$Endian vals = data_decoder(orig, encoding = encoding, datatype = datatype, endian = endian) enc = data_encoder(vals, encoding = encoding, datatype = datatype, endian = endian) enc == orig }
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) L = gifti_list(gii_files[1]) orig = L$DataArray$Data[[1]] encoding = attributes(L$DataArray)$Encoding datatype = attributes(L$DataArray)$DataType endian = attributes(L$DataArray)$Endian vals = data_decoder(orig, encoding = encoding, datatype = datatype, endian = endian) enc = data_encoder(vals, encoding = encoding, datatype = datatype, endian = endian) enc == orig }
Encodes values for a GIFTI image
data_encoder( values, encoding = c("ASCII", "Base64Binary", "GZipBase64Binary"), datatype = NULL, endian = c("little", "big", "LittleEndian", "BigEndian") )
data_encoder( values, encoding = c("ASCII", "Base64Binary", "GZipBase64Binary"), datatype = NULL, endian = c("little", "big", "LittleEndian", "BigEndian") )
values |
values to be encoded |
encoding |
encoding of GIFTI values |
datatype |
Passed to |
endian |
Endian to pass in |
Single character vector
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) L = gifti_list(gii_files[1]) orig = L$DataArray$Data[[1]] encoding = attributes(L$DataArray)$Encoding datatype = attributes(L$DataArray)$DataType endian = attributes(L$DataArray)$Endian vals = data_decoder(orig, encoding = encoding, datatype = datatype, endian = endian) enc = data_encoder(vals, encoding = encoding, datatype = datatype, endian = endian) enc == orig }
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) L = gifti_list(gii_files[1]) orig = L$DataArray$Data[[1]] encoding = attributes(L$DataArray)$Encoding datatype = attributes(L$DataArray)$DataType endian = attributes(L$DataArray)$Endian vals = data_decoder(orig, encoding = encoding, datatype = datatype, endian = endian) enc = data_encoder(vals, encoding = encoding, datatype = datatype, endian = endian) enc == orig }
If a GIFTI file is compressed, as in .gii.gz, this will decompress the file. This has nothing to do with the encoding WITHIN the file
decompress_gii(file)
decompress_gii(file)
file |
file name of GIFTI file |
Filename of decompressed GIFTI
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) outfile = decompress_gii(gii_files[1]) print(outfile) }
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) outfile = decompress_gii(gii_files[1]) print(outfile) }
Downloads GIFTI test data from https://www.nitrc.org/frs/download.php/411/BV_GIFTI_1.3.tar.gz
download_gifti_data( outdir = system.file(package = "gifti"), overwrite = FALSE, ... )
download_gifti_data( outdir = system.file(package = "gifti"), overwrite = FALSE, ... )
outdir |
Output directory for test file directory |
overwrite |
Should files be overwritten if already exist? |
... |
additional arguments to |
Vector of file names
Reads in a GIFTI file and coerces it to a list
gifti_list(file)
gifti_list(file)
file |
file name of GIFTI file |
List of elements
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) L = gifti_list(gii_files[1]) orig = L$DataArray$Data[[1]] encoding = attributes(L$DataArray)$Encoding datatype = attributes(L$DataArray)$DataType endian = attributes(L$DataArray)$Endian vals = data_decoder(orig, encoding = encoding, datatype = datatype, endian = endian) enc = data_encoder(vals, encoding = encoding, datatype = datatype, endian = endian) enc == orig }
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) L = gifti_list(gii_files[1]) orig = L$DataArray$Data[[1]] encoding = attributes(L$DataArray)$Encoding datatype = attributes(L$DataArray)$DataType endian = attributes(L$DataArray)$Endian vals = data_decoder(orig, encoding = encoding, datatype = datatype, endian = endian) enc = data_encoder(vals, encoding = encoding, datatype = datatype, endian = endian) enc == orig }
Takes values and maps them to the correct triangles in space.
gifti_map_value( pointset, triangle, values, indices = seq(nrow(pointset)), add_one = TRUE )
gifti_map_value( pointset, triangle, values, indices = seq(nrow(pointset)), add_one = TRUE )
pointset |
pointset from GIFTI |
triangle |
triangles from GIFTI |
values |
Values to map to the triangles. Same length as indices |
indices |
indices to place the values, must be in the range of 1 and
the number of rows of |
add_one |
Should |
A list of coordinates (in triangles) and the corresponding value mapped to those triangles
Checks if GIFTI test data is downloaded
have_gifti_test_data(outdir = system.file(package = "gifti"))
have_gifti_test_data(outdir = system.file(package = "gifti"))
outdir |
Output directory for test file directory |
Logical indicator
have_gifti_test_data(outdir = NULL)
have_gifti_test_data(outdir = NULL)
Simple wrapper to determine if class is GIFTI
is.gifti(x) is_gifti(x)
is.gifti(x) is_gifti(x)
x |
object to test |
Logical if x
is GIFTI
Reads a GIFTI File and parses the output
readgii(file) readGIfTI(file) read_gifti(file)
readgii(file) readGIfTI(file) read_gifti(file)
file |
Name of file to read |
List of values
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) gii_list = lapply(gii_files, readgii) surf_files = grep("white[.]surf[.]gii", gii_files, value = TRUE) surfs = lapply(surf_files, surf_triangles) col_file = grep("white[.]shape[.]gii", gii_files, value = TRUE) cdata = readgii(col_file) cdata = cdata$data$shape mypal = grDevices::colorRampPalette(colors = c("blue", "black", "red")) n = 4 breaks = quantile(cdata) ints = cut(cdata, include.lowest = TRUE, breaks = breaks) ints = as.integer(ints) stopifnot(!any(is.na(ints))) cols = mypal(n)[ints] cols = cols[surfs[[1]]$triangle] } ## Not run: if (have_gifti_test_data(outdir = NULL)) { if (requireNamespace("rgl", quietly = TRUE)) { rgl::rgl.open() rgl::rgl.triangles(surfs[[1]]$pointset, color = cols) rgl::play3d(rgl::spin3d(), duration = 5) } } ## End(Not run)
if (have_gifti_test_data(outdir = NULL)) { gii_files = download_gifti_data(outdir = NULL) gii_list = lapply(gii_files, readgii) surf_files = grep("white[.]surf[.]gii", gii_files, value = TRUE) surfs = lapply(surf_files, surf_triangles) col_file = grep("white[.]shape[.]gii", gii_files, value = TRUE) cdata = readgii(col_file) cdata = cdata$data$shape mypal = grDevices::colorRampPalette(colors = c("blue", "black", "red")) n = 4 breaks = quantile(cdata) ints = cut(cdata, include.lowest = TRUE, breaks = breaks) ints = as.integer(ints) stopifnot(!any(is.na(ints))) cols = mypal(n)[ints] cols = cols[surfs[[1]]$triangle] } ## Not run: if (have_gifti_test_data(outdir = NULL)) { if (requireNamespace("rgl", quietly = TRUE)) { rgl::rgl.open() rgl::rgl.triangles(surfs[[1]]$pointset, color = cols) rgl::play3d(rgl::spin3d(), duration = 5) } } ## End(Not run)
Creates Triangles for plotting in RGL from a GIfTI image
surf_triangles(file)
surf_triangles(file)
file |
File name of GIfTI image, usually |
List of values corresponding to the data
element from
readgii
Writes a "gifti" object to a GIFTI file (ends in *.gii).
writegii(gii, out_file, use_parsed_transformations = FALSE) writeGIfTI(gii, out_file, use_parsed_transformations = FALSE) write_gifti(gii, out_file, use_parsed_transformations = FALSE)
writegii(gii, out_file, use_parsed_transformations = FALSE) writeGIfTI(gii, out_file, use_parsed_transformations = FALSE) write_gifti(gii, out_file, use_parsed_transformations = FALSE)
gii |
The "gifti" object |
out_file |
Where to write the new GIFTI file |
use_parsed_transformations |
Should the |