1 function [ score ] = match_detections( wrfout, cycle,wrf_time_step)
2 %function score = match_detections( input_args )
3 %Function evaluates a simulation by finding how well it was able to predict
4 %where satellites detections would indicate a fire was burning
6 % wrfout: string with path to wrfout file containing the fire arrival
8 % wrf_time-step: optional string with time step in wrfout to be read
10 % score: evaluation of the goodness of the fit
13 % use which time step?
15 w = read_wrfout_tign(wrfout,wrf_time_step);
18 w = read_wrfout_tign(wrfout);
20 fprintf('wrfout is already a .mat file, loading \n')
24 red = subset_domain(w,1);
27 %use the wrfout file to find subset of detections
29 time_bounds(2) = red.max_tign;
30 end_date = datestr(time_bounds(2));
31 %time_bounds(2) = 7.354637292824074e+05
32 time_bounds(1) = red.min_tign;
33 %time_bounds(1) = time_bounds(2)-3;
34 fire_choice = input_num('which fire? Patch: [0], Camp: [1], Cougar: [3]',0,1)
35 %cycle = input_num('Which cycle? ',0)
37 fire_name = 'Camp fire';
39 prefix='../campTIFs/';
40 elseif fire_choice == 0
41 fire_name = 'Patch Springs fire';
45 fire_name = 'Cougar Creek fire';
47 prefix = '../cougarTIFs/';
53 g_str = sprintf('g_match_%d.mat',cycle);
54 if exist(g_str,'file')
57 det_list=sort_rsac_files(prefix);
58 g = load_subset_detections(prefix,det_list,red,time_bounds,fig);
59 save(g_str, 'g', '-v7.3')
61 %find list of detections
65 fire_mask = g(i).data >=min_con;
66 lons = g(i).xlon(fire_mask);
67 lats = g(i).xlat(fire_mask);
69 fire_mask = g(i).data >= min_con;
70 lon_update = g(i).xlon(fire_mask);
71 lat_update = g(i).xlat(fire_mask);
72 %looking for bad cougar granule
73 %if max(lat_update(:)) > 46.2 | min(lat_update(:)) < 46.05
74 % fprintf('bad granule : %s \n',g(i).file)
76 if sum(fire_mask(:)) > 0
77 lons = [lons(:);lon_update(:)];
78 lats = [lats(:);lat_update(:)];
84 %find polygon containing fire perimter from wrf
85 fire_area = red.tign <= time_bounds(2)-0.001;
86 % cells within simulation perimeter
87 fire_lon = red.fxlong(fire_area);
88 fire_lat = red.fxlat(fire_area);
89 fire_boundary = boundary(fire_lon,fire_lat);
90 x = fire_lon(fire_boundary);
91 y = fire_lat(fire_boundary);
94 %[fire_in, fire_on] = inpolygon(red.fxlong(:),red.fxlat(:),x,y);
95 [in, on] = inpolygon(lons,lats,x,y);
96 %perim_lon = fire_lon(fire_on);
97 %perim_y = fire_lat(fire_on);
101 score = (sum(in)+sum(on))/numel(lats);
102 score_str = sprintf('Cycle %d: %f percent of detections within perimeter',cycle,score*100);
106 scatter(lons(in),lats(in),'g*')
107 scatter(lons(~in),lats(~in),'b*')
111 title_str = sprintf('Satellite Fire Detections and Forecast Perimeters \n %s \n %s, %s',score_str,fire_name,end_date);
113 legend({'Forecast perimeter','Detections inside perimeter','Detections outside perimeter'});
115 %xlim([-121.9 -121.3])
116 save_str = sprintf('match_%s_%s_%s.fig',save_name,num2str(time_bounds(2)),num2str(cycle))
117 fprintf('Saving figure as: %s \n',save_str)
119 saveas(gcf,[save_str '.png']);