-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloc-01-setup.Rmd
191 lines (124 loc) · 4.84 KB
/
loc-01-setup.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
---
title: "loc-01-setup"
author: "Kate Morkeski"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## load libraries
```{r}
library(here)
library(lubridate)
library(tidyverse)
```
## read in GPS and other underway data
```{r}
combined <- read_delim(here('LOC-01_Combined_Nav_TSG_Fluo_HydroFIA.txt'))
combined$DateTime_UTC <- as.POSIXct(combined$DateTime_UTC, tz = "UTC", format="%d-%b-%Y %H:%M:%OS")
met <- read_delim(here('Metdat.dat'), skip = 1)
pressure <- met |> select(TIMESTAMP, BaroPress)
pressure <- pressure |> rename(BaroPress_hPa = BaroPress)
pressure <- pressure[-1,]
pressure <- pressure[-1,]
#format columns as date and time for later interpolation
pressure$TIMESTAMP <- as.POSIXct(pressure$TIMESTAMP, tz = "UTC", format="%Y-%m-%d %H:%M:%OS")
pressure$BaroPress_hPa <- as.double(pressure$BaroPress_hPa)
```
```{r}
ggplot(combined, aes(x = DateTime_UTC, y = Temp1_C)) +
geom_point() +
theme_minimal()
ggplot(combined, aes(x = DateTime_UTC, y = Temp2_C)) +
geom_point() +
theme_minimal()
ggplot(combined, aes(x = DateTime_UTC, y = Corrected_TA_umol_kg_)) +
geom_point() +
theme_minimal()
ggplot(pressure, aes(x = TIMESTAMP, y = BaroPress_hPa)) +
geom_line() +
theme_minimal()
```
```{r}
# read in GO data
GOfiles <- dir(here("LOC-01_GO-Data/"), "*.txt") # get file names
GO_LOC01 <- GOfiles %>% map_dfr(~ read_tsv(here("LOC-01_GO-Data/", .), show_col_types = FALSE, ))
```
```{r}
# handle date and time columns
# combine date and time
GO_LOC01$PcDate <- as.character(GO_LOC01$PcDate)
GO_LOC01$PcTime <- as.character(GO_LOC01$PcTime)
#GO_LOC01$PcTime <- as.character(GO_LOC01$PcTime)
GO_LOC01$date_time <- paste(GO_LOC01$PcDate, GO_LOC01$PcTime)
GO_LOC01$date_time_utc <- as.POSIXct(GO_LOC01$date_time, tz = "UTC", format="%d/%m/%y %H:%M:%OS")
ggplot(GO_LOC01, aes(x = date_time_utc, y = EquPress)) +
geom_point() +
theme_minimal()
ggplot(GO_LOC01, aes(x = date_time_utc, y = CO2ppm)) +
geom_point() +
theme_minimal()
```
# Interpolate CTD data to GO timestamps
```{r}
Lat <- data.frame(approx(combined$DateTime_UTC, combined$Latitude, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
latitude <- Lat$y
Lon <- data.frame(approx(combined$DateTime_UTC, combined$Longitude, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
longitude <- Lon$y
dye <- data.frame(approx(combined$DateTime_UTC, combined$Dye_ppb, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
dye_ppb <- dye$y
Temp1_C <- data.frame(approx(combined$DateTime_UTC, combined$Temp1_C, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
temp1_C <- Temp1_C$y
Temp2_C <- data.frame(approx(combined$DateTime_UTC, combined$Temp2_C, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
temp2_C <- Temp2_C$y
sal <- data.frame(approx(combined$DateTime_UTC, combined$Salinity_PSU, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
salinity_psu <- sal$y
alk <- data.frame(approx(combined$DateTime_UTC, combined$Corrected_TA_umol_kg_, xout = GO_LOC01$date_time_utc, rule = 2, method = "linear"))
alkalinity_umolkg <- alk$y
press <- data.frame(approx(pressure$TIMESTAMP, pressure$BaroPress_hPa, xout = GO_LOC01$date_time_utc, rule = 1, method = "linear"))
atm_pressure_hPa <- press$y
GO_LOC01 <- cbind(GO_LOC01, latitude, longitude, atm_pressure_hPa, dye_ppb, temp1_C, temp2_C, salinity_psu, alkalinity_umolkg)
```
# Inspect interpolated ancillary data
```{r}
ggplot(GO_LOC01, aes(x = date_time_utc, y = temp1_C)) +
geom_point() +
theme_minimal()
ggplot(GO_LOC01, aes(x = date_time_utc, y = temp2_C)) +
geom_point() +
theme_minimal()
ggplot(GO_LOC01, aes(x = date_time_utc, y = salinity_psu)) +
geom_point() +
theme_minimal()
ggplot(GO_LOC01, aes(x = date_time_utc, y = alkalinity_umolkg)) +
geom_point() +
theme_minimal()
```
# Adjust columns and write csv
```{r}
GO_LOC01 <- GO_LOC01 |>
select(-date_time, -'N/A') |>
relocate(date_time_utc, .before = Type) |>
relocate(latitude, .before = Type) |>
relocate(longitude, .before = Type)
write.csv(GO_LOC01, here('GO_LOC01.csv'), row.names = FALSE)
```
# Add bottle salinity to CTD data set
```{r}
ctd_bottles <- read_csv(here('CTD_Bottles_combined.csv'))
#combined$DateTime_UTC <- as.POSIXct(combined$DateTime_UTC, tz = "UTC", format="%d-%b-%Y %H:%M:%OS")
sal <- read_delim(here('LOC-01_CTD_bottle_salinometer.txt'), col_names = FALSE)
# define headers for columns in desired order
sal <- sal |>
rename('Salinity bottle' = X1) |>
select(-X2) |>
rename(salinity_psu = X3) |>
rename(flag = X4)
ctd_bottles <- left_join(ctd_bottles, sal, by = 'Salinity bottle')
ggplot(ctd_bottles, aes(x = salinity_psu, y = Sal00)) +
geom_point() +
theme_minimal()
ggsave('ctd-vs-bottle-sal.png')
write.csv(ctd_bottles, here('CTD_Bottles_combined_bottlesal.csv'), row.names = FALSE)
```