prints
[wrf-fire-matlab.git] / cycling / analyze_paths.m
blob081d7d14c900f8e87a396c1af7721ee941469edc
1 function a = analyze_paths(ps,new_tign)
2 %looks at the paths in a path struct and figures out some basic statistics
3 % input   ps - struct, from ps = cluster_paths(w,1);
4 %         new_tign - analysis from squish4(ps)
6 %vector for speeds between points in the paths new_tign
7 p_speeds = [];
8 %vector for speeds between pts in tigndist = ps.raw_dist(p2,p1);
9 t_speeds = [];
10 speeds_count = 0;
11 %figure(117),contour(ps.red.fxlong,ps.red.fxlat,ps.red.tign);
12 hold on
13 %loop through the paths, collect ROS info from each path segment
14 %extrapolate one poin on the end of each path
15 for i = 1:length(ps.paths)
16     p = ps.paths(i).p;
17     %fprintf('Path %d, %d points in path  \n',i,length(p))
18     %find speed between points in the paths
19     pl = length(p);
20     for j = 1:pl
21         %pause for plotting
22         %pause(0.01)
23         if j > 1
24             speeds_count = speeds_count + 1;
25             %point pair in path segment
26             p1 = p(j-1);
27             p2 = p(j);
28             path_points(speeds_count,1:2)=[p1,p2];
29             p_speeds(speeds_count) = ps.speeds(p2,p1)/(24*3600);
30             p_fuel_1(speeds_count) = ps.red.nfuel_cat(ps.idx(p1,1),ps.idx(p1,2));
31             p_fuel_2(speeds_count) = ps.red.nfuel_cat(ps.idx(p2,1),ps.idx(p2,2));
32             %plot path on countour
33             %plot(ps.points(p,2),ps.points(p,1),'r','LineWidth',0.5);
34             % find these locations on the grid
35             %tign at these points
36 %             t_p1 = ps.red.tign(ps.idx(p1,1),ps.idx(p1,2));
37 %             t_p2 = ps.red.tign(ps.idx(p2,1),ps.idx(p2,2));
38             % time at L2 data recording
39             t_p1 = ps.points(j-1,3);
40             t_p2 = ps.points(j,3);
41             % time at the analysis
42             %t_p1 = new_tign(ps.idx(p1,1),ps.idx(p1,2));
43             %t_p2 = new_tign(ps.idx(p2,1),ps.idx(p2,2));
44             dt = abs(t_p2-t_p1);
45             dist = ps.raw_dist(p2,p1);
46             %reall, this is the p_speeds
47             t_speeds(speeds_count)= (dist/dt)/(24*3600);
48             %elevation data
49             e_p1 = ps.red.fhgt(ps.idx(p1,1),ps.idx(p1,2));
50             e_p2 = ps.red.fhgt(ps.idx(p2,1),ps.idx(p2,2));
51             slopes(speeds_count) = (e_p2-e_p1)/dist;
53         end
54         %scatter(ps.points(p(end),2),ps.points(p(end),1),'*r')
55     end
56 end
57 hold off
58 a.path_points = path_points;
59 a.p_speeds = p_speeds';
60 a.t_speeds = t_speeds';
61 a.p_fuel_1 = p_fuel_1';
62 a.p_fuel_2 = p_fuel_2';
63 a.matrix(:,1)=p_speeds';
64 a.matrix(:,2)=p_fuel_1';
65 a.matrix(:,3)=p_fuel_2';
66 a.slopes = slopes';
68 %%%%%% wtf happened %%%%
69 %% (figure(117),contour(ps.red.fxlong,ps.red.fxlat,ps.red.tign);;
71 %look at averages
72 %number by which to multiply standard deviation
73 std_mult = 0.5;
75 unq = unique([a.matrix,a.path_points],'rows');
76 common_fuel1 = mode(unq(:,2));
77 common_fuel2 = mode(unq(:,3));
78 fuel_mask = unq(:,2:3) == common_fuel2;
79 avg_speed_common_fuel = mean([p_speeds(fuel_mask(:,1)),p_speeds(fuel_mask(:,2))]);
80 figure,histogram([p_speeds(fuel_mask(:,1)),p_speeds(fuel_mask(:,2))]),title('Histogram ROS in common fuel')
81 %std deviation of ROS in the common fuel type
82 std_speed_common_fuel = std([p_speeds(fuel_mask(:,1)),p_speeds(fuel_mask(:,2))]);
83 fast_common_fuel = avg_speed_common_fuel+std_mult*std_speed_common_fuel;
84 fast_mask = unq(:,1)>fast_common_fuel;
85 %locations where the most common fuel is and ROS is one standard deviation
86 %obove mean
87 fast_fuel_mask = logical([fast_mask.*fuel_mask(:,1),fast_mask.*fuel_mask(:,2)]);
88 %plot the location of the fast fuel
89 %figure(21),contourf(ps.red.fxlong,ps.red.fxlat,ps.red.tign,'--k');
90 figure(21),mesh(ps.red.fxlong,ps.red.fxlat,new_tign);
91 hold on
92 title('Locations of high ROS in common fuel')
93 fast_count = 0;
94 point_speeds = unq(:,1);
95 for i =1:length(unq)
96     if  unq(i,1) > fast_common_fuel
97         fast_count = fast_count+1;
98         
99         %scatter(ps.points(unq(i,5),2),ps.points(unq(i,5),1),'*r')
100         idx_1 = unq(i,4);
101         idx_2 = unq(i,5);
102         scatter3(ps.points(unq(i,4),2),ps.points(unq(i,4),1),new_tign(ps.idx(idx_1,1),ps.idx(idx_1,2)),'*r')
103         scatter3(ps.points(unq(i,5),2),ps.points(unq(i,5),1),new_tign(ps.idx(idx_2,1),ps.idx(idx_2,2)),'*r')
104     end