0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 initialize_spectrometer_workspace
0015
0016 dark = [];
0017 flat = [];
0018
0019
0020
0021
0022
0023
0024 so.dir_light = [so.bd s 'light_frames' s so.exposure s so.sdate];
0025
0026
0027
0028
0029
0030
0031 y0 = 1175;
0032 h = 500;
0033
0034
0035 roi_light = [y0, h, 0, 0];
0036
0037
0038 g = waitbar(0, ['Loading ' so.ftype ' master frames and ' ...
0039 'processing reference frames. ']);
0040 waitbar(0.001, g);
0041 Ns = 4;
0042
0043 if isempty(dark)
0044 load([so.bd s 'dark_frames' s 'light_darks' s so.ftype ...
0045 '_master_dark_' so.exposure '.mat']);
0046 end
0047 waitbar(1/Ns, g);
0048
0049 if isempty(flat)
0050 load([so.bd s 'flat_frames' s so.ftype '_master_flat.mat']);
0051 end
0052 waitbar(2/Ns, g);
0053
0054
0055
0056
0057
0058
0059 imgdir = [so.dir_light s 'reference' s 'spectral' s so.ftype];
0060 spectral_ref = ensemble_average(imgdir);
0061
0062 spectral_ref = spectral_ref - dark;
0063 spectral_ref = flat_correct(spectral_ref, flat);
0064 spectral_ref = crop_image(spectral_ref, roi_light);
0065
0066 if strcmpi(so.ftype, 'PGM')
0067 spectral_ref = bayer_demosaic(spectral_ref);
0068 end
0069
0070 [ign, pdirpath] = pop_dirname(imgdir);
0071 metadata = process_metadata_file(pdirpath);
0072
0073 matname = [so.ftype '_spectral_ref.mat'];
0074 save('-V6', [pdirpath s matname], 'spectral_ref', 'metadata');
0075 waitbar(3/Ns, g);
0076
0077
0078 imgdir = [so.dir_light s 'reference' s 'radiometric' s so.ftype];
0079 radiometric_ref = ensemble_average(imgdir);
0080
0081 radiometric_ref = radiometric_ref - dark;
0082 radiometric_ref = flat_correct(radiometric_ref, flat);
0083 radiometric_ref = crop_image(radiometric_ref, roi_light);
0084
0085 if strcmpi(so.ftype, 'PGM')
0086 radiometric_ref = bayer_demosaic(radiometric_ref);
0087 end
0088
0089 [ign, pdirpath] = pop_dirname(imgdir);
0090 metadata = process_metadata_file(pdirpath);
0091
0092 matname = [so.ftype '_radiometric_ref.mat'];
0093 save('-V6', [pdirpath s matname], 'radiometric_ref', 'metadata');
0094 clear spectral_ref radiometric_ref;
0095 waitbar((4/Ns)-0.001, g);
0096
0097
0098
0099
0100 g = waitbar(0, ['Processing ' so.ftype ' spectrographs. ' ...
0101 'This may take several minutes.']);
0102 waitbar(0.001, g);
0103 dl = list_dir([so.dir_light s 'spectrographs'], so.ftype, 3);
0104 Ns = length(dl);
0105
0106 for jj=1:Ns
0107 waitbar(((jj-1)/Ns)-0.001, g);
0108 fl = list_dir(dl{jj}, ['*.' so.ftype], 1);
0109 if isempty(fl)
0110 continue;
0111 end
0112 spctgrph = ensemble_average(dl{jj});
0113 spctgrph = spctgrph - dark;
0114
0115 spctgrph = flat_correct(spctgrph, flat);
0116 spctgrph = crop_image(spctgrph, roi_light);
0117
0118 if strcmpi(so.ftype, 'PGM')
0119 spctgrph = bayer_demosaic(spctgrph);
0120 end
0121
0122 [ign, pdirpath] = pop_dirname(dl{jj});
0123 metadata = process_metadata_file(pdirpath);
0124
0125 [ensemble_number, pdirpath] = pop_dirname(pdirpath);
0126 spectrographs_descriptor = pop_dirname(pdirpath);
0127 matname = [so.ftype '_' spectrographs_descriptor '_' ensemble_number ...
0128 '.mat'];
0129 save('-V6', [pdirpath s matname], 'spctgrph', 'metadata');
0130
0131 end
0132 waitbar(1-0.001, g);
0133
0134 disp('')
0135 disp([mfilename() ' finished.'])
0136 clear all