-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
171 lines (113 loc) · 4.29 KB
/
README.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
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
message = FALSE,
warning = FALSE
)
set.seed(0)
```
# wire <a href="https://yuhangtom.github.io/wire/"><img src="man/figures/logo.png" align="right" height="139" alt="wire website" /></a>
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main)
[![CRAN
status](https://www.r-pkg.org/badges/version/wire.png)](https://CRAN.R-project.org/package=wire)
[![Codecov test coverage](https://codecov.io/gh/YuhangTom/wire/branch/main/graph/badge.svg)](https://app.codecov.io/gh/YuhangTom/wire?branch=main)
[![R-CMD-check](https://github.com/YuhangTom/wire/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/YuhangTom/wire/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of `wire` is to provide a systematic reproducible automatic algorithm to analyze the similarity between wire cut scans.
# Installation
You can install the development version of wire from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("YuhangTom/wire")
```
# Usage
## Data
The original scans for the wire cuts are stored in `x3p` format of width around 2300 and height around 1800,
under a resolution $0.645 \mu m \times 0.645 \mu m$,
with each file being at least 15 MB,
which is much larger compared to the file limit of 5 MB for a `R` package.
Therefore,
we subsampled the original scans by a factor of 10,
and saved them as `x3p_subsamples` in the package.
The data can be used by:
```{r data}
library(wire)
x3p_subsamples
```
## Inner polygon
To remove the edge effect,
we extract the inner part of the scan,
which can be achieved by:
```{r insidepoly}
x3p <- x3p_subsamples[[1]]
insidepoly_df <- x3p_insidepoly_df(x3p, mask_col = "#FF0000", concavity = 1.5, b = 1, ifplot = TRUE)
attr(insidepoly_df, "x3p_plot")
attr(insidepoly_df, "number_of_missing_immediate_neighbors_plot")
attr(insidepoly_df, "standard_deviation_of_non_missing_immediate_neighbors_plot")
attr(insidepoly_df, "number_of_missing_immediate_neighbors_boxplot")
```
## Remove trend
To remove the overall trend on the inner surface,
we can use:
```{r rmtrend}
x3p_inner_nomiss_res <- df_rmtrend_x3p(insidepoly_df)
x3p_inner_nomiss_res
```
## Imputation
We can impute the missing values inside the surface by:
```{r impute}
x3p_inner_impute <- x3p_impute(x3p_inner_nomiss_res, ifout = TRUE, ifsave = FALSE, dir_name = NULL, ifplot = TRUE)
attr(x3p_inner_impute, "x3p_impute_0_plot")
attr(x3p_inner_impute, "x3p_impute_1_plot")
attr(x3p_inner_impute, "x3p_impute_n_plot")
```
## Rotation
We can rotate the surface to the correct angle by:
```{r rotate}
x3p_bin_rotate <- x3p_vertical(x3p_inner_impute, min_score_cut = 5, ifplot = TRUE)
attr(x3p_bin_rotate, "nfline_red_plot")
attr(x3p_bin_rotate, "MLE_loess_red_plot")
attr(x3p_bin_rotate, "nfline_blue_plot")
attr(x3p_bin_rotate, "MLE_loess_blue_plot")
```
## Signal extraction
To extract signals from the rotated surface,
two methods are provided,
implemented by
`wire::x3p_raw_sig_df`
and
`wire::x3p_shift_sig_df`,
respectively:
```{r signal}
raw_sig_df <- x3p_raw_sig_df(x3p_bin_rotate, ifplot = TRUE)
attr(raw_sig_df, "sig_df_plot")
shift_sig_df <- x3p_shift_sig_df(x3p_bin_rotate, ifplot = TRUE)
attr(shift_sig_df, "x3p_before_shift_plot")
attr(shift_sig_df, "x3p_after_shift_plot")
attr(shift_sig_df, "fn_align_plot")
attr(shift_sig_df, "MSE_plot")
attr(shift_sig_df, "sig_df_plot")
```
The signals and hooks can be further smoothed and removed by:
```{r ccsignals}
raw_ccsig_df <- df_ccsig(raw_sig_df, ifplot = TRUE)
attr(raw_ccsig_df, "sig_df_plot")
```
## Signal alignment
Extracted signals can be aligned,
and the cross-correlation can be computed:
```{r align}
aligned <- vec_align_sigs_list(raw_sig_df$sig, shift_sig_df$sig, ifplot = TRUE)
attr(aligned, "sig_align_plot")
```