Show code
library(OSLdecomposition)
source("../R/plot_MultiExponential.R")
This document collects scripts for developing, bug-fixing and pre-release validating a specific function.
Is the function successfully sourced?
library(OSLdecomposition)
source("../R/plot_MultiExponential.R")
# ToDo: Create a couple of test curves with wild varity of signal shapes
<- list()
cases <-
add_component_case function(cases, lambda, n,
channel_width = 0.1,
channel_number = 400,
noise = 0,
background = 0,
reiterate = FALSE,
title = "Unspecified test case"){
<- data.frame(name = paste("Component", 1:length(n)),
components lambda = lambda,
n = n)
<- simulate_OSLcomponents(components,
curve channel.width = channel_width,
channel.number = channel_number,
simulate.curve = TRUE,
add.poisson.noise = TRUE,
add.gaussian.noise = noise,
add.background = background)
# Re-iterate components to add some uncertainty
if (reiterate) {
<- decompose_OSLcurve(curve,
components
components, verbose = FALSE)
}
<- list(components = components,
case curve = curve,
title = title)
<- c(cases, list(case))
cases return(cases)
}
<- add_component_case(cases,
cases lambda = c(1, 0.2, 0.02),
n = c(1000, 1000, 10000),
reiterate = TRUE,
title = "Typical quartz OSL curve")
<- add_component_case(cases,
cases lambda = c(2, 0.5, 0.2, 0.001),
n = c(200, -500, 2000, 100000),
channel_width = 0.875,
channel_number = 42,
title = "Atypical low-res measurement with stretched medium component")
<- add_component_case(cases,
cases lambda = c(0.02, 0.005, 0.002, 0.0005, 0.00001),
n = c(-10e5, 10e5, 10e6, 10e7, 5e9),
channel_width = 2,
channel_number = 5000,
noise = 2000,
title = "Typical IR-RF curve")
<- add_component_case(cases,
cases lambda = c(0.1, 0.02),
n = c(-10e4, 10e5),
channel_width = 0.2,
channel_number = 200,
title = "Increasing signal")
<- add_component_case(cases,
cases lambda = c(1, 0.01),
n = c(10, 100),
noise = 10,
reiterate = TRUE,
title = "Background-corrected noise")
<- add_component_case(cases,
cases lambda = c(2, 0.03, 0.0001),
n = c(20e5, -10e6, 10e9),
channel_number = 500,
title = "Sharp drop then slowly increasing")
<- add_component_case(cases,
cases lambda = c(0.3),
background = 20,
n = c(3000),
reiterate = TRUE,
title = "Single component with some background")
for (case in cases) {
plot_MultiExponential(case$curve, case$components,
fill.components = TRUE, main = case$title)
}
for (case in cases) {
plot_MultiExponential(case$curve, case$components,
fill.components = FALSE, main = case$title)
}
After Bulur (2000)
for (case in cases) {
cat("CASE:", case$title, "\n")
# Randomizer
<- sample(c(FALSE,TRUE), size = 1)
fill.components cat("fill.components =", fill.components, "\n")
plot_MultiExponential(case$curve, case$components,
fill.components = fill.components,
linear.modulation = TRUE,
main = case$title)
cat("\n\n")
}
CASE: Typical quartz OSL curve
fill.components = TRUE
CASE: Atypical low-res measurement with stretched medium component
fill.components = FALSE
CASE: Typical IR-RF curve
fill.components = TRUE
CASE: Increasing signal
fill.components = FALSE
CASE: Background-corrected noise
fill.components = TRUE
CASE: Sharp drop then slowly increasing
fill.components = FALSE
CASE: Single component with some background
fill.components = FALSE
for (case in cases) {
cat("CASE:", case$title, "\n")
# Randomizer
<- sample(c(FALSE,TRUE), size = 1)
fill.components <- sample(c(FALSE,FALSE,TRUE), size = 1)
linear.modulation <- sample(c(FALSE,TRUE), size = 1)
xlog cat("fill.components =", fill.components, "|",
"linear.modulation =", linear.modulation, "|",
"xlog =", xlog, "\n")
plot_MultiExponential(case$curve, case$components,
fill.components = fill.components,
linear.modulation = linear.modulation,
xlog = xlog,
ylog = TRUE,
main = case$title)
}
CASE: Typical quartz OSL curve
fill.components = TRUE | linear.modulation = FALSE | xlog = TRUE
CASE: Atypical low-res measurement with stretched medium component
fill.components = FALSE | linear.modulation = TRUE | xlog = TRUE
Input data contains signal components with negative intensity (increasing signals). These can not be displayed with logarithmic y-axis and are therefore omitted.
`geom_line()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
CASE: Typical IR-RF curve
fill.components = TRUE | linear.modulation = TRUE | xlog = TRUE
Input data contains signal components with negative intensity (increasing signals). These can not be displayed with logarithmic y-axis and are therefore omitted.
CASE: Increasing signal
fill.components = FALSE | linear.modulation = TRUE | xlog = TRUE
Input data contains signal components with negative intensity (increasing signals). These can not be displayed with logarithmic y-axis and are therefore omitted.
CASE: Background-corrected noise
fill.components = TRUE | linear.modulation = FALSE | xlog = TRUE
Input data contains signal components with negative intensity (increasing signals). These can not be displayed with logarithmic y-axis and are therefore omitted.
Signal curve contains value equal/lower zero. Values below 0.1 will not be displayed.
CASE: Sharp drop then slowly increasing
fill.components = FALSE | linear.modulation = TRUE | xlog = FALSE
Input data contains signal components with negative intensity (increasing signals). These can not be displayed with logarithmic y-axis and are therefore omitted.
CASE: Single component with some background
fill.components = TRUE | linear.modulation = FALSE | xlog = FALSE
# Rescale y-axis, put legend inside plot and add units
<- cases[[5]]
case plot_MultiExponential(case$curve, case$components,
fill.components = FALSE,
xlab = "Stimulation time [sec]",
ylab = "PMT signal [cts]",
font.size = 12,
legend.position = c(1, 1),
legend.justification = c(1, 1),
ylim = c(-20, 50))
Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
3.5.0.
ℹ Please use the `legend.position.inside` argument of `theme()` instead.
# IR-RF example with some individual colors
<- cases[[3]]
case plot_MultiExponential(case$curve, case$components,
main = "Infrared radiofluorescence of abritrary mineral",
xlab = "Accumulated dose [Gy]",
ylab = "IR-RF signal [cts]",
graph.colors = c("black", "red", rev(heat.colors(5))),
xlim = c(0, 3000),
theme.set = ggplot2::theme_bw())
# User-set graph names
<- cases[[1]]
case plot_MultiExponential(case$curve, case$components,
main = "Quartz CW-OSL measurement",
xlab = "Time (s)",
ylab = "Signal (counts)",
graph.colors = c("black", "blue", grey.colors(3)),
graph.names = c("OSL decay", "Component sum", "Res",
"Fast comp.", "Medium comp.", "Slow comp."),
legend.position = "bottom",
font.size = 8,
theme.set = ggplot2::theme_minimal())
# Use common quartz CW-OSL as example
<- cases[[1]]
case
# Define test cases
<- list("Decay rates only" = case$components$lambda,
component_inputs "Named vector as input" = c(Schnell = 1,
Mittel = 0.1,
Langsam = 0.01),
"Only a single decay rate" = 0.3,
"Too many decay rates" = c(2,1,0.5,0.2,0.1,0.05, 0.01))
for (i in 1:length(component_inputs)) {
plot_MultiExponential(case$curve,
component_inputs[[i]],main = names(component_inputs)[i])
}
plot_MultiExponential(components = case$components,
main = "No curve, just component table given")
source("../R/plot_MultiExponential.R")
plot_MultiExponential(curve = case$curve,
main = "No components, just curve given")
Input object 'curve' has more than two columns. Just the first two are used to define time and signal
plot_MultiExponential(curve = cbind(case$curve$time, case$curve$signal),
main = "Just curve as matrix with time and signal column")
ToDo: