@ -1,5 +1,3 @@
source ( " /home/taha/chepec/chetex/common/R/common.R" )
##################################################
################ tifftags2df #####################
##################################################
@ -20,10 +18,10 @@ tifftags2df <- function(tiffimage) {
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
t rimtags <-
# Clean certain special characters from the tiff tags strings
# If these strings are left untreated, they cause all sorts of weird errors later
t ifftags.clean <-
sub ( " [ ]+$" , " " , #trim trailing spaces, if any
sub ( " \\r$" , " " , #remove trailing \r
gsub ( " \\xb9" , " " , #remove special character
@ -35,7 +33,7 @@ tifftags2df <- function(tiffimage) {
gsub ( " \\xb3" , " " , #remove special character
gsub ( " \\xb2" , " " , #remove special character
gsub ( " \\xb1" , " " , #remove special character
gsub ( " \\xb0" , " " , tifftags [48 : length ( tifftags ) - 1 ] ,
gsub ( " \\xb0" , " " , tifftags ,
useBytes = T ) ,
useBytes = T ) ,
useBytes = T ) ,
@ -46,85 +44,78 @@ tifftags2df <- function(tiffimage) {
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 ] ]
}
# These are the tags we are looking for
tags.df <- data.frame ( stringsAsFactors = FALSE , substrate.id , matrix ( #
# Name # REGEXP # splitchar # unit
c ( " EHT" , " AP\\_ACTUALKV" , " = " , " \\kilo\\volt" ,
" High current" , " DP\\_HIGH\\_CURRENT" , " = " , " " ,
" WD" , " AP\\_WD" , " = " , " \\milli\\metre" ,
" Magnification" , " AP\\_MAG" , " = " , " " , # could warrant special treatment
" Brightness" , " AP\\_BRIGHTNESS" , " = " , " \\percent" ,
" Contrast" , " AP\\_CONTRAST" , " = " , " \\percent" ,
" Signal A" , " DP\\_DETECTOR\\_CHANNEL" , " = " , " " ,
" SCM status" , " DP\\_SCM\\_STATUS" , " = " , " " ,
" Specimen current" , " AP\\_SCM" , " = " , " \\femto\\ampere" ,
# Beam
#"Filament curent", "AP\\_ACTUALCURRENT", " = ", "\\ampere",
" Stigmation Y" , " AP\\_STIG\\_Y" , " = " , " \\percent" ,
" Stigmation X" , " AP\\_STIG\\_X" , " = " , " \\percent" ,
" Aperture align Y" , " AP\\_APERTURE\\_ALIGN\\_Y" , " = " , " \\percent" ,
" Aperture align X" , " AP\\_APERTURE\\_ALIGN\\_X" , " = " , " \\percent" ,
" Aperture size" , " AP\\_APERTURESIZE" , " = " , " \\micro\\metre" ,
" Beam shift Y" , " AP\\_BEAMSHIFT\\_Y" , " = " , " \\percent" ,
" Beam shift X" , " AP\\_BEAMSHIFT\\_X" , " = " , " \\percent" ,
#"Beam offset Y", "AP\\_BEAM\\_OFFSET\\_Y", " = ", "\\nano\\metre",
#"Beam offset X", "AP\\_BEAM\\_OFFSET\\_X", " = ", "\\nano\\metre",
# Stage
" Track Z" , " DP\\_TRACK\\_Z" , " = " , " " ,
" Stage at Z" , " AP\\_STAGE\\_AT\\_Z" , " = " , " \\milli\\metre" ,
" Stage at Y" , " AP\\_STAGE\\_AT\\_Y" , " = " , " \\milli\\metre" ,
" Stage at X" , " AP\\_STAGE\\_AT\\_X" , " = " , " \\milli\\metre" ,
# Tilt
" Stage tilted?" , " DP\\_STAGE\\_TILTED" , " = " , " " ,
" Tilt angle" , " AP\\_TILT\\_ANGLE" , " = " , " " ,
" Tilt axis" , " AP\\_TILT\\_AXIS" , " = " , " " ,
# Image
" Scan speed" , " DP\\_SCANRATE" , " = " , " " ,
" Cycle time" , " AP\\_FRAME\\_TIME" , " = " , " \\second" ,
" Freeze on" , " DP\\_FREEZE\\_ON" , " = " , " " ,
" Dwell time" , " DP\\_DWELL\\_TIME" , " = " , " \\nano\\second" ,
" Noise reduction" , " DP\\_NOISE\\_REDUCTION" , " = " , " " ,
" Frames to integrate" , " AP\\_FRAME\\_INT\\_COUNT" , " = " , " " ,
" Frames to average" , " AP\\_FRAME\\_AVERAGE\\_COUNT" , " = " , " " ,
#"Profile width", "AP\\_PROFILE\\_W", " = ", "\\micro\\metre",
" Pixel size" , " AP\\_PIXEL\\_SIZE" , " = " , " \\nano\\metre" ,
# System
" Gun vacuum" , " AP\\_COLUMN\\_VAC" , " = " , " \\milli\\bar" ,
" System vacuum" , " AP\\_SYSTEM\\_VAC" , " = " , " \\milli\\bar" ,
" Filament age" , " AP\\_FILAMENT\\_AGE" , " = " , " \\hour" ,
# Misc
" Photo no." , " AP\\_PHOTO\\_NUMBER" , " = " , " " ,
" Date" , " AP\\_DATE" , " :" , " " ,
" Time" , " AP\\_TIME" , " :" , " " ) ,
ncol = 4 , byrow = T ) )
names ( tags.df ) <- c ( " sampleid" , " name" , " regexp" , " splitchar" , " unit" )
for ( i in 1 : dim ( tags.df ) [1 ] ) {
current.tag <- which ( regexpr ( tags.df $ regexp [i ] , tifftags.clean ) == 1 ) + 1
value.tmp <- strsplit ( tifftags.clean [current.tag ] , split = tags.df $ splitchar [i ] ) [ [1 ] ] [2 ]
# Remove leading spaces from tags.df$value
tags.df $ value [i ] <- sub ( " ^\\s+" , " " , value.tmp , useBytes = T )
if ( tags.df $ unit [i ] != " " ) {
tags.df $ value [i ] <- paste ( " \\SI{" , strsplit ( tags.df $ value [i ] , split = " " ) [ [1 ] ] [1 ] , " }{" , tags.df $ unit [i ] , " }" , sep = " " )
}
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 )
}