-
Notifications
You must be signed in to change notification settings - Fork 0
/
standardizeKeys.Rmd
147 lines (102 loc) · 2.73 KB
/
standardizeKeys.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
---
title: "lipd Values standardization with ISO2k"
author: "Dave Edge"
date: "2023-01-13"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
devtools::load_all()
```
###Load Data
First we grab the ISO2k data and the standardization tables
```{r}
library(lipdR)
iso2k <- readLipd("https://lipdverse.org/iso2k/current_version/iso2k1_0_1.zip")
```
And now we'll convert that to a LiPD TS object
```{r}
TS <- as.lipdTs(iso2k)
```
First, update the metadata
```{r}
TS1 <- updateMetaDataFromStandardTables(TS, "paleoData_units")
```
This function produces an updated TS object as well as a data frame showing the changes
`standardizeValue()` looks for synonyms and replaces them with valid lipd names
```{r}
TS2 <- standardizeValue(lipdTS=TS1$TS, key="paleoData_units")
```
#This function also produces a data frame showing any changes
A quick sanity check
```{r}
isValidValue(TS2$TS, "paleoData_units")
TS[[2]]$paleoData_units
TS2$TS[[2]]$paleoData_units
```
#Looks good
Finally we can update either `paleoData_notes` or `notes` with the changes made
```{r}
TS1 <- lipdR:::updateNotes(lipdTS=TS2$TS,
key = "paleoData_units",
metadataChangesDF=TS1$ChangesDF,
standardizeSynonymDF=TS2$synonymDF$synonymDF)
```
Let's have a look at some examples
unchanged
```{r}
TS[[1]]$paleoData_notes
TS1[[1]]$paleoData_notes
```
#Changed a peice of metadata
```{r}
TS[[2]]$paleoData_notes
TS1[[2]]$paleoData_notes
```
#Changed metadata and standardized value
```{r}
TS[[240]]$paleoData_notes
TS1[[240]]$paleoData_notes
```
Now let's try this for a more complicated key
```{r}
TS1 <- updateMetaDataFromStandardTables(TS, "interpretation_seasonality")
TS1
```
There is no metadata to update this time
Let's try standardizing
```{r}
TS2 <- standardizeValue(TS, "interpretation_seasonality")
```
We see a long string of output here, reflecting the 7 unique interpretation_seasonality keys
Let's have a look now
```{r}
a2 <- isValidValue(lipdTS=TS2$TS, key="interpretation_seasonality")
```
Cool, that took care of all of them
An example of values changed
```{r}
TS[[1851]]$interpretation5_seasonality
TS2$TS[[1851]]$interpretation5_seasonality
```
#Finally, the notes
#This is set up to be run once per interpretation, although the automation could be added
```{r}
TS1 <- lipdR:::updateNotes(lipdTS=TS2$TS,
standardizeSynonymDF=TS2$synonymDF[[1]]$synonymDF)
```
#before and after
```{r}
TS[[328]]$notes
TS1[[328]]$notes
```
#for interp 5
```{r}
TS1 <- lipdR:::updateNotes(lipdTS=TS2$TS,
standardizeSynonymDF=TS2$synonymDF[[5]]$synonymDF)
```
#before and after
```{r}
TS[[1851]]$notes
TS1[[1851]]$notes
```