knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Our objective is to convert an output spectrum from a Monte Carlo simulation using PENEPMA into a R dataframe for analysis and other processing.

Load a spectrum

First we get our exemplar file.

spcPath <- system.file("extdata", "pe-spect-01.dat", package = "rEDS")
spcPath

Then we create an R dataframe using the penepmaSpcToDF function.

library(rEDS)
library(pander)
library(ggplot2)

df <- penepmaSpcToDF(spcPath)
rownames(df) <- c()

pander(head(df))

and the tail

pander(tail(df))
pander(summary(df))

Now we are ready to plot the spectrum. There is a very large dynamic range for both the probability density and the uncertainty. Penepma sets a lower limit for data at 1.0e-35. Missing values are set to zero. We want to remove values from the dataframe that are below a useful limit. We do this below and plot a copy of the dataframe that is limited to the useful values.

plt <- ggplot(df, aes(x = keV, y = pd)) +
       geom_line() + 
       scale_x_continuous(breaks = seq(from = 0, to = 15, by = 1),
                          limits = c(0,15)) +
       scale_y_log10(limits = c(1.0,1.0e+6)) +
       xlab(label="X-ray energy [keV]") +
       ylab(label="probability density") +
       # (1/(eV*sr*electron)") +
       ggtitle('PENEPMA simulation of Corning EagleXG glass at 15 kV') +
       theme(axis.text=element_text(size=12),
             axis.title=element_text(size=12),
             # center the title
             plot.title = element_text(hjust = 0.5))

print(plt)


jrminter/rEDS documentation built on May 19, 2019, 11:54 p.m.