Skip to content

Commit

Permalink
Removed R and T calculations to their own functions to ensure consist…
Browse files Browse the repository at this point in the history
…ancy between different scans
  • Loading branch information
tjconstant committed Feb 24, 2015
1 parent 1c926b8 commit 073a423
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
16 changes: 16 additions & 0 deletions R/RTCalc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ReflectionCalc <-function(r){
return(r*Conj(r))
}

TransmissionCalc <-function(t,angle,theta2, incident_medium.index,exit_medium.index,polarisation){

#remember t*conj(t) does NOT in general equal T.
#correct phase conditions accounted for in scan files, and
#found originally at https://github.com/sbyrnes321/tmm

if(polarisation=="s"){
return(t*Conj(t)*(exit_medium.index*cos(theta2)/(incident_medium.index*cos(angle))))
} else if(polarisation=="p"){
return(t*Conj(t)*(exit_medium.index*Conj(cos(theta2))/(incident_medium.index*Conj(cos(angle)))))
}
}
File renamed without changes.
18 changes: 9 additions & 9 deletions R/angle_scan.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ angle_scan<-function(angle_range=seq(0,pi/2,,500),wavelength=633e-9, polarisatio
M<-mtx.exp(M,layers$repetitions)

r<-rFromTMatrix(M=M,gamma0=gamma0,gamma2=gamma2)
Reflection[counting_variable]<-r*Conj(r)
Reflection[counting_variable]<-ReflectionCalc(r)

t<-tFromTMatrix(M=M,gamma0=gamma0,gamma2=gamma2)
if(polarisation=="s"){
Transmission[counting_variable]<- t*Conj(t)*(exit_medium.index*cos(L$theta2)/(incident_medium.index*cos(angle)))
} else if(polarisation=="p"){
Transmission[counting_variable]<- t*Conj(t)*(exit_medium.index*Conj(cos(L$theta2))/(incident_medium.index*Conj(cos(angle))))
}
}
return(data.frame(angle=angle_range,Reflection=Re(Reflection),Transmission=Re(Transmission)))
Transmission[counting_variable]<-TransmissionCalc(t,angle,L$theta2,incident_medium.index,exit_medium.index,polarisation)

}
return(data.frame(angle=angle_range,
Reflection=Re(Reflection),
Transmission=Re(Transmission),
Absorption=1-Re(Transmission)-Re(Reflection)))
}


6 changes: 5 additions & 1 deletion R/dispersion_scan.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ dispersion_scan<-function(angle_range=seq(0,pi/2,,100),wavelength_range=seq(350e

}
}
return(data.frame(angle=cum_angle,wavelength=cum_wavelength,Reflection=Re(Reflection),Transmission=Re(Transmission)))
return(data.frame(angle=cum_angle,
wavelength=cum_wavelength,
Reflection=Re(Reflection),
Transmission=Re(Transmission),
Absorption=1-Re(Transmission)-Re(Reflection)))
}

3 changes: 0 additions & 3 deletions R/rtFromTMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ rFromTMatrix<- function(M,gamma0,gamma2){
}

tFromTMatrix<- function(M,gamma0,gamma2){
#remember t*conj(t) does NOT in general equal T.
#correct phase conditions accounted for in scan files, and
#found originally at https://github.com/sbyrnes321/tmm

t<-(2*gamma0)/((gamma0*M[1,1])+(gamma0*gamma2*M[1,2])+(M[2,1])+(gamma2*M[2,2]))
return(t)
Expand Down
13 changes: 6 additions & 7 deletions R/wavelength_scan.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ wavelength_scan<-function(wavelength_range=seq(350e-9,850e-9,,500),angle=0, pola
M<-mtx.exp(M,layers$repetitions)

r<-rFromTMatrix(M=M,gamma0=gamma0,gamma2=gamma2)
Reflection[counting_variable]<-r*Conj(r)
Reflection[counting_variable]<-ReflectionCalc(r)

t<-tFromTMatrix(M=M,gamma0=gamma0,gamma2=gamma2)
Transmission[counting_variable]<-TransmissionCalc(t,angle,L$theta2,incident_medium.index,exit_medium.index,polarisation)

if(polarisation=="s"){
Transmission[counting_variable]<- t*Conj(t)*(exit_medium.index*cos(L$theta2)/(incident_medium.index*cos(angle)))
} else if(polarisation=="p"){
Transmission[counting_variable]<- t*Conj(t)*(exit_medium.index*Conj(cos(L$theta2))/(incident_medium.index*Conj(cos(angle))))
}

}

return(data.frame(wavelength=wavelength_range,Reflection=Re(Reflection),Transmission=Re(Transmission)))
return(data.frame(wavelength=wavelength_range,
Reflection=Re(Reflection),
Transmission=Re(Transmission),
Absorption=1-Re(Transmission)-Re(Reflection)))
}


File renamed without changes.

0 comments on commit 073a423

Please sign in to comment.