-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfoo
More file actions
97 lines (85 loc) · 4.02 KB
/
foo
File metadata and controls
97 lines (85 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
============================================================================
// similarity spectrum
mode similarity spectrum
group spectrum
labels concentrate unfiltered
prereqs 1 2 21
userMenu target sample [[
sample current sample
phyto selected phyto model
]]
userArg derivIndex 4
userArg modelCount 3
userArg siRanges 400 700
chart {{
if (prereq[0] == null || prereq[1] == null || prereq[2] == null) {
addCurve(lib.rawWavelengths, spectrum);
return;
}
out("Similarity spectra based on foreground of absorbance\n\n" +
"The target menu selects either the current sample spectrum or " +
"the spectrum of the currently selected phytoplankton model.\n\n" +
"The derivIndex parameter specifies which derivative to base " +
"the similarity index calculation on.\n\n" +
"The modelCount parameter specifies the number of phytoplankton " +
"model spectra to show, along with the target spectrum; " +
"these spectra are scaled to match magnitude of target.\n\n" +
"All spectra are clipped, using clipping method specified " +
"in adjust settings mode; sim index calculation omits wavelengths " +
"where either spectrum is clipped.\n\n");
let pmod = phyto.currentModel();
let [ sample, dark, ref, wavelengths, nlcCoef ] = (target == "sample" ?
[spectrum, prereq[0], prereq[1],
lib.rawWavelengths, lib.nlcCoef] :
[pmod.unfiltered, pmod.dark, pmod.filtered,
pmod.wavelengths, pmod.nlcCoef]);
derivIndex = parseInt(derivIndex);
modelCount = parseInt(modelCount);
siRanges = siRanges.trim().split(/ +/);
for (let i = 0; i < siRanges.length; i++)
siRanges[i] = parseInt(siRanges[i]) - lib.MINWAVE;
if (siRanges.length&1 == 1)
siRanges.push(lib.SIM_MAXWAVE - lib.MAXWAVE);
// siRanges is now a rake, assuming menu values are increasing
let absorb = lib.absorbance(sample, [dark,ref,dark], wavelengths, nlcCoef);
let foreground = lib.extractForeground(absorb);
let rake = lib.joinRakes(lib.makeRake(foreground, lib.validFore), siRanges);
let deriv = lib.deriv(foreground, derivIndex);
addCurve(lib.cookedWavelengths, lib.vectorCrop(deriv, rake));
markup.label = "";
let simx = lib.getAllSimx(foreground, derivIndex, rake);
simx.sort(function(a,b){return b.si-a.si;});
let mag = lib.vectorMagnitude(deriv, rake);
out("The black curve is the derivative of the target spectrum. " +
"The vector magnitude of the deriviative is " + mag.toExponential(3) +
"\n\nSim indexes for all models (starting with closest match)\n\n");
markup.label = "";
let first = true; let n = 0;
for (let i = 0; i < simx.length; i++) {
let model = phyto.model(simx[i].name);
if (target == "phyto" && pmod.name == model.name) continue;
out(simx[i].si.toFixed(4) + " " + simx[i].name + "\n");
if (!phyto.included(model.name) &&
(n >= modelCount || phyto.excluded(model.name)))
continue;
n++;
let modelDeriv = lib.deriv(model.foreground, derivIndex);
let rakePair = lib.joinRakes(rake, model.rake);
let scale = lib.vectorMagnitude(deriv, rakePair) /
lib.vectorMagnitude(modelDeriv, rakePair);
addCurve(lib.cookedWavelengths, lib.vectorScale(
lib.vectorCrop(modelDeriv, rakePair), scale));
// lib.vectorCrop(modelDeriv, model.rake), scale));
if (n > 3 && !phyto.included(model.name)) continue;
if (first) first = false;
else markup.label += ", ";
markup.label += model.name + ":" + simx[i].si.toFixed(3);
}
markup.label += " mag:" + mag.toExponential(3);
addLine(lib.cookedWavelengths, 0, "gray");
markup.leftMargin = 65;
y.interval = 1.e-6; y.ticks = 5; y.scaling = "full"; y.precision = 3;
y.margin = .1;
x.min = lib.SIM_MINWAVE; x.max = lib.SIM_MAXWAVE; x.scaling = "none";
markup.qa = lib.qaAbsorbance(sample, [dark,ref,dark], wavelengths, nlcCoef);
}}