Last active
August 29, 2015 14:01
-
-
Save benmarwick/c38a8d4fdef766f19eee to your computer and use it in GitHub Desktop.
Get elemental data from the Bruker AXS Tracer handheld pXRF
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
130125-brickn679-500sec-5 | Energy1 | Energy2 | Chan-Start | Chan-End | Chan-Counts | Compton | |
---|---|---|---|---|---|---|---|
CaKa1 | 3.6043 | 3.779 | 180.2158 | 188.9522 | 1208.35 | 10.102452 | |
ScKa1 | 4.001 | 4.1802 | 200.0508 | 209.0092 | 856.45 | 7.1603729 | |
TiKa1 | 4.419 | 4.6027 | 220.9488 | 230.1352 | 1683.66 | 14.076247 | |
V Ka1 | 4.858 | 5.0464 | 242.9 | 252.32 | 671.9 | 5.6174401 | |
CrKa1 | 5.3181 | 5.5113 | 265.9066 | 275.5654 | 477.09 | 3.9887208 | |
MnKa1 | 5.7997 | 5.9978 | 289.9863 | 299.8887 | 1657.74 | 13.859547 | |
FeKa1 | 6.3023 | 6.5053 | 315.1168 | 325.2672 | 99098.04 | 828.50964 | |
CoKa1 | 6.8263 | 7.0343 | 341.3147 | 351.7173 | 8706.4 | 72.789874 | |
NiKa1 | 7.3716 | 7.5847 | 368.5782 | 379.2368 | 892.66 | 7.4630925 | |
CuKa1 | 7.9386 | 8.157 | 396.9297 | 407.8483 | 380.19 | 3.1786068 | |
ZnKa1 | 8.527 | 8.7507 | 426.352 | 437.534 | 691.96 | 5.785131 | |
AsKa1 | 10.4238 | 10.6636 | 521.1904 | 533.1816 | 319.36 | 2.6700286 | |
SeKa1 | 11.0997 | 11.3451 | 554.9866 | 567.2534 | 151.37 | 1.2655638 | |
PbLb1 | 12.4856 | 12.7418 | 624.2785 | 637.0915 | 305.48 | 2.5539278 | |
KrKa1 | 12.5207 | 12.7773 | 626.0367 | 638.8633 | 318.94 | 2.6665053 | |
RbKa1 | 13.2642 | 13.5264 | 663.2101 | 676.3199 | 3921.79 | 32.788149 | |
SrKa1 | 14.031 | 14.299 | 701.5521 | 714.9479 | 1902.77 | 15.908154 | |
Y Ka1 | 14.8216 | 15.0952 | 741.0779 | 754.7621 | 1837.01 | 15.358314 | |
ZrKa1 | 15.6354 | 15.9148 | 781.7675 | 795.7425 | 5213.02 | 43.583471 | |
NbKa1 | 16.4724 | 16.7578 | 823.6211 | 837.8889 | 1027.51 | 8.5905203 | |
MoKa1 | 17.3337 | 17.625 | 866.6855 | 881.2485 | 1367.43 | 11.432433 | |
TcKa1 | 18.2185 | 18.5157 | 910.925 | 925.785 | 1503.33 | 12.56857 | |
RuKa1 | 19.1276 | 19.4308 | 956.3804 | 971.5396 | 4204.37 | 35.150649 | |
RhKa1 | 20.0615 | 20.3707 | 1003.0748 | 1018.5352 | 5049.78 | 42.218711 | |
PdKa1 | 21.0195 | 21.3347 | 1050.9733 | 1066.7367 | 4723.53 | 39.491055 | |
CdKa1 | 23.0098 | 23.3374 | 1150.4924 | 1166.8676 | 5445.21 | 45.524666 | |
SnKa1 | 25.1014 | 25.4412 | 1255.068 | 1272.062 | 8917.46 | 74.554458 | |
SbKa1 | 26.186 | 26.5322 | 1309.3018 | 1326.6082 | 9592.72 | 80.199988 | |
BaKa1 | 32.0047 | 32.3825 | 1600.2334 | 1619.1266 | 11831.31 | 98.91574 | |
LaKa1 | 33.2496 | 33.634 | 1662.4821 | 1681.6979 | 9113.12 | 76.190283 | |
CMPT | 1.13 | 1.86 | 56.5 | 93 | 119.61 |
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
#' Get elemental data from the Bruker AXS Tracer handheld pXRF | |
#' | |
#' This function starts with directory of csv files (or a directory | |
#' of directories) that are the raw output from the | |
#' pXRF and returns a list of two dataframes, one with | |
#' just the counts per channel for each | |
#' run, and one with counts and all the diagnostic details. | |
#' | |
#' @param mydir the full path of the directory containing the | |
#' csv files | |
#' | |
#' @example mydata <- get_pXRF_data("C:/Users/marwick/UW-Dropbox/Dropbox/MKII_pXRF_data_SP14/MKII-SW-sec-S-pxrf/140527 Beads") | |
#' | |
get_pXRF_data <- function(mydir){ | |
# require(data.table) | |
myfiles <- list.files(mydir, pattern = '.csv', full.names = TRUE, recursive = TRUE) | |
# data <- lapply(myfiles, fread) | |
data <- lapply(myfiles, read.csv) | |
# make a data frame where each column is one analysis and the colname is the filename | |
# create empty dataframe to hold the data | |
# df <- data.table(matrix(nrow=length(data), ncol = nrow(data[[1]]))) | |
df <- data.frame(matrix(nrow=length(data), ncol = nrow(data[[1]]))) | |
# loop through each CSV file and get the counts and put | |
# them into a column of a single data frame | |
# for (i in 1:length(myfiles)) { | |
# df[i, ] <- as.numeric(as.character((data[[i]][[2]]))) | |
# print(i) # this loop is very slow with data.table! | |
# } | |
for (i in 1:length(myfiles)) { | |
df[i,] <- data[[i]]$Bruker.AXS.Handheld.Inc..S1PXRF.Spectrum | |
print(i) # it's nice to see the progress... | |
} | |
# put the CSV file names as the column names in the new dataframe | |
colnames(df) <- rownames(data[[1]]) | |
# and as first row to use later | |
df$filename <- myfiles | |
# from line 21 - 2068 are the channels, separate them out | |
channels <- df[,c((which(names(df) %in% 0):ncol(df)))] | |
rownames(channels) <- df$filename | |
return(list(channels, df)) | |
} | |
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
isolate_channels <- function(){ | |
# isolate and name channels by element | |
channel_ranges <- read.csv("https://gist.githubusercontent.com/benmarwick/c38a8d4fdef766f19eee/raw/a3ad7be4892bccdb13f26aabf8e55aa3565583b1/channels.csv") | |
# extract channels to ID elements | |
channelRangesStartEnd <- channel_ranges[,c(1,4:5)] | |
# round to whole numbers | |
channelRangesStartEnd$Chan.Start <- round(channelRangesStartEnd$Chan.Start) | |
channelRangesStartEnd$Chan.End <- round(channelRangesStartEnd$Chan.End) | |
return(channelRangesStartEnd) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment