library(ggplot2)
Read filter data from file
filter <- read.filter("Baader Solar Continuum Filter.csv")
Read data for scotopic and photopic vision from file
photopic.vision <- read.vision("vljve.csv", "Photopic")
scotopic.vision <- read.vision("scvle.csv", "Scotopic")
Filter transmission curve and vision efficency
vision <- rbind(scotopic.vision, photopic.vision)
vision$type = factor(vision$type, levels=c("Scotopic", "Photopic")) # Reorder
p <- ggplot() +
geom_line(data=filter, aes(wavelength,transmission), color="darkgreen") +
geom_line(data=vision, aes(wavelength,100*rle,color=type)) +
scale_color_manual(name="Vision", values=c("black","grey70")) +
labs(title="Baader Solar Continuum Filter", x="Wavelength [nm]", y="Transmission [%]") +
coord_cartesian(xlim=c(300, 850), ylim=c(0.0,100.0)) +
theme_bw()
print(p)
Filter parameters
filter.parameters(filter$wavelength, filter$transmission)
## $center
## [1] 535.75
##
## $fwhm
## [1] 8.400024
##
## $peak
## [1] 95.08367
# Function to calculate filter parameters
filter.parameters <- function(x, y, peak=NULL, dx=100) {
# Create data frame from input data.
df <- data.frame(x, y)
# Find maximum y.
if (is.null(peak)) {
maximum <- df[which.max(df$y),]
} else {
lo <- subset(df, x > peak-dx)
hi <- subset(df, x < peak+dx)
df <- merge(lo, hi, by="x")
df <- df[,1:2]
names(df) <- c("x","y")
maximum <- df[which.max(df$y),]
}
# Find x#0 of FWHM (< x at y maximum).
lo <- subset(df, x<maximum$x & x>maximum$x-dx & y<maximum$y/2)
hi <- subset(df, x<maximum$x & x>maximum$x-dx & y>maximum$y/2)
x0 <- (lo[which.max(lo$x),1] + hi[which.min(hi$x),1]) / 2
# Find x#1 of FWHM (> x at y maximum).
lo <- subset(df, x>maximum$x & x<maximum$x+dx & y<maximum$y/2)
hi <- subset(df, x>maximum$x & x<maximum$x+dx & y>maximum$y/2)
x1 <- (lo[which.min(lo$x),1] + hi[which.max(hi$x),1]) / 2
# Result.
list(center=(x1+x0)/2, fwhm=x1-x0, peak=maximum$y)
}
# Function to read filter data from file
read.filter <- function(file.name) {
read.csv(file.name, col.names=c("wavelength","transmission","X"))[,1:2]
}
# Function to read vision data from file
read.vision <- function(filename, type) {
df <- read.csv(filename)
df$type <- type
df
}