-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_phase.Rmd
244 lines (180 loc) · 5.75 KB
/
add_phase.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
---
title: "Add phases after EPMA analysis"
author: "YASUMOTO Atsushi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Add phases after EPMA analysis}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
<!-- © 2018 JAMSTEC -->
```{r setup, include = FALSE}
wd <- tempdir()
knitr::opts_chunk$set(
root.dir = wd,
fig.width = 5,
fig.height = 5,
collapse = TRUE,
comment = "#>"
)
library(qntmap)
library(dplyr)
library(pipeR)
library(ggplot2)
```
# Intro
This document introduces a way to quantify X-ray map even if, in accident,
there are some phases without spot analysis.
For accurate analysis, I highly recommend careful observation prior to EPMA analysis,
so that as less phases as possible being missed.
Please read ["Get started"](qntmap.html) before hand.
# Preparation
This section prepares package, files, and modify sample data.
An original sample dataset is same as that used in ["Get started"](qntmap.html).
However, the dataset will be modified to let a phase be not analyzed by EPMA spot analysis.
This is why "[Specify directories containing data]" and "[Load Data]" belongs to "[Preparation]" despite
they belongs to [Analysis section of "Basic usage"](basic#Analysis).
## Load package
```{r load-qntmap, eval = FALSE}
library(qntmap)
```
## Move to working directory
```{r setwd, eval = FALSE}
wd <- tempdir() # Arbitrary
setwd(wd)
```
## Copy example data
or any original data.
```{r copy-example-data}
file.copy(
from = system.file('extdata', 'minimal', package = 'qntmap'),
to = wd,
recursive = TRUE
)
```
`TRUE` indicates files are successfully copied.
Check if really files are copied by `dir()`.
```{r check-file-structure}
dir(file.path(wd, 'minimal'), recursive = TRUE, all.files = TRUE)
```
## Specify directories containing data
```{r specify-paths, include = FALSE}
dir_map <- file.path(wd, 'minimal/.map/1')
dir_qnt <- file.path(wd, 'minimal/.qnt')
```
``` r
dir_map <- 'minimal/.map/1'
dir_qnt <- 'minimal/.qnt'
```
## Load data
```{r read-data, message = FALSE}
xmap <- read_xmap(dir_map)
qnt <- read_qnt(dir_qnt)
```
## Check quantified data
In the original dataet, 20 spots are analyzed by EPMA on both olivine and quartz.
```{r summarize-qnt}
table(qnt$cnd$phase)
```
## Modify data
Let's delete quartz from dataset and reload.
After `read_qnt()` is performed,
a file `phase_list0.csv` is created under working directory.
This file consists of 3 columns `id`, `phase`, and `use`.
Edit **only** `phase` and `use`. Do not edit `id`.
If certain phases have large compositional variations, fill `phase` column with
different names.
(e.g., Ol_Fe and Ol_Mg for Fe-rich olivine and Mg-rich olivine).
If certain analysis show bad results, fill `use` column with `FALSE`, otherwise `TRUE`.
To do it on R, execute codes below.
Be sure to specify a path to modified csv file to `phase_list` parameter of `read_qnt`.
Also, `renew` parameter of `read_qnt` must be `TRUE`.
```{r phase-list}
phase_list <- read.csv('phase_list0.csv')
phase_list$use[phase_list$phase == 'Qtz'] <- FALSE
write.csv(phase_list, file.path(dir_qnt, 'phase_list_no_qtz.csv'))
qnt <- read_qnt(dir_qnt, phase_list = file.path(dir_qnt, 'phase_list_no_qtz.csv'))
```
After editing, only olivine is said to be quantified.
```{r table-phase}
table(qnt$cnd$phase)
```
```{r plot-quantified-points, message = FALSE, echo = FALSE}
epma <- tidy_epma(qnt, xmap) %>>%
filter(elm == elm[[1]]) %>>%
select(x_px, y_px, phase)
plot(xmap, 'Si', interactive = FALSE, colors = "gray") +
geom_point(
aes(y_px, x_px, colour = phase),
data = epma, inherit.aes = FALSE
) +
guides(
fill = guide_colourbar(barheight = grid::unit(1, "npc") - unit(10, "line"))
)
```
# Analysis
## Cluster analysis
### Initialize cluster centers
```{r init-centers}
centers <- find_centers(xmap, qnt)
centers
```
### Compare the initial centroids with X-ray map plotted with heatmap
```{r plot-si}
plot(xmap, 'Si', interactive = FALSE)
```
In this case, an analysist will notice there is something other than olivine.
Let's mouse over the **interactive map** and one will see one of the coordinates of quartz (e.g., x = 18, y = 28).
Keep it on your note.
### Add initial centers
#### on R
Add initial centers by using `add_centers`.
```{r add-centers}
centers <- add_centers(centers = centers, xmap = xmap, x = 18, y = 28, p = 'Qtz')
```
Then, Qtz is properly added to `centers`.
```{r print-centers}
print(centers)
```
#### on Spreadsheet program + R
- Open `centers_initial0.csv` in the current directory (try `getwd()` on R if unknown).
- Edit it
- Save it
- Reload on R by `centers <- read.csv('path to an updated csv file')`
### Cluster and quantify
As Qtz is not quantified during spot analysis,
calibration curves for Qtz is substituted by results of regression analysis
without considering different phases.
Try "[Quasi-calibrations]" in case phases not quantified have known and
constant chemical compositions.
```{r quantify, fig.show = 'hide'}
cluster <- cluster_xmap(xmap, centers)
qmap <- quantify(xmap, qnt, cluster)
```
```{r summary}
summary(cluster)
summary(qmap)
```
#### Quasi-calibrations
In case phases without spot analysis have known chemical compositions,
their calibration curves can be calculated by
specifying their chemical compositions in csv format.
For example, prepare a csv file, and specify it to `fix` parameter of `quantify()`.
```{r csv}
csv <- paste(
'phase, oxide, wt',
'Qtz, SiO2, 100',
sep = "\n"
)
cat(csv)
```
```{r quantify2}
qmap2 <- quantify(xmap, qnt, cluster, fix = csv)
summary(qmap2)
```
Of course, `csv` parameter can be a path to a csv file,
unlike the above example, which gave csv data the `csv` parameter.
```{r on-exit-unlink, include = FALSE}
unlink(c('centers0.csv', 'center_add.csv'))
```