% MATALB CODE for Lidar Data Reduction. %

Total Page:16

File Type:pdf, Size:1020Kb

% MATALB CODE for Lidar Data Reduction. %

%************************************************************************** %************************************************************************** % MATALB CODE for lidar data reduction. % [email protected] % Last modified 26 Feb. 2007 function [Ns_process, altitude_kmb]= Proj4(go_func_go); clear all; clc; close all; bin_res = 7; % bin resolution t_bin = 160e-9; % bin width [nsec] c = 2.99792458e8; % speed of light [m/s] file_ii = 1; % file step counter for file_num =1:8:9

%********************************************************************** % Read the raw data for both files

% File and data path construction file_name = strcat('AR1102.00', int2str(file_num)); dir = 'C:\Program Files\MATLAB704\work\Lidar\proj4\Data\';

file_dir = strcat(dir, file_name);

% Read Lidar Data File, Data is indexed as: Ns(10240,3) = Ns(bins,freq) [Ns, tot_bins, low_bin, freq_tot, set_num, prof_num, shot_num, month,... day, year, UT_time, hour, minute, second, az_ang, bin_res, zen_ang, ... base_alt, lat, lon] = ReadLidarData(file_dir);

% Convert Bins to Ranges, this is common for all three frequencies. n_bin = [low_bin(1):tot_bins(1)]; % Create the bin array delta_R = t_bin*c/2; % [m] Compute range resolution, ie. Bin width in terms of range range = n_bin .* delta_R; %[m] Convert bin array to range array bin_bas = round((base_alt(1)*1e3) / delta_R);% Convert base altitude of lidar instrument into number of bins

%********************************************************************** % Convert Range to Height over sea level, account for the zenith angle

height = (range .* cosd(zen_ang(1))) + base_alt(1)*1e3; % [m] altitude_km =height./1e3; all_bin =n_bin + bin_bas;

% plot raw photon counts vs. bin number and altitude figure(1) [AX,H1,H2] =plotyy(Ns,all_bin, 0,altitude_km,'plot'); set(get(AX(1),'Ylabel'),'String','Bin number') set(get(AX(2),'Ylabel'),'String','Altitude [km]') title('2) Raw photon counts vs. altitude and bin number') xlabel('Photon Counts') legend('f_a','f_+','f_-')

%********************************************************************** % PMT/discriminator saturation correction .Do the photon count % correction one profile at the time.

for profile=1:3

% Flatten the photon counts array Ns_flat = Ns(:,profile);

% PMT Saturation Correction using Newtonian method (function given) Ns_corr = SaturationCorrectionVector(Ns_flat, delta_R, tot_bins(profile), shot_num(profile));

% Plot PMT Staturation Corrected Data if profile == 1 figure(2) plot(Ns_corr,altitude_km,'m') title('3) PMT Saturation Corrected Data') ylabel('Altitude [km]') xlabel('Photon Counts') legend('f_a (profile 1)') axis tight end

%****************************************************************** % Chopper Correction

% Read in chopper profiles from data files chop_open_file = 'chopperopen.dat';

% Data is ordered as: chopdata(bin, count, Hamming) chop_open = ReadChopperData(dir, chop_open_file);

% Divide the profile bins that actually needs to be chopper corrected % with the chopper function data Ns_corr(chop_open(:,1))= Ns_corr(chop_open(:,1))./chop_open(:,3)';

% Plot chopper corrected peak frequency vs. height if profile == 1 figure(3) plot(Ns_corr,altitude_km, 'k') title('Corrected Data for Chopper') ylabel('Altitude [km]') xlabel('Photon Counts') axis tight end

%****************************************************************** % Subtract background and plot peak-freq profile % Good background is assumed to be 138-180 km (J.F). From here a % mean is derived and subtracted from all altitudes.

%find index possition at 130 km and 180 km [trash array_pos_bot] = min(abs(altitude_km -130)); [trash array_pos_top] = min(abs(altitude_km -180));

% Take mean of the signal at the back ground range indicated above % as the back ground signal for all altitudes Nb_corr = (Ns_corr - (mean(Ns_corr(array_pos_bot:array_pos_top))));

% Plot background corrected peak frequency vs. height if profile == 1 figure(4) plot(Nb_corr, altitude_km, 'k') title('5) Data with backgound noise removed') ylabel('Altitude [km]') xlabel('Photon Counts') axis tight end

%****************************************************************** % Remove range dependence, ie multiply by range squared range_corr = Nb_corr.*(range.^2);

% Plot range corrected peak frequency vs. height if profile == 1 figure(5) plot(range_corr, altitude_km) title('6)Data (Range Corrected)') ylabel('Altitude [km]') xlabel('Photon Counts') axis tight end

%****************************************************************** % Add base altitude (to the bins)and take the Rayleigh % signal at 40km as the Rayleigh normalization signal. % Plot Rayleigh fitting and Rayleigh signal for the peak-freq data % profiles.

% Rayleigh fit (35-40) & Rayleigh signal @ 40 km [trash ray_pos_bot] = min(abs(altitude_km -35)); [trash ray_pos_cen] = min(abs(altitude_km -40)); [trash ray_pos_top] = min(abs(altitude_km -45)); logfit = polyfit(altitude_km(ray_pos_bot:ray_pos_top),... log(range_corr(ray_pos_bot:ray_pos_top)),1); fit_pts_log =polyval(logfit,altitude_km((ray_pos_bot:ray_pos_top)),1); fit_pts_lin = exp(fit_pts_log); Ray_Ns = exp(mean(fit_pts_log));

% Plot data with Rayligh fit @ 40 km if profile == 1 figure(6) plot(range_corr, altitude_km,'c', Ray_Ns,altitude_km(ray_pos_cen),... 'kp',fit_pts_lin, altitude_km(ray_pos_bot:ray_pos_top),'r') title('7) Rayleigh signal @ 40 km & Rayleigh fit(35-40 km)') ylabel('Altitude [km]') xlabel('Photon Counts') axis tight end

%****************************************************************** % Normalized signal with Ray_Ns Ns_norm = range_corr ./Ray_Ns;

%Plot normalized data if profile == 1 figure(7) plot(Ns_norm, altitude_km) title('8) Normalized signal with Ray_Ns') ylabel('Altitude [km]') xlabel('Photon Counts') axis tight end

% Save the different profile Ns_norm_profile(profile,:) = Ns_norm;

%****************************************************************** % Rebin. 24m => 480m each bin rep. 24 m. (10 240 bins)

%Create the binner array to use with function accumarray when binning rebinX = 20; binner = ones(1, rebinX); for bc=2:(tot_bins(1)/rebinX) binner = [binner ones(1, rebinX).*bc]; end binner = binner';

% rebin altitude bindex = [rebinX/2:rebinX:tot_bins(1)]; altitude_kmb = altitude_km(bindex);

Ns_norm = accumarray(binner, Ns_norm)'; if profile == 1 figure(8) plot(Ns_norm, altitude_kmb) title('Re Binned Ns_ norm') ylabel('Altitude [km]') xlabel('Photon Counts') axis tight end

% Save the different profile Ns_norm_rebin_profile(profile,:) = Ns_norm;

end %of for profile

Ns_process(file_ii,:,:)= Ns_norm_rebin_profile; file_ii = file_ii+1; end

%End of file

Recommended publications