Added functions for converting to/from wavelength and wavenumbers.

master
Taha Ahmed 8 years ago
parent e2d0d21236
commit c00fcc54a9

@ -1,6 +1,6 @@
source("/home/taha/chepec/chetex/common/R/common/SHE2AVS.R")
source("/home/taha/chepec/chetex/common/R/common/AVS2SHE.R")
source("/home/taha/chepec/chetex/common/R/common/ConvertRefPotEC.R")
source(HomeByHost("/home/taha/chepec/chetex/common/R/common/SHE2AVS.R"))
source(HomeByHost("/home/taha/chepec/chetex/common/R/common/AVS2SHE.R"))
source(HomeByHost("/home/taha/chepec/chetex/common/R/common/ConvertRefPotEC.R"))
##################################################
################# ConvertRefPot ##################

@ -0,0 +1,26 @@
##################################################
################## CountRods #####################
##################################################
CountRods <- function() {
## Description:
##
## Usage:
##
## Arguments:
##
##
##
##
##
##
##
##
##
##
##
## Return value:
##
#
return()
}

@ -47,7 +47,7 @@ SubfigureGenerator <- function(images,
if (landscape == TRUE) {
cat("\\begin{sidewaysfigure}\\centering\n", file = zz)
} else {
cat("\\begin{figure}[tb]\\centering\n", file = zz)
cat("\\begin{figure}[hb]\\centering\n", file = zz)
}
# display images in a X-by-Y grid

@ -1,4 +1,4 @@
source("/home/taha/chepec/chetex/common/R/common/LoadRData2Variable.R")
source(HomeByHost("/home/taha/chepec/chetex/common/R/common/LoadRData2Variable.R"))
##################################################
############## SubstrateHistory ##################

@ -1,13 +1,16 @@
##################################################
#################### eV2nm #######################
##################################################
source(HomeByHost("/home/taha/chepec/chetex/common/R/sunlight/solarconstants.R"))
eV2nm <- function(eV) {
# Converts energy in eV to wavelength in nm
#
# Define some constants needed for the calculations
Plancks.constant <- 4.135667516E-15 # \electron\volt\per\second
speed.of.light <- 299792458 # \meter\per\second
sun.constants <- solar.constants()
nm <-
sun.constants["h.eV", "value"] *
1E9 * sun.constants["c", "value"] / eV
nm <- Plancks.constant * 1E9 * speed.of.light / eV
return(nm)
}

@ -1,13 +1,16 @@
##################################################
#################### nm2eV #######################
##################################################
source(HomeByHost("/home/taha/chepec/chetex/common/R/sunlight/solarconstants.R"))
nm2eV <- function(nm) {
# Converts wavelength in nm to energy in eV
#
# Define some constants needed for the calculations
Plancks.constant <- 4.135667516E-15 # \electron\volt\per\second
speed.of.light <- 299792458 # \meter\per\second
sun.constants <- solar.constants()
eV <-
sun.constants["h.eV", "value"] *
1E9 * sun.constants["c", "value"] / nm
eV <- Plancks.constant * 1E9 * speed.of.light / nm
return(eV)
}

@ -0,0 +1,81 @@
# Writing number with exponent (such as scientific notation) with uncertainty using siunitx
# Origin of problem, this kind of code:
# \SI[separate-uncertainty=true]{\Sexpr{formatC(cd.flux, format = "e", digits = 2)} \pm \Sexpr{formatC(cd.flux.error, format = "e", digits = 2)}}{\milli\coulomb\per\square\cm\per\second}
# makes siunitx throw the error:
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !
# ! siunitx error: "misplaced-sign-token"
# !
# ! Misplaced sign token '\pm '.
# !
# ! See the siunitx documentation for further information.
# !
# ! For immediate help type H <return>.
# !...............................................
# This is status-by-design according to Joseph Wright.
# http://tex.stackexchange.com/questions/123771/exponent-notation-in-siunitx
# But if the two numbers (number and uncertainty) have the same exponent, that is ok.
# So here we try to write a function that accepts two numbers,
# and returns them written in a common exponent (as strings).
siunitx.uncertainty <- function(quantity, uncertainty, digits = 6) {
# both arguments should be numeric
# how to find common exponent for two numbers?
# find exponent of quantity (tiopotensen for kvantiteten)
quantity.exponent <- floor(log(abs(quantity), 10))
# find coefficient of quantity
# warning, numeric-to-string-to-numeric conversion ...
quantity.coefficient <-
as.numeric(strsplit(formatC(quantity, format="e", digits=digits), "[Ee]-")[[1]][1])
# construct return quantity string
rquantity.string <-
paste0(formatC(quantity.coefficient, format="f", digits=digits), "e", quantity.exponent)
# find exponent of uncertainty (tiopotensen for the uncertainty)
uncertainty.exponent <- floor(log(abs(uncertainty), 10))
# find coefficient of uncertainty
# warning, numeric-to-string-to-numeric conversion ...
uncertainty.coefficient <-
as.numeric(strsplit(formatC(uncertainty, format="e", digits=digits), "[Ee]-")[[1]][1])
# adjust uncertainty to the same exponent as the quantity
# express uncertainty with the same exponent as quantity
# (adjust number of uncertainty accordingly)
runcertainty.exponent <- quantity.exponent
runcertainty.coefficient <- uncertainty.coefficient * 10^(uncertainty.exponent - quantity.exponent)
runcertainty.string <-
paste0(formatC(runcertainty.coefficient, format="f", digits=digits), "e", runcertainty.exponent)
# create a string directly suitable for the siunitx \num{} command
siunitx.string <- paste(quantity.coefficient, "\\pm", runcertainty.string)
return(c(quantity = rquantity.string,
uncertainty = runcertainty.string,
siunitx = siunitx.string))
}

@ -33,6 +33,6 @@ thth2d <- function(thth, wavelength = 1.540562) {
# Zn-Kb1 wavelength=1.295250
# Usage:
# thth : vector with thth values in degrees
# wavelength : radiation wavelength in Ångström
# wavelength : radiation wavelength in Angstrom
return (wavelength / (2 * sin(as.radians(thth))))
}

@ -0,0 +1,13 @@
##################################################
################ wavelength2num ##################
##################################################
wavelength2num <- function(wavelength) {
# Converts wavelength (nm) to wavenumber (cm-1)
# Only valid for absolute wavelengths,
# NOT delta wavelengths (ranges)
# http://www.powerstream.com/inverse-cm.htm
wavenumber <-
10E6 / wavelength
return(wavenumber)
}

@ -0,0 +1,13 @@
##################################################
################ wavenum2length ##################
##################################################
wavenum2length <- function(wavenumber) {
# Converts wavenumber (cm-1) to wavelength (nm)
# Only valid for absolute wavenumbers,
# NOT delta wavenumbers (ranges)
# http://www.powerstream.com/inverse-cm.htm
wavelength <-
10E6 / wavenumber
return(wavelength)
}
Loading…
Cancel
Save