%example script for running SPIReS with Landsat 8

% Bair, E.H., Stillinger, T., and Dozier, J. (2021) 
% Snow Property Inversion from Remote Sensing (SPIReS), 
% IEEE Transactions on Remote Sensing and Geoscience, 
% doi: 10.1109/TGRS.2020.3040328

%unzip example files
unzip('L8example.zip')

%files
r0dir=fullfile(pwd,'R0'); %snow/ice minima background, p42r34 20201014
rdir=fullfile(pwd,'R'); %snow covered scene, p42r34 20160426
demfile=fullfile(pwd,'DEM','p042r034.mat'); % DEM for p42r34 - extraneous 
%if terrain correction set to false & el_cutoff = 0 m
Ffile=fullfile(pwd,'Ffile','lut_oli_b1to7_3um_dust.mat'); % look up tables
%Mie-RT calcs for snow for L8 bands 1-7 w/ 3 um dust
CCfile=fullfile(pwd,'CC','p042r034.mat'); % canopy cover percent file, NLCD
WaterMaskfile=fullfile(pwd,'watermask','p042r034.mat'); %watermask file, NLCD
fIcefile=fullfile(pwd,'fice','p042r034.mat'); %fractional ice, derived from
%Randolph Glacier Inventory

%parameters
shade=0; % ideal shade endmember, fraction 0-1
tolval=0.05; % tolerance value for uniquetol for grouping spectra, fraction 0-1
fsca_thresh=0.10; %minimum fsca value, fraction 0-1
dust_rg_thresh=300; %minimum dirty snow grain size, um
el_cutoff=0; %minimum elevation for snow, m, in this case 0 m ignores
subset=[1052 3032; 1471 3529]; %bounding box in pixel coordinates for subset 
% of scene 

%takes 2.09 min running w/ 50 cores
out=run_spires_landsat(r0dir,rdir,demfile,Ffile,shade,tolval,...
    fsca_thresh,dust_rg_thresh,grain_thresh,dust_thresh,CCfile,...
    WaterMaskfile,CloudMaskfile,fIcefile,...
    el_cutoff,subset,false);
