From fd62a103c88f11ea0683e9ace55307812d81e7f7 Mon Sep 17 00:00:00 2001 From: Taha Ahmed Date: Sat, 26 Mar 2011 16:25:10 +0100 Subject: [PATCH] Created LEO1550.R: created tifftags2df() function. In common.R: marked LinearBaseline() as deprecated. --- CHI.R | 4 +- LEO1550.R | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ common.R | 2 +- 3 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 LEO1550.R diff --git a/CHI.R b/CHI.R index dae9ced..032b6ff 100644 --- a/CHI.R +++ b/CHI.R @@ -369,13 +369,13 @@ cv2df <- function(datafilename, wearea = 1) { for (s in 1:length(starts)) { zz <- textConnection(chifile[starts[s]:ends[s]], "r") ff <- rbind(ff, - data.frame(sampleid, segment = s, cycle = as.integer(ceiling(s/2)), + data.frame(sampleid, cycle = as.integer(ceiling(s/2)), segment = s, matrix(scan(zz, what = numeric(), sep = ","), ncol = 3, byrow = T))) close(zz) } # Column names after initial assignment - names(ff) <- c("sampleid", "segment", "cycle", "potential", "current", "charge") + names(ff) <- c("sampleid", "cycle", "segment", "potential", "current", "charge") # Calculate current density currentdensity <- ff$current / wearea ff <- cbind(ff[, 1:5], currentdensity = currentdensity, charge = ff[, 6]) diff --git a/LEO1550.R b/LEO1550.R new file mode 100644 index 0000000..d68140b --- /dev/null +++ b/LEO1550.R @@ -0,0 +1,158 @@ +# LEO1550.R +# Functions to read and manipulate data from the LEO1550 scanning electron microscope +# Taha Ahmed, March 2011 + +# CONTENTS +source("/home/taha/chepec/chetex/common/R/common.R") +# >>>> tifftags2df + + + + +################################################## +################ tifftags2df ##################### +################################################## +tifftags2df <- function(tiffimage) { + ## Description: + ## Extracts all tags from a TIFF image file + ## using the tiffinfo tool and stores + ## a selection of the tags in a dataframe. + ## Usage: + ## tifftags2df(fulltiffpath) + ## Arguments: + ## tiffimage: character string, the full filename + ## (with path) to one TIFF file. + ## Value: + ## A dataframe with three columns: + ## sampleid, parameter, value. + # + substrate.id <- strsplit(basename(tiffimage), "\\.")[[1]][1] + tifftags <- system(paste("tiffinfo", tiffimage, sep = " "), + intern = TRUE, ignore.stderr = TRUE) + # The first 47 rows of tifftags contains info about + # the image itself, and is not interesting + # The last row of tifftags is the empty string + trimtags <- + sub("[ ]+$", "", #trim trailing spaces, if any + sub("\\r$", "", #remove trailing \r + gsub("\\xb9", "", #remove special character + gsub("\\xb8", "", #remove special character + gsub("\\xb7", "", #remove special character + gsub("\\xb6", "", #remove special character + gsub("\\xb5", "", #remove special character + gsub("\\xb4", "", #remove special character + gsub("\\xb3", "", #remove special character + gsub("\\xb2", "", #remove special character + gsub("\\xb1", "", #remove special character + gsub("\\xb0", "", tifftags[48:length(tifftags) - 1], + useBytes=T), + useBytes=T), + useBytes=T), + useBytes=T), + 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, + sampleid = substrate.id, + tag = oddtags, + value = eventags) + # A vector of displayed tags + displaytags <- + c("AP_ACTUALKV", # EHT = 5.00 kV + "DP_HIGH_CURRENT", # High Current = Off # commonly used for EDS analysis + "AP_WD", # WD = 4.1 mm + "AP_MAG", # Mag = 15.00 K X + "AP_BRIGHTNESS", # Brightness = 49.0 % + "AP_CONTRAST", # Contrast = 32.4 % + "DP_DETECTOR_CHANNEL", # InLens + "DP_SCM_STATUS", # SCM Status = Off + "AP_SCM", # Specimen I = 0 fA # zero if SCM Status = Off + # Beam + #notrelevant#"AP_ACTUALCURRENT", # Fil I = 2.370 A + "AP_STIG_Y", # Stigmation Y = -0.2 % + "AP_STIG_X", # Stigmation X = 1.9 % + "AP_APERTURE_ALIGN_Y", # Aperture Align Y = -1.5 % + "AP_APERTURE_ALIGN_X", # Aperture Align X = -2.4 % + "AP_APERTURESIZE", # Aperture Size = 30.00 m + "AP_BEAMSHIFT_Y", # Beam Shift Y = 0.1% + "AP_BEAMSHIFT_X", # Beam Shift X = 0.1% + #notrelevant#"AP_BEAM_OFFSET_Y", # Beam Offset Y = 13.89 nm + #notrelevant#"AP_BEAM_OFFSET_X", # Beam Offset X = 9.13 nm + # Stage + "DP_TRACK_Z", # Track Z = On + "AP_STAGE_AT_Z", # Stage at Z = 25.857 mm + "AP_STAGE_AT_Y", # Stage at Y = 49.0708 mm + "AP_STAGE_AT_X", # Stage at X = 50.0753 mm + # Tilt + "DP_STAGE_TILTED", # Stage Tilt = In Y + "AP_TILT_ANGLE", # Tilt Angle = 0.0 + "AP_TILT_AXIS", # Tilt Axis = 0.0 + # Image + "DP_SCANRATE", # Scan Speed = 10 + "AP_FRAME_TIME", # Cycle Time = 48.7 Secs + "DP_FREEZE_ON", # Freeze on = End Frame + "DP_DWELL_TIME", # Dwell time = 100 ns + "DP_NOISE_REDUCTION", # Noise Reduction = Pixel Avg. + "AP_FRAME_INT_COUNT", # Frames to integrate = 0 + "AP_FRAME_AVERAGE_COUNT", # Frames to average = 1 + #notrelevant#"AP_PROFILE_W", # Profile Width = 71.79 m + "AP_PIXEL_SIZE", # Pixel Size = 23.96 nm + # System + "AP_COLUMN_VAC", # Gun Vacuum = 1.74e-009 mbar + "AP_SYSTEM_VAC", # System Vacuum = 2.32e-006 mbar + "AP_FILAMENT_AGE", # Filament Age = 1378.35 Hours + # Misc + "AP_PHOTO_NUMBER", # Photo No. = 9069 + "AP_DATE", # Date :23 Mar 2011 + "AP_TIME") # Time :19:10:46 + # + extracted.tagsdf <- data.frame() + for (i in 1:length(displaytags)) { + rows.extract <- which(displaytags[i] == tmp.tagsdf$tag) + extracted.tagsdf <- rbind(extracted.tagsdf, + data.frame(stringsAsFactors = FALSE, + tmp.tagsdf[rows.extract, ])) + } + # Fix split of time and date fields + splittags <- strsplit(extracted.tagsdf$value, " = ") + for (i in 1:length(splittags)) { + 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) +} + + + + + + + + + + + + + + + + + + + diff --git a/common.R b/common.R index 00f106b..e2f8be5 100644 --- a/common.R +++ b/common.R @@ -3,7 +3,7 @@ # Taha Ahmed, Jan 2011 # CONTENTS -# >>>> LinearBaseline +# >>>> LinearBaseline (deprecated) # >>>> int2padstr # >>>> It2charge # >>>> ProvideSampleId