bsa0.2 = structure(list(x = c(240, 240.5, 241, 241.5, 242, 242.5, 243,
243.5, 244, 244.5, 245, 245.5, 246, 246.5, 247, 247.5, 248, 248.5,
249, 249.5, 250, 250.5, 251, 251.5, 252, 252.5, 253, 253.5, 254,
254.5, 255, 255.5, 256, 256.5, 257, 257.5, 258, 258.5, 259, 259.5,
260, 260.5, 261, 261.5, 262, 262.5, 263, 263.5, 264, 264.5, 265,
265.5, 266, 266.5, 267, 267.5, 268, 268.5, 269, 269.5, 270, 270.5,
271, 271.5, 272, 272.5, 273, 273.5, 274, 274.5, 275, 275.5, 276,
276.5, 277, 277.5, 278, 278.5, 279, 279.5, 280, 280.5, 281, 281.5,
282, 282.5, 283, 283.5, 284, 284.5, 285, 285.5, 286, 286.5, 287,
287.5, 288, 288.5, 289, 289.5, 290, 290.5, 291, 291.5, 292, 292.5,
293, 293.5, 294, 294.5, 295, 295.5, 296, 296.5, 297, 297.5, 298,
298.5, 299, 299.5, 300, 300.5, 301, 301.5, 302, 302.5, 303, 303.5,
304, 304.5, 305, 305.5, 306, 306.5, 307, 307.5, 308, 308.5, 309,
309.5, 310, 310.5, 311, 311.5, 312, 312.5, 313, 313.5, 314, 314.5,
315, 315.5, 316, 316.5, 317, 317.5, 318, 318.5, 319, 319.5, 320,
320.5, 321, 321.5, 322, 322.5, 323, 323.5, 324, 324.5, 325, 325.5,
326, 326.5, 327, 327.5, 328, 328.5, 329, 329.5, 330, 330.5, 331,
331.5, 332, 332.5, 333, 333.5, 334, 334.5, 335, 335.5, 336, 336.5,
337, 337.5, 338, 338.5, 339, 339.5, 340, 340.5, 341, 341.5, 342,
342.5, 343, 343.5, 344, 344.5, 345, 345.5, 346, 346.5, 347, 347.5,
348, 348.5, 349, 349.5, 350, 350.5, 351, 351.5, 352, 352.5, 353,
353.5, 354, 354.5, 355, 355.5, 356, 356.5, 357, 357.5, 358, 358.5,
359, 359.5, 360), y = c(0.399505615234375, 0.363082885742188,
0.347564697265625, 0.336196899414062, 0.320999145507812, 0.299407958984375,
0.2896728515625, 0.274063110351562, 0.256195068359375, 0.247543334960938,
0.240432739257812, 0.229461669921875, 0.236053466796875, 0.22271728515625,
0.218505859375, 0.211898803710938, 0.204544067382812, 0.206756591796875,
0.208648681640625, 0.206100463867188, 0.202651977539062, 0.198287963867188,
0.196517944335938, 0.189178466796875, 0.203125, 0.195892333984375,
0.19537353515625, 0.201095581054688, 0.198974609375, 0.20135498046875,
0.1990966796875, 0.19830322265625, 0.203765869140625, 0.200180053710938,
0.205841064453125, 0.2076416015625, 0.20428466796875, 0.211532592773438,
0.210296630859375, 0.2110595703125, 0.215164184570312, 0.212921142578125,
0.20941162109375, 0.220993041992188, 0.214599609375, 0.208023071289062,
0.221481323242188, 0.225204467773438, 0.226547241210938, 0.227554321289062,
0.232269287109375, 0.232772827148438, 0.240036010742188, 0.2364501953125,
0.240234375, 0.246856689453125, 0.245330810546875, 0.260086059570312,
0.2550048828125, 0.264312744140625, 0.250961303710938, 0.25567626953125,
0.26788330078125, 0.273269653320312, 0.263015747070312, 0.269241333007812,
0.26837158203125, 0.28179931640625, 0.27691650390625, 0.283554077148438,
0.287063598632812, 0.278457641601562, 0.289291381835938, 0.285003662109375,
0.280319213867188, 0.28515625, 0.283920288085938, 0.292831420898438,
0.289031982421875, 0.28863525390625, 0.27764892578125, 0.2906494140625,
0.277557373046875, 0.27850341796875, 0.273361206054688, 0.284561157226562,
0.268234252929688, 0.262054443359375, 0.266952514648438, 0.259429931640625,
0.256576538085938, 0.253616333007812, 0.24249267578125, 0.242080688476562,
0.227081298828125, 0.195022583007812, 0.210006713867188, 0.198577880859375,
0.185287475585938, 0.18365478515625, 0.1910400390625, 0.17364501953125,
0.168075561523438, 0.159378051757812, 0.1495361328125, 0.154342651367188,
0.133468627929688, 0.13897705078125, 0.127853393554688, 0.130203247070312,
0.127609252929688, 0.122406005859375, 0.10906982421875, 0.109161376953125,
0.10968017578125, 0.096649169921875, 0.098419189453125, 0.108657836914062,
0.106689453125, 0.0980377197265625, 0.0936279296875, 0.0960540771484375,
0.0955810546875, 0.0939483642578125, 0.0936126708984375, 0.08172607421875,
0.09149169921875, 0.09490966796875, 0.0884246826171875, 0.08819580078125,
0.0938568115234375, 0.0894622802734375, 0.0926513671875, 0.0837249755859375,
0.08843994140625, 0.09100341796875, 0.0876922607421875, 0.0858154296875,
0.086944580078125, 0.08087158203125, 0.0830535888671875, 0.0872039794921875,
0.083740234375, 0.084991455078125, 0.0854644775390625, 0.082427978515625,
0.0836334228515625, 0.079559326171875, 0.073577880859375, 0.0856475830078125,
0.078155517578125, 0.0776214599609375, 0.08050537109375, 0.07208251953125,
0.074249267578125, 0.0821380615234375, 0.07537841796875, 0.0762176513671875,
0.0694427490234375, 0.0778350830078125, 0.0811920166015625, 0.078094482421875,
0.0759124755859375, 0.0779571533203125, 0.0799560546875, 0.076629638671875,
0.074798583984375, 0.07696533203125, 0.0777435302734375, 0.07672119140625,
0.075653076171875, 0.07501220703125, 0.0784454345703125, 0.071258544921875,
0.0685882568359375, 0.0756988525390625, 0.076019287109375, 0.0701904296875,
0.0706939697265625, 0.0717926025390625, 0.06341552734375, 0.07379150390625,
0.07470703125, 0.0700225830078125, 0.075408935546875, 0.0740203857421875,
0.0732574462890625, 0.07720947265625, 0.08062744140625, 0.076812744140625,
0.076141357421875, 0.0730438232421875, 0.070648193359375, 0.0705108642578125,
0.0732421875, 0.0718536376953125, 0.07244873046875, 0.07611083984375,
0.0783233642578125, 0.066436767578125, 0.0683746337890625, 0.0764923095703125,
0.076629638671875, 0.07012939453125, 0.0737457275390625, 0.073272705078125,
0.074005126953125, 0.0748748779296875, 0.068023681640625, 0.0676727294921875,
0.0723724365234375, 0.0686492919921875, 0.0703582763671875, 0.065155029296875,
0.068450927734375, 0.06787109375, 0.0711517333984375, 0.068817138671875,
0.0736083984375, 0.0676116943359375, 0.07366943359375, 0.069183349609375,
0.0725860595703125, 0.0771484375, 0.075897216796875, 0.063079833984375,
0.0665435791015625, 0.0679473876953125, 0.07025146484375, 0.0731658935546875,
0.0659027099609375, 0.069549560546875, 0.067626953125, 0.06982421875,
0.068939208984375, 0.06304931640625, 0.0649871826171875, 0.0709381103515625,
0.065826416015625, 0.0646820068359375, 0.0689544677734375)), .Names = c("x",
"y"), row.names = c(NA, 241L), class = "data.frame", filename = "BSA 0.2.XLS")
ref = structure(list(x = c(240, 240.5, 241, 241.5, 242, 242.5, 243,
243.5, 244, 244.5, 245, 245.5, 246, 246.5, 247, 247.5, 248, 248.5,
249, 249.5, 250, 250.5, 251, 251.5, 252, 252.5, 253, 253.5, 254,
254.5, 255, 255.5, 256, 256.5, 257, 257.5, 258, 258.5, 259, 259.5,
260, 260.5, 261, 261.5, 262, 262.5, 263, 263.5, 264, 264.5, 265,
265.5, 266, 266.5, 267, 267.5, 268, 268.5, 269, 269.5, 270, 270.5,
271, 271.5, 272, 272.5, 273, 273.5, 274, 274.5, 275, 275.5, 276,
276.5, 277, 277.5, 278, 278.5, 279, 279.5, 280, 280.5, 281, 281.5,
282, 282.5, 283, 283.5, 284, 284.5, 285, 285.5, 286, 286.5, 287,
287.5, 288, 288.5, 289, 289.5, 290, 290.5, 291, 291.5, 292, 292.5,
293, 293.5, 294, 294.5, 295, 295.5, 296, 296.5, 297, 297.5, 298,
298.5, 299, 299.5, 300, 300.5, 301, 301.5, 302, 302.5, 303, 303.5,
304, 304.5, 305, 305.5, 306, 306.5, 307, 307.5, 308, 308.5, 309,
309.5, 310, 310.5, 311, 311.5, 312, 312.5, 313, 313.5, 314, 314.5,
315, 315.5, 316, 316.5, 317, 317.5, 318, 318.5, 319, 319.5, 320,
320.5, 321, 321.5, 322, 322.5, 323, 323.5, 324, 324.5, 325, 325.5,
326, 326.5, 327, 327.5, 328, 328.5, 329, 329.5, 330, 330.5, 331,
331.5, 332, 332.5, 333, 333.5, 334, 334.5, 335, 335.5, 336, 336.5,
337, 337.5, 338, 338.5, 339, 339.5, 340, 340.5, 341, 341.5, 342,
342.5, 343, 343.5, 344, 344.5, 345, 345.5, 346, 346.5, 347, 347.5,
348, 348.5, 349, 349.5, 350, 350.5, 351, 351.5, 352, 352.5, 353,
353.5, 354, 354.5, 355, 355.5, 356, 356.5, 357, 357.5, 358, 358.5,
359, 359.5, 360), y = c(0.144378662109375, 0.131134033203125,
0.136627197265625, 0.129898071289062, 0.125717163085938, 0.127227783203125,
0.126617431640625, 0.122726440429688, 0.122390747070312, 0.129074096679688,
0.120193481445312, 0.116607666015625, 0.120513916015625, 0.111831665039062,
0.119155883789062, 0.116546630859375, 0.118270874023438, 0.116500854492188,
0.114898681640625, 0.110610961914062, 0.11669921875, 0.120513916015625,
0.10992431640625, 0.109161376953125, 0.113433837890625, 0.114959716796875,
0.11065673828125, 0.102188110351562, 0.0933685302734375, 0.113204956054688,
0.105010986328125, 0.11041259765625, 0.1048583984375, 0.107498168945312,
0.10968017578125, 0.102264404296875, 0.100128173828125, 0.103729248046875,
0.107742309570312, 0.09783935546875, 0.109115600585938, 0.10186767578125,
0.107757568359375, 0.10467529296875, 0.1058349609375, 0.1004638671875,
0.103729248046875, 0.112152099609375, 0.109664916992188, 0.1005859375,
0.109466552734375, 0.101760864257812, 0.104843139648438, 0.101119995117188,
0.11663818359375, 0.10430908203125, 0.106216430664062, 0.110824584960938,
0.104827880859375, 0.106430053710938, 0.10284423828125, 0.10821533203125,
0.092132568359375, 0.100631713867188, 0.098968505859375, 0.103424072265625,
0.10162353515625, 0.094940185546875, 0.110000610351562, 0.0979156494140625,
0.103271484375, 0.107192993164062, 0.103622436523438, 0.0901031494140625,
0.1015625, 0.101547241210938, 0.0958251953125, 0.103866577148438,
0.10296630859375, 0.09442138671875, 0.0986480712890625, 0.0968170166015625,
0.10101318359375, 0.100830078125, 0.105880737304688, 0.087432861328125,
0.102249145507812, 0.098541259765625, 0.0992431640625, 0.0926361083984375,
0.097564697265625, 0.092041015625, 0.098388671875, 0.101669311523438,
0.084991455078125, 0.099151611328125, 0.0976409912109375, 0.0919952392578125,
0.0933990478515625, 0.101348876953125, 0.0877227783203125, 0.0898895263671875,
0.100265502929688, 0.0925140380859375, 0.09765625, 0.08270263671875,
0.0890960693359375, 0.086822509765625, 0.0894012451171875, 0.0821533203125,
0.092681884765625, 0.086181640625, 0.084381103515625, 0.085540771484375,
0.0902252197265625, 0.0890045166015625, 0.0790252685546875, 0.0883636474609375,
0.0864715576171875, 0.0802459716796875, 0.091400146484375, 0.082733154296875,
0.0857696533203125, 0.094024658203125, 0.0819091796875, 0.082977294921875,
0.089630126953125, 0.0800628662109375, 0.076080322265625, 0.079559326171875,
0.08319091796875, 0.084442138671875, 0.0872955322265625, 0.079681396484375,
0.0809326171875, 0.0821990966796875, 0.070892333984375, 0.0765838623046875,
0.08575439453125, 0.0816650390625, 0.083770751953125, 0.0688323974609375,
0.078857421875, 0.0748748779296875, 0.07916259765625, 0.0721893310546875,
0.0696868896484375, 0.0748443603515625, 0.07623291015625, 0.08135986328125,
0.0738525390625, 0.074981689453125, 0.0748291015625, 0.072906494140625,
0.08197021484375, 0.06927490234375, 0.0723876953125, 0.077789306640625,
0.0762939453125, 0.078369140625, 0.0764312744140625, 0.077423095703125,
0.07708740234375, 0.07794189453125, 0.0767822265625, 0.079071044921875,
0.0944061279296875, 0.082794189453125, 0.074493408203125, 0.0721893310546875,
0.0750885009765625, 0.0814208984375, 0.0761260986328125, 0.070770263671875,
0.0764617919921875, 0.0796356201171875, 0.06829833984375, 0.072174072265625,
0.0754547119140625, 0.0726165771484375, 0.0701751708984375, 0.0750732421875,
0.0665283203125, 0.07171630859375, 0.0680999755859375, 0.07373046875,
0.0718231201171875, 0.074188232421875, 0.06561279296875, 0.070953369140625,
0.07073974609375, 0.069671630859375, 0.07318115234375, 0.068450927734375,
0.0679473876953125, 0.0667724609375, 0.0654449462890625, 0.069183349609375,
0.0676116943359375, 0.072479248046875, 0.069305419921875, 0.0735626220703125,
0.072174072265625, 0.0670166015625, 0.0734710693359375, 0.0641937255859375,
0.0614166259765625, 0.0708770751953125, 0.069732666015625, 0.0692138671875,
0.066314697265625, 0.0703887939453125, 0.0654296875, 0.06689453125,
0.07086181640625, 0.0693511962890625, 0.0720977783203125, 0.0704498291015625,
0.0663909912109375, 0.0678253173828125, 0.064453125, 0.08056640625,
0.0684051513671875, 0.066925048828125, 0.066253662109375, 0.0713043212890625,
0.0681304931640625, 0.0643157958984375, 0.07098388671875, 0.0643310546875,
0.0662841796875, 0.0673675537109375, 0.0698699951171875, 0.068695068359375,
0.065948486328125, 0.0650787353515625, 0.06646728515625, 0.0711517333984375,
0.059417724609375, 0.0630035400390625, 0.061065673828125)), .Names = c("x",
"y"), row.names = c(NA, 241L), class = "data.frame", filename = "/Volumes/Document/Personal/Altshuler_E/misc/2017-10-03 ultrospec (k344 test)/ref MQ.XLS")
#loadSpectrum
loadSpectrum = function(filename){
f = read.xlsx(filename, 1)
# get the start row
start_row_number = -1
i = 1
while (start_row_number<0){
if (f[i, 1] == "Wavelength") {
start_row_number = i+1
break
}
i = i+1
}
mf = as.matrix(f)
df=as.data.frame(cbind(as.numeric(mf[start_row_number:nrow(mf),1]),as.numeric( mf[start_row_number:nrow(mf),2])))
colnames(df) = c("x","y")
attributes(df)$filename = filename
return(df)
}
compare_spectra = function(SAMPLE,REF,title="",ss.spar=0.5){
require(ggplot2)
require(cowplot)
require(scales)
#SAMPLE$y = -SAMPLE$y
#REF$y = -REF$y
SAMPLE_ = SAMPLE[SAMPLE$x >=250 & SAMPLE$x <= 320,]
REF_ = REF[REF$x >=250 & REF$x <= 320,]
ss = smooth.spline(REF_$x, SAMPLE_$y-REF_$y, spar=ss.spar)
res = predict(ss, REF_$x)$y - (SAMPLE_$y-REF_$y)
sp.p = ggplot() +
theme_bw() +
theme(axis.title.x = element_blank(), axis.text.x = element_blank(), axis.ticks.x = element_blank()) +
geom_point(aes(x=REF_$x,y=SAMPLE_$y-REF_$y), shape=21, col="black", fill="gray", alpha=0.7) +
geom_line(aes(x=ss$x,y=ss$y), col="red") +
labs(x="Wavelength, nm", y="OD", title=title,subtitle=paste("SD of residuals = ",sprintf('%0.4f',sd(res)),sep=""))
res.p = ggplot() +
theme_bw() +
geom_point(aes(x=REF_$x,y=res), shape=21, col="black", fill="gray", alpha=0.7) +
xlab("Wavelength, nm") +
ylab("Residuals") +
scale_y_continuous(labels = comma)
plots = align_plots(sp.p, res.p, align="v",axis="l")
ggdraw() +
draw_plot(plots[[1]], x=0,y=0.3, width=1, height=0.7) +
draw_plot(plots[[2]], x=0,y=0, width=1, height=0.3)
}
compare_spectra(bsa0.2,ref,"Room 128 (dept)",0.6)
## Loading required package: ggplot2
## Loading required package: cowplot
##
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggplot2':
##
## ggsave
## Loading required package: scales
