-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassSpec.R
526 lines (518 loc) · 21 KB
/
massSpec.R
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
### ---------------------------------------------------------------- ###
### atmosch-R ###
### ---------------------------------------------------------------- ###
### Functions for mass spectrometry:
### - fLoadTOF() : load PTR-TOF-MS spectra
### - fNormTOF() : normalize and average PTR-TOF-MS spectra
### - fPlotSpect() : rotate spectra and make timeseries plots
### - fLoadCIMS() : load CIMS data
### - fSpectraCIMS() : load CIMS spectra
### - fProcessCIMS() : process CIMS data
### - fNormCIMS() : normalize CIMS data
### - fDiagnCIMS() : run CIMS diagnostics
###
### version 4.2, Aug 2019
### author: RS
### ---------------------------------------------------------------- ###
fLoadTOF <- function(tof.dir, tof.fn) {
## load spectra file generated by the Leicester PTR-TOF-MS
##
## the PTR-TOF-MS spectra files have m/z on the first row and the
## ion counts of each scan in the following rows:
##
## 18 19 20 21
## 3880 112395 125 253
## 4469 107648 122 263
## 4942 106513 131 233
##
## input:
## tof.dir = PTR-TOF spectra file directory
## tof.fn = name of PTR-TOF spectra file
## output:
## tof.out = data.frame ( mz, scan1, scan2, scan3, ... )
## ------------------------------------------------------------
## load PTR-TOF spectra file
tof.file <- paste(tof.dir, tof.fn, sep="")
tof.df <- read.table(tof.file, header=FALSE, sep=",")
## spectra header (first row)
n.scan <- nrow(tof.df) - 1
tof.ions <- paste("scan", seq(1, n.scan, by=1), sep="")
tof.head <- c("mz", tof.ions)
## rotate PTR-TOF spectra data
## drop first column (m/z=0) and last column (blank)
n.ion <- ncol(tof.df) - 1
tof.matx <- t(tof.df[,2:n.ion])
## output data.frame
cat("> data file loaded:", tof.fn, "\n")
tof.out <- data.frame(tof.matx) #!
rownames(tof.out) <- NULL
colnames(tof.out) <- tof.head
return(tof.out)
}
fNormTOF <- function(spect.df, ref.mz, scan.ini, scan.fin) {
## normalize PTR-TOF-MS spectra to 1 million counts of a reference
## ion (e.g., [H3O]+)
## calculate average spectrum and standard deviation of a group of
## normalized scans
##
## NB: see documentation of fLoadTOF()
##
## input:
## spect.df = data.frame of spectra (m/z, scan1, scan2, ...)
## ref.mz = mass of reference ion
## scan.ini = n. initial scans to exclude from average
## scan.fin = n. final scans to exclude from average
## output:
## spect.out = data.frame ( mz, scan1, scan2, ...,
## scan.avg, scan.std )
## ------------------------------------------------------------
if (!is.data.frame(spect.df)) {
df.name <- deparse(substitute(spect.df))
stop(paste(df.name, "must be a data.frame", sep=" "))
}
## reference ion count
ref.r <- which(spect.df["mz"] == as.numeric(ref.mz))
ref.ic <- as.numeric(spect.df[ref.r,])
## normalize spectra
spect.norm <- t(apply(spect.df, 1, function(x) x * 1e6 / ref.ic)
)
spect.norm[,1] <- spect.df[,1]
nsp <- ncol(spect.norm)
## calculate average spectrum and standard deviation
smin <- as.numeric(scan.ini) + 2
smax <- nsp - as.numeric(scan.fin)
spect.avg <- apply(spect.norm[,smin:smax], 1, mean)
spect.std <- apply(spect.norm[,smin:smax], 1, sd)
## output data.frame
spect.out <- as.data.frame(spect.norm) #!
spect.out[,(nsp+1)] <- spect.avg
spect.out[,(nsp+2)] <- spect.std
colnames(spect.out)[(nsp+1)] <- "scan.avg"
colnames(spect.out)[(nsp+2)] <- "scan.std"
return(spect.out)
}
fPlotSpect <- function(spect.df, mz.min, mz.max, sc.min, sc.max, fn.str) {
## rotate data.frame of spectra and make plots of time spectra (ion
## counts vs. number of scans) for a given interval of masses
##
## optional: save plots of time spectra to pdf file
##
## input:
## spect.df = data.frame ( mass, scan1, scan2, scan3, ... )
## mz.min = smallest mass to plot
## mz.max = largest mass to plot
## sc.min = smallest mass to plot
## sc.max = largest mass to plot
## fn.str = name of png file to save plots OR ""
## output:
## spect.out = data.frame ( n. scan, mass1, mass2, mass3, ... )
## --> plot of time spectra
## --> png file : `fn.str`.png
## ------------------------------------------------------------
if (!is.data.frame(spect.df)) {
df.name <- deparse(substitute(spect.df))
stop(paste(df.name, "must be a data.frame", sep=" "))
}
## rotate data.frame and add vector with scan number
mz.vec <- spect.df[,1]
spect.t <- t(spect.df[,-1])
rownames(spect.t) <- NULL
colnames(spect.t) <- paste("m", mz.vec, sep="")
n.scan <- seq(1, nrow(spect.t), by=1)
## select range of masses
mz.inter <- which((mz.vec > mz.min) & (mz.vec < mz.max))
## plot time spectra in 4x4 panels
par(mfrow = c(4,4))
for (i in mz.inter) {
spect.ic <- spect.t[,i]
if (all(is.na(spect.ic)) == FALSE) { # time spectrum #!
plot(n.scan, spect.ic, type="o", cex=0.6,
main=paste("mass ", mz.vec[i], sep=""),
xlab="scan n.", ylab="ion count")
} else { # empty plot
plot(0, 0, type="o", cex=0.6,
xlim=c(-1,1), ylim=c(-1,1),
main=paste("mass ", mz.vec[i], sep=""),
xlab="scan n.", ylab="ion count")
}
}
if (fn.str != "") {
dev.copy(png, paste(fn.str, ".png", sep=""),
width=297, height=210, units="mm", res=150)
dev.off()
}
## output data.frame
spect.out <- as.data.frame(cbind(n.scan, spect.t)) #!
return(spect.out)
}
fLoadCIMS <- function(cims.dir, cims.fn) {
## Load data file generated by the Leicester CIMS.
##
## The CIMS data files have the format:
##
## time, year, month, day, hour, minute, second,
## instrument parameters and flags, ion counts per second,
## ion masses, dwell times, analog signals
##
## input:
## cims.dir = CIMS data file directory
## cims.fn = name of CIMS data file
## output:
## cims.out = data.frame ( time variables, data variables,
## diagnostic variables )
## ------------------------------------------------------------
## load CIMS data file
cims.file <- paste(cims.dir, cims.fn, sep="")
cims.df <- read.table(cims.file, header=TRUE, sep="")
## drop last row of the file
cims.df <- cims.df[-nrow(cims.df),]
## separate CIMS variables into groups
nvar <- length(colnames(cims.df))
cims1 <- cims.df[,1:8] # time
cims2 <- cims.df[,9:11] # n. cycles, mass channels, analog signals
cims3 <- cims.df[,12:15] # cycles
cims4 <- cims.df[,16:(nvar-32)] # Hz, mass, dwell time
cims5 <- cims.df[,(nvar-31):nvar] # analog signals
## convert date/time strings to chron
tst.d <- paste(cims1$yr, cims1$mo, cims1$dm, sep="-")
tst.t <- paste(cims1$hr, cims1$mn, cims1$sc, sep=":")
tst.dt <- paste(tst.d, tst.t, sep=" ")
cims.d <- fChronStr(tst.d, "y-m-d")
cims.t <- fChronStr(tst.t, "h:m:s")
cims.dt <- fChronStr(tst.dt, "y-m-d h:m:s")
cims.time <- data.frame(cims.dt, cims.d, cims.t)
rownames(cims.time) <- NULL
colnames(cims.time) <- c("Datetime", "Date", "Time")
## output data.frame
cat("> data file loaded:", cims.fn)
cat("\t[", as.character(cims2$nh[1]), "mass channels ]\n")
cims.out <- data.frame(cims.time, cims4, cims2, cims3, cims5)
return(cims.out)
}
fSpectraCIMS <- function(cims.dir, cims.lst) {
## Load spectra files generated by the Leicester CIMS and extract
## the start/stop times of each spectrum.
##
## input:
## cims.dir = CIMS spectra files directory
## cims.lst = list of CIMS spectra files
## output:
## cims.out = list ( data.frame ( start chron, stop chron ),
## data.frame ( amu, scan1, scan2, ... ) )
## ------------------------------------------------------------
if (!is.list(cims.lst)) {
lst.name <- deparse(substitute(cims.lst))
stop(paste(lst.name, "must be a list", sep=" "))
}
## initialize lists and chron variables
scan.lst <- list()
scan.name <- list()
scan.start <- chron(format=c(dates="d-m-y", times="h:m:s"))
scan.stop <- chron(format=c(dates="d-m-y", times="h:m:s"))
## load all CIMS spectra
for (i in 1:length(cims.lst)) {
## load spectrum
cims.fn <- cims.lst[[i]]
cims.df <- fLoadCIMS(cims.dir, cims.fn)
## spectrum data (mass, ion count)
cims.ic <- data.frame(amu = (cims.df[,5] / 1000),
ic = cims.df[,4])
scan.lst[[i]] <- cims.ic
## name of spectrum file: `filename_S_yyyy-mm-dd_hh-mm-ss.txt`
n.fn <- nchar(cims.fn)
cims.str <- gsub("-", "", substr(cims.fn, n.fn-18, n.fn-7))
scan.name[[i]] <- paste("_", cims.str, sep="")
## spectrum start/stop times
cims.dt <- cims.df$Datetime
scan.start[i] <- cims.dt[1]
scan.stop[i] <- cims.dt[length(cims.dt)]
}
## data.frame of spectra start/stop times
scan.tst <- data.frame(StartTime = scan.start,
StopTime = scan.stop)
## data.frame of spectra
if (length(scan.name) == 1) {
scan.df <- scan.lst[[1]]
colnames(scan.df) <- c("amu", paste("ic", scan.name[[1]], sep=""))
} else {
scan.df <- fMergeDF(scan.lst, "amu", "TRUE", scan.name)
}
## output list:
## [1] data.frame of spectra start/stop times
## [2] data.frame of spectra
cims.out <- list(scan.tst, scan.df)
return(cims.out)
}
fProcessCIMS <- function(cims.df, bkgd.set) {
## Process the Leicester CIMS raw data:
## * convert and rename data and diagnostic variables
## * calculate temperature and humidity of the calibration flow
## * create instrument background flag
##
## NB: use fLoadCIMS() to import the CIMS data files and generate
## the data.frame of CIMS data.
##
## input:
## cims.df = data.frame of CIMS data
## bkgd.set = instrument background setting ("on" OR "off")
## output:
## cims.out = data.frame ( time variables, processed data,
## diagnostic variables, relative humidity,
## temperature, background flag )
## ------------------------------------------------------------
if (!is.data.frame(cims.df)) {
df.name <- deparse(substitute(cims.df))
stop(paste(df.name, "must be a data.frame", sep=" "))
}
## separate time, data and diagnostic variables
var.str <- colnames(cims.df)
cims.time <- cims.df[,c("Datetime", "Date", "Time")]
cims.data <- cbind(cims.df[,grep("^Hz", var.str)],
cims.df[,grep("^mamu", var.str)],
cims.df[,grep("^ms", var.str)])
cims.diagn <- cbind(cims.df[,grep("^n", var.str)],
cims.df[,grep("^c", var.str)],
cims.df[,grep("^A", var.str)])
## ion count (Hz), atomic mass (amu), dwell time (sec)
n.mz <- length(colnames(cims.data)) / 3
ic.hz <- cims.data[,1:n.mz]
ic.am <- cims.data[,(n.mz+1):(2*n.mz)]
ic.ms <- cims.data[,(2*n.mz+1):(3*n.mz)]
cims.ic <- ic.hz
cims.amu <- ic.am / 1000
cims.sec <- ic.ms / 1000
colnames(cims.ic) <- gsub("Hz", "m", colnames(cims.ic))
colnames(cims.amu) <- gsub("mamu", "amu", colnames(cims.amu))
colnames(cims.sec) <- gsub("ms", "sec", colnames(cims.sec))
## temperature (C) and relative humidity (%) of the calibration flow
## NB: the conversion factors are for the Vaisala HMP110 probe
probe.rh <- (cims.diagn$A05 / 1000) * 20
probe.temp <- (cims.diagn$A06 / 1000) * 30 - 70
cims.probe <- data.frame(probe_RH = probe.rh, probe_T = probe.temp)
## create instrument background flag:
## 0 = signal
## 1 = background
cims.flag <- rep(0, nrow(cims.time))
if (bkgd.set == "on") {
## drop 10 data points before/after valve switch
cims.diagn1 <- fSwitchFlag(cims.diagn, "cB", 1, 10, 10)
cims.flag <- cims.diagn1$Flag
}
## output data.frame
cims.out <- data.frame(cims.time, cims.amu, cims.ic, cims.sec,
cims.diagn, cims.probe,
Flag_Bgd = cims.flag)
return(cims.out)
}
fNormCIMS <- function(cims.df, ref.mz, norm.fac, scale.str) {
## Normalize the Leicester CIMS data to a reference ion. Standard
## practice is to normalize to 1 million counts of the reagent ion
## (e.g., iodide). Optionally, the reference ion can be scaled to
## the absolute humidity of the calibration flow ("AH").
##
## NB: use fProcessCIMS() to process the raw CIMS data before
## normalizing with fNormCIMS().
##
## input:
## cims.df = data.frame of processed CIMS data
## ref.mz = mass of reference ion
## norm.fac = normalization factor (1 OR 1e6)
## scale.str = scaling parameter ("none" OR "AH")
## output:
## cims.out = data.frame ( time variables, normalized data,
## diagnostic variables, t/rh variables,
## scaling parameter, background flag )
## ------------------------------------------------------------
if (!is.data.frame(cims.df)) {
df.name <- deparse(substitute(cims.df))
stop(paste(df.name, "must be a data.frame", sep=" "))
}
## separate time, ion counts and other variables
var.str <- colnames(cims.df)
cims.time <- cims.df[,c("Datetime", "Date", "Time")]
cims.ic <- cims.df[,grep("^m", var.str)]
cims.var1 <- cbind(cims.df[,grep("^amu", var.str)],
cims.df[,grep("^sec", var.str)],
cims.df[,grep("^n", var.str)],
cims.df[,grep("^c", var.str)],
cims.df[,grep("^A", var.str)])
cims.var2 <- cims.df[,c("probe_RH", "probe_T", "Flag_Bgd")]
## convert relative humidity (%) to absolute humidity (g/m3)
## NB: assume standard atmospheric pressure (1 atm = 1013.25 mbar)
probe.ah <- fHumid(cims.var2$probe_RH, "RH", "AH", cims.var2$probe_T, 1.01325e+05)
## get reference ion counts
ref.str <- paste("m", as.character(ref.mz), sep="")
ref.ic <- cims.ic[,ref.str]
## scaling parameter for the reference ion
switch(scale.str,
"none" = { # no scaling
ref.ion <- ref.ic
},
"AH" = { # scale to absolute humidity
ref.ion <- ref.ic / probe.ah
},
stop("INPUT ERROR: invalid parameter")
)
## normalize data to reference ion
ref.ion[ref.ion == 0] <- NaN
cims.norm <- apply(cims.ic, 2, function(x) x * norm.fac / ref.ion)
## rename normalized data variables
colnames(cims.norm) <- paste(colnames(cims.ic), "ncps", sep="_")
## output data.frame
cims.out <- data.frame(cims.time, cims.norm, cims.var1, cims.var2)
return(cims.out)
}
fDiagnCIMS <- function(cims.df, start.str, stop.str, fn.str) {
## Run basic diagnostic checks on the Leicester CIMS data and make
## plots of the diagnostic variables:
## * consistency of parameters and flags
## * plots of analog signals
## * consistency of monitored masses and dwell times
##
## Optional: save plots of diagnostic variables to pdf file.
##
## NB: use fProcessCIMS() to process the raw CIMS data before
## running the diagnostics with fDiagnCIMS().
##
## input:
## cims.df = data.frame of CIMS data
## start.str = start datetime string ("d-m-y h:m:s")
## stop.str = stop datetime string ("d-m-y h:m:s")
## fn.str = name of pdf file to save plots OR ""
## output:
## --> pdf file : `fn.str`.pdf
## ------------------------------------------------------------
if (!is.data.frame(cims.df)) {
df.name <- deparse(substitute(cims.df))
stop(paste(df.name, "must be a data.frame", sep=" "))
}
## check consistency of parameters and flags
n.cyc <- cims.df$nc # n. cycles
n.hop <- cims.df$nh # n. mass channels
n.ans <- cims.df$na # n. analog signals
cyc.0 <- cims.df$cB # flag x cycle 0 (background valve B)
cyc.1 <- cims.df$cC # flag x cycle 1 (background valve C)
cyc.2 <- cims.df$c2 # flag x cycle 2
cyc.3 <- cims.df$c3 # flag x cycle 3
if (length(unique(n.cyc)) != 1) {
cat("CONFLICT! n. cycles:", unique(n.cyc), "\n")
}
if (length(unique(n.hop)) != 1) {
cat("CONFLICT! n. mass channels:", unique(n.hop), "\n")
}
if (length(unique(n.ans)) != 1) {
cat("CONFLICT! n. analog signals:", unique(n.ans), "\n")
}
if (length(unique(cyc.0)) != 2) {
cat("CONFLICT! flag x cycle 0:", unique(cyc.0), "\n")
}
if (length(unique(cyc.1)) != 2) {
cat("CONFLICT! flag x cycle 1:", unique(cyc.1), "\n")
}
if (length(unique(cyc.2)) != 1) {
cat("CONFLICT! flag x cycle 2:", unique(cyc.2), "\n")
}
if (length(unique(cyc.3)) != 1) {
cat("CONFLICT! flag x cycle 3:", unique(cyc.3), "\n")
}
if (identical(cyc.0, cyc.1) != TRUE) {
cat("CONFLICT! flags x background cycles:", unique(cyc.0), "\n")
cat("CONFLICT! flags x background cycles:", unique(cyc.1), "\n")
}
## check analog signals (flows, voltages, pressures)
fptv.a01 <- cims.df$A01 # MFC1
fptv.a02 <- cims.df$A02 # MFC2 (CH3I flow)
fptv.a05 <- cims.df$A05 # calibration probe RH
fptv.a06 <- cims.df$A06 # calibration probe T
fptv.a07 <- cims.df$A07 # MFC3 (N2 flow)
fptv.a08 <- cims.df$A08 # FT pressure
hv.a01 <- cims.df$A17 # pinhole
hv.a06 <- cims.df$A22 # octopole plate
hv.a07 <- cims.df$A23 # CDC DC
hv.a08 <- cims.df$A24 # CDC RF
hv.a09 <- cims.df$A25 # octopole RF
hv.a10 <- cims.df$A26 # octopole DC
hv.b01 <- cims.df$A27 # detector rear (PS1)
hv.b02 <- cims.df$A28 # detector front (PS2)
hv.b03 <- cims.df$A29 # detector front (PS3)
hv.b05 <- cims.df$A30 # CDC pressure
hv.b06 <- cims.df$A31 # Main pressure
hv.b07 <- cims.df$A32 # Quad pressure
## time interval for plotting
tst.dt <- cims.df$Datetime
x1 <- fFindIdx(tst.dt, "G", fChronStr(start.str, "d-m-y h:m:s"))
x2 <- fFindIdx(tst.dt, "L", fChronStr(stop.str, "d-m-y h:m:s"))
## open pdf file to save plots [optional]
if (fn.str != "") {
pdf(paste(fn.str, ".pdf", sep=""), paper="a4r", width=0, height=0)
}
## plot analog signals with reference values
par(mfrow = c(3,3), bg="white")
plot(tst.dt[x1:x2], fptv.a01[x1:x2], type="l", ylim=c(0,500),
xlab="time", ylab="mV", main="MFC #1")
abline(h=0, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], fptv.a02[x1:x2], type="l", ylim=c(400,600),
xlab="time", ylab="mV", main="CH3I flow")
abline(h=500, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], fptv.a07[x1:x2], type="l", ylim=c(1900,2100),
xlab="time", ylab="mV", main="N2 flow")
abline(h=2000, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.a01[x1:x2], type="l", ylim=c(-300,-150),
xlab="time", ylab="mV", main="pinhole")
abline(h=-250, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.a06[x1:x2], type="l", ylim=c(0,150),
xlab="time", ylab="mV", main="octopole plate")
abline(h=67, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.a07[x1:x2], type="l", ylim=c(-100,50),
xlab="time", ylab="mV", main="CDC DC")
abline(h=-46, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.a08[x1:x2], type="l", ylim=c(1700,1900),
xlab="time", ylab="mV", main="CDC RF")
abline(h=1850, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.a09[x1:x2], type="l", ylim=c(1000,3000),
xlab="time", ylab="mV", main="octopole RF")
abline(h=1900, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.a10[x1:x2], type="l", ylim=c(400,800),
xlab="time", ylab="mV", main="octopole DC")
abline(h=496, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], fptv.a08[x1:x2], type="l", ylim=c(700,1400),
xlab="time", ylab="mV", main="FT pressure")
abline(h=1000, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.b05[x1:x2], type="l", ylim=c(5500,5900),
xlab="time", ylab="mV", main="CDC pressure")
abline(h=5650, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.b06[x1:x2], type="l", ylim=c(3500,3900),
xlab="time", ylab="mV", main="Main pressure")
abline(h=36500, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.b07[x1:x2], type="l", ylim=c(1800,2100),
xlab="time", ylab="mV", main="Quad pressure")
abline(h=1900, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.b01[x1:x2], type="l", ylim=c(3200,3800),
xlab="time", ylab="mV", main="detector rear")
abline(h=3519, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.b02[x1:x2], type="l", ylim=c(1400,1800),
xlab="time", ylab="mV", main="detector front")
abline(h=1502, col="red", lwd=2, lty=2)
plot(tst.dt[x1:x2], hv.b03[x1:x2], type="l", ylim=c(0,1000),
xlab="time", ylab="mV", main="PS3")
abline(h=0, col="red", lwd=2, lty=2)
## close pdf file
if (fn.str != "") {
dev.off()
cat("> diagnostic plots saved to:", paste(fn.str, ".pdf", sep=""), "\n")
}
## check consistency of monitored masses and dwell times
var.str <- colnames(cims.df)
ic.amu <- cims.df[,grep("^amu", var.str)]
ic.sec <- cims.df[,grep("^sec", var.str)]
rsd.amu <- apply(ic.amu, 2, sd) / apply(ic.amu, 2, mean)
rsd.sec <- apply(ic.sec, 2, sd) / apply(ic.sec, 2, mean)
if (length(which(rsd.amu > 0.005)) != 0) {
cat("CONFLICT! variability of monitored masses:\n")
print(rsd.amu)
}
if (length(which(rsd.sec > 0.005)) != 0) {
cat("CONFLICT! variability of dwell times:\n")
print(rsd.sec)
}
}