Skip to content

Commit

Permalink
add date to file name of plot
Browse files Browse the repository at this point in the history
  • Loading branch information
buddekai committed Aug 25, 2022
1 parent 2d5130c commit ef96ef2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ vignettes/*.pdf

# R Environment Variables
.Renviron

# Project file
*.Rproj
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: oscilliscopeR
Type: Package
Title: Import and work with data from oscilloscope
Version: 0.1.1
Version: 0.1.2
Author: c(person("Kai", "Budde", email = "[email protected]",
role = c("aut", "cre"))
Maintainer: Kai Budde <[email protected]>
Expand All @@ -10,5 +10,5 @@ Description: This package reads recorded data from measurements
License: LICENSE
Encoding: UTF-8
LazyData: true
Imports: tidyverse, yaml, ggplot2, scattermore
Imports: tidyverse, yaml, scattermore
RoxygenNote: 7.1.2
6 changes: 4 additions & 2 deletions R/convertMeasurementListToTibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ convertMeasurementListToTibble <- function(df_data_list){
for(j in 1:length(df_data_list)){
if(j == 1){
df_data <- dplyr::as_tibble(df_data_list[[j]])
df_data$Channel <- gsub(pattern = "CHAN", replacement = "", x = names(df_data_list)[j])
# df_data$Channel <- gsub(pattern = "CHAN", replacement = "", x = names(df_data_list)[j])
df_data$Channel <- names(df_data_list)[j]
}else{
df_data_dummy <- dplyr::as_tibble(df_data_list[[j]])
df_data_dummy$Channel <- gsub(pattern = "CHAN", replacement = "", x = names(df_data_list)[j])
# df_data_dummy$Channel <- gsub(pattern = "CHAN", replacement = "", x = names(df_data_list)[j])
df_data_dummy$Channel <- names(df_data_list)[j]

df_data <- dplyr::bind_rows(df_data, df_data_dummy)
}
Expand Down
9 changes: 6 additions & 3 deletions R/plotMeasurements.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @return 0

# Created: 2022/04/20
# Last changed: 2022/04/20
# Last changed: 2022/08/25

plotMeasurements <- function(input_data = NULL, output_dir = NULL,
vavg_min = NULL, vavg_max = NULL,
Expand Down Expand Up @@ -45,6 +45,9 @@ plotMeasurements <- function(input_data = NULL, output_dir = NULL,
plot_title <- ""
}

# Get date of experiment
date_of_experiment <- unique(as.Date(input_data$date_time))[1]

# Determine Vavg minimum and maximum if not given
if(is.null(vavg_min)){
vavg_min <- as.numeric(quantile(df_data$VAVG, 0.01, na.rm = TRUE))*factor_for_min_max_scaling
Expand Down Expand Up @@ -134,7 +137,7 @@ plotMeasurements <- function(input_data = NULL, output_dir = NULL,
# }

# Save files
file_path <- file.path(output_dir, "vavg_measurement.png")
file_path <- file.path(output_dir, paste0(date_of_experiment, "_vavg_measurement.png"))
ggsave(plot = plot_vavg, filename = file_path, device = "png", width = 19.2, height = 10.8, units = "cm")

# Find VPP #################################################################
Expand All @@ -155,7 +158,7 @@ plotMeasurements <- function(input_data = NULL, output_dir = NULL,
# scale_x_datetime(date_breaks = timedate_breaks)
# }

file_path <- file.path(output_dir, "vp2p_measurement.png")
file_path <- file.path(output_dir, paste0(date_of_experiment, "_vp2p_measurement.png"))
ggsave(plot = plot_vpp, filename = file_path, device = "png", width = 19.2, height = 10.8, units = "cm")

return(invisible(NULL))
Expand Down
29 changes: 16 additions & 13 deletions R/plotWaveforms.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#' the stimulation pulse)
#' @param channel_function_generator A character (name of the channel with
#' the function generator pulse (for GATE TTL))
#' @param voltage_plot_bound A number (value of min (negativ of the value)
#' @param voltage_limits_of_plot A number (value of min (negativ of the value)
#' and max values to be shown on y axis)
#' @param filter_stim_off A boolean (indicates whether measurements while
#' stim==off are to be filtered)
#' @param epsilon A number (min. distance for mean from 0 needed)
#' @param epsilon_for_filtering A number (min. distance for mean from 0 needed for filtering out the signal generator)
#' @param plot_title A character (title of the plot)
#' @return 0

Expand All @@ -28,9 +28,9 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
show_time_in_us = FALSE,
channel_function_generator = "CHAN1",
channel_stimulation_pulse = "CHAN2",
voltage_plot_bound = NULL,
voltage_limits_of_plot = NULL,
filter_stim_off = TRUE,
epsilon = 1,
epsilon_for_filtering = 1,
plot_title = NULL) {

# Some function parameters
Expand All @@ -56,6 +56,9 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
plot_title <- ""
}

# Get date of experiment
date_of_experiment <- unique(as.Date(input_data$date_time))[1]

# Convert time to \mu s ##################################################
if(show_time_in_us){
# Time is given in s
Expand All @@ -66,8 +69,8 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
global_max_value <- as.numeric(quantile(input_data$U[input_data$Channel == channel_stimulation_pulse], 0.99, na.rm = TRUE))
global_min_value <- as.numeric(quantile(input_data$U[input_data$Channel == channel_stimulation_pulse], 0.01, na.rm = TRUE))

if(is.null(voltage_plot_bound)){
voltage_plot_bound <- factor_for_min_max_scaling *
if(is.null(voltage_limits_of_plot)){
voltage_limits_of_plot <- factor_for_min_max_scaling *
max(abs(global_max_value), abs(global_min_value))
}

Expand All @@ -79,7 +82,7 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
dplyr::group_by(ID) %>%
dplyr::summarise(mean = mean(U, na.rm=TRUE))

ID_with_frequency_signal <- df_dummy$ID[df_dummy$mean > epsilon & !is.na(df_dummy$mean)][1]
ID_with_frequency_signal <- df_dummy$ID[df_dummy$mean > epsilon_for_filtering & !is.na(df_dummy$mean)][1]

filter_date <- unique(input_data$date_time[input_data$ID == ID_with_frequency_signal])[1]
df_dummy <- input_data %>%
Expand Down Expand Up @@ -111,7 +114,7 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
dplyr::group_by(ID) %>%
dplyr::summarise(PeakToPeak=max(U)-min(U))

ID_without_stim <- df_dummy$ID[df_dummy$PeakToPeak < epsilon]
ID_without_stim <- df_dummy$ID[df_dummy$PeakToPeak < epsilon_for_filtering]

if(filter_stim_off){
input_data <- input_data %>%
Expand Down Expand Up @@ -177,8 +180,8 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
geom_hline(yintercept=max_value, linetype="dashed", color = "darkgray", size=1) +
geom_hline(yintercept=min_value, linetype="dashed", color = "darkgray", size=1) +
geom_hline(yintercept=mean_value, linetype="dotdash", color = "darkgray", size=1) +
annotate("text", x=plot_annotation_x, y=(voltage_plot_bound-2), label=p2p_value) +
coord_cartesian(ylim = c(-voltage_plot_bound, voltage_plot_bound)) +
annotate("text", x=plot_annotation_x, y=(voltage_limits_of_plot-2), label=p2p_value) +
coord_cartesian(ylim = c(-voltage_limits_of_plot, voltage_limits_of_plot)) +
labs(title=paste(plot_title, input_data_filtered$date_time[1], sep=" "),
x = xaxis_lab, y = "U/V") +
theme_bw() +
Expand Down Expand Up @@ -237,16 +240,16 @@ plotWaveforms <- function(input_data = NULL, output_dir = NULL,
geom_hline(yintercept=max_value, linetype="dashed", color = "darkgray") +
geom_hline(yintercept=min_value, linetype="dashed", color = "darkgray") +
geom_hline(yintercept=mean_value, linetype="dotdash", color = "darkgray", size=1) +
annotate("text", x=plot_annotation_x, y=(voltage_plot_bound-2), label=p2p_value) +
coord_cartesian(ylim = c(-voltage_plot_bound, voltage_plot_bound)) +
annotate("text", x=plot_annotation_x, y=(voltage_limits_of_plot-2), label=p2p_value) +
coord_cartesian(ylim = c(-voltage_limits_of_plot, voltage_limits_of_plot)) +
labs(title=paste(plot_title, sep=" "),
x = "time/\U00B5s", y = "U/V") +
theme_bw() +
theme(axis.text.x = element_text(angle=90, vjust = 0.5),
plot.title = element_text(hjust = 0.5))

# Save files
file_path <- file.path(output_dir, paste0("all_in_one_", plot_title, ".png"))
file_path <- file.path(output_dir, paste0(date_of_experiment, "_all_in_one_", plot_title, ".png"))
ggsave(plot = plot_waveform, filename = file_path, device = "png", width = 19.2, height = 10.8, units = "cm")

return(invisible(NULL))
Expand Down

0 comments on commit ef96ef2

Please sign in to comment.