Commit 04f6935d authored by Joe Taylor's avatar Joe Taylor
Browse files

Initial commit of RU sample code into public user repo

parent 7d3a56e9
*.nc filter=lfs diff=lfs merge=lfs -text
*.mat filter=lfs diff=lfs merge=lfs -text
*.nc filter=lfs diff=lfs merge=lfs -text
function E_p = Ep_approx(prpt,alph,delta_ext,L_cbb,L_hbb,B_ssm,L,d_cbb,d_hbb)
%
% function E_p = Ep_approx(prpt,alph,delta_ext,L_cbb,L_hbb,B_ssm,L,d_cbb,d_hbb)
%
% The SSM and sensor act like a polarizer-analyzer pair. This function calculates
% the approximate radiance error generated by the polarizer-analyzer pair
%
% Inputs
% prpt: p_r * p_t for sensor + SSM (unitless) [nchan x 1]
% alph: analyzer angle alpha for sensor (radians) [scalar]
% delta_ext: polarizer angle for N scene views (radians) [1 x N]
% L_cbb: Radiance for cold cal reference (Rad units)) [nChan x N]
% L_hbb: Radiance for hot cal reference (Rad units)) [nChan x 1]
% B_ssm: Planck radiance for scene mirror temp (Rad units)) [nChan x 1]
% L: Scene radiance for N scene views (Rad units)) [nChan x 1] or [nChan x N]
% d_cbb: polarizer angle for CBB view (radians) [scalar]
% d_hbb: polarizer angle for HBB view (radians) [scalar]
%
% Outputs
% E_p calibration bias due to polarization (Rad units) [nChan x N]
%
% 2020-08-19 JKT
% University of Wisconsin-Madison Space Science and Engineering Center (UW-SSEC)
if size(L,2) == 1
L = repmat(L,1,length(delta_ext));
elseif size(L,2) ~= length(delta_ext)
fprintf(1, 'Ep_approx: ERROR Invalid scene radiance dimensions\n');
end
if abs(d_cbb) > 2*pi
fprintf(1, 'Ep_approx: ERROR delta CBB out of range, should be in units of radians\n')
return
end
if abs(d_hbb) > 2*pi
fprintf('Ep_approx: ERROR delta HBB out of range, should be in units of radians\n')
return
end
E_p = NaN*ones(length(L_cbb),length(delta_ext)); % N_{d.wn} x N_{d.delta_ext}
for ii = 1:length(delta_ext)
d_ext = delta_ext(ii);
L_ext = L(:,ii);
% approximate equation
term1 = prpt.*(L_ext*cos(2*(d_ext - alph)));
term2 = -prpt.*(L_hbb.*((L_ext - L_cbb)./(L_hbb - L_cbb))*cos(2*(d_hbb - alph)));
term3 = -prpt.*(L_cbb.*((L_hbb - L_ext)./(L_hbb - L_cbb))*cos(2*(d_cbb - alph)));
term4 = -B_ssm.*prpt.*(cos(2*(d_ext - alph)));
term5 = +B_ssm.*prpt.*(((L_ext - L_cbb)./(L_hbb - L_cbb))*cos(2*(d_hbb - alph)));
term6 = +B_ssm.*prpt.*(((L_hbb - L_ext)./(L_hbb - L_cbb))*cos(2*(d_cbb - alph)));
E_p(:,ii) = term1 + term2 + term3 + term4 + term5 + term6;
end
return
function B = ICTradModelRU_L1b_aux(sensor,T_ICT,T_CRIS,ICT_Param,ru_term,ru_value)
%
% function B = ICTradModelRU_L1b_aux(sensor,T_ICT,T_CRIS,ICT_Param,ru_term,ru_value)
%
% Compute ICT predicted radiance using ICT radiometric model prescribed by ATBD
% with perturbation to a single term
%
% Inputs
% sensor sparse spectral params structure
% .band
% .v
% .output_range
% T_ICT ICT Temperature
% T_CRIS CrIS temperature struct
% ICT_Param ICT radiometric model parameters
% ru_term string indicating ru_term to perturb
% ru_value size of perturbation
%
% Outputs
% B Structure of predicted ICT radiance variables
% .emitted emitted radiance
% .wn wavenumber scale
% .SSM_Baffle SSM Baffle term reflected radiance
% .ICT_baffle ICT baffle term reflected radiance
% .OMA OMA term reflected radiance
% .BS_warm BS_warm term reflected radiance
% .BS_cold BS_cold term reflected radiance
% .Space Earth/Space term reflected radiance
% .reflected total reflected radiance
% .total total radiance (emitted and reflected)
% .V view factors (struct)
% .e emissivities (struct)
% .r reflectivies (.SSM)
% .T temperatures (struct)
% .e_ICT ICT emissivity
% .T_ICT ICT temperature
% .ru_term RU term to perturb
% .ru_value value of perturbation
% .no_perturb_val
% .perturbed_val
%
% 2020-08-19 JKT
% University of Wisconsin-Madison Space Science and Engineering Center (UW-SSEC)
wn = sensor.v_onaxis;
ICT_wnum = ICT_Param.(sprintf('%s_ICT_wnum',lower(sensor.band)));
ICT_emiss = ICT_Param.(sprintf('%s_ICT_emiss',lower(sensor.band)));
ICT_Baffle_emiss = ICT_Param.(sprintf('%s_ICT_Baffle_emiss',lower(sensor.band)));
Housing_emiss = ICT_Param.(sprintf('%s_Housing_emiss',lower(sensor.band)));
ScanBaffle_emiss = ICT_Param.(sprintf('%s_ScanBaffle_emiss',lower(sensor.band)));
ScanMirror_emiss = ICT_Param.(sprintf('%s_ScanMirror_emiss',lower(sensor.band)));
Earth_emiss = ICT_Param.(sprintf('%s_Earth_emiss',lower(sensor.band)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ICT emissivity interpolation to wavenumber grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Interpolate 4-min-EP emissivity to the on-axis sensor grid.
%% The wavenumber values corresponding to the emissivity values in the engineering packet are on the normal spectral resolution and on user grid
e_ICT = interp1(ICT_wnum,ICT_emiss,wn,'nearest','extrap');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Temperature, emissivity and view factor init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SSM
%%----------
%r.SSM = 1-ICT_Param.Band(iband).Emissivity.ScanMirrorPts;
r.SSM = 1-ScanMirror_emiss;
%% SSM_Baffle
%%----------
%e.SSM_Baffle = ICT_Param.Band(iband).Emissivity.ScanBafflePts;
e.SSM_Baffle = ScanBaffle_emiss;
T.SSM_Baffle = T_CRIS.ssm_baffle_temp + T_CRIS.ssm_baffle_corr_temp;
T.SSM_Baffle(isnan(T.SSM_Baffle)) = 0;
V.SSM_Baffle = ICT_Param.View_Factor.ScanBaffle;
%% ICT_baffle
%%----------
%e.ICT_baffle = ICT_Param.Band(iband).Emissivity.ICT_BafflePts;
e.ICT_baffle = ICT_Baffle_emiss;
T.ICT_baffle = T_ICT;
V.ICT_baffle = ICT_Param.View_Factor.ICTBaffle;
%% OMA + Frame + Other
%%----------
%e.OMA = ICT_Param.Band(iband).Emissivity.HousingPts;
e.OMA = Housing_emiss;
T.OMA = mean(0.5*T_CRIS.oma_struct_temp_1 + 0.5*T_CRIS.oma_struct_temp_2);
V.OMA = ICT_Param.View_Factor.OMAandFrame;
%% BS_warm
%%----------
e.BS_warm = e.OMA;
T.BS_warm = T.OMA;
V.BS_warm = ICT_Param.View_Factor.BeamSplitterWarm;
%% BS_cold
%%----------
T.BS_cold = T_ICT;
V.BS_cold = ICT_Param.View_Factor.BeamSplitterCold;
%% Space/Earth Reflected
%%----------
e.Space = Earth_emiss;
T.Space = ICT_Param.Earth_Temperature;
V.Space = ICT_Param.View_Factor.Space;
no_perturb_val = []; % initialize, will remain at this value for no perturbation
perturbed_val = []; % initialize, will remain at this value for no perturbation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Perturbation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch ru_term
case 'e_ICT'
no_perturb_val = e_ICT;
e_ICT = e_ICT*(1-ru_value);
e_ICT(e_ICT > 1) = 1;
e_ICT(e_ICT < 0) = 0;
perturbed_val = e_ICT;
case 'T_ICT'
no_perturb_val = T_ICT;
T_ICT = T_ICT + ru_value;
perturbed_val = T_ICT;
case 'SSM_scan_mirror_baffle'
no_perturb_val = T.SSM_Baffle;
T.SSM_Baffle = T.SSM_Baffle + ru_value;
perturbed_val = T.SSM_Baffle;
case 'T_ScanBaffleCorrection'
no_perturb_val = T.SSM_Baffle;
T.SSM_Baffle = T.SSM_Baffle + ru_value;
perturbed_val = T.SSM_Baffle;
case 'T_ICT_baffle'
no_perturb_val = T.ICT_baffle;
T.ICT_baffle = T.ICT_baffle + ru_value;
perturbed_val = T.ICT_baffle;
case 'T_OMA' % OMA + Frame + Other
no_perturb_val = T.OMA;
T.OMA = T.OMA + ru_value;
perturbed_val = T.OMA;
case 'T_Frame' % no longer used
no_perturb_val = T.Frame;
T.Frame = T.Frame + ru_value;
perturbed_val = T.Frame;
case 'T_BS_warm'
no_perturb_val = T.BS_warm;
T.BS_warm = T.BS_warm + ru_value;
perturbed_val = T.BS_warm;
case 'T_BS_cold'
no_perturb_val = T.BS_cold;
T.BS_cold = T.BS_cold + ru_value;
perturbed_val = T.BS_cold;
case 'T_Space'
no_perturb_val = T.Space;
T.Space = T.Space + ru_value;
perturbed_val = T.Space;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ICT emission
% (ref: eq 75 in 474-00032, Rev C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
B.emitted = e_ICT .* bt2rad(wn,T_ICT);
B.wn = wn;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reflected term 1: SSM Baffle
% (ref: eq 76 in 474-00032, Rev C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if V.SSM_Baffle == 0
B.SSM_Baffle = zeros(size(B.wn));
else
B.SSM_Baffle = (1 - e_ICT) .* e.SSM_Baffle * V.SSM_Baffle .* bt2rad(wn,T.SSM_Baffle);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reflected term 2: ICT Baffle
% (ref: eq 78a in 474-00032, Rev C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if V.ICT_baffle == 0
B.ICT_baffle = zeros(size(B.wn));
else
B.ICT_baffle = (1 - e_ICT) .* e.ICT_baffle * V.ICT_baffle .* bt2rad(wn,T.ICT_baffle);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reflected term 3a,b,c: OMA, frame, other, Beamsplitter Warm
% (ref: eq 77 in 474-00032, Rev C)
% V = 0.214 for OMA, Other, Frame terms in ATBD (= 0.0590 + 0.0100 + 0.1450)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% OMA
%%----------
if V.OMA == 0
B.OMA = zeros(size(B.wn));
else
B.OMA = (1 - e_ICT) .* e.OMA * r.SSM * V.OMA .* bt2rad(wn,T.OMA);
end
%% BS_Warm
%%----------
if V.BS_warm == 0
B.BS_warm = zeros(size(B.wn));;
else
B.BS_warm = (1 - e_ICT) .* e.BS_warm * r.SSM * V.BS_warm .* bt2rad(wn,T.BS_warm);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reflected term 4: Beamsplitter Cold
% (ref: eq 78b in 474-00032, Rev C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if V.BS_cold == 1
B.BS_cold = (1 - e_ICT) .* r.SSM^2 .* 0.5 * V.BS_cold .* bt2rad(wn,T.BS_cold); % Consistent with ATBD
else
B.BS_cold = (1 - e_ICT) .* r.SSM^2 .* 0.5 * V.BS_cold .* bt2rad(wn,T.BS_cold); % SNPP
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reflected term 5: Space/Earth View
% (ref: eq 78c in 474-00032, Rev C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if V.Space == 0
B.Space = zeros(size(B.wn));;
else
B.Space = (1 - e_ICT) .* V.Space .* e.Space .* bt2rad(wn,T.Space);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% total reflected radiance into ICT cavity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V.Total = V.SSM_Baffle + V.ICT_baffle + V.OMA + V.BS_warm + V.BS_cold + V.Space; % should total 1, for check only
B.reflected = B.SSM_Baffle + B.ICT_baffle + B.OMA + B.BS_warm + B.BS_cold + B.Space;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Total radiance from ICT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
B.total = B.emitted + B.reflected;
B.wn = wn;
B.V = V;
B.e = e;
B.r = r;
B.T = T;
B.e_ICT = e_ICT;
B.T_ICT = T_ICT;
B.ru_term = ru_term;
B.ru_value = ru_value;
B.no_perturb_val = no_perturb_val;
B.perturbed_val = perturbed_val;
return
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
function radiance = bt2rad(freq,bt);
%
% function radiance = bt2rad(freq,bt);
%
% compute radiance given wavenumbers and brightness temperature.
%
% Inputs:
% freq wavenumbers (Nx1) in 1/cm
% bt brightnes temperature (Nx1) in Kelvin
% Outputs:
% radiance Planck radiances (Nx1) in mW/(m^2 sr. 1/cm)
%
% see also RADTOT.M, RAD2BT.M, TTORAD.M
%
% DCT 11/11-99
% University of Wisconsin-Madison Space Science and Engineering Center (UW-SSEC)
%
% fundamental constants:
% (Cohen, E.R. and B.N. Taylor, The 1986 CODATA recommended values
% of the fundamental physical constants, Journal of Research of
% the National Bureau of Standard, 92(2), March-April 1987.)
h = 6.6260755E-34; % Planck constant in Js
c = 2.99792458E8; % photon speed in m/s
k = 1.380658E-23; % Boltzmann constant in J/K
c1 = 2*h*c*c*1e8;
c2 = h*c/k*1e2;
radiance = 1e3 * c1.*(freq.*freq.*freq)./(exp((c2.*freq)./bt)-1);
ind = find(bt < 0);
if length(ind) ~= 0
radiance = nan*real(radiance);
disp('WARNING: negative inputs to BT2RAD')
end
ind = find(~isreal(bt));
if length(ind) ~= 0
radiance = nan*real(radiance);
disp('WARNING: imaginary inputs to BT2RAD')
end
ind = find(isnan(bt));
if length(ind) ~= 0
radiance = nan*real(radiance);
disp('WARNING: NaN inputs to BT2RAD')
end
ind = find(isinf(bt));
if length(ind) ~= 0
radiance = nan*real(radiance);
disp('WARNING: Inf inputs to BT2RAD')
end
return
function [ICT_Param,RU,nonlin,polcorr_param] = convert_anc_to_structs(nc_struct);
%
% function [ICT_Param,RU,nonlin,polcorr_param] = convert_anc_to_structs(nc_struct);
%
% This function converts the contents from the CrIS L1b RU ancillary file
% to ICT_Param, RU, nonlin, and polcorr structures for use in the RU calculations
%
% Input
% nc_struct structure of vars read from CrIS L1b RU ancillary file
%
% Output
% ICT_Param ICT ancillary parameters [struct]
% RU Radiometric Uncertainty ancillary parameters [struct]
% nonlin nonlinearity corretion ancillary parameters [struct]
% polcorr_param polarization correction ancillary parameters [struct]
%
% JKT 2021-Aug-26
% University of Wisconsin-Madison Space Science and Engineering Center (UW-SSEC)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ICT_Param.Earth_Temperature = nc_struct.ICT_Param_Earth_Temperature;
ICT_Param.lw_ICT_wnum = nc_struct.wnum_lw;
ICT_Param.lw_ICT_emiss = nc_struct.ICT_Param_lw_ICT_emiss;
ICT_Param.lw_ICT_Baffle_emiss = nc_struct.ICT_Param_lw_ICT_Baffle_emiss;
ICT_Param.lw_Housing_emiss = nc_struct.ICT_Param_lw_Housing_emiss;
ICT_Param.lw_ScanBaffle_emiss = nc_struct.ICT_Param_lw_ScanBaffle_emiss;
ICT_Param.lw_ScanMirror_emiss = nc_struct.ICT_Param_lw_ScanMirror_emiss;
ICT_Param.lw_Earth_emiss = nc_struct.ICT_Param_lw_Earth_emiss;
ICT_Param.mw_ICT_wnum = nc_struct.wnum_mw;
ICT_Param.mw_ICT_emiss = nc_struct.ICT_Param_mw_ICT_emiss;
ICT_Param.mw_ICT_Baffle_emiss = nc_struct.ICT_Param_mw_ICT_Baffle_emiss;
ICT_Param.mw_Housing_emiss = nc_struct.ICT_Param_mw_Housing_emiss;
ICT_Param.mw_ScanBaffle_emiss = nc_struct.ICT_Param_mw_ScanBaffle_emiss;
ICT_Param.mw_ScanMirror_emiss = nc_struct.ICT_Param_mw_ScanMirror_emiss;
ICT_Param.mw_Earth_emiss = nc_struct.ICT_Param_mw_Earth_emiss;
ICT_Param.sw_ICT_wnum = nc_struct.wnum_sw;
ICT_Param.sw_ICT_emiss = nc_struct.ICT_Param_sw_ICT_emiss;
ICT_Param.sw_ICT_Baffle_emiss = nc_struct.ICT_Param_sw_ICT_Baffle_emiss;
ICT_Param.sw_Housing_emiss = nc_struct.ICT_Param_sw_Housing_emiss;
ICT_Param.sw_ScanBaffle_emiss = nc_struct.ICT_Param_sw_ScanBaffle_emiss;
ICT_Param.sw_ScanMirror_emiss = nc_struct.ICT_Param_sw_ScanMirror_emiss;
ICT_Param.sw_Earth_emiss = nc_struct.ICT_Param_sw_Earth_emiss;
ICT_Param.View_Factor.Space = nc_struct.ICT_Param_A_Space;
ICT_Param.View_Factor.BeamSplitterCold = nc_struct.ICT_Param_A_BeamSplitterCold;
ICT_Param.View_Factor.BeamSplitterWarm = nc_struct.ICT_Param_A_BeamSplitterWarm;
ICT_Param.View_Factor.OMAandFrame = nc_struct.ICT_Param_A_OMAandFrame;
ICT_Param.View_Factor.ICTBaffle = nc_struct.ICT_Param_A_ICTBaffle;
ICT_Param.View_Factor.ScanBaffle = nc_struct.ICT_Param_A_ScanBaffle;
RU.dT_ict = nc_struct.RU_dT_ict;
RU.de_ict = nc_struct.RU_de_ict;
RU.dT_ict_ref_meas = nc_struct.RU_dT_ict_ref_meas;
RU.dT_ict_ref_model = nc_struct.RU_dT_ict_ref_model;
RU.dprpt = nc_struct.RU_dprpt;
RU.dalpha = nc_struct.RU_dalpha;
RU.lw_da2 = nc_struct.RU_lw_da2;
RU.mw_da2 = nc_struct.RU_mw_da2;
RU.sw_da2 = nc_struct.RU_sw_da2;
nonlin.lw_a2 = nc_struct.nonlin_lw_a2;
nonlin.mw_a2 = nc_struct.nonlin_mw_a2;
nonlin.sw_a2 = nc_struct.nonlin_sw_a2;
polcorr_param.delta_SSM = nc_struct.polcorr_delta_SSM;
polcorr_param.lw_wn = repmat(nc_struct.wnum_lw(:),1,9);
polcorr_param.lw_prpt = nc_struct.polcorr_lw_prpt;
polcorr_param.lw_alph = nc_struct.polcorr_lw_alph;
polcorr_param.lw_delta_cbb = nc_struct.polcorr_delta_cbb;
polcorr_param.lw_delta_hbb = nc_struct.polcorr_delta_hbb;
polcorr_param.mw_wn = repmat(nc_struct.wnum_mw(:),1,9);
polcorr_param.mw_prpt = nc_struct.polcorr_mw_prpt;
polcorr_param.mw_alph = nc_struct.polcorr_mw_alph;
polcorr_param.mw_delta_cbb = nc_struct.polcorr_delta_cbb;
polcorr_param.mw_delta_hbb = nc_struct.polcorr_delta_hbb;
polcorr_param.sw_wn = repmat(nc_struct.wnum_sw,1,9);
polcorr_param.sw_prpt = nc_struct.polcorr_sw_prpt;
polcorr_param.sw_alph = nc_struct.polcorr_sw_alph;
polcorr_param.sw_delta_cbb = nc_struct.polcorr_delta_cbb;
polcorr_param.sw_delta_hbb = nc_struct.polcorr_delta_hbb;
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a wrapper script for testing the generation of the CrIS NASA L1b for a single L1b granule
% and utilizes the netcdf4 formatted parameter files
% The user must set the following (within USER INPUT section of script)
%
% sat_name satellite name ('J1' or 'SNPP')
% l1b_fname L1b granule name (including path if not in same directory as code)
% saveTotalRU_FLAG set to 1 if you want to save the RSS RU to a mat file
%
% The primary contributors to the CrIS radiometric uncertainty are
% ICT temperature uncertainty
% ICT emissivity uncertainty
% uncertainty in the the other temperatures in the ICT radiometric model (modeled and measured)
% uncertainty in the quadratic coefficient NLC coefficient (a2)
% polarization correction uncertainty
% (sensor polarization angle alpha, and combined SSM and sensor polarization prpt)
%
% RU term 1: e_ict ICT rad model, emitted radiance
% RU term 2: T_ict ICT rad model, emitted radiance
% RU term 3: T_SSM_scan_mirror_baffle ICT rad model, reflected radiance (measured T)
% RU term 4: T_ScanBaffleCorrection ICT rad model, reflected radiance (modeled T)
% RU term 5: T_ICT_baffle ICT rad model, reflected radiance (measured T)
% RU term 6a: T_OMA, T_Frame ICT rad model, reflected radiance (measured T)
% RU term 6b: T_BS_warm ICT rad model, reflected radiance (measured T)
% RU term 7: T_BS_cold ICT rad model, reflected radiance (measured T)
% RU term 8: T_Space ICT rad model, reflected radiance (modeled T)
% RU term 9: prpt polarization correction
% RU term 10: alpha polarization correction
% RU term 11: a2 nonlinearity correction
%
% Refer to the NASA CrIS L1b RU document and ATBD for details on the ICT radiometric model
% Each reflected term in the ICT radiometric model also has a view factor and emissivity, but the uncertainty
% in those quantities produce negligible contributions to the CrIS radiometric uncertainty and are not perturbed for the RU estimate
% J1 has an improved ICT emissivity, and the view factors of some of the reflected terms are set to zero as a result
%
% JKT 2020-Sep-13
% University of Wisconsin-Madison Space Science and Engineering Center (UW-SSEC)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% START: USER INPUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sat_name = 'SNPP'; % set to 'J1' or 'SNPP'
l1b_fname = 'SNDR.SNPP.CRIS.20191031T0012.m06.g003.L1B.std.v03_08.G.201219125854.nc'; % set to file name of v3 L1b granule
%sat_name = 'J1'; % set to 'J1' or 'SNPP'
%l1b_fname = 'SNDR.J1.CRIS.20191031T0012.m06.g003.L1B.std.v03_08.G.201204050506.nc'; % set to file name of v3 L1b granule
l1b_pname = '/Users/joet/git/cris_l1b_user/RU/TEST_INPUT'; % set to path to v3 L1b granule
ru_code_pname = pwd; % set to path of the RU code
saveTotalRU_FLAG = 1; % set to 1 if you want to save the RSS RU to a mat file
pname_out = fullfile(pwd,'RU_OUT_NC'); % set to path for RU output files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% END: USER INPUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mkdir(pname_out)
addpath(ru_code_pname);
RU = cris_gran_RU_ncparam(sat_name,fullfile(l1b_pname,l1b_fname),saveTotalRU_FLAG,pname_out);
function RU = cris_gran_RU_ncparam(sat_name,l1b_fname,saveTotalRU_FLAG,pname_out);
%
% function RU = cris_gran_RU_ncparam(sat_name,l1b_fname,saveTotalRU_FLAG,pname_out);
%
% This is a function for generation of the CrIS NASA L1b for a single L1b granule
% and utilizes the netcdf4 formatted parameter files
%
% Inputs
% sat_name satellite name ('J1' or 'SNPP')
% l1b_fname L1b granule name (including path if not in same directory as code)
% saveTotalRU_FLAG set to 1 if you want to save the RSS RU to a mat file
% pname_out output directory
%
% JKT 2021-Aug-26
% University of Wisconsin-Madison Space Science and Engineering Center (UW-SSEC)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% code will loop over bands
bands{1} = 'lw';
bands{2} = 'mw';
bands{3} = 'sw';
%%============================================================
%% RU STEP 1a: Load ancillary data from static file (satellite dependent)
%%============================================================
switch sat_name
case 'J1'
% J1
jnk = rd_nc4('J1_L1B_ru_tool_param_file.nc');
case 'SNPP'
% SNPP
jnk = rd_nc4('SNPP_L1B_ru_tool_param_file.nc');
end
%%============================================================
%% RU STEP 1b: separate .nc param file contents into ICT_Param, RU,
%% nonlin, polcorr_param structures used in this code package
%%============================================================
[ICT_Param,RU,nonlin,polcorr_param] = convert_anc_to_structs(jnk);
%%============================================================
%% RU STEP 1c: copy data from anc file to expected var names for this code package
%%============================================================
dT_ict = RU.dT_ict;
de_ict = RU.de_ict;
dT_ict_ref_meas = RU.dT_ict_ref_meas;
dT_ict_ref_model = RU.dT_ict_ref_model;
dprpt = RU.dprpt;
dalpha = RU.dalpha;
da2.lw = RU.lw_da2;
da2.mw = RU.mw_da2;
da2.sw = RU.sw_da2;
sensor_all.lw.a2_now = nonlin.lw_a2;
sensor_all.mw.a2_now = nonlin.mw_a2;
sensor_all.sw.a2_now = nonlin.sw_a2;
%%%%%%%%%%
%% create an opts structure
%% not needed to calc RU estimate, but used here to record configuration options
%%%%%%%%%%
opts.extraFLAG = 1;
opts.l1b_fname = l1b_fname;
opts.bands = bands;
opts.sat_name = sat_name;
%%%%%%%%%%
% create output file name
% not required to calc RU estimate, but used here for optional output
%%%%%%%%%%
[~,fname_out,~] = fileparts(l1b_fname);
fname_out = sprintf('%s_RU',fname_out);
%%============================================================
%% RU STEP 2: Load v3 L1b data
%%============================================================
l1b_dat = read_l1b_for_RU(l1b_fname);
%%%%%%%%%%
%% save opts params