Merge branch 'fixf'
[wrf-fire-matlab.git] / vis3d / compare_fire_area.m
blobf4eeb67bafd25a8be19fd1999bcc67081fe049bb
1 function r=compare_fire_area(f1,f2)
2 % r=compare_fire_area(f1,f2)
3 % finds the differences in fire area between two wrfouts
4 % arguments:
5 %     f1, f2 wrfout file names
6 % returns:
7 %     structure with results
9 vars={'Times','FIRE_AREA','ROS'};
10 p1 = nc2struct(f1,vars,{});
11 p2 = nc2struct(f2,vars,{});
12 times1=char(p1.times)';
13 times2=char(p2.times)';
14 steps1=size(times1,1);
15 steps2=size(times2,1);
16 steps=min(steps1,steps2);
17 r = [];
18 ssum = @(a) sum(a(:));
19 for step=1:steps
20     if(any(times1(step,:)-times2(step,:)))then
21         disp(['frame ',num2str(i),' file ',f1,' time ',times1(step,:)])
22         disp(['frame ',num2str(i),' file ',f2,' time ',times2(step,:)])
23         warning('times in input files are not the same')
24     end
25     fa1 = p1.fire_area(:,:,step);  % fire areas this step
26     fa2 = p2.fire_area(:,:,step);
27     dfa = fa1 - fa2;
28     px1 = fa1>0;                   % 0-1 arrays burning/not burning 
29     px2 = fa2>0;                   % 0-1 arrays burning/not burning 
30     dpx = px1 - px2;
31     r.fire_area_1(1,step) = ssum(fa1);
32     r.fire_area_2(1,step) = ssum(fa2);
33     r.fire_area_set_diff(1,step) = ssum(abs(fa2-fa1));
34     r.fire_area_diff(1,step) = ssum(fa2)--ssum(fa1);
35     r.fire_area_diff_rel(1,step) = (ssum(fa2)-ssum(fa1))/((ssum(fa1)+ssum(fa1))/2+realmin);
36     r.fire_area_set_diff_rel(1,step) = ssum(abs(fa2-fa1))/((ssum(fa1)+ssum(fa1))/2+realmin);
37     r.fire_pixels_1(1,step) = ssum(px1);
38     r.fire_pixels_2(1,step) = ssum(px2);
39     r.fire_pixels_diff(1,step) = ssum(px2)-ssum(px1);
40     r.fire_pixels_diff_rel(1,step) = (ssum(px2)-ssum(px1))/((ssum(px1)+ssum(px1))/2+realmin);
41     r.fire_pixels_set_diff(1,step) = ssum(abs(px2-px1));
42     r.fire_pixels_set_diff_rel(1,step) = ssum(abs(px2-px1))/((ssum(px1)+ssum(px1))/2+realmin);
43     ros1=p1.ros(:,:,step);
44     ros2=p2.ros(:,:,step);
45     rosd=ros2(:)-ros1(:);
46     r.ros_diff_avg(1,step)=sum(rosd)/prod(size(rosd));
47     r.ros_diff_max(1,step)=max(rosd);
48     r.ros_diff_min(1,step)=min(rosd);
49 end
50 end
51 %r.file_1=f1;
52 %r.file_2=f2;
53         
54         
55