1 function path_struct = tign_try(w,cpd,grid_dist)
2 %scatter fake data on TIGN cone, try to recover the shape
3 %cpd clusters per day of data
4 %[fire_name,save_name,prefix] = fire_choice();
5 clear_q = input_num('Delete mat files? 1 = yes',1,1);
11 if ~exist('red.mat','file')
12 red = subset_domain(w,1);
20 dlon= distance(red.min_lat,red.min_lon,red.min_lat,red.max_lon,E);
21 dlat= distance(red.min_lat,red.min_lon,red.max_lat,red.min_lon,E);
22 if ~exist('grid_dist','var')
25 new_m = round(dlon/grid_dist);
26 new_n = round(dlat/grid_dist);
28 time_bounds(2) = red.max_tign;
29 time_bounds(1) = red.min_tign;
31 %shrink the size for large matrices
32 target_size = max(new_m,new_n);
34 if max(size(red.tign)) > target_size
36 [m,n] = size(red.tign);
40 sf = target_size/max_dim;
44 red = subset_small(red,m,n);
52 [m,n] = size(red.tign);
54 [ig_x,ig_y] = find(red.tign == min(red.tign(:)));
58 pts = [red.fxlat(ig_x,ig_y),red.fxlong(ig_x,ig_y),min(red.tign(:)),100,100,1];
61 % k can be expanded to loop through discrete lime levels like MODIS, VIIRS
63 % i,j are indices of the mesh
66 if red.tign(i,j) < red.end_datenum - rm
68 %pts = [pts;[lats',lons',times',confs',frps',gran']];
69 pts = [pts;[red.fxlat(i,j),red.fxlong(i,j),red.tign(i,j),100,100,2*round(red.tign(i,j)-red.start_datenum)]];
77 pt_length = length(pts);
78 msk = rand(pt_length,1);
79 msk = msk > 500/pt_length;
84 %add perimeter, optional
85 [new_pts,new_idx] = make_perims(red.tign,red);
93 sim_days = time_bounds(2)-time_bounds(1);
94 over_passes = round(sim_days*3);
95 time_bin = linspace(time_bounds(1),time_bounds(2),over_passes)+1/10*randn(1,over_passes);
98 if pts(j,3) > time_bin(i-1) && pts(j,3) <= time_bin(i)
99 pts(j,3) = time_bin(i);
105 %use same set of points from previous example / multi step
106 % if exist('pts.mat','file')
110 % save pts.mat pts idx
113 figure,mesh(red.fxlong,red.fxlat,red.tign-red.start_datenum),hold on
114 scatter3(pts(:,2),pts(:,1),pts(:,3)-red.start_datenum,'r*')
115 [st1,st2]=sort(pts(:,3));
116 pts(:,1) = pts(st2,1);
117 pts(:,2) = pts(st2,2);
118 pts(:,3) = pts(st2,3);
119 idx(:,1) = idx(st2,1);
120 idx(:,2) = idx(st2,2);
126 %clusters = round((t2-t1)*cpd);
127 %clusters = round(length(pts)/20);
128 %clusters = min(cpd,length(pts(:,3)));
130 [s_idx,s_c] = kmeans(pts(:,1:2),clusters);
131 %scatter the clusters with coloring
132 figure,scatter3(pts(s_idx==1,2),pts(s_idx==1,1),pts(s_idx==1,3)-red.start_datenum);
135 scatter3(pts(s_idx==i,2),pts(s_idx==i,1),pts(s_idx==i,3)-red.start_datenum);
141 %adjacency / distance matrix
149 grid_pts = pts(:,1:2);
152 %% computing distance between points using GPS coords
155 %make cluster center distance matrix
156 clust_dist=zeros(clusters);
159 i_clust = [s_c(i,1),s_c(i,2)];
161 j_clust = [s_c(j,1),s_c(j,2)];
162 clust_dist(i,j) = distance(i_clust,j_clust,E);
166 %max distance from ignition
168 %error in time of fire from time of detection
171 ig_point = [pts(1,1),pts(1,2)];
174 %%% local time for help in figuring out day/night
175 locs(i) = local_time(time);
176 i_point = [pts(i,1),pts(i,2)];
177 %find furthest detection from ignition
178 new_d = distance(ig_point,i_point,E);
183 %distance from all points
185 time_diff = (pts(j,3)-time)*(24*3600);
187 t(i,j) = time_diff; %pts(j,3)-time;
189 j_point = [pts(j,1),pts(j,2)];
190 a(i,j) = distance(i_point,j_point,E);
191 v(i,j) = a(i,j)/max(time_diff,0.1);
197 %start filtering distance
201 % % make points in same cluster close
202 if (a(i,j) > 0) && (s_idx(i) == s_idx(j)) %in same cluster
203 a(i,j) = cluster_mult*a(i,j);
205 % make points in different clusters further apart
206 % if (a(i,j) > 0) && (s_idx(i)~=s_idx(j))
207 % a(i,j) = a(i,j) + clust_dist(s_idx(i),s_idx(j));
220 figure(222),close(gcf)
223 % finds shortest path between points i,j
224 % p is the points in the path, d is the total distance
225 [p,d] = shortestpath(fg,i,j);
227 path_count = path_count + 1;
228 paths(path_count).p = p;
229 paths(path_count).d = d;
230 %path confidenc is geometric mean of detections in path
231 paths(path_count).c = prod(pts(p,4))^(1/length(p));
232 %fprintf('%d points in path \n',length(p))
236 %plot3(pts(p,2),pts(p,1),pts(p,3)-red.start_datenum,':r');
238 plot3(pts(p,2),pts(p,1),pts(p,3)-red.start_datenum,'g');
240 scatter3(pts(p(k),2),pts(p(k),1),pts(p(k),3)-red.start_datenum,'*r');
243 % % add a new point to the list by interpolation
244 % for k = 1:length(p)-1
245 % new_pt = ([pts(p(k),1),pts(p(k),2),pts(p(k),3)]+[pts(p(k+1),1),pts(p(k+1),2),pts(p(k+1),3)])/2;
246 % new_points = [new_points;new_pt];
252 path_struct.raw_dist = raw_dist+raw_dist';
253 path_struct.paths = paths;
254 path_struct.graph = fg;
255 path_struct.distances = a;
256 path_struct.speeds = v;
257 path_struct.points = double(pts);
258 path_struct.red = red;
259 % path_struct.new_points = new_points;
260 path_struct.grid_pts = grid_pts;
261 path_struct.idx = idx;
269 function lt = local_time(time)
271 lt = 24*((time-shift)-floor(time-shift));