Skip to content

Commit

Permalink
travis
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste authored and baptiste committed Dec 5, 2013
1 parent c704ed6 commit bdf78e1
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gitignore
.git
.RS_Store
.travis.yml
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Sample .travis.yml for R projects.
#
# See the r-travis repo and its wiki
# https://github.com/craigcitro/r-travis/wiki

language: c

env:
global:
- R_BUILD_ARGS="--no-build-vignettes --no-manual"
- R_CHECK_ARGS="--no-build-vignettes --no-manual --as-cran"

before_install:
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
- chmod 755 ./travis-tool.sh
- ./travis-tool.sh bootstrap

install:
- ./travis-tool.sh install_r testthat knitr

script:
- ./travis-tool.sh run_tests

after_script:
- ./travis-tool.sh dump_logs

notifications:
email:
on_success: change
on_failure: change


2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Authors@R: person("Baptiste", "Auguie", email = "[email protected]",
source listed in the help file.")
Description: Physical constants. Gold, silver and glass permittivities,
together with spline interpolation functions.
Version: 0.2.2
Version: 0.2.3
Date: 2012-03-04
Depends:
R (>= 2.13),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export(dielectric2plot)
export(drude)
export(epsAg)
export(epsAu)
export(fitDrude)
export(fit_drude)
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

dielectric 0.2.3 (2013-11-08)

* silly typo in Au_JC demo

dielectric 0.2.2 (2013-05-18)

* cleaning examples for CRAN
Expand Down
43 changes: 24 additions & 19 deletions R/drude.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@
##'
##' a bacground contribution eps_inf is assumed for the core electrons
##' @title drude
##' @param wavelength wavelength in m
##' @param omega angular frequency in rad/s
##' @param wavelength wavelength in nm
##' @param p vector of 3 parameters
##' @param omega angular frequency in rad/s
##' @param omega_p plasma frequency in rad/s
##' @param gamma_p damping constant, in rad/s
##' @param epsilon_inf background dielectric function
##' @param ... not used
##' @return a data.frame with wavelength in microns and complex dielectric function
##' @return a data.frame with wavelength in nm and complex dielectric function
##' @author Baptiste Auguie
##' @export
drude <- function(wavelength, omega=NULL, p=c(1e16, 1e14, 1),
drude <- function(wavelength=633, p=c(1e16, 1e14, 1),
omega=2*pi*1e9 * 2.99792458e8 / wavelength,
omega_p = p[1], gamma_p = p[2], epsilon_inf = p[3], ...){
cel <- 2.99792458e8
if(is.null(omega))
omega <- 2*pi * cel / wavelength
data.frame(wavelength=wavelength *1e6,
epsilon = epsilon_inf - omega_p^2 / (omega^2 + (0+1i) * omega * gamma_p))


if(missing(wavelength))
wavelength <- 2*pi*1e9 * 2.99792458e8 / omega

data.frame(wavelength=wavelength,
epsilon = epsilon_inf - omega_p^2 / (omega^2 + (0+1i) * omega * gamma_p))

}

##' Objective function for the Drude model
##'
##' Used to fit a Drude model to a material
##' @title fitFDrude
##' @title fit_drude
##' @param p parameters vector (3)
##' @param material data.frame with wavelength in microns and complex epsilon
##' @param ... passed to Drude
##' @param material data.frame with wavelength in nm and complex epsilon
##' @param ... passed to drude
##' @return sum of squares
##' @author Baptiste Auguie
##' @export
fitDrude <- function(p, material, ...){

res <- drude(material$wavelength*1e-9, omega_p=p[1], gamma_p=p[2], epsilon_inf=p[3], ...)

sos.real <- sum((Re(res$epsilon) - Re(material$epsilon))^2) / sum(Re(material$epsilon)^2)
sos.imag <- sum((Im(res$epsilon) - Im(material$epsilon))^2) / sum(Im(material$epsilon)^2)
fit_drude <- function(p, material, ...){

res <- drude(material[['wavelength']], p, ...)

sos.real <- sum((Re(res[['epsilon']]) - Re(material[['epsilon']]))^2) /
sum(Re(material[['epsilon']])^2)
sos.imag <- sum((Im(res[['epsilon']]) - Im(material[['epsilon']]))^2) /
sum(Im(material[['epsilon']])^2)

sos.real + sos.imag
}
4 changes: 2 additions & 2 deletions demo/AuJC.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ data(AuJC)

AuJC$set_span(300, 800)
raw <- dielectric2plot(AuJC$raw())
silver <- AuJC$predict(n=300, all.knots=TRUE)
gold <- AuJC$predict(n=300, all.knots=TRUE)

d <- dielectric2plot(silver)
d <- dielectric2plot(gold)

ggplot(d, aes(wavelength, value)) + geom_path() +
facet_grid(variable~., scales="free") +
Expand Down
13 changes: 7 additions & 6 deletions man/drude.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
\alias{drude}
\title{drude}
\usage{
drude(wavelength, omega = NULL, p = c(1e+16, 1e+14, 1),
drude(wavelength = 633, p = c(1e+16, 1e+14, 1),
omega = 2 * pi * 1e+09 * 299792458/wavelength,
omega_p = p[1], gamma_p = p[2], epsilon_inf = p[3],
...)
}
\arguments{
\item{wavelength}{wavelength in m}

\item{omega}{angular frequency in rad/s}
\item{wavelength}{wavelength in nm}

\item{p}{vector of 3 parameters}

\item{omega}{angular frequency in rad/s}

\item{omega_p}{plasma frequency in rad/s}

\item{gamma_p}{damping constant, in rad/s}
Expand All @@ -22,8 +23,8 @@
\item{...}{not used}
}
\value{
a data.frame with wavelength in microns and complex
dielectric function
a data.frame with wavelength in nm and complex dielectric
function
}
\description{
Drude model for the dielectric function of good (governed
Expand Down
12 changes: 6 additions & 6 deletions man/fitDrude.Rd → man/fit_drude.Rd
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
\name{fitDrude}
\alias{fitDrude}
\title{fitFDrude}
\name{fit_drude}
\alias{fit_drude}
\title{fit_drude}
\usage{
fitDrude(p, material, ...)
fit_drude(p, material, ...)
}
\arguments{
\item{p}{parameters vector (3)}

\item{material}{data.frame with wavelength in microns and
\item{material}{data.frame with wavelength in nm and
complex epsilon}

\item{...}{passed to Drude}
\item{...}{passed to drude}
}
\value{
sum of squares
Expand Down

0 comments on commit bdf78e1

Please sign in to comment.