knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6
)

Objective: Finding all the XRD peaks can be difficult, if the peaks are not prominent. Let us explore an algorithm, which eliminates areas, where fitting for a peak is not possible, and other areas, where fitting for a peak is straight-forward.

library(rigakuXRD)
library(dplyr)
library(ggplot2)
# Loading the date
filename = xrd.getSampleFiles()[1]
d = xrd.read.ASC(filename)

Plot different ranges, the following plot shows at least 6 peaks that should be found:

d = data.frame(th = d$theta, I = d$I)
plot(d, log='y', col='red')

Region

d %>%
  filter(th>36 & th < 42) %>%
  ggplot(aes(th, I)) + 
  geom_point(col='red') + 
  theme_bw()
  d1 = d %>% filter(th>36 & th<43)
  p = xrd.peakEstimate(d1$th, d1$I, verbose=TRUE)
  fit <- NULL
  try(fit <-
        nls(data = d1,
            I ~ b + A*exp(-(th-t)^2/(2*s*s)),
            start = list(b=p$b0, A = p$A0, 
                         t=p$th0, s=p$s0))
  ); # does not stop in case of error
  summary(fit) 


thomasgredig/rigakuXRD documentation built on Feb. 3, 2024, 10:49 p.m.