load robbins_sinus_sabeus.mat  

%Discard little craters
good = (e.DIAM_CIRCLE_IMAGE >= 10);
e = structfun(@(x) ( x(good==1) ), e, 'UniformOutput',false);

%Find overlaps
% distances between circles:
dx = bsxfun(@minus, e.LATITUDE_CIRCLE_IMAGE, e.LATITUDE_CIRCLE_IMAGE');
dy = bsxfun(@minus, e.LONGITUDE_CIRCLE_IMAGE, e.LONGITUDE_CIRCLE_IMAGE');
sumr = bsxfun(@plus, (e.DIAM_CIRCLE_IMAGE/(59*2)), (e.DIAM_CIRCLE_IMAGE./(59*2))');

% distance between centers:
dist = sqrt(dx.^2 + dy.^2);
overlap = (dist<sumr);

% pairs that have overlap:
pairs = find(dist < sumr);


%relative age of overlapping >10 km diameter craters. High numbes = OLDER.
ra = zeros(length(e.DIAM_CIRCLE_IMAGE),1); 
ra(sum(dist<sumr)>1) = NaN;
ra(618) = 9; ra(1034) = 1; ra(176) = 5;
 ra(420) = 9; ra(973) = 1; ra(752) = 5; 
 ra(1170) = 1; ra(79) = 9; ra(991) = 1;
 ra(141) = 9; ra(299) = 1; ra(699) = 1; ra(548) = 1; 
 ra(166) = 9; ra(790) = 1; ra(439) = 1; 
 ra(1305) = 9; ra(353) = 5; ra(1244) = 1;
 ra(598) = 9; ra(1179) = 1;
 ra(167) = 9; ra(731) = 1;
 ra(790) = 9; ra(166) = 5; ra(439) = 1;
 ra(839) = 1; ra(418) = 1; ra(710) = 1; ra(82) = 5; ra(15) = 9; ra(36) = 9;
 ra(712) = 5; ra(824) = 5; %indeterminate in CTX (which crosscuts which?)
 ra(108) = 9; ra(75) = 1; %Nice :-)
 ra(662) = 9; ra(156) = 1;
 ra(791) = 1; ra(131) = 9;
 ra(311) = 9; ra(246) = 9; ra(119) = 1; 
 ra(765) = 1; ra(62) = 5; ra(356) = 9; %can't find 356
 ra(506) = 1; ra(53) = 9; ra(93) = 2 ; ra(1352) = 1; ra(1378) = 9; %1378 undetermined in CTX
 ra(856) = 1; ra(1082) = 1; ra(50) = 9; ra(105) = 5; 
 ra(8) = 9; ra(521) = 1; ra(1321) = 1; ra(677) = 1; ra(146) = 5;
 ra(444) = 1; ra(200) = 7; ra(106) = 3; ra(920) = 3; 
 ra(882) = 1; ra(1172) = 1; ra(379) = 9; 
 ra(326) = 1; %nice alluvial fans
 ra(205) = 5; ra(960) = 1; ra(529) = 9;
 ra(417) = 9; ra(1109) = 9; ra(863) = 1; ra(271) = 5;
 ra(284) = 9; ra(1316) = 1;
 ra(884) = 1; ra(631) = 9;
 ra(686) = 1; ra(158) = 9; ra(239) = 9; %indeterminate
 ra(1285) = 1; ra(1307) = 9;
 ra(281) = 1; ra(39) = 5; ra(455) = 9; %nice dissection of 455 by chanels draining to 39
 ra(241) = 5; ra(584) = 5; %indeterminate
 ra(337) = 5; ra(610) = 5; %indeterminate
 ra(481) = 9; ra(19) = 5; ra(581) = 1; ra(526) = 1;
 ra(1376) = 9; ra(522) = 1; ra(385) = 1; %indeterminate
 ra(1435) = 9; ra(1117) = 1;
 ra(975) = 9; ra(130) = 9; ra(611) = 1; %indeterminate
 ra(1002) = 1; ra(264) = 9;  ra(165) = 5; ra(306) = 5; ra(599) = 5; ra(769) = 1;
 ra(1050) = 1; ra(437) = 9; 
 ra(996) = 1; ra(78) = 9; ra(91) = 9; ra(29) = 5; ra(1122) = 1; ra(1372) = 3;
 ra(782) = 1; ra(1337) = 9; %Leet.
 ra(487) = 1; ra(109) = 9;
 ra(104) = 1; ra(378) = 3; ra(133) = 7; ra(11)  = 9;
 ra(32) = 7; %relative timing of 133 and 11 is not known.
 ra(1086) = 1; ra(258) = 9;
 ra(149) = 1; ra(1102) = 5; ra(419) = 5; ra(250) = 9; %relative timing of 250 and 11 not known. 
 ra(401) = 5; ra(1071) = 1; ra(1111) = 5;
 ra(138) = 1; ra(81) = 9; ra(1114) = 1; ra(517) = 1;
 ra(1193) = 1; ra(429) = 9; 
 ra(215) = 1; ra(61) = 9; ra(1080) = 1;
 ra(199) = 9; ra(37) = 5; ra(323) = 1; ra(182) = 3; ra(472) = 1;
 ra(214) = 1; ra(358) = 9; ra(463) = 1;
 ra(944) = 1; ra(348) = 5; ra(179) = 9;
 ra(259) = 9; ra(151) = 5; ra(296) = 1;
 ra(226) = 5; ra(714) = 1; ra(21) = 9; ra(796) = 5; 
 ra(110) = 1; ra(9) = 9; ra(184) = 3; ra(168) = 7; ra(344) = 7;
 ra(376) = 1; ra(783) = 1; ra(452) = 1; ra(22) = 5; ra(14) = 9; ra(35) = 1;
 ra(546) = 1; ra(51) = 9; ra(1295) = 1; ra(38) = 9;
 ra(399) = 1; ra(660) = 5; ra(33) = 9; ra(907) = 1; ra(459) = 5;
 ra(122) = 5; ra(583); %indeterminate
 ra(4) = 9; ra(301) = 5; ra(722) = 1; ra(967) = 1; ra(415) = 5; ra(377) = 5;
 ra(1124) = 1; ra(531) = 1; ra(810) = 1; ra(103) = 9; ra(726) = 9;
 ra(902) = 1; ra(946) = 9; ra(155) = 9; %155, 946 indeterminate
 ra(80) = 1; ra(1310) = 1; a(1373) = 1; ra(361) = 1; ra(538) = 1;
 ra(16) = 1;
 ra(135) = 1; ra(989) = 1; ra(1418) = 1; ra(1280) = 5; ra(10) = 9; ra(671) = 1; ra(1146) = 5;
 ra(993) = 1; ra(261) = 5; ra(488) = 5; ra(787) = 1; ra(1310) = 1;
 ra(153) = 1; ra(112) = 9; 
 ra(483) = 1; ra(585) = 9; 
 ra(652) = 9; ra(1341) = 1;
 ra(92) = 9; ra(45) = 5; ra(432) = 1; ra(332) = 1; ra(1199) = 1;
 ra(914) = 1; ra(809) = 9;
 ra(416) = 1; ra(43) = 9; ra(280) = 1; ra(61) = 5; ra(215) = 1; ra(1080) = 5;
 ra(1156) = 1; ra(915) = 5; ra(56) = 9; ra(126) = 7; ra(457) = 3; ra(1055) = 1;   %1156 is oblique
 ra(1218) = 1; ra(512) = 1; %ra 445 indeterminate
 ra(110) = 7; ra(554) = 9; ra(90) = 1; ra(193) = 9; ra(461) = 9;
 ra(1107) = 1; ra(1383) = 3; 
 ra(1254) = 1; ra(772) = 9;
 ra(1010) = 9; ra(840) = 1;
 ra(260) = 9; ra(908) = 1;
 ra(650) = 1; ra(1044) = 5; ra(20) = 9; ra(561) = 1; ra(441) = 1; 
 ra(1427) = 1; ra(866) = 5; ra(1148) = 1;
 ra(217) = 7; ra(291) = 3; ra(692) = 9; ra(823) = 3; %823 indeterminate
 ra(597) = 1; ra(577) = 9;
 ra(77) = 9; ra(613) = 1; ra(469) = 1; 
 ra(87) = 9; ra(186) = 8; ra(7) = 7; ra(695) = 1; ra(691) = 1; 
 ra(87) = 9; ra(409) = 1; ra(335) = 1;
 ra(31) = 9; ra(465) = 5; ra(374) = 1;
 ra(139) = 9; ra(845) = 1;
 ra(704) = 1; ra(371) = 9;
 ra(516) = 1; ra(405) = 9; 
 ra(343) = 9; ra(943) = 5; ra(1284) = 1;
 ra(507) = 1; ra(821) = 9; 
 ra(1332) = 1; ra(292) = 9;
 ra(1326) = 9 ; ra(387) = 1;
 ra(307) = 9; ra(234) = 1;
 ra(154) = 9; ra(52) = 5; ra(800) = 1; ra(394) = 1; ra(1093) = 1; ra(359) = 9;
 ra(3) = 9; ra(984) = 1; ra(1100) = 5; ra(88) = 5; ra(1228) = 1;
 ra(1108) = 1; %Only using crater crosscuts, not "valley" crosscuts
 ra(84) = 1;
 ra(333) = 1; ra(489) = 3; ra(530) = 7;
 ra(238) = 5; ra(170) = 5; ra(198) = 5; %indeterminate
 ra(932) = 1; ra(503) = 9; 
 ra(492) = 1; ra(411) = 1; ra(427) = 9; ra(213) = 5;
 ra(875) = 5; ra(1180) = 5; %cannot locate (crater in crater)
 ra(814) = 1; ra(647) = 1; ra(797) = 1;
 ra(563) = 1; ra(899) = 1; ra(949) = 1;
 ra(630) = 1; ra(630) = 3; ra(1063) = 1;
 ra(468) = 9;
 ra(1221) = 5; ra(1241) = 5;
 ra(407) = 1; ra(137) = 5; ra(212) = 9; 
 ra(1401) = 1; ra(1187) = 1;
 ra(24) = 5; ra(94) = 9;
 ra(175) = 1; ra(541) = 1; ra(63) = 9;
 ra(789) = 1; ra(70) = 9; ra(68) = 1; 
 ra(171) = 9; ra(1011) = 9; ra(703) = 5; ra(525) = 1;
 ra(778) = 1; ra(59) = 9; ra(254) = 9; %259 indeterminate
 ra(169) = 1; ra(196) = 9; %196-59 intederminate
 ra(470) = 1; ra(162) = 9; ra(278) = 9; ra(1421) = 9; %1421. 278 indeterminate
 ra(270) = 9; ra(608) = 1;
 ra(990) = 1; ra(398) = 9;
 ra(347) = 1; ra(34) = 5; ra(1046) = 1; ra(1232) = 9; %Status of 1232 isn't certain.
 ra(811) = 9; ra(221) = 1; ra(204) = 9; ra(49) = 5; ra(745) = 1; ra(655) = 1;  
 ra(891) = 1; ra(282) = 5; ra(244) = 9;
 ra(636) = 9; ra(623) = 1;
 ra(1346) = 1; ra(225) = 9; %interesting because small late crater was infilled to 200m above large early crater
 ra(102) = 1; ra(668) = 1; ra(336) = 1; ra(1157) = 5; ra(939) = 1; ra(13) = 9;  %Wislicenus
 ra(1005) = 1; ra(1209) = 9;
 ra(1038) = 9; ra(1012) = 1;
 ra(111) = 1; ra(124) = 9; ra(702) = 1; ra(713) = 1; 
 
 ra(312) = 9; ra(1422) = 1; ra(1160) = 1; ra(486) = 3; ra(129) = 7; ra(150) = 9; ra(844) = 9; %150 and 844 indeterminate
 ra(365) = 1; ra(218) = 9; 
 ra(586) = 1; ra(709) = 5; %on edge of large crater
 ra(224) = 1; ra(410) = 1; ra(67) = 5; ra(57) = 9; ra(189) = 9; %lots of indeterminate relations
 ra(276) = 8; ra(249) = 5; ra(262) = 1; %Nice example of 3 craters, same size, no rims, different degradation states!
 ra(876) = 1; ra(425) = 3; ra(95) = 7; 
 ra(883) = 1; ra(1059) = 1; ra(123) = 1; 
 ra(1382) = 9; ra(799) = 1; %questionable relative timing
 ra(1441) = 1;
 ra(1060) = 1; ra(163) = 5; %Nice example of elliptical late-striking crater with intact shared rim!
ra(934) = 1; ra(986) = 1; ra(781) = 1; ra(47) = 5; ra(44) = 9; ra(30) = 9; %30,44 indeterminate
ra(1022) = 9; %1022 relative age uncertain due to possibility of backwasting.
ra(289) = 1; ra(1058) = 3; ra(888) = 7; ra(116) = 9;
ra(758) = 1; ra(188) = 9; ra(147) = 1; ra(1266) = 9;
ra(560) = 1; ra(190) = 9;
ra(646) = 9; ra(228) = 1;
ra(473) = 1; ra(58) = 5; ra(1271) = 9; 
ra(900) = 9; ra(624) = 1; 
ra(1127) = 1; ra(288) = 9; ra(101) = 5;
ra(222) = 9; ra(107) = 1;
ra(1207) = 1; ra(675) = 5; ra(144) = 9;
ra(942) = 1; ra(219) = 9; ra(720) = 1;
ra(114) =9; ra(428) = 1;
ra(1276) = 1; ra(240) = 9; ra(242) = 1; ra(604) = 1;
ra(436) = 9; ra(1016) =1;
 %ra(1402) = 1; ra(460) = 5; ra(173) = 9; ra(1144) = 9;

ra(173) = 5; ra(1144) = 1; ra(460) = 9; ra(1402) = 9; %460 and 1402 uncertain (backwasting?)
ra(1096) = 1; ra(71) = 5; ra(230) = 7; ra(1121) = 9; %316 and 1192 indeterminate
ra(718) = 1; ra(269) = 5; ra(1017) = 9; 
ra(402) = 1; ra(1390) = 1; ra(1407) = 1; ra(18) = 9;
ra(26) = 9; ra(501) = 1; ra(715) = 1; %ra(1440): indeterminate
ra(329) = 9; ra(304) = 1;
ra(421) = 9; ra(136) = 5; ra(1037) = 1;
ra(1338) = 1; ra(86) = 9; ra(447) = 5; %elliptical deformation? possibly nice example
ra(1257) = 1; ra(220) = 9;
ra(1304) = 1; ra(1331) = 9;
ra(329) = 9; ra(304) = 1;
ra(328) = 1; ra(41) =  9;
%ra 576, 66 indeterminate (backwasting?)
ra(680) = 1; ra(453) = 9;
ra(953) = 1; ra(327) = 9;
ra(448) = 1; ra(466) = 9;
ra(1272) = 1; ra(142) = 9;
ra(48) = 1; ra(499) = 9; ra(322) = 9;
ra(339) = 9; ra(569) = 1;
%248, 1336 indeterminate
ra(1092) = 9; ra(351) = 1; ra(342) = 5; ra(187) = 9; %interesting (unexpected?) pattern of shared-rim degradation
ra(1437) = 1; ra(661) = 9; ra(780) = 7; ra(657) = 3;
ra(60) = 1; ra(701) = 9; ra(134) = 5;
ra(97) = 1; ra(426) = 9; ra(159) = 1;
ra(1079) = 1; ra(911) = 1; ra(206) = 5;
ra(1317) = 1; ra(1183) = 9;
ra(1142) = 1; ra(438) = 9;
ra(237) = 1; ra(1255) = 9;
ra(621) = 1; ra(160) = 9;
ra(345) = 1; ra(23) = 5; ra(27) = 9;
ra(373) = 1; ra(734) = 9;
ra(360) = 1; ra(1178) = 9; %hard to determine.
ra(1275) = 1; ra(848) = 9;
ra(997) = 1; ra(424) = 1;
ra(829) = 1; ra(532) = 9;
ra(804) = 1; ra(202) = 9; %backwasting?
ra(659) = 5; ra(1419) = 1; ra(614) = 9;
ra(775) = 1; ra(325) = 9;
ra(564) = 1; ra(117) = 9;
ra(1236) = 1; ra(223) = 9;
ra(736) = 1; ra(450) = 9;
ra(566) = 1; ra(303) = 9;
ra(768) = 5; ra(315) = 5; %indeterminate.
ra(450) = 9; ra(736) = 1;
ra(566) = 1; ra(303) = 9;
%
figure
viscircles([e.LONGITUDE_CIRCLE_IMAGE, e.LATITUDE_CIRCLE_IMAGE],e.DIAM_CIRCLE_IMAGE/(59*2), ...
    'EdgeColor','k')
hold on
viscircles([e.LONGITUDE_CIRCLE_IMAGE(sum(dist<sumr)>1), ...
            e.LATITUDE_CIRCLE_IMAGE(sum(dist<sumr)>1)], ...
            e.DIAM_CIRCLE_IMAGE(sum(dist<sumr)>1)/(59*2), ...
    'EdgeColor','r')
viscircles([e.LONGITUDE_CIRCLE_IMAGE(ra>0), ...
            e.LATITUDE_CIRCLE_IMAGE(ra>0)], ...
            e.DIAM_CIRCLE_IMAGE(ra>0)/(59*2), ...
    'EdgeColor','m')
overlappers = num2str(find(sum(dist<sumr)>1)');
text(e.LONGITUDE_CIRCLE_IMAGE(sum(dist<sumr)>1), e.LATITUDE_CIRCLE_IMAGE(sum(dist<sumr)>1), ...
     overlappers)
  
 
figure  
for l = 1:size(dist,1)
    for m = 1:size(dist,2)
        if overlap(l,m)==1
            if ra(l) > 0
                
                if (ra(l) - ra(m))* ...
                   (e.DEPTH_RIMFLOOR_TOPOG(l)./e.DIAM_CIRCLE_TOPOG(l) - ...
                    e.DEPTH_RIMFLOOR_TOPOG(m)./e.DIAM_CIRCLE_TOPOG(m)) <= 0
                    linkcolor = 'r';
                else
                    linkcolor = 'k';
                end
            line([e.DIAM_CIRCLE_TOPOG(l) e.DIAM_CIRCLE_TOPOG(m)], ...
                [e.DEPTH_RIMFLOOR_TOPOG(l)./e.DIAM_CIRCLE_TOPOG(l) ...
                 e.DEPTH_RIMFLOOR_TOPOG(m)./e.DIAM_CIRCLE_TOPOG(m)],'Color',linkcolor);
            end
        end
    end
end
hold on
%scatter(e.DIAM_CIRCLE_TOPOG, e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG,30, e.DEGRADATION_STATE,'.');
hold on
scatter(e.DIAM_CIRCLE_TOPOG(sum(dist<sumr)>1), ...
       e.DEPTH_RIMFLOOR_TOPOG(sum(dist<sumr)>1)./e.DIAM_CIRCLE_TOPOG(sum(dist<sumr)>1), ...
       (ra(sum(dist<sumr)>1)+0.01)*25, (ra(sum(dist<sumr)>1)+0.01)*25,'Filled');

   
figure  
for l = 1:size(dist,1)
    for m = 1:size(dist,2)
        if overlap(l,m)==1
            if ra(l) > 0
                
                if (ra(l) - ra(m))* ...
                   (e.DEPTH_RIMFLOOR_TOPOG(l)./e.DIAM_CIRCLE_TOPOG(l) - ...
                    e.DEPTH_RIMFLOOR_TOPOG(m)./e.DIAM_CIRCLE_TOPOG(m)) <= 0
                    linkcolor = 'r';
                else
                    linkcolor = 'k';
                end
            line([e.DIAM_CIRCLE_TOPOG(l) e.DIAM_CIRCLE_TOPOG(m)], ...
                [e.DEPTH_RIMFLOOR_TOPOG(l) ...
                 e.DEPTH_RIMFLOOR_TOPOG(m)],'Color',linkcolor);
            end
        end
    end
end
hold on
%scatter(e.DIAM_CIRCLE_TOPOG, e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG,30, e.DEGRADATION_STATE,'.');
hold on
scatter(e.DIAM_CIRCLE_TOPOG(sum(dist<sumr)>1), ...
       e.DEPTH_RIMFLOOR_TOPOG(sum(dist<sumr)>1), ...
       (ra(sum(dist<sumr)>1)+0.01)*25, (ra(sum(dist<sumr)>1)+0.01)*25,'Filled');

   
figure; hint = 0.005;

critdd = 0.05; %critical depth:diameter ratio

plot([0:hint:0.2],histc(e.DEPTH_RIMFLOOR_TOPOG(ra==1)./e.DIAM_CIRCLE_TOPOG(ra==1),[0:hint:0.2]),'b')
hold on
plot([0:hint:0.2],histc(e.DEPTH_RIMFLOOR_TOPOG(ra==9)./e.DIAM_CIRCLE_TOPOG(ra==9),[0:hint:0.2]),'r')
plot([0:hint:0.2],histc(e.DEPTH_RIMFLOOR_TOPOG(ra>1 & ra<9)./e.DIAM_CIRCLE_TOPOG(ra>1 & ra<9),[0:hint:0.2]),'g')
plot([0:hint:0.2],histc(e.DEPTH_RIMFLOOR_TOPOG(ra==0)./e.DIAM_CIRCLE_TOPOG(ra==0),[0:hint:0.2]),'k')
plot([0:hint:0.2],histc(e.DEPTH_RIMFLOOR_TOPOG(ra>5 & ra<9)./e.DIAM_CIRCLE_TOPOG(ra>5 & ra<9),[0:hint:0.2]),'m')
plot([0:hint:0.2],histc(e.DEPTH_RIMFLOOR_TOPOG(ra>1 & ra<5)./e.DIAM_CIRCLE_TOPOG(ra>1 & ra<5),[0:hint:0.2]),'c')

figure; hint = 0.005;
[h,stats(1)] = cdfplot((e.DEPTH_RIMFLOOR_TOPOG(ra==1 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd) ...
              ./e.DIAM_CIRCLE_TOPOG(ra==1 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd))); set(h,'Color','b')
hold on
[h,stats(2)] = cdfplot((e.DEPTH_RIMFLOOR_TOPOG(ra==9 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd) ...
              ./e.DIAM_CIRCLE_TOPOG(ra==9 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd))); set(h,'Color','r')
[h,stats(3)] = cdfplot((e.DEPTH_RIMFLOOR_TOPOG(ra>1 & ra<9 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd) ...
              ./e.DIAM_CIRCLE_TOPOG(ra>1 & ra<9 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd))); set(h,'Color','g')
[h,stats(4)] = cdfplot((e.DEPTH_RIMFLOOR_TOPOG(ra==0 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd) ...
              ./e.DIAM_CIRCLE_TOPOG(ra==0 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd))); set(h,'Color','k'); title('Observed CDF')
          %h = cdfplot((e.DEPTH_RIMFLOOR_TOPOG(ra>5 & ra<9 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd) ...
          %    ./e.DIAM_CIRCLE_TOPOG(ra>5 & ra<9 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd))); set(h,'Color','m')
%h = cdfplot((e.DEPTH_RIMFLOOR_TOPOG(ra>1 & ra<5 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd) ...
          %    ./e.DIAM_CIRCLE_TOPOG(ra>1 & ra<5 & e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG < critdd))); set(h,'Color','c')
          
          
%Randomly redistribute crater depths and recalculate:
n_bs = 2e2; %number of bootstraps

e.ddr = e.DEPTH_RIMFLOOR_TOPOG./e.DIAM_CIRCLE_TOPOG; %depth to diameter ratio
temp = e.ddr(e.ddr<critdd);

e.sdr = NaN.*zeros(n_bs,size(e.ddr,1));

figure;hint = 0.005;
disp('Bootstrapping')
for l = 1:n_bs
    e.sdr(l,e.ddr<critdd) = temp(randperm(length(temp)));

[h, systats(l,1)] = cdfplot((e.sdr(l,(ra==1 & e.sdr(l,:)' < critdd)))); set(h,'Color','b')
hold on
[h, systats(l,2)] = cdfplot((e.sdr(l,ra==9 & e.sdr(l,:)' < critdd))); set(h,'Color','r')
[h, systats(l,3)] = cdfplot((e.sdr(l,ra>1 & ra<9 & e.sdr(l,:)' < critdd))); set(h,'Color','g')
[h, systats(l,4)] = cdfplot((e.sdr(l,ra==0 & e.sdr(l,:)' < critdd))); set(h,'Color','k'); title('Synthetic CDF')
end

figure
hist([systats(:,1).mean]);hold on;line([stats(1).mean stats(1).mean],[0 n_bs/8]);title('ra==1')
figure
hist([systats(:,2).mean]);hold on;line([stats(2).mean stats(2).mean],[0 n_bs/8],'Color','r');title('ra==9')
figure
hist([systats(:,3).mean]);hold on;line([stats(3).mean stats(3).mean],[0 n_bs/8],'Color','g');title('ra>9 & ra < 1')
figure
hist([systats(:,4).mean]);hold on;line([stats(4).mean stats(4).mean],[0 n_bs/8],'Color','k');title('ra==ZERO')


figure;h=cdfplot(e.ddr(e.DIAM_CIRCLE_TOPOG>30 & e.ddr<0.05));set(h,'Color','r');hold on
h=cdfplot(e.ddr(e.DIAM_CIRCLE_TOPOG<30 & e.ddr<0.05)); title('Small craters (blue) versus large craters (red)');