@ -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
t rimtags <-
t ifftags.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
# Beam
" DP_SCM_STATUS" , # SCM Status = Off
#"Filament curent", "AP\\_ACTUALCURRENT", " = ", "\\ampere",
" AP_SCM" , # Specimen I = 0 fA # zero if SCM Status = Off
" Stigmation Y" , " AP\\_STIG\\_Y" , " = " , " \\percent" ,
# Beam
" Stigmation X" , " AP\\_STIG\\_X" , " = " , " \\percent" ,
#notrelevant#"AP_ACTUALCURRENT", # Fil I = 2.370 A
" Aperture align Y" , " AP\\_APERTURE\\_ALIGN\\_Y" , " = " , " \\percent" ,
" AP_STIG_Y" , # Stigmation Y = -0.2 %
" Aperture align X" , " AP\\_APERTURE\\_ALIGN\\_X" , " = " , " \\percent" ,
" AP_STIG_X" , # Stigmation X = 1.9 %
" Aperture size" , " AP\\_APERTURESIZE" , " = " , " \\micro\\metre" ,
" AP_APERTURE_ALIGN_Y" , # Aperture Align Y = -1.5 %
" Beam shift Y" , " AP\\_BEAMSHIFT\\_Y" , " = " , " \\percent" ,
" AP_APERTURE_ALIGN_X" , # Aperture Align X = -2.4 %
" Beam shift X" , " AP\\_BEAMSHIFT\\_X" , " = " , " \\percent" ,
" AP_APERTURESIZE" , # Aperture Size = 30.00 m
#"Beam offset Y", "AP\\_BEAM\\_OFFSET\\_Y", " = ", "\\nano\\metre",
" AP_BEAMSHIFT_Y" , # Beam Shift Y = 0.1%
#"Beam offset X", "AP\\_BEAM\\_OFFSET\\_X", " = ", "\\nano\\metre",
" AP_BEAMSHIFT_X" , # Beam Shift X = 0.1%
# Stage
#notrelevant#"AP_BEAM_OFFSET_Y", # Beam Offset Y = 13.89 nm
" Track Z" , " DP\\_TRACK\\_Z" , " = " , " " ,
#notrelevant#"AP_BEAM_OFFSET_X", # Beam Offset X = 9.13 nm
" Stage at Z" , " AP\\_STAGE\\_AT\\_Z" , " = " , " \\milli\\metre" ,
# Stage
" Stage at Y" , " AP\\_STAGE\\_AT\\_Y" , " = " , " \\milli\\metre" ,
" DP_TRACK_Z" , # Track Z = On
" Stage at X" , " AP\\_STAGE\\_AT\\_X" , " = " , " \\milli\\metre" ,
" AP_STAGE_AT_Z" , # Stage at Z = 25.857 mm
# Tilt
" AP_STAGE_AT_Y" , # Stage at Y = 49.0708 mm
" Stage tilted?" , " DP\\_STAGE\\_TILTED" , " = " , " " ,
" AP_STAGE_AT_X" , # Stage at X = 50.0753 mm
" Tilt angle" , " AP\\_TILT\\_ANGLE" , " = " , " " ,
# Tilt
" Tilt axis" , " AP\\_TILT\\_AXIS" , " = " , " " ,
" DP_STAGE_TILTED" , # Stage Tilt = In Y
# Image
" AP_TILT_ANGLE" , # Tilt Angle = 0.0
" Scan speed" , " DP\\_SCANRATE" , " = " , " " ,
" AP_TILT_AXIS" , # Tilt Axis = 0.0
" Cycle time" , " AP\\_FRAME\\_TIME" , " = " , " \\second" ,
# Image
" Freeze on" , " DP\\_FREEZE\\_ON" , " = " , " " ,
" DP_SCANRATE" , # Scan Speed = 10
" Dwell time" , " DP\\_DWELL\\_TIME" , " = " , " \\nano\\second" ,
" AP_FRAME_TIME" , # Cycle Time = 48.7 Secs
" Noise reduction" , " DP\\_NOISE\\_REDUCTION" , " = " , " " ,
" DP_FREEZE_ON" , # Freeze on = End Frame
" Frames to integrate" , " AP\\_FRAME\\_INT\\_COUNT" , " = " , " " ,
" DP_DWELL_TIME" , # Dwell time = 100 ns
" Frames to average" , " AP\\_FRAME\\_AVERAGE\\_COUNT" , " = " , " " ,
" DP_NOISE_REDUCTION" , # Noise Reduction = Pixel Avg.
#"Profile width", "AP\\_PROFILE\\_W", " = ", "\\micro\\metre",
" AP_FRAME_INT_COUNT" , # Frames to integrate = 0
" Pixel size" , " AP\\_PIXEL\\_SIZE" , " = " , " \\nano\\metre" ,
" AP_FRAME_AVERAGE_COUNT" , # Frames to average = 1
# System
#notrelevant#"AP_PROFILE_W", # Profile Width = 71.79 m
" Gun vacuum" , " AP\\_COLUMN\\_VAC" , " = " , " \\milli\\bar" ,
" AP_PIXEL_SIZE" , # Pixel Size = 23.96 nm
" System vacuum" , " AP\\_SYSTEM\\_VAC" , " = " , " \\milli\\bar" ,
# System
" Filament age" , " AP\\_FILAMENT\\_AGE" , " = " , " \\hour" ,
" AP_COLUMN_VAC" , # Gun Vacuum = 1.74e-009 mbar
# Misc
" AP_SYSTEM_VAC" , # System Vacuum = 2.32e-006 mbar
" Photo no." , " AP\\_PHOTO\\_NUMBER" , " = " , " " ,
" AP_FILAMENT_AGE" , # Filament Age = 1378.35 Hours
" Date" , " AP\\_DATE" , " :" , " " ,
# Misc
" Time" , " AP\\_TIME" , " :" , " " ) ,
" AP_PHOTO_NUMBER" , # Photo No. = 9069
ncol = 4 , byrow = T ) )
" AP_DATE" , # Date :23 Mar 2011
names ( tags.df ) <- c ( " sampleid" , " name" , " regexp" , " splitchar" , " unit" )
" AP_TIME" ) # Time :19:10:46
#
extracted.tagsdf <- data.frame ( )
for ( i in 1 : dim ( tags.df ) [1 ] ) {
for ( i in 1 : length ( displaytags ) ) {
current.tag <- which ( regexpr ( tags.df $ regexp [i ] , tifftags.clean ) == 1 ) + 1
rows.extract <- which ( displaytags [i ] == tmp.tagsdf $ tag )
value.tmp <- strsplit ( tifftags.clean [current.tag ] , split = tags.df $ splitchar [i ] ) [ [1 ] ] [2 ]
extracted.tagsdf <- rbind ( extracted.tagsdf ,
# Remove leading spaces from tags.df$value
data.frame ( stringsAsFactors = FALSE ,
tags.df $ value [i ] <- sub ( " ^\\s+" , " " , value.tmp , useBytes = T )
tmp.tagsdf [rows.extract , ] ) )
if ( tags.df $ unit [i ] != " " ) {
}
tags.df $ value [i ] <- paste ( " \\SI{" , strsplit ( tags.df $ value [i ] , split = " " ) [ [1 ] ] [1 ] , " }{" , tags.df $ unit [i ] , " }" , sep = " " )
# 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 )
tags <- data.frame ( stringsAsFactors = FALSE ,
sampleid = tags.df $ sampleid ,
parameter = tags.df $ name ,
value = tags.df $ value )
return ( tags )
}
}