Updated chronoamp2df() to the new attributes system. Also improved docs.

master
Taha Ahmed 13 years ago
parent b687e77eb5
commit e3a7e20ff8

99
CHI.R

@ -183,10 +183,37 @@ chronocm2df <- function(datafilename) {
################# chronoamp2df ################### ################# chronoamp2df ###################
################################################## ##################################################
chronoamp2df <- function(datafilename, wearea = 1) { chronoamp2df <- function(datafilename, wearea = 1) {
# Function description: chronoamperometry data ## Description:
# CH Instruments potentiostat records all data using standard SI units, ## Reads current-time data (from CHI 760 potentiostat)
# so all potential values are in volts, currents are in amperes, ## and returns a dataframe with the data and the
# charges in Coulombs, time in seconds, etc. ## data attributes (experimental conditions).
## Usage:
## chronoamp2df(datafilename, wearea)
## Arguments:
## datafilename: text string with full path to experimental file
## wearea: (optional) area of working electrode (in square centimeters)
## Value:
## Dataframe with the following columns (and no extra attributes):
## $ sampleid : chr
## $ step : num
## $ time : num
## $ current : num
## $ currentdensity : num
## $ InitE : num
## $ HighE : num
## $ LowE : num
## $ InitPN : num
## $ Step : num
## $ Pulse width : num
## $ Sample interval : num
## $ Quiet Time : num
## $ Sensitivity : num
## Note:
## The CH Instruments 760 potentiostat records all data
## using standard SI units, therefore this function
## assumes all potential values to be in volts,
## currents to be in amperes, charges in Coulombs,
## time in seconds, and so on.
# #
datafile <- file(datafilename, "r") datafile <- file(datafilename, "r")
chifile <- readLines(datafile, n = -1) #read all lines of input file chifile <- readLines(datafile, n = -1) #read all lines of input file
@ -231,34 +258,44 @@ chronoamp2df <- function(datafilename, wearea = 1) {
currentdensity <- ff$current / wearea currentdensity <- ff$current / wearea
ff <- cbind(ff, currentdensity = currentdensity) ff <- cbind(ff, currentdensity = currentdensity)
# #
### Collect attributes of this experiment ### Collect attributes of this experiment
# These attributes are specific for each kind of experiment, # InitE (volt)
# be careful when adapting to other electrochemical data position.InitE <- regexpr("^Init\\sE\\s\\(V\\)", chifile)
rgxp.attr <- c("^Init\\sE\\s\\(V\\)", InitE <- as.numeric(strsplit(chifile[which(position.InitE == 1)], "\\s=\\s")[[1]][2])
"^High\\sE\\s\\(V\\)", ff$InitE <- InitE
"^Low\\sE\\s\\(V\\)", # HighE (volt)
"^Init\\sP/N", position.HighE <- regexpr("^High\\sE\\s\\(V\\)", chifile)
"^Step\\s", HighE <- as.numeric(strsplit(chifile[which(position.HighE == 1)], "\\s=\\s")[[1]][2])
"^Pulse\\sWidth\\s\\(sec\\)", ff$HighE <- HighE
"^Sample\\sInterval\\s\\(s\\)", # LowE (volt)
"^Quiet\\sTime\\s\\(sec\\)", position.LowE <- regexpr("^Low\\sE\\s\\(V\\)", chifile)
"^Sensitivity\\s\\(A/V\\)") LowE <- as.numeric(strsplit(chifile[which(position.LowE == 1)], "\\s=\\s")[[1]][2])
names.attr <- c("InitE", ff$LowE <- LowE
"HighE", # InitPN
"LowE", position.InitPN <- regexpr("^Init\\sP/N", chifile)
"InitPN", InitPN <- as.numeric(strsplit(chifile[which(position.InitPN == 1)], "\\s=\\s")[[1]][2])
"Steps", ff$InitPN <- InitPN
"PulseWidth", # Step
"SamplingInterval", position.Step <- regexpr("^Step\\s", chifile)
"QuietTime", Step <- as.numeric(strsplit(chifile[which(position.Step == 1)], "\\s=\\s")[[1]][2])
"Sensitivity") ff$Step <- Step
for (n in 1:length(rgxp.attr)) { # Pulse width (s)
attrow.idx <- regexpr(rgxp.attr[n], chifile) position.PulseWidth <- regexpr("^Pulse\\sWidth\\s\\(sec\\)", chifile)
attrow.len <- attr(attrow.idx, "match.length") PulseWidth <- as.numeric(strsplit(chifile[which(position.PulseWidth == 1)], "\\s=\\s")[[1]][2])
attr(attrow.idx, "match.length") <- NULL ff$PulseWidth <- PulseWidth
attr(ff, names.attr[n]) <- strsplit(chifile[which(attrow.idx == 1)], # Sample interval (s)
"\\s=\\s")[[1]][2] position.SampleInterval <- regexpr("^Sample\\sInterval\\s\\(s\\)", chifile)
} SampleInterval <- as.numeric(strsplit(chifile[which(position.SampleInterval == 1)], "\\s=\\s")[[1]][2])
ff$SampleInterval <- SampleInterval
# Quiet Time (s)
position.QuietTime <- regexpr("^Quiet\\sTime\\s\\(sec\\)", chifile)
QuietTime <- as.numeric(strsplit(chifile[which(position.QuietTime == 1)], "\\s=\\s")[[1]][2])
ff$QuietTime <- QuietTime
# Sensitivity (A/V)
position.Sensitivity <- regexpr("^Sensitivity\\s\\(A/V\\)", chifile)
Sensitivity <- as.numeric(strsplit(chifile[which(position.Sensitivity == 1)], "\\s=\\s")[[1]][2])
ff$Sensitivity <- Sensitivity
# #
return(ff) return(ff)
} }

Loading…
Cancel
Save