-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspecting_clumped-processing.Rmd
1608 lines (1478 loc) · 64.4 KB
/
inspecting_clumped-processing.Rmd
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Useful inspection plots for the MotU"
output: html_notebook
---
# Backlog and Notes
2022-12-15: **NOTE** this is a messy file, use the Outline to navigate quickly!
2022-12-15: **TODO** make copies for pacman did/caf -> might need further tweaking because some metadata is different.
2022-12-16: **TODO** once this file is cleaned up and to your liking, include it in the targets pipeline so it auto-updates? https://books.ropensci.org/targets/literate-programming.html
2022-12-20: **NOTE** I've now cleaned this up a bit, it looks at everything since 2021.
2023-01-19: **NOTE** Updated pacman workflow, should include pacman inspection plots here or in a separate file?
Once you have [run the code](running_clumped-processing.Rmd), we can inspect the output!
# Libraries
This loads the libraries + plotting helpers (sam = scale_alpha_manual for outliers).
```{r}
source("R/libraries.R")
```
# Interactive Plots
If there is ever a plot you'd like to zoom in on, make an interactive version of
it with this `ggp()` function.
Note that it sets the axis titles to blank, because plotly cannot handle formula
axis labels and we use those a lot (e.g. ylab = delta^{18}*O~"(VPDB \u2030)").
```{r}
ggp <- function(pl = ggplot2::last_plot(), h = NULL) {
# convert to WebGL for speed -> doesn't work in RStudio browser
#plotly::toWebGL(
plotly::ggplotly(
# select the last ggplot object
# you can also replace that with an object that holds the plot
p = pl +
# disable the axis titles (needed in case you have formulae for the axes)
theme(axis.title.x = element_blank(),
axis.title.y = element_blank()),
# make new tickmarks show up when you zoom in/out
dynamicTicks = TRUE, height = h)
#)
}
```
# Custom Filters
These are used to zoom in on only the measurements you want to see!
Currently it focuses on all measurements since 2021. The last manual outlier was marked in November 2021.
```{r}
scan_filter <- function(data) {
data |>
filter(scan_datetime > lubridate::ymd("2021-01-01"))
}
measurement_filter <- function(data) {
data |>
filter(file_datetime > lubridate::ymd("2021-01-01"))
}
```
# Background Scans
## Raw scans
This is a plot of the raw scans. It takes quite a while to make, so it might be useful to filter first.
```{r}
pl_scn <- tar_read(motu_scn_fix) |>
bind_rows() |>
group_by(file_id) |>
scan_filter() |>
pivot_longer(cols = v44.mV:v49.mV,
names_to = "mass",
values_to="intensity") |>
ggplot(aes(x = x, y = intensity, colour = mass## , linetype = scan_group
)) +
geom_line(aes(group = paste(file_id, mass, voltage))) +
geom_vline(aes(xintercept = value, range = range, label = scan_group),
data = tar_read(motu_scn_fix) |>
bind_rows() |>
scan_filter() |>
distinct(min_start_44, min_end_44,
min_start_45_49, min_end_45_49,
max_start, max_end, .keep_all = TRUE) |>
pivot_longer(cols = c(min_start_44, min_end_44,
min_start_45_49, min_end_45_49,
max_start, max_end),
names_to = "range", values_to = "value")) +
# below works but is very slow
## facet_zoom(xlim = c(9.385, 9.465), ylim = c(-1000, 100), horizontal = FALSE) + # for the minimum
coord_cartesian(xlim = c(9.385, 9.465),
ylim = c(-500, 100)) + # for the minimum
scale_x_continuous(breaks = seq(9, 10, .01),
minor_breaks = seq(9, 10, .001))
# show the minimum and maximum side-by-side
pl_scn + (pl_scn + coord_cartesian(xlim = c(9.44, 9.5),
ylim = c(-500, 4e4))) + # for the maximum
plot_layout(guides = "collect")
```
## Min/Max vs. Time
```{r}
tar_read(motu_scn_mod) |>
#tar_read(pacman_scn_mod) |>
bind_rows() |>
# filter your range of interest
scan_filter() |>
unnest(cols = data) |>
ggplot(aes(x = scan_datetime,
label = scan_group,
colour = factor(voltage),
file_id = file_id,
alpha = outlier_scan_manual,
##y = min_44
## y = min_45
## y = min_46
y = min_47
## y = min_48
## y = min_49
## y = min_54
## y = max_44
)) +
geom_point() +
sam
```
## BG Models
Here I also quickly fit 2nd order polynomials (parabola's) that go through the origin to see if they perform better than the already calculated (less visible) straight lines that are not forced through 0.
It looks like for mass 45 it might make a difference, but then again the y-axis value is only 2 on a scale of 15000 so I'll just leave it be for now.
```{r}
wr_minmaxs <- tar_read(motu_scn_mod) |>
bind_rows() |>
scan_filter() |>
unnest(cols = data) |>
# remove metadata for easier pivoting
select(-c(min, max, min_start_44, min_end_44,
min_start_45_49, min_end_45_49,
max_start, max_end)) |>
pivot_longer(cols = starts_with("min_"),
names_to = "min_mass",
values_to = "minimum") |>
mutate(mass = str_extract(min_mass, "\\d{2}"))
wr_minmaxs |>
ggplot(aes(x = max_44, y = minimum, #colour = mass,
label = scan_group,
file_id = file_id)) +
## geom_smooth(aes(group = mass), method = "lm", se = F) +
## geom_smooth(aes(group = mass), formula = y ~ x - 1, method = "lm", se = F, colour = "orange") +
## geom_smooth(aes(group = paste(scan_group, mass), colour = scan_datetime),
## formula = y ~ poly(x, 2, raw = TRUE) - 1,
## method = "lm", se = F, alpha = .2) +
geom_smooth(aes(group = paste(scan_group, mass),
colour = scan_datetime),
formula = y ~ poly(x, 3, raw = TRUE),
method = "lm", se = F, alpha = .2,
data = wr_minmaxs |> filter(!outlier_scan_manual)) +
geom_point(aes(alpha = outlier_scan_manual, colour = scan_datetime),
size = 3) +
sam +
## geom_abline(aes(slope = slope, intercept = intercept, colour = scan_datetime),
## data = wr_lines,
## alpha = .1) +
## geom_hline(yintercept = -500, colour = "red") +
facet_wrap(vars(mass), scales = "free_y")
```
## Weird Scans
I think by now I've adjusted all the ranges to match all the WR scans that had weird slopes before, remainder may be from contamination (e.g. 190619 etc.)
```{r}
weird_scans <- c(#"17April2018", # problematic ones
## "22November2017", ## "17April2018", # large shift in x, even after correcting off from remainder
## "190415" # this run has very different ETH-1 and ETH-2, but appears normal here
## this whole period has very weird scans, machine contaminated with corals? continues probably until 2019-07-02
## "14March2018", "16March2018", "19March2018", "21March2018", "22March2018", "23March2018"
## "17April2018"
## "14September2018"
#"190130"
## "190619"## ,
## "190621",
## "190624",
## "190625",
## "190627",
## "190628", ## between 2020-01-03 and 2020-04-07 there is larger scatter than usual!
## "200213", # not as bad as before anymore after adjusting ranges
## "200302",
## "200831", # is higher than bracketing scans
## "200901", # is higher than bracketing scans
## "200903" # is higher than bracketing scans
## "201216", # fixed after adjusting scan range
## "201223", # maybe a bit low?
## "210104",
## "210107", # fixed after adjusting scan range
## "210114",
## "210115" # a little high but they all are
"220207",
"211112"
)
tar_read(motu_scn_fix) |>
bind_rows() |>
tidylog::filter(scan_group %in% weird_scans) |>
pivot_longer(cols = v44.mV:v49.mV,
names_to = "mass",
values_to="intensity") |>
ggplot(aes(x = x, y = intensity,
colour = mass,
# below aesthetics don't do anything, but assigning them
# is useful: if you make this plot interactive, all the
# aesthetics will show up on hovering a point!
sg = scan_group,
fi = file_id,
fd = file_datetime,
fs = fix_software,
o = outlier_scan_manual)) +
geom_line(aes(group = paste(file_id, mass, voltage))) +
# sam = scale_alpha_manual(...) defined in libraries.R
sam +
geom_vline(aes(xintercept = value),
data = tar_read(motu_scn_mod) |>
bind_rows() |>
filter(scan_group %in% weird_scans) |>
unnest(data) |>
distinct(min_start_44, min_end_44, min_start_45_49, min_end_45_49, max_start, max_end) |>
pivot_longer(cols = c(starts_with("min"), starts_with("max")))) #+
## facet_wrap(vars(scan_group))
```
# Inspect the metadata
## Analysis
Are all the files represented in the metadata file?
```{r}
mm <- tar_read(motu_metadata) |> bind_rows()
mi <- tar_read(motu_file_info) |> bind_rows()
c(analysis = all(mm$Analysis %in% mi$Analysis), file_id = all(mm$file_id %in% mi$file_id))
```
## file_id
which file_id's that are in the metadata are not in the file info?
These rows need to be deleted from the ~motu_metadata_parameters~ excel file
```{r}
mm |> tidylog::filter(!file_id %in% mi$file_id)
```
## which file_id's that are in the file info are not in the metadata?
These need to be added to the metadata
```{r}
# motu info, filtered for those file_id's that are NOT in motu_metadata
mi |> tidylog::filter(!file_id %in% mm$file_id | !Analysis %in% mm$Analysis) |>
# copied from export_metadata
rename(c("manual_outlier" = "outlier_manual")) |>
tidylog::select(all_of(c("Analysis",
"file_id",
"file_root",
"file_subpath",
"file_path",
"file_datetime",
"file_size",
"Row",
"Peak Center",
"Background",
"Pressadjust",
"Reference Refill",
"Line",
"Sample",
"Weight [mg]",
"Identifier 1",
"Identifier 2",
"Comment",
"Preparation",
"Method",
# new columns!
"ref_mbar",
"ref_pos",
"bellow_pos_smp",
"init_int",
"background",
"PC",
"VM1_aftr_trfr",
"CO2_after_exp",
"no_exp",
"total_CO2",
"p_gases",
"p_no_acid",
"extra_drops",
"leak_rate",
"acid_temperature",
"MS_integration_time.s",
"timeofday",
"d13C_PDB_wg",
"d18O_PDBCO2_wg",
# /new columns
"s44_init",
"r44_init",
# more new parms columns
## "bg_group",
"scan_group",
"scan_datetime",
"scan_files",
"scan_n",
"bg_fac",
"dis_min", "dis_max", "dis_fac", "dis_rel",
"init_low", "init_high", "init_diff",
"p49_crit",
"prop_bad_param49",
"prop_bad_cyc",
"sd_D47", "sd_d13C", "sd_d18O",
"off_D47_min", "off_D47_max", "off_D47_grp", "off_D47_width", "off_D47_stds",
"off_d13C_min", "off_d13C_max", "off_d13C_grp", "off_d13C_width", "off_d13C_stds",
"off_d18O_min", "off_d18O_max", "off_d18O_grp", "off_d18O_width", "off_d18O_stds",
"etf_stds", "etf_width",
"acid_fractionation_factor",
"temperature_slope", "temperature_intercept",
# /parms columns
"manual_outlier",
"Preparation_overwrite",
"Identifier 1_overwrite",
"Identifier 2_overwrite",
"Weight [mg]_overwrite",
"Comment_overwrite",
"scan_group_overwrite",
"Mineralogy",
"checked_by",
"checked_date",
"checked_comment"))) |>
writexl::write_xlsx("out/more_motu.xlsx")
```
## preparation assignment
Did we fix all the run number assignments when they were entered incorrectly? (Often we forgot to update the field in the sequence, but we did update the filenames.)
```{r}
tar_read(motu_badruns) |>
tidylog::left_join(tar_read(motu_metadata) |>
select(file_id, Preparation_overwrite))
```
This should be empty if all runs have been assigned correct run numbers
```{r}
tar_read(motu_temperature) |>
group_by(preparation) |>
## group_by(Preparation) |>
mutate(mn = min(file_datetime), mx = max(file_datetime)) |>
## filter(mn > mx)
distinct(preparation, .keep_all = TRUE) |>
select(file_id, Preparation, preparation, mn, mx) |>
tidylog::mutate(wrong = mx > lag(mn) | mn < lead(mx)) |>
## filter(preparation != Preparation)
tidylog::filter(wrong) |>
glimpse()
## tidylog::filter(preparation %in% 85:87) |>
```
# All Raw Cycles
These become slow pretty quickly, adjust your `measurement_filter`!
```{r}
tar_read(motu_raw_deltas) |>
bind_rows() |>
# NOTE: raw delta's doesn't have file_datetime, so need to filter in another way. This is the first measurement in 2022
filter(Analysis >= 24653L) |>
add_count(file_id, Analysis) |>
#mutate(Analysis = parse_double(Analysis)) |>
select(-scan_files) |>
rename(cycle_outlier_temp = outlier) |>
tidylog::left_join(tar_read(motu_temperature) |>
bind_rows()) |>
mutate(out = cycle_outlier_temp | outlier) |>
## filter(!cycle_has_drop) |> # i've checked the dropped cycles now, they seem good. This shows the remainder. Did I miss anything?
## filter(!cycle_outlier_temp, !outlier) |>
## pivot_longer(cols = c(r44:s54, s45_bg:r49_bg), names_to = "mass", values_to = "intensity") |>
## glimpse()
ggplot(aes(x = cycle, group = paste(file_id, Analysis),
a = Analysis, alpha = out,
colour = broadid)) +
## gghighlight(cycle_has_drop_s44) +
geom_line(aes(y = s44), alpha = .4) +
## gghighlight(cycle_has_drop_r44) +
geom_line(aes(y = r44), alpha = .4) +
sam +
facet_grid(cols = vars(n), rows = vars(out),
scales = "free", space = "free") + theme(legend.pos = "top")
```
## initial intensity outliers
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = s44_init,#init_int,
colour = broadid, alpha = outlier,
a = Analysis, fi = file_id,
ro = reason_for_outlier)) +
sam +
geom_point() +
geom_rug(aes(y = NULL),
data = tar_read(motu_temperature) |>
measurement_filter() |>
filter(is.na(s44_init)),
colour = "red", show.legend = FALSE) +
geom_hline(yintercept = tar_read(motu_temperature) |>
measurement_filter() |>
distinct(init_low, init_high) |> unlist())
```
### difference in initial intensity outliers
```{r}
tar_read(motu_temperature) |>
## filter(file_id %in% wr_ss$file_id) |>
measurement_filter() |> # the whole range for Robin van der Ploeg's MECO runs
ggplot(aes(x = file_datetime, y = s44_init - r44_init, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
sam +
geom_point() +
# here I plot it as the diff, but in the calculations I use abs(s44 - r44)
geom_hline(yintercept = tar_read(motu_temperature) |>
distinct(init_diff) |> unlist() * c(-1, 1)) +
coord_cartesian(ylim = c(-3000, 3000))
```
# Measurement Info
Plot all the stuff from IsoDat.
## acid temperature
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = acid_temperature, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
## ref_mbar
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = ref_mbar, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
```
## ref_pos
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = ref_pos, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
## bellow_pos_smp always 100
```{r}
tar_read(motu_temperature) |>
ggplot(aes(x = file_datetime, y = bellow_pos_smp, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() #+
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
## init_int : not more informative than s44_init or r44_init
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = init_int, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
## background always NA
```{r}
tar_read(motu_temperature) |>
ggplot(aes(x = file_datetime, y = background,
colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() #+
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
## PC : peak centre
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = PC, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
this peak center PC is the same as the `step` in the scan data! So we can see where it does the peak centering in the scans for comparison.
Seems like it might be a bit too much to the right for the latest measurements?
```{r}
tar_read(motu_scn_fix) |>
bind_rows() |>
scan_filter() |>
pivot_longer(v44.mV:v49.mV, names_to = "mass", values_to = "intensity") |>
ggplot(aes(x = x, y = intensity, colour = mass)) +
geom_line(aes(group = paste(file_id, voltage, mass))) +
#geom_vline(xintercept = c(9.392386, 9.39527, 9.424277, 9.429723, 9.463, 9.466)) +
scale_x_continuous(breaks = seq(0, 10, 0.01),
minor_breaks = seq(0, 10, 0.001)) +
coord_cartesian(ylim = c(-500, 200))
## geom_vline(xintercept=c(62100, 62130), colour = "red") # manually entered the range in the last period
```
make sure that we have set a nice range similar to the PC here
```{r}
library(patchwork)
(tar_read(motu_temperature) |>
ggplot(aes(x = file_datetime, y = PC, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point()) /
(ggplot(tar_read(motu_scn_meta), aes(x = file_datetime, y = min_start_45_49, alpha = manual_outlier, label = scan_group)) + geom_point() + geom_point(aes(y = min_end_45_49))) /
(ggplot(tar_read(motu_scn_meta), aes(x = file_datetime, y = max_start, alpha = manual_outlier, label = scan_group)) + geom_point() + geom_point(aes(y = max_end)))
```
**** VM1_aftr_trfr
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = VM1_aftr_trfr, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam #+
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(NA, 200))
```
**** CO2_after_exp
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = CO2_after_exp, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier
)) +
geom_point() +
## gghighlight(VM1_aftr_trfr > 0) +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** COMMENT no_exp always 0
```{r}
tar_read(motu_temperature) |>
ggplot(aes(x = file_datetime, y = no_exp, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() #+
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** total_CO2
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = total_CO2, colour = broadid, alpha = outlier,
## a = Analysis, fi = file_id, ro = reason_for_outlier
)) +
geom_point() +
## gghighlight(VM1_aftr_trfr > 0) +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** total_CO2 vs initial intensity
```{r}
tar_read(motu_temperature) |>
#measurement_filter() |>
ggplot(aes(x = init_int, y = total_CO2, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier
)) +
geom_point() +
sam #+
#scale_y_log10()
```
**** total_CO2 vs weight
```{r}
tar_read(motu_temperature) |>
#measurement_filter() |>
filter(broadid != "other") |>
ggplot(aes(x = `Weight [mg]`, y = total_CO2, colour = broadid## factor(Line)
, alpha = outlier,
## a = Analysis, fi = file_id, ro = reason_for_outlier
)) +
geom_point() +
## gghighlight(file_datetime > as.POSIXct(ymd("2021-05-10"))) +
sam +
facet_grid(cols = vars(outlier)) +
geom_smooth(aes(group = "all"), method = "lm")
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** p_gases
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = p_gases, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** p_no_acid
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = p_no_acid, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
sam
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** extra_drops
```{r}
tar_read(motu_temperature) |>
ggplot(aes(x = file_datetime, y = extra_drops, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() #+
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
**** leak rates
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = leak_rate, ## colour = Row,
alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() +
geom_hline(yintercept = 900) + # I think this is when it cancels the sample/stops the run?
geom_smooth(aes(group = Line)) +
sam +
facet_grid(rows = vars(Line))
```
**** MS_integration_time.s
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = MS_integration_time.s, colour = broadid, alpha = outlier,
a = Analysis, fi = file_id, ro = reason_for_outlier)) +
geom_point() #+
## coord_cartesian(xlim = as.POSIXct(c(ymd("2021-05-10"), today())), ylim = c(65, NA))
```
# Raw Data
## raw D47
```{r}
pl_D47raw <- tar_read(motu_temperature) |>
measurement_filter() |>
arrange(file_id, Analysis, file_datetime) |>
ggplot(aes(x=file_datetime,
y=D47_raw_mean,
## shape = outlier_param49,
ymin=D47_raw_mean-D47_raw_sd,
ymax=D47_raw_mean+D47_raw_sd,
col=broadid,
file_id = file_id,
Analysis = Analysis,
preparation = preparation,
sg = scan_group,
reason_for_outlier = reason_for_outlier,
alpha=outlier)) +
## # annotate logbook issues etc.
## geom_vline(aes(xintercept = datetime,
## n = Name,
## p = `Samples (Name, material, #)`,
## label = `Comments (issues, observations, maintenance):`),
## data = tar_read(motu_log), alpha = .2, colour = "gray3") +
## geom_text(aes(x = datetime, y = .2, label = Name),
## hjust = 0, size = 3,
## inherit.aes = FALSE,
## data = tar_read(motu_log), alpha = .2, colour = "gray3") +
## geom_vline(aes(xintercept = Date,
## n = Name,
## p = `Problem (issues, observations):`,
## a = Actions),
## data = tar_read(motu_maintenance)) +
## geom_pointrange() +
# annotate measurements that didn't get a D47_raw_mean value
geom_rug(sides = "b", data = ## wr_ss
tar_read(motu_temperature) |>
filter(is.na(D47_raw_mean)) |>
measurement_filter()
) + # annotate failed measurements
# vertical lines for each scan start
geom_vline(aes(xintercept = scan_datetime, sg = scan_group, bgg = bg_group),
colour = "cyan", alpha = .3,
data = tar_read(motu_temperature) |>
measurement_filter() |>
distinct(scan_datetime, .keep_all = TRUE)
) +
# segments for each preparation (is nicest for interactive graph)
geom_segment(aes(x = mn, xend = mx, y = 0.2, yend = 0.2, prep = preparation),
alpha = .4, size = 2,
inherit.aes = FALSE,
data = tar_read(motu_temperature) |>
measurement_filter() |>
group_by(preparation) |>
summarize(mn = min(file_datetime), mx = max(file_datetime))
) +
# the data itself
geom_errorbar(aes(ymin = D47_raw_lwr, ymax = D47_raw_upr)) +
geom_point() +
geom_line(aes(group = broadid)) +
# customize the plot legends etc.
scale_alpha_manual(values=c("TRUE" = 0.2, "FALSE" = 1)) +
labs(y = "Raw Δ47")
pl_D47raw
```
I've added logbook and maintenance notes (commented out now), this makes this full-view figure very useless, but this is great for the interactive version of the plot.
## raw D48
```{r}
pl_D48raw <- tar_read(motu_temperature) |>
measurement_filter() |>
filter(!outlier, broadid == "IAEA-C2", # file_datetime > as.POSIXct("2021-04-01")
) |>
arrange(file_id, Analysis, file_datetime) |>
ggplot(aes(x=file_datetime,
y=D48_raw_mean,
## shape = outlier_param49,
ymin=D48_raw_mean-D48_raw_sd,
ymax=D48_raw_mean+D48_raw_sd,
col=broadid,
file_id = file_id,
Analysis = Analysis,
preparation = preparation,
sg = scan_group,
reason_for_outlier = reason_for_outlier,
alpha=outlier)) +
## geom_vline(aes(xintercept = datetime,
## n = Name,
## p = `Samples (Name, material, #)`,
## label = `Comments (issues, observations, maintenance):`),
## data = tar_read(motu_log), alpha = .2, colour = "gray3") +
## geom_text(aes(x = datetime, y = .2, label = Name),
## hjust = 0, size = 3,
## inherit.aes = FALSE,
## data = tar_read(motu_log), alpha = .2, colour = "gray3") +
## geom_vline(aes(xintercept = Date,
## n = Name,
## p = `Problem (issues, observations):`,
## a = Actions),
## data = tar_read(motu_maintenance)) +
## geom_pointrange() +
## geom_rug(sides = "b", data = ## wr_ss
## tar_read(motu_temperature) |> filter(is.na(D47_raw_mean))
## ) +
# annotate failed measurements
geom_point() +
geom_line(aes(group = broadid)) +
## gghighlight(.data$file_id %in% wr_ss$file_id) +
scale_alpha_manual(values=c("TRUE" = 0.2, "FALSE" = 1)) +
labs(y = "Raw Δ48") +
geom_hline(yintercept = c(-1, 1))
pl_D48raw
```
# Background Factors
## what are the bg factors?
```{r}
tar_read(motu_metadata) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = bg_fac, fi = file_id, a = Analysis)) +
geom_point() #+
## coord_cartesian(ylim = c(0, 1))
```
## background factors from final averages
We can calculate this already at the raw_cycle level so that we do not have to do unnecessary computations for bad bg factors.
This does mean we have to redo some simple house-keeping, i.e. getting ETH-1 and ETH-2 filtered out somehow.
```{r}
pl_bgc <- tar_read(motu_temperature) |>
measurement_filter() |>
filter(broadid %in% c("ETH-1", "ETH-2", "Merck")) |>
# cut up into monthly/yearly slices and tweak factor accordingly?
ggplot(aes(x = file_datetime, y = D47_raw_mean,
colour = broadid, alpha = outlier, #label = reason_for_outlier,
fi = file_id, A = Analysis,
s4 = s44_init, r4 = r44_init,
p49 = param_49_mean, p = preparation)) +
geom_point() +
sam +
## # a simple loess fit
## geom_smooth(aes(linetype = outlier, group = broadid), method = "loess", se = F, span = .1,
## data = tar_read(motu_temperature) |>
## filter(!outlier, broadid %in% c("ETH-1", "ETH-2"))) +
## # a weekly average line
## stat_summary(aes(x = summ, group = broadid), geom = "line",
## alpha = .4, size = 2,
## data = tar_read(motu_temperature) |>
## filter(# Analysis %in% wr_ss$Analysis,
## broadid %in% c("ETH-1", "ETH-2"), !outlier) |>
## mutate(summ = lubridate::floor_date(file_datetime, "week"))
## ) +
# a line through all the preparation averages
stat_summary(aes(x = summ, group = broadid), geom = "line",
alpha = .4, #size = 2,
data = tar_read(motu_temperature) |>
measurement_filter() |>
filter(# Analysis %in% wr_ss$Analysis,
broadid %in% c("ETH-1", "ETH-2"), !outlier) |>
group_by(preparation) |>
mutate(summ = mean(file_datetime))
) +
# segments for each preparation (is nicest for interactive graph)
stat_summary(aes(x = mn, xend = mx, group = broadid), geom = "segment",
alpha = .4, size = 2,
fun.data = ~ data.frame(y = mean(.x, na.rm = TRUE), yend = mean(.x, na.rm = TRUE)),
data = tar_read(motu_temperature) |>
measurement_filter() |>
group_by(preparation) |>
mutate(summ = mean(file_datetime), mn = min(file_datetime), mx = max(file_datetime)) |>
filter(# Analysis %in% wr_ss$Analysis,
broadid %in% c("ETH-1", "ETH-2"), !outlier)
) +
geom_point(aes(y = bg_fac / 10 - .7), colour = "black",
data = tar_read(motu_temperature) |>
measurement_filter()) #+
#coord_cartesian(ylim = c(-.74, -.07))
pl_bgc
```
for the interval between 2020-01 and 2020-11 I've first tried changing the bg factor from:
- 0.9 (default for rest)
- 1.0 seems to make it a lot better!
- 0.7 made them move very far apart
this is quite slow to calculate so I only tried a few. Note that perhaps the BG fac should be changed to 1 also for the most recent runs!
for the one interval that's acting up weird (end of 2019) we currently tried:
bg factor (sorted by factor in the end)
- 0.7 ETH-2 is lower than ETH-1
- 0.8: ETH-2 is lower than ETH-1, farther apart.
- 0.85: ETH-2 is still lower than ETH-1, but they're much closer
- 0.9 (default) ETH-1 is XXX than ETH-2 (forgot :O)
- 0.91 (so that I can still search and replace if I need to change these values): now they're great, but they cross near 5402
- 0.99 ETH-1 is lower than ETH-2, but closer. So perhaps I just overshot it with 0.7?
for the youngest part (since 15089 until 21275), I have overshot it a bit with the bg fac of
- 1: ETH-1 is slightly lower than ETH-2
- 0.95: now ETH-2 is lower during
then I tweaked some more parts where it seemed obvious that for several runs one of the two was higher/lower than the other.
**** did these issues get fixed in final values?
```{r}
## pl_bgc <- #wr_raw_ss |>
library(patchwork)
tar_read(motu_temperature) |>
measurement_filter() |>
filter(## Analysis %in% wr_ss$Analysis,
broadid %in% c("ETH-1", "ETH-2")) |>
ggplot(aes(x = file_datetime, y = D47_final,
colour = broadid, alpha = outlier,
label = reason_for_outlier,
fi = file_id, A = Analysis,
s4 = s44_init, r4 = r44_init,
p49 = param_49_mean, f = bg_fac)) +
geom_point() +
geom_point(aes(y = bg_fac / 10), colour = "black",
data = tar_read(motu_temperature)) +
sam +
## geom_smooth(aes(group = broadid), method = "loess", se = F, span = .3,
## data = # wr_raw_ss |> filter(!is.na(outlier_manual) & !outlier_manual)
## tar_read(motu_temperature) |>
## filter(## Analysis %in% wr_ss$Analysis,
## broadid %in% c("ETH-1", "ETH-2"), !outlier)
## ) +
stat_summary(aes(x = summ, group = broadid), geom = "line",
alpha = .4,
data = tar_read(motu_temperature) |>
filter(# Analysis %in% wr_ss$Analysis,
broadid %in% c("ETH-1", "ETH-2"), !outlier) |>
group_by(preparation) |>
mutate(summ = mean(file_datetime))
) +
stat_summary(aes(x = mn, xend = mx, group = broadid), geom = "segment",
alpha = .4, size = 2,
fun.data = ~ data.frame(y = mean(.x, na.rm = TRUE), yend = mean(.x, na.rm = TRUE)),
data = tar_read(motu_temperature) |>
group_by(preparation) |>
mutate(summ = mean(file_datetime), mn = min(file_datetime), mx = max(file_datetime)) |>
filter(# Analysis %in% wr_ss$Analysis,
broadid %in% c("ETH-1", "ETH-2"), !outlier)
) +
coord_cartesian(ylim = c(0., .45))
```
**** what does the final d47 vs D47 plot look like?
```{r}
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = d47_mean, y = D47_raw_mean,
colour = broadid, alpha = outlier,
label = reason_for_outlier,
fi = file_id, A = Analysis,
s4 = s44_init, r4 = r44_init, p49 = param_49_mean, f = bg_fac)) +
geom_point() +
sam +
ggnewscale::new_scale_colour() +
stat_smooth(aes(group = preparation, colour = bg_fac),
geom = "line", method = "lm", se = F, alpha = .3,
data = # wr_raw_ss |> filter(!is.na(outlier_manual) & !outlier_manual)
tar_read(motu_temperature) |>
measurement_filter() |>
filter(## Analysis %in% wr_ss$Analysis,
broadid %in% c("ETH-1", "ETH-2"), !outlier)
) #+
# coord_cartesian(xlim = c(-40, 22), ylim = c(-.7, .15))
```
the bottom line that's sloped downward (lower ETH-1 than ETH-2) is preparation 447 \to it's bg_fac should be changed from 0.95 to 0.91
# Critical P49
*** motu
```{r}
pl_p49 <- tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = param_49_mean, colour = broadid,
alpha = outlier, label = reason_for_outlier,
fi = file_id, a = Analysis)) +
## geom_vline(aes(xintercept = datetime,
## n = Name,
## p = `Samples (Name, material, #)`,
## label = `Comments (issues, observations, maintenance):`),
## data = tar_read(motu_log), alpha = .2, colour = "gray3") +
## geom_vline(aes(xintercept = Date,
## n = Name,
## p = `Problem (issues, observations):`,
## a = Actions),
## data = tar_read(motu_maintenance), alpha = .4) +
geom_point() +
geom_line(aes(group = broadid)) +
scale_alpha_manual(values=c("TRUE" = 0.2, "FALSE" = 1)) +
geom_hline(yintercept = tar_read(motu_temperature) |> distinct(p49_crit) |> pull(p49_crit) * c(-1, 1)) +
geom_hline(yintercept = c(-.3, -.2, .2, .3), colour = "red") +
coord_cartesian(ylim = c(-1, 1))
pl_p49
```
# SDx4
** standard deviations of individual measurements
## d13C
we can also calculate the average standard deviation and multiply it by 4 to find a very very weak criterion
```{r}
motu_d13C_weak <- tar_read(motu_temperature) |>
measurement_filter() |>
## tidylog::filter(!is.na(outlier_init), !outlier_init, !is.na(outlier_cycles), !outlier_cycles) |>
tidylog::filter(!outlier) |>
pull(d13C_PDB_sd) |>
median()
tar_read(motu_temperature) |>
measurement_filter() |>
ggplot(aes(x = file_datetime, y = d13C_PDB_sd, colour = broadid, alpha = outlier, label = reason_for_outlier,
a = Analysis, fi = file_id, s4i = s44_init, r4i = r44_init, p49 = param_49_mean)) +
geom_point() +
scale_alpha_manual(values=c("TRUE" = 0.2, "FALSE" = 1)) +
geom_hline(yintercept = tar_read(motu_temperature) |> distinct(sd_d13C) |> pull(sd_d13C)) +
geom_hline(yintercept = motu_d13C_weak * c(1, 2, 3, 4), colour = "red") +
coord_cartesian(ylim = c(0, .2))
```
## d18O