knitr::opts_chunk$set(echo = TRUE)

golem::document_and_reload()

library(dplyr)
library(lubridate)
library(plotly)
library(readr)
library(sear)
library(tidyr)

Calibration data

BBFL2CalFile <- sear:::app_sys("cal", "bbfl2", "5745.cal")

BBFL2Cal <- sear:::read_bbfl2_cal()

Load data

# Station <- interval(ymd_hms("2022-07-05 12:23:13"), ymd_hms("2022-07-05 12:23:15"))
Station <- interval(ymd_hms("2022-07-05 12:23:00"), ymd_hms("2022-07-05 12:24:00"))

DataFile <- sear:::app_sys("extdata", "DATA_20220705_105732.txt")

MTELog <- sear:::read_mtelog(DataFile)

MTELog <- MTELog %>% filter(date_time %within% Station)

BBFl2_data <- sear:::read_bbfl2(MTELog)

Calibrate data

cal_bbfl2 <- function(BBFl2_data, BBFL2Cal) {
  BBFl2_data %>%
    mutate(
      ntu = BBFL2Cal$ntu_scale_factor * (ntu_channel - BBFL2Cal$ntu_dark_count),
      pe = BBFL2Cal$pe_scale_factor * (pe_channel - BBFL2Cal$pe_dark_count),
      pc = BBFL2Cal$pc_scale_factor * (pc_channel - BBFL2Cal$pc_dark_count)
    ) %>%
    select(date_time, ntu, pe, pc)
}

bbfl2_l1b <- cal_bbfl2(BBFl2_data, BBFL2Cal) %>%
  mutate(
    id = seq_along(rownames(BBFl2_data)),
    qc = "1"
  )

Plot data

L1b

BBFL2L1bNest <- bbfl2_l1b %>%
  pivot_longer(
    cols = any_of(c("ntu", "pe", "pc")),
    names_to = "parameter",
    values_to = "value"
  ) %>%
  group_by(parameter) %>%
  nest(Data = !matches("parameter"))


PlyFont <- list(family = "times New Roman", size = 18)
BlackSquare <- list(
  type = "rect",
  fillcolor = "transparent",
  line = list(width = 0.5),
  xref = "paper",
  yref = "paper",
  x0 = 0,
  x1 = 1,
  y0 = 0,
  y1 = 1
)


ply <- BBFL2L1bNest %>%
  mutate(
    Plot = purrr::map2(.x = Data, .y = parameter, ~
      plot_ly(.x, text = ~id) %>%
        add_markers(x = ~date_time, y = ~value) %>%
        layout(
          shapes = BlackSquare,
          yaxis = list(title = list(text = .y))
        ))
  )


# format(SBE19nest[[2]][[1]]$date_time, "%Y-%m-%d %H:%M:%OS3")

subplot(ply$Plot, nrows = nrow(BBFL2L1bNest), shareX = TRUE, titleY = TRUE)


raphidoc/sear documentation built on April 14, 2025, 2:13 a.m.