-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from mandymejia/12.0
12.0
- Loading branch information
Showing
57 changed files
with
846 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
^\.Rproj\.user$ | ||
^README\.Rmd$ | ||
^\.github$ | ||
^appveyor\.yml$ | ||
^vignettes$ | ||
^LICENSE\.md$ | ||
^CRAN-RELEASE$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Version: 0.12.2 | ||
Date: 2023-08-12 20:49:46 UTC | ||
SHA: c99106242136b9f2e9b6c06726df52a3937caac5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#' Apply function over locations in each parcel | ||
#' | ||
#' Apply a function across all locations in each parcel. By default, the mean | ||
#' value in each parcel is calculated. | ||
#' | ||
#' @param xii The \code{"xifti"} data to apply the function over, within each | ||
#' parcel. | ||
#' @param parc The \code{"xifti"} "dlabel" parcellation. Each parcel is defined | ||
#' by a unique key in the label table. If there are multiple columns, only the | ||
#' first column will be used. Alternatively, \code{parc} can just be a vector | ||
#' of keys whose length is the number of data locations in \code{"xii"}. | ||
#' @param FUN A function that takes as input an \eqn{M \times N} matrix (\eqn{M} | ||
#' locations in a given parcel, and \eqn{N} measurements/columns in \code{xii}) | ||
#' and outputs a constant-sized (\eqn{Q}) numeric vector. | ||
#' @param mwall_value If there is a medial wall in \code{xii}, what should value | ||
#' should medial wall locations be replaced with prior to calculation? | ||
#' Default: \code{NA}. | ||
#' @param ... Additional arguments to \code{FUN}. | ||
#' | ||
#' @return A \eqn{P \times Q} matrix, where \eqn{P} is the number of parcels and | ||
#' \eqn{Q} is the length of the output of \code{FUN}. (For \code{mean}, | ||
#' \eqn{Q = 1}). | ||
#' | ||
#' @export | ||
#' | ||
apply_parc <- function(xii, parc, FUN=mean, mwall_value=NA, ...){ | ||
# Arg checks | ||
stopifnot(is.xifti(xii)) | ||
stopifnot(is.xifti(parc)) | ||
|
||
# Replace medial wall and convert `xifti` to matrix. | ||
xii <- move_from_mwall(xii, value=mwall_value) | ||
if (nrow(xii) != nrow(parc)) { | ||
stop( | ||
"`xii` has ", nrow(xii), " locations (including any medial wall), but ", | ||
"`parc` has ", nrow(parc), " locations. They need to have the same resolution." | ||
) | ||
} | ||
xii <- as.matrix(xii) | ||
|
||
# Convert `parc` to vector. | ||
if (ncol(parc) > 1) { ciftiTools_warn("Using the first column of `parc`.") } | ||
parc_names <- rownames(parc$meta$cifti$labels[[1]]) | ||
parc_keys <- parc$meta$cifti$labels[[1]]$Key | ||
parc <- as.matrix(parc)[,1] | ||
|
||
nP <- length(parc_keys) | ||
nV <- nrow(xii) | ||
nT <- ncol(xii) | ||
|
||
# In case the keys are not 1 through nP | ||
parc <- as.numeric(factor(parc, levels=parc_keys)) | ||
|
||
# Compute function for each parcel. | ||
out <- vector("list", nP) | ||
names(out) <- parc_names | ||
for (ii in seq(length(parc_keys))) { | ||
out[ii] <- FUN(xii[parc==ii,], ...) | ||
} | ||
|
||
# Check that the output length is the same for each parcel. | ||
stopifnot(length(unique(lapply(out, dim)))==1) | ||
|
||
# Return. | ||
do.call(rbind, out) | ||
|
||
# [TO DO]: could consider using matrix multiplication, instead, for mean/avg. | ||
# Scrubbing paper should have code for this. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' Evenly sample vertices of mesh | ||
#' | ||
#' Get a subset of the mesh vertices that are spatially evenly-sampled, by | ||
#' resampling the mesh and choosing the original vertices closest (Euclidian | ||
#' distance) to the new vertices. | ||
#' | ||
#' @param surf A \code{"surf"} object | ||
#' @param n_vert The desired number of vertices in the evenly-spaced sample. | ||
#' Note that the actual size of the subset will likely be close to but not | ||
#' exactly \code{n_vert} because it depends on the size of the resampled | ||
#' surface. | ||
#' | ||
#' @return An integer vector giving the indices of the vertices in the subset. | ||
#' | ||
#' @export | ||
even_vert_samp <- function(surf, n_vert) { | ||
stopifnot(is.surf(surf)) | ||
stopifnot(is.numeric(n_vert) && length(n_vert)==1) | ||
stopifnot(n_vert>0 && n_vert==round(n_vert)) | ||
|
||
vert_og <- t(surf$vertices) # 3 x original_res | ||
vert_rs <- t(resample_surf(surf, n_vert)$vertices) # 3 x n_vert | ||
|
||
# The size of the resampled surface is not exactly `n_vert`. | ||
n_vert <- ncol(vert_rs) | ||
|
||
vmask <- rep(NA, n_vert) | ||
for (ii in seq(n_vert)) { | ||
vdist <- colSums((vert_og - vert_rs[,ii])^2) | ||
vmask[ii] <- which.min(vdist) | ||
} | ||
|
||
vmask | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.