Browse Source

Added functions for converting to/from wavelength and wavenumbers.

master
Taha Ahmed 5 years ago
parent
commit
c00fcc54a9
  1. 0
      .gitignore
  2. 0
      AVS2SHE.R
  3. 0
      Celsius2Kelvin.R
  4. 6
      ConvertRefPot.R
  5. 0
      ConvertRefPot.tex
  6. 0
      ConvertRefPotEC.R
  7. 0
      ConvertRefPotEC.tex
  8. 26
      CountRods.R
  9. 0
      GenericXtableSetAttributes.R
  10. 0
      Kelvin2Celsius.R
  11. 0
      LoadRData2Variable.R
  12. 0
      LongtableXtableHeader.R
  13. 0
      ProvideSampleId.R
  14. 0
      ProvideSampleId.tex
  15. 0
      SHE2AVS.R
  16. 2
      SubfigureGenerator.R
  17. 2
      SubstrateHistory.R
  18. 0
      TabularXtableHeader.R
  19. 0
      as.degrees.R
  20. 0
      as.radians.R
  21. 0
      capitalize.R
  22. 11
      eV2nm.R
  23. 0
      hms2seconds.R
  24. 0
      int2padstr.R
  25. 0
      is.wholenumber.R
  26. 0
      molarity2mass.R
  27. 11
      nm2eV.R
  28. 0
      numbers2words.R
  29. 0
      roundup.R
  30. 81
      siunitx-exp-uncert.R
  31. 2
      thth2d.R
  32. 0
      trapz.R
  33. 13
      wavelength2num.R
  34. 13
      wavenum2length.R

0
.gitignore

0
AVS2SHE.R

0
Celsius2Kelvin.R

6
ConvertRefPot.R

@ -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
ConvertRefPot.tex

0
ConvertRefPotEC.R

0
ConvertRefPotEC.tex

26
CountRods.R

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

0
GenericXtableSetAttributes.R

0
Kelvin2Celsius.R

0
LoadRData2Variable.R

0
LongtableXtableHeader.R

0
ProvideSampleId.R

0
ProvideSampleId.tex

0
SHE2AVS.R

2
SubfigureGenerator.R

@ -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

2
SubstrateHistory.R

@ -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 ##################

0
TabularXtableHeader.R

0
as.degrees.R

0
as.radians.R

0
capitalize.R

11
eV2nm.R

@ -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)
}

0
hms2seconds.R

0
int2padstr.R

0
is.wholenumber.R

0
molarity2mass.R

11
nm2eV.R

@ -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
numbers2words.R

0
roundup.R

81
siunitx-exp-uncert.R

@ -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))
}

2
thth2d.R

@ -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
trapz.R

13
wavelength2num.R

@ -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)
}

13
wavenum2length.R

@ -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