Code Download
spectrometer code README.TXT
spectrometer code and sample spectrographs zip file
CHDK scripts and grid
CHDK_files.zip contains two lua scripts and a custom grid. shootn.lua sets the camera’s exposure time, aperture, zoom, focus, and ISO, then shoots N spectrographs. get_values.lua outputs the current camera settings, which can then be used to modify shootn.lua to alter the camera settings desired for shooting spectrographs. These scripts have only been tested on my Canon PowerShot A590, so you may have to modify them to work on your camera. Neither script is essential for taking spectrographs; they simply help automate the process. cfl.grd is a grid of vertical lines that occur at the locations of the most pronounced spectral peaks of a mercury compact fluorescent lamp’s spectrograph as recorded by my A590. You may not be able to use the grid directly, but you should be able to modify it easily so it better matches the CFL spectrum your camera captures.
Spectrometer Code HTML Prettyprint
Browse spectrometer code
Important Functions
image2spectrum() – converts a spectrograph to a spectrogram by summing the columns within a region of interest.
wavelength_calibrate() – takes a spectrograph of a CFL bulb and plots a spectrogram, requests that the user picks out specific spectral peaks, and then uses the peaks pixel locations to calculate a wavelength scale to replace the column number scale.
bayer_demosaic() – converts a Bayer raw image into an RGB image matrix by interpolating missing pixels in a channel from the nearest neighbors in that channel.
generate_Wbb_spectrum() – outputs the emissivity corrected, black-body spectrum of a tungsten filament incandescent bulb.
determine_y0(img, h) – finds the y-component (ym) of a spectrograph’s center of mass and outputs y0 = ym-(h/2), which defines the beginning of a spectrographs region of interest.
Important Scripts
batch_preprocess – ensemble averages and calibrates (noise reduction) every spectrograph. This script needs to be run once for every new set of spectrographs.
batch_raw_decode – decodes all raw images found within a parent directory and all of it’s children directories. This script needs to be run once for every new set of spectrographs.
make_master_dark_flat_bias – converts a collection of calibration frames into master calibrations frames. This script only needs to be run on a new set of calibration frames. It’s necessary to take a new set of dark frames if you change the exposure time. Each camera needs it’s own set of calibration frames.