Complete re-write of tifftags2df (only internal changes).

No changes in input or output of this function, only of the internal
mechanism with which tags are chosen and formatted for output.
init.R contains the sourceDir() function which is necessary for sourcing
all .R files in a directory.
master
Taha Ahmed 13 years ago
parent b55af5d478
commit 4fff82be0c

@ -1,5 +1,3 @@
source("/home/taha/chepec/chetex/common/R/common.R")
################################################## ##################################################
################ tifftags2df ##################### ################ tifftags2df #####################
################################################## ##################################################
@ -20,10 +18,10 @@ tifftags2df <- function(tiffimage) {
substrate.id <- strsplit(basename(tiffimage), "\\.")[[1]][1] substrate.id <- strsplit(basename(tiffimage), "\\.")[[1]][1]
tifftags <- system(paste("tiffinfo", tiffimage, sep = " "), tifftags <- system(paste("tiffinfo", tiffimage, sep = " "),
intern = TRUE, ignore.stderr = TRUE) intern = TRUE, ignore.stderr = TRUE)
# The first 47 rows of tifftags contains info about
# the image itself, and is not interesting # Clean certain special characters from the tiff tags strings
# The last row of tifftags is the empty string # If these strings are left untreated, they cause all sorts of weird errors later
trimtags <- tifftags.clean <-
sub("[ ]+$", "", #trim trailing spaces, if any sub("[ ]+$", "", #trim trailing spaces, if any
sub("\\r$", "", #remove trailing \r sub("\\r$", "", #remove trailing \r
gsub("\\xb9", "", #remove special character gsub("\\xb9", "", #remove special character
@ -35,7 +33,7 @@ tifftags2df <- function(tiffimage) {
gsub("\\xb3", "", #remove special character gsub("\\xb3", "", #remove special character
gsub("\\xb2", "", #remove special character gsub("\\xb2", "", #remove special character
gsub("\\xb1", "", #remove special character gsub("\\xb1", "", #remove special character
gsub("\\xb0", "", tifftags[48:length(tifftags) - 1], gsub("\\xb0", "", tifftags,
useBytes=T), useBytes=T),
useBytes=T), useBytes=T),
useBytes=T), useBytes=T),
@ -46,85 +44,78 @@ tifftags2df <- function(tiffimage) {
useBytes=T), useBytes=T),
useBytes=T), useBytes=T),
useBytes=T))) useBytes=T)))
oddtags <- trimtags[seq(1, length(trimtags), by = 2)]
eventags <- trimtags[seq(2, length(trimtags), by = 2)]
tmp.tagsdf <-
data.frame(stringsAsFactors = FALSE, # These are the tags we are looking for
sampleid = substrate.id, tags.df <- data.frame(stringsAsFactors = FALSE, substrate.id, matrix(#
tag = oddtags, # Name # REGEXP # splitchar # unit
value = eventags) c("EHT", "AP\\_ACTUALKV", " = ", "\\kilo\\volt",
# A vector of displayed tags "High current", "DP\\_HIGH\\_CURRENT", " = ", "",
displaytags <- "WD", "AP\\_WD", " = ", "\\milli\\metre",
c("AP_ACTUALKV", # EHT = 5.00 kV "Magnification", "AP\\_MAG", " = ", "", # could warrant special treatment
"DP_HIGH_CURRENT", # High Current = Off # commonly used for EDS analysis "Brightness", "AP\\_BRIGHTNESS", " = ", "\\percent",
"AP_WD", # WD = 4.1 mm "Contrast", "AP\\_CONTRAST", " = ", "\\percent",
"AP_MAG", # Mag = 15.00 K X "Signal A", "DP\\_DETECTOR\\_CHANNEL", " = ", "",
"AP_BRIGHTNESS", # Brightness = 49.0 % "SCM status", "DP\\_SCM\\_STATUS", " = ", "",
"AP_CONTRAST", # Contrast = 32.4 % "Specimen current", "AP\\_SCM", " = ", "\\femto\\ampere",
"DP_DETECTOR_CHANNEL", # InLens
"DP_SCM_STATUS", # SCM Status = Off
"AP_SCM", # Specimen I = 0 fA # zero if SCM Status = Off
# Beam # Beam
#notrelevant#"AP_ACTUALCURRENT", # Fil I = 2.370 A #"Filament curent", "AP\\_ACTUALCURRENT", " = ", "\\ampere",
"AP_STIG_Y", # Stigmation Y = -0.2 % "Stigmation Y", "AP\\_STIG\\_Y", " = ", "\\percent",
"AP_STIG_X", # Stigmation X = 1.9 % "Stigmation X", "AP\\_STIG\\_X", " = ", "\\percent",
"AP_APERTURE_ALIGN_Y", # Aperture Align Y = -1.5 % "Aperture align Y", "AP\\_APERTURE\\_ALIGN\\_Y", " = ", "\\percent",
"AP_APERTURE_ALIGN_X", # Aperture Align X = -2.4 % "Aperture align X", "AP\\_APERTURE\\_ALIGN\\_X", " = ", "\\percent",
"AP_APERTURESIZE", # Aperture Size = 30.00 m "Aperture size", "AP\\_APERTURESIZE", " = ", "\\micro\\metre",
"AP_BEAMSHIFT_Y", # Beam Shift Y = 0.1% "Beam shift Y", "AP\\_BEAMSHIFT\\_Y", " = ", "\\percent",
"AP_BEAMSHIFT_X", # Beam Shift X = 0.1% "Beam shift X", "AP\\_BEAMSHIFT\\_X", " = ", "\\percent",
#notrelevant#"AP_BEAM_OFFSET_Y", # Beam Offset Y = 13.89 nm #"Beam offset Y", "AP\\_BEAM\\_OFFSET\\_Y", " = ", "\\nano\\metre",
#notrelevant#"AP_BEAM_OFFSET_X", # Beam Offset X = 9.13 nm #"Beam offset X", "AP\\_BEAM\\_OFFSET\\_X", " = ", "\\nano\\metre",
# Stage # Stage
"DP_TRACK_Z", # Track Z = On "Track Z", "DP\\_TRACK\\_Z", " = ", "",
"AP_STAGE_AT_Z", # Stage at Z = 25.857 mm "Stage at Z", "AP\\_STAGE\\_AT\\_Z", " = ", "\\milli\\metre",
"AP_STAGE_AT_Y", # Stage at Y = 49.0708 mm "Stage at Y", "AP\\_STAGE\\_AT\\_Y", " = ", "\\milli\\metre",
"AP_STAGE_AT_X", # Stage at X = 50.0753 mm "Stage at X", "AP\\_STAGE\\_AT\\_X", " = ", "\\milli\\metre",
# Tilt # Tilt
"DP_STAGE_TILTED", # Stage Tilt = In Y "Stage tilted?", "DP\\_STAGE\\_TILTED", " = ", "",
"AP_TILT_ANGLE", # Tilt Angle = 0.0 "Tilt angle", "AP\\_TILT\\_ANGLE", " = ", "",
"AP_TILT_AXIS", # Tilt Axis = 0.0 "Tilt axis", "AP\\_TILT\\_AXIS", " = ", "",
# Image # Image
"DP_SCANRATE", # Scan Speed = 10 "Scan speed", "DP\\_SCANRATE", " = ", "",
"AP_FRAME_TIME", # Cycle Time = 48.7 Secs "Cycle time", "AP\\_FRAME\\_TIME", " = ", "\\second",
"DP_FREEZE_ON", # Freeze on = End Frame "Freeze on", "DP\\_FREEZE\\_ON", " = ", "",
"DP_DWELL_TIME", # Dwell time = 100 ns "Dwell time", "DP\\_DWELL\\_TIME", " = ", "\\nano\\second",
"DP_NOISE_REDUCTION", # Noise Reduction = Pixel Avg. "Noise reduction", "DP\\_NOISE\\_REDUCTION", " = ", "",
"AP_FRAME_INT_COUNT", # Frames to integrate = 0 "Frames to integrate", "AP\\_FRAME\\_INT\\_COUNT", " = ", "",
"AP_FRAME_AVERAGE_COUNT", # Frames to average = 1 "Frames to average", "AP\\_FRAME\\_AVERAGE\\_COUNT", " = ", "",
#notrelevant#"AP_PROFILE_W", # Profile Width = 71.79 m #"Profile width", "AP\\_PROFILE\\_W", " = ", "\\micro\\metre",
"AP_PIXEL_SIZE", # Pixel Size = 23.96 nm "Pixel size", "AP\\_PIXEL\\_SIZE", " = ", "\\nano\\metre",
# System # System
"AP_COLUMN_VAC", # Gun Vacuum = 1.74e-009 mbar "Gun vacuum", "AP\\_COLUMN\\_VAC", " = ", "\\milli\\bar",
"AP_SYSTEM_VAC", # System Vacuum = 2.32e-006 mbar "System vacuum", "AP\\_SYSTEM\\_VAC", " = ", "\\milli\\bar",
"AP_FILAMENT_AGE", # Filament Age = 1378.35 Hours "Filament age", "AP\\_FILAMENT\\_AGE", " = ", "\\hour",
# Misc # Misc
"AP_PHOTO_NUMBER", # Photo No. = 9069 "Photo no.", "AP\\_PHOTO\\_NUMBER", " = ", "",
"AP_DATE", # Date :23 Mar 2011 "Date", "AP\\_DATE", " :", "",
"AP_TIME") # Time :19:10:46 "Time", "AP\\_TIME", " :", ""),
# ncol = 4, byrow = T))
extracted.tagsdf <- data.frame() names(tags.df) <- c("sampleid", "name", "regexp", "splitchar", "unit")
for (i in 1:length(displaytags)) {
rows.extract <- which(displaytags[i] == tmp.tagsdf$tag)
extracted.tagsdf <- rbind(extracted.tagsdf, for (i in 1:dim(tags.df)[1]) {
data.frame(stringsAsFactors = FALSE, current.tag <- which(regexpr(tags.df$regexp[i], tifftags.clean) == 1) + 1
tmp.tagsdf[rows.extract, ])) value.tmp <- strsplit(tifftags.clean[current.tag], split = tags.df$splitchar[i])[[1]][2]
} # Remove leading spaces from tags.df$value
# Fix split of time and date fields tags.df$value[i] <- sub("^\\s+", "", value.tmp, useBytes = T)
splittags <- strsplit(extracted.tagsdf$value, " = ") if (tags.df$unit[i] != "") {
for (i in 1:length(splittags)) { tags.df$value[i] <- paste("\\SI{", strsplit(tags.df$value[i], split = " ")[[1]][1], "}{", tags.df$unit[i], "}", sep = "")
if (length(splittags[[i]]) == 1) {
splittags[[i]] <- strsplit(splittags[[i]], " :")[[1]]
}
} }
tagsdf <- data.frame()
for (i in 1:length(splittags)) {
tagsdf <- rbind(tagsdf,
data.frame(stringsAsFactors = FALSE,
sampleid = extracted.tagsdf$sampleid[i],
parameter = splittags[[i]][1],
value = splittags[[i]][2]))
} }
#
return(tagsdf)
tags <- data.frame(stringsAsFactors = FALSE,
sampleid = tags.df$sampleid,
parameter = tags.df$name,
value = tags.df$value)
return(tags)
} }

@ -0,0 +1,13 @@
# To source a bunch of files in the same directory
sourceDir <- function(path, trace = TRUE) {
for (nm in list.files(path, pattern = "\\.[Rr]$")) {
if(trace) {
cat(nm,":")
}
source(file.path(path, nm))
if(trace) {
cat("\n")
}
}
}
Loading…
Cancel
Save