Skip to content

Commit

Permalink
new version 0.2.0 adding sinusoidal stimulation
Browse files Browse the repository at this point in the history
  • Loading branch information
buddekai committed Oct 30, 2024
1 parent 95c2e49 commit ee4884f
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 101 deletions.
30 changes: 20 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
Package: oscilliscopeR
Type: Package
Title: Import and work with data from oscilloscope
Version: 0.1.4
Author: c(person("Kai", "Budde", email = "[email protected]",
role = c("aut", "cre"))
Maintainer: Kai Budde <[email protected]>
Description: This package reads recorded data from measurements
of an oscilloscope (as yaml files) and plots them.
License: LICENSE
Package: oscilloscopeR
Title: Import and work with data from oscilloscope(s)
Version: 0.2.0
Authors@R:
person("Kai", "Budde-Sagert", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-6836-9865"))
Maintainer: Kai Budde-Sagert <[email protected]>
Description: This package reads recorded data from measurements of an
oscilloscope (as yaml files), calculates some values, and plots them.
License: GPL-3 + file LICENSE
URL: https://github.com/SFB-ELAINE/oscilloscopeR
BugReports: https://github.com/SFB-ELAINE/oscilloscopeR/issues
Depends:
R (>= 4.0.0)
Imports:
lubridate (>= 1.9.0),
scattermore (>= 0.8),
tidyverse (>= 1.3.2),
yaml (>= 2.3.6)
ByteCompile: TRUE
Encoding: UTF-8
LazyData: true
Imports: tidyverse, yaml, scattermore
RoxygenNote: 7.2.3
1 change: 0 additions & 1 deletion R/convertMeasurementListToTibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#' @author Kai Budde-Sagert
#' @export convertMeasurementListToTibble
#' @param df_data_list A list (list of data)
#' @param variabel_name A character ()
#' @return A tibble with the data

# Created: 2022/04/19
Expand Down
25 changes: 21 additions & 4 deletions R/getMeasurements.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @return A tibble with the data

# Created: 2022/04/19
# Last changed: 2022/04/19
# Last changed: 2024/04/25

getMeasurements <- function(input_file = NULL, input_directory = NULL) {

Expand Down Expand Up @@ -68,9 +68,9 @@ getMeasurements <- function(input_file = NULL, input_directory = NULL) {
if(zip_container){
yaml_files <- unzip(zipfile = file.path(input_directory, input_file), list = TRUE)
yaml_files <- yaml_files$Name
yaml_files <- yaml_files[grepl(pattern = "measurement\\.yml", x = yaml_files, ignore.case = TRUE)]
yaml_files <- yaml_files[grepl(pattern = "measurement.+yml", x = yaml_files, ignore.case = TRUE)]
}else if(yml_directory){
yaml_files <- list.files(path = input_directory, pattern = "measurement\\.yml")
yaml_files <- list.files(path = input_directory, pattern = "measurement.+yml")
}else{
yaml_files <- input_file
}
Expand All @@ -89,9 +89,23 @@ getMeasurements <- function(input_file = NULL, input_directory = NULL) {
df_data_dummy <- convertMeasurementListToTibble(df_data_list)

# Get date and time of measurement
df_data_dummy$date_time <- gsub(pattern = "-measurement\\.yml",
df_data_dummy$date_time <- gsub(pattern = "-measurement.+yml",
replacement = "",
x = basename(yaml_files[i]))

# Get further information depending on file name
if(length(grep(pattern = ".+-measurement(.+)\\.yml", x = basename(yaml_files[i]), ignore.case = TRUE)) > 0){
df_data_dummy$file_name_extension <- gsub(pattern = ".+-measurement(.+)\\.yml",
replacement = "\\1",
x = basename(yaml_files[i]))
}else{
df_data_dummy$file_name_extension <- NA
}

# Delete possible character of Channel column
df_data_dummy$Channel <- as.numeric(gsub(pattern = "[^0-9.-]", replacement = "", x = df_data_dummy$Channel))

# Add ID (file index)
df_data_dummy$ID <- i

if(i == 1){
Expand All @@ -107,5 +121,8 @@ getMeasurements <- function(input_file = NULL, input_directory = NULL) {
# Convert date and time
df_data$date_time <- as.POSIXct(strptime(df_data$date_time, "%Y%m%d-%H%M%S"))

# Make channel number as factor
df_data$Channel <- as.factor(df_data$Channel)

return(df_data)
}
48 changes: 40 additions & 8 deletions R/getWaveforms.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
#' @export getWaveforms
#' @param input_file A character (path to yaml file to be converted)
#' @param input_directory A character (path to directory with yaml files)
#' @param reduce_resolution_of_input_data A Boolean (showing if fewer point
#' are to be imported)
#' @return A tibble with the data

# Created: 2022/04/21
# Last changed: 2022/04/21
# Last changed: 2024/04/17

getWaveforms <- function(input_file = NULL, input_directory = NULL) {
getWaveforms <- function(input_file = NULL,
input_directory = NULL,
reduce_resolution_of_input_data = TRUE) {

# Check for null input
if(is.null(input_file) & is.null(input_directory)){
Expand All @@ -32,7 +36,7 @@ getWaveforms <- function(input_file = NULL, input_directory = NULL) {
print("Please call function with a correct input file ('*.yml' or '*.zip').")
return()
}else{
if(grepl(pattern = "wave\\.yml", x = input_file, ignore.case = TRUE)){
if(grepl(pattern = "wave.+yml", x = input_file, ignore.case = TRUE)){
# A yml file is given
yml_file <- TRUE
yml_directory <- FALSE
Expand Down Expand Up @@ -68,9 +72,9 @@ getWaveforms <- function(input_file = NULL, input_directory = NULL) {
if(zip_container){
yaml_files <- unzip(zipfile = file.path(input_directory, input_file), list = TRUE)
yaml_files <- yaml_files$Name
yaml_files <- yaml_files[grepl(pattern = "wave\\.yml", x = yaml_files, ignore.case = TRUE)]
yaml_files <- yaml_files[grepl(pattern = "wave.+yml", x = yaml_files, ignore.case = TRUE)]
}else if(yml_directory){
yaml_files <- list.files(path = input_directory, pattern = "wave\\.yml")
yaml_files <- list.files(path = input_directory, pattern = "wave.+yml")
}else{
yaml_files <- input_file
}
Expand All @@ -97,13 +101,41 @@ getWaveforms <- function(input_file = NULL, input_directory = NULL) {
# Convert list to tibble
df_data_dummy <- dplyr::as_tibble(df_data_list)

# Reduce dimension of input if required
if(reduce_resolution_of_input_data){
max_number_of_points <- 2000
if(nrow(df_data_dummy) > max_number_of_points){
# time_step <- min(diff(df_data_dummy$time))
# time_interval <- max(df_data_dummy$time) - min(df_data_dummy$time)

df_data_dummy <- df_data_dummy[seq(1, nrow(df_data_dummy), floor(nrow(df_data_dummy)/max_number_of_points)), ]
}
}


# Get date and time of measurement
df_data_dummy$date_time <- gsub(pattern = "-wave\\.yml",
df_data_dummy$date_time <- gsub(pattern = "-wave.+yml",
replacement = "",
x = basename(yaml_files[i]))

# Get further information depending on file name
if(length(grep(pattern = ".+-wave(.+)\\.yml", x = basename(yaml_files[i]), ignore.case = TRUE)) > 0){
df_data_dummy$file_name_extension <- gsub(pattern = ".+-wave(.+)\\.yml",
replacement = "\\1",
x = basename(yaml_files[i]))
}else{
df_data_dummy$file_name_extension <- NA
}

# Add ID (file index)
df_data_dummy$ID <- i

# Put all voltages into one column and the respective channel into another one
df_data_dummy <- tidyr::gather(data = df_data_dummy, key = "Channel", value = "U", -c("time", "date_time", "file_name_extension", "ID"))

# Delete possible character of Channel column
df_data_dummy$Channel <- as.numeric(gsub(pattern = "[^0-9.-]", replacement = "", x = df_data_dummy$Channel))

if(i == 1 || first_non_zero_data){
df_data <- df_data_dummy
first_non_zero_data <- FALSE
Expand All @@ -124,8 +156,8 @@ getWaveforms <- function(input_file = NULL, input_directory = NULL) {
# Convert date and time
df_data$date_time <- as.POSIXct(strptime(df_data$date_time, "%Y%m%d-%H%M%S"))

# Put all voltages into one column and the respective channel into another one
df_data <- tidyr::gather(data = df_data, key = "Channel", value = "U", -c("time", "date_time", "ID"))
# Make channel number as factor
df_data$Channel <- as.factor(df_data$Channel)

return(df_data)
}
Loading

0 comments on commit ee4884f

Please sign in to comment.