read_distrometer <- function(file, pad_na = TRUE, ...) { unit_diameter <- c(120, 250, 375, 500, 750, 1000, 1250, 1500, 1750, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000) unit_velocity <- c(0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.4, 1.8, 2.2, 2.6, 3.0, 3.4, 4.2, 5.0, 5.8, 6.6, 7.4, 8.2, 9.0, 10.0) data_raw <- as.data.frame(data.table::fread(input = file, ...)) header <- data_raw[,1:68] time <- as.POSIXct(P$header$date_time, format = "%d.%m.%Y %H:%M", tz = "UTC") data_matrix <- as.matrix(data_raw[,69:508]) data_array <- numeric(length(data_matrix)) dim(data_array) <- c(nrow(data_matrix), 22, 20) i_diameter <- seq(from = 1, to = 440, by = 20) i_velocity <- 0:19 for(i in 1:22) { data_array[,i,] <- data_matrix[,i_diameter[i] + i_velocity] } velocity <- matrix(nrow = length(time), ncol = 20) diameter <- matrix(nrow = length(time), ncol = 22) for(i in 1:length(time)) { velocity[i,] <- colSums(data_array[i,,], na.rm = TRUE) diameter[i,] <- rowSums(data_array[i,,], na.rm = TRUE) } if(pad_na == TRUE) { data_array[data_array == 0] <- NA velocity[velocity == 0] <- NA diameter[diameter == 0] <- NA } data_out <- list(header = header, time = time, diameter = diameter, velocity = velocity, n = rowSums(velocity), unit_diameter = unit_diameter, unit_velocity = unit_velocity, data = data_array) return(data_out) } setwd(dir = "~/Documents/projects/Environmental_seismology/Uckermark") P <- read_distrometer(file = "data/distrometer/raw/1_complete_seismo.CSV", pad_na = FALSE) jpeg(filename = "figures/distrometer_data.jpg", width = 4000, height = 4000, res = 300) par(mfcol = c(3, 1)) image(x = P$time, y = P$unit_velocity, z = (P$velocity)^(1/10), main = "Velocity spectrum", xlab = "Time", ylab = "v (m/s)", col = fields::tim.colors(5)) image(x = P$time, y = P$unit_diameter, z = (P$diameter)^(1/10), main = "Diameter spectrum", xlab = "Time", ylab = expression(paste("d (", mu, "m)", sep = "")), log = "y", col = fields::tim.colors(5)) plot(x = P$time, y = P$n, main = "Rain drop counts", xlab = "Time", ylab = "Number of drops", type = "l", xaxs = "i") dev.off()