2 % download http://firemapper.sc.egov.usda.gov/data_viirs/kml/conus_hist/conus_20120914.kmz
6 % run Adam's simulation, currently results in
8 % /share_home/akochans/WRF341F/wrf-fire/WRFV3/test/em_utfire_1d_med_4km_200m
10 % arrays needed only once
11 % f='wrfout_d01_2013-08-20_00:00:00';
12 % t=nc2struct(f,{'Times'},{}); n=size(t.times,2)
13 % w=nc2struct(f,{'Times','TIGN_G','FXLONG','FXLAT','UNIT_FXLAT','UNIT_FXLONG','XLONG','XLAT','NFUEL_CAT'},{},n);
16 % array at fire resolution every saved timestep
18 % a=dir('wrfout_d01*');
19 % s=read_wrfout_sel({a.name},{'FGRNHFX',Times});
22 % arrays at atm resolution every saved timestep
24 % a=dir('wrfout_d01*')
25 % s=read_wrfout_sel({a.name},{'Times','UAH','VAH'})
28 % fuels.m is created by WRF-SFIRE at the beginning of the run
30 % ****** REQUIRES Matlab 2013a - will not run in earlier versions *******
32 % run patch_load first
38 %historical='previous';
40 % convert tign_g to datenum
41 w.time=datenum(char(w.times)');
42 red.tign=(red.tign_g - max(red.tign_g(:)))/(24*60*60) + w.time;
43 min_tign=min(red.tign(:));
44 max_tign=max(red.tign(:));
48 [cmap,imax]=cmapmod14;
52 for step=2:length(ss.time) % over WRF frames
53 figure(figmap);clf;hold off
54 granules{1}=find(r.time <= ss.time(step));
57 % take all satellite overpasses from the beginning of time
58 granules{2}=granules{1};
61 granules{2}=find(r.time <= ss.time(step) & r.time > ss.time(step-1));
63 % the previous granules persist until replaced
64 new_det=find(r.time <= ss.time(step) & r.time > ss.time(step-1));
70 error('unknown parameter historical')
76 if det, fprintf('pass %i using satellite granules ',ipass),disp(granules{1}), end
78 fprintf('%i %s\n',det(idet),datestr(r.time(det(idet))))
83 x=r.x{det(idet)}; % load fire detection image
84 age=t-r.time(idet); % age of detection in days
85 offset = min(imax,floor(4*age)); % offset in colormap for detection age
86 dd=x.data(:)>6; % indices of detected
87 x.data(dd)=x.data(dd)+3*offset; % transition to yellow
89 fprintf('step %i pass %i granule %i detections %i\n',step,ipass,idet,sum(dd))
91 if ipass==1, % build up the background
93 elseif any(dd), % all except fire transparent
102 maxw=max(sqrt(u(:).*u(:)+v(:).*v(:)));
103 fprintf('step %i max windspeed %g granules %i\n',step,maxw,ndet)
104 sc=0.006;quiver(w.xlong,w.xlat,sc*u,sc*v,0); % wind
107 contour(red.fxlong,red.fxlat,red.tign,[t t],'-k'); % fireline
110 avg_lat=0.5*(red.min_lat+red.max_lat);
111 daspect([1,cos(avg_lat*pi/180),1]);
115 M(step-1)=getframe(gcf);