Skip to content

Commit ec94b99

Browse files
committed
Add custom radionuclide half life to weighting functions
1 parent 3d6ce8f commit ec94b99

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

R/kinfitr_miscfuncs.R

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ unit_convert <- function(values,
584584
#' @param t_end The end times of the frames in minutes.
585585
#' @param tac The uncorrected radioactivity values.
586586
#' @param radioisotope The radioisotope.
587+
#' @param radionuclide_halflife The half-life of the radionuclide in minutes. If specified, this overrides the radioisotope parameter. Defaults to NULL.
587588
#'
588589
#' @return The tac before decay correction
589590
#' @export
@@ -599,15 +600,18 @@ unit_convert <- function(values,
599600
#' tac = s1$FC)
600601
#'
601602
#' @author Granville J Matheson, \email{mathesong@@gmail.com}
602-
decay_uncorrect <- function(t_start, t_end, tac, radioisotope = c("C11", "O15", "F18")) {
603+
decay_uncorrect <- function(t_start, t_end, tac, radioisotope = c("C11", "O15", "F18"), radionuclide_halflife = NULL) {
603604

604-
radioisotope <- match.arg(radioisotope, c("C11", "O15", "F18"))
605-
606-
hl <- dplyr::case_when(
607-
radioisotope == "C11" ~ 20.4,
608-
radioisotope == "O15" ~ 2.05,
609-
radioisotope == "F18" ~ 109.8
610-
)
605+
if (!is.null(radionuclide_halflife)) {
606+
hl <- radionuclide_halflife
607+
} else {
608+
radioisotope <- match.arg(radioisotope, c("C11", "O15", "F18"))
609+
hl <- dplyr::case_when(
610+
radioisotope == "C11" ~ 20.4,
611+
radioisotope == "O15" ~ 2.05,
612+
radioisotope == "F18" ~ 109.8
613+
)
614+
}
611615

612616
lambda <- log(2) / hl
613617

@@ -630,6 +634,7 @@ decay_uncorrect <- function(t_start, t_end, tac, radioisotope = c("C11", "O15",
630634
#' @param t_end The end times of the frames in minutes.
631635
#' @param tac_uncor The uncorrected radioactivity values.
632636
#' @param radioisotope The radioisotope.
637+
#' @param radionuclide_halflife The half-life of the radionuclide in minutes. If specified, this overrides the radioisotope parameter. Defaults to NULL.
633638
#'
634639
#' @return The tac after decay correction
635640
#' @export
@@ -646,15 +651,19 @@ decay_uncorrect <- function(t_start, t_end, tac, radioisotope = c("C11", "O15",
646651
#'
647652
#' @author Granville J Matheson, \email{mathesong@@gmail.com}
648653
decay_correct <- function(t_start, t_end, tac_uncor,
649-
radioisotope = c("C11", "O15", "F18")) {
654+
radioisotope = c("C11", "O15", "F18"),
655+
radionuclide_halflife = NULL) {
650656

651-
radioisotope <- match.arg(radioisotope, c("C11", "O15", "F18"))
652-
653-
hl <- dplyr::case_when(
654-
radioisotope == "C11" ~ 20.4,
655-
radioisotope == "O15" ~ 2.05,
656-
radioisotope == "F18" ~ 109.8
657-
)
657+
if (!is.null(radionuclide_halflife)) {
658+
hl <- radionuclide_halflife
659+
} else {
660+
radioisotope <- match.arg(radioisotope, c("C11", "O15", "F18"))
661+
hl <- dplyr::case_when(
662+
radioisotope == "C11" ~ 20.4,
663+
radioisotope == "O15" ~ 2.05,
664+
radioisotope == "F18" ~ 109.8
665+
)
666+
}
658667

659668
lambda <- log(2) / hl
660669

R/kinfitr_weights.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' @param t_end The end times of the frames in minutes.
99
#' @param tac The time activity curve.
1010
#' @param radioisotope The radioisotope.
11+
#' @param radionuclide_halflife The half-life of the radionuclide in minutes. If specified, this overrides the radioisotope parameter. Defaults to NULL.
1112
#' @param method Which method should be used? 1 represents duration /
1213
#' (tac_uncorrected). 2 represents sqrt(durations*tac_uncorrected). 3
1314
#' represents duration / tac. 4 represents sqrt(durations). 5 represents
@@ -53,24 +54,29 @@ weights_create <- function(t_start, t_end, tac,
5354
method = 2,
5455
minweight = 0.5,
5556
minweight_risetopeak = FALSE,
56-
weight_checkn = 5) {
57+
weight_checkn = 5,
58+
radionuclide_halflife = NULL) {
5759

5860
radioisotope <- match.arg(radioisotope, c("C11", "O15", "F18"))
5961

6062
tac <- ifelse(tac < 0, 0, tac)
6163

62-
tac_uncor <- decay_uncorrect(t_start, t_end, tac, radioisotope)
64+
tac_uncor <- decay_uncorrect(t_start, t_end, tac, radioisotope, radionuclide_halflife)
6365
durations <- t_end - t_start
6466
t_tac <- t_start + durations/2
6567

6668
corrections <- tac_uncor / tac
6769
if( is.nan(corrections[1]) ) corrections[1] <- 1
6870

69-
hl <- dplyr::case_when(
70-
radioisotope == "C11" ~ 20.4,
71-
radioisotope == "O15" ~ 2.05,
72-
radioisotope == "F18" ~ 109.8
73-
)
71+
if (!is.null(radionuclide_halflife)) {
72+
hl <- radionuclide_halflife
73+
} else {
74+
hl <- dplyr::case_when(
75+
radioisotope == "C11" ~ 20.4,
76+
radioisotope == "O15" ~ 2.05,
77+
radioisotope == "F18" ~ 109.8
78+
)
79+
}
7480

7581

7682
# pmaxes here to prevent denominators sending weights to infinity

0 commit comments

Comments
 (0)