EPGminer Example Workflow
EPGminerReprex.Rmd
The following R code is illustrative of how to use this software on our data to reproduce calculations. In essence, data and annotations are read in using the read_epg data function. The label_ana function is used to combine the raw data and annotation files. Then wave_topfreq and wave_volts are used to calculate frequency and relative amplitude of volts respectively.
library(epgminer)
# The time needed to run this script is dependent on the number of datasets
# load necessary packages
library(tidyverse)
library(epgminer)
# Set working directory to folder containing dataset folders and ANA files
folder <- "insert_here"
setwd(folder)
# list out ANA files
label <- list.files(pattern = ".ANA")
# Read all datasets into a list
raw_dat <- list()
lab_dat <- list()
for (i in 1:length(label)) {
# find specified raw hourly files
set <- str_sub(label[i], end = -5)
# read in the specified dataset
raw_dat[[i]] <- paste(set, "/", list.files(paste(set, "/", sep = "")), sep = "") %>%
map_df(~epgminer::read_epg(.))
}
# for each dataset, combine raw and ANA
for (i in 1:length(label)) {
ana <- epgminer::read_epg(label[i], extension = "ANA")
# lab dat contains fully labeled tibble - time, volts, wavform
# to be used for metrics
lab_dat[[i]] <- epgminer::label_ana(raw_dat[[i]], ana)
# track when data has been labeled
print(i)
}
# Now calculate top frequencies for each waveform
for (i in 1:length(lab_dat)) {
set <- str_sub(label[i], end = -5)
# returns tibble with waveform, frequency columns
# pds (subform independent) are on bottom
out <- epgminer::wave_topfreq(lab_dat[[i]])
# save frequency results in a csv
write.table(out, file = paste(set, "_frequencies.csv", sep = ""),
row.names = FALSE, col.names = TRUE, sep = ",")
# track table writing
print(paste(set, "_frequencies.csv", sep = ""))
}
# voltage metrics ----
for (i in 1:length(lab_dat)) {
set <- str_sub(label[i], end = -5)
# returns tibble with waveform, duration columns
# pds (subform independent) are on bottom
out <- epgminer::wave_volts(lab_dat[[i]])
# save results in a csv
write.table(out, file = paste(set, "_volts.csv", sep = ""),
row.names = FALSE, col.names = TRUE, sep = ",")
# track table writing
print(paste(set, "_volts.csv", sep = ""))
}