pro radar_mask_mmcr common mask_variables, dif_sig, count_pro, levels_t, mask ; assume the mask comes in already scanned for obvious positives (1) and negatives (-1) ;mask=intarr(count_pro,levels_t) prob=dblarr(count_pro,levels_t) noise_k=fltarr(count_pro) ;mask(where(alog10(dif_sig) lt -1.))=-1 ;;print, min(alog10(dif_sig)) ;mask(where(alog10(dif_sig) gt 0))=1 ;print, 'total elements ', n_elements(mask) ;print, 'elements eq to 0 ', n_elements(mask(where(mask eq 0))) ;print, 'elements eq to 1 ', n_elements(mask(where(mask eq 1))) if min(mask) eq -1 then print, 'elements eq to -1 ', n_elements(mask(where(mask eq -1))) print, 'minimum signal value is ',min(dif_sig) lower_thresh=1.d11 ; origial 700. upper_thresh=1.d9 ; original 100. num_t=2 num_z=2 iter=1 factor=1. for j=num_t+1,count_pro-num_t-1 do begin min_noise=1.e9 sdv_top=0. min_sdv=1. ;c need to find the min noise in the profile if max(mask(j,*)) ge 0 then begin noise_flag=-1 k=levels_t-5 while noise_flag eq -1 and k gt 5 do begin ;for k=6,levels_t-5,5 do begin if max(mask[j-num_t:j+num_t,k-num_z:k+num_z]) le 0 then begin x=moment(dif_sig[j-num_t:j+num_t,k-num_z:k+num_z]) mean_noise=x[0] if mean_noise lt min_noise then begin min_noise=mean_noise min_sdv=sqrt(x[1]) noise_k[j]=k endif noise_flag=1 endif ; max(dif_sig[j-num_t:j+num_t,k-num_z:k+num_z]) lt 0 ;endif ; flag check ;endfor ; k=6,levels_t-5 do begin k=k-1 endwhile mean_noise=min_noise sdv_top=min_sdv sigma=sdv_top low_signal=where(dif_sig[j,0:levels_t-num_z] lt min_noise-(2.*min_sdv)) high_signal=where(dif_sig[j,0:levels_t-num_z] gt min_noise+(2.*min_sdv)) if n_elements(low_signal) gt 1 then begin for lll=0,(n_elements(low_signal))-1 do begin mask[j,low_signal[lll]]=-1 endfor endif if n_elements(high_signal) gt 1 then begin for lll=0,(n_elements(high_signal))-1 do begin mask[j,high_signal[lll]]=1 endfor endif ;ccccccccccccccccccccccccc if min_noise lt 1.e9 and noise_flag eq 1 then begin start_index=1 for k=start_index+num_z,levels_t-num_z-1 do begin ;cur_gate=hts(k) ;c now go through each point in 3 by 5 boxes. estimate significance. if mask[j,k] eq 0 then begin sum=0. count2=0 for jj=j-num_t,j+num_t do begin for kk=k-num_z,k+num_z do begin if mask[jj,kk] ne 1 then begin sum=sum+(dif_sig[jj,kk]) count2=count2+1 endif endfor endfor ;z=((double(sum)/double(count2))-double(mean_noise)))/double(sigma) z=((double(sum)/double(count2))-double(mean_noise))/double(sigma) z=z/100. prob[j,k]=((2.d/sqrt(2.d*3.14159d)))*exp(-(abs(z))^2) ;if prob[j,k] eq 0. then begin ; print, z ;endif ;if prob[j,k] lt prob_temp then prob[j,k]=prob_temp ;prob[j,k]=prob[j,k]+((2./sqrt(2.*3.14159)))*exp(-(abs(z))^2) endif endfor ;k=start_index+num_z,levels_t-num_z do begin endif else begin prob[j,*]=1.e9 endelse endif ; if max(mask(j,*)) ge 0 then begin endfor ;j=num_t+1,count_pro-num_t do begin for j=num_t+1,count_pro-num_t-1 do begin if min(mask(j,*)) le 0 and noise_k[j] gt 0 then begin num_thresh=0 & thresh=0. for k=noise_k[j]-num_z,noise_k[j]+num_z do begin thresh=thresh+prob[j,k] & num_thresh=num_thresh+1 endfor thresh=thresh/double(num_thresh) for k=1,levels_t-3 do begin if mask[j,k] eq 0 then begin if k lt 50 then param=lower_thresh if k ge 100 then param=upper_thresh if k ge 50 and k lt 100 then begin param=lower_thresh+(((upper_thresh-lower_thresh)/((100.d)-(50.d)))*(double(k)-(50.d))) endif if prob[j,k] lt thresh/param then begin mask[j,k]=1 endif else begin mask[j,k]=0 endelse endif else begin ; mask eq 0 if mask[j,k] eq -1 then mask[j,k]=0 endelse endfor endif ; if max(mask(j,*)) ge 0 then begin endfor if min(mask) lt 0 then mask[where(mask lt 0)]=0 for j=0,num_t do begin for k=0,levels_t-1 do begin if mask[j,k] ne 1 then begin mask[j,k]=0 endif endfor endfor for j=count_pro-num_t-1,count_pro-1 do begin for k=0,levels_t-1 do begin if mask[j,k] ne 1 then begin mask[j,k]=0 endif endfor endfor for j=0,count_pro-1 do begin for k=0,5 do begin if mask[j,k] ne 1 then begin mask[j,k]=0 endif if mask[j,k] eq 1 and alog10(dif_sig[j,k]) lt -1.0 then begin mask[j,k]=0 endif endfor endfor for j=0,count_pro-1 do begin for k=levels_t-num_z-1,levels_t-1 do begin if mask[j,k] ne 1 then begin mask[j,k]=0 endif endfor endfor return end