;NAME: ; Puffy_Events_star_region_ndb_counts2.pro ; ; ;PURPOSE: ; This script will attempt to locate the events on the H2RG-015 that are attributed ; to electron-hole pairs in the CdZnTe 800 um substrate. These events are believed to be ; "Poofy" or "Puffy" ; ; The program first finds all pixels that have a count greater than THRESHOLD and flags them. Next it ; looks at symmetric regions (star-shaped regions of radius r, where the star approaches a circle as r ; goes to infinity) like the ones shown below ; ; ; r=1 r=2 r=.... ; - ; - --- ; --- ----- ..... ; - --- ; - ; ; and checks to see if all the pixels in that region are greater than THRESHOLD. If so ; that event is logged in logfile and all of the pixels are set to zero so that it will not be double counted. ; ;CALLING SEQUENCE ; ; ; puffy_events_star_region_ndb_counts2, testdir, [outdir [,darklistfile]] ; ;INPUTS: ; indir the full path name containing index file 'dark.lst' and corresponding ; dark current files to be analyzed ; ; ;KEYWORD PARAMATERS: ; ; outdir the full path name of the directory where the statistics file and the difference ; images will be written ; ; THRESHOLD the value used to flag regions of pixels. If the count value of a region of pixels is higher ; than threshold,they will be flagged. ; ; darklistfile the name of the file containing the list of the dark current files in indir pro Puffy_Events_star_region_ndb_counts3, indir, outdir=outdir, THRESHOLD=THRESHOLD, darklistfile=darklistfile ;CONSTANTS********************************************************************************************* array_Dimension=2048. ;Number of pixels in rows & columns numpixrd=array_dimension*array_dimension ;Number of pixels on device max_radius=5 ;Maximum size of region that will be evaluated min_radius=1 ;Minimum size of region that will be evaluated ;****************************************************************************************************** ;set directory path delimiter if (!version.os_family eq 'unix') then begin delim='/' endif else begin delim='\' endelse ;If output directory is not specified, then default to indir\Star_Region if (not keyword_set(outdir)) then outdir = indir+'\Star_Region\' if (not keyword_set(THRESHOLD)) then THRESHOLD=100 if (not keyword_set(darklistfile)) then darklistfile='\dark.lst' ;Check to see if output directory \Star_Region exists. If it does not, then create it if (FILE_TEST(outdir) eq 0) then FILE_MKDIR,outdir ;Open the file dark.lst that contains all of the dark current files ;in indir and read them into an array of strings. Then sort them by ;temperature. dark_list_path=indir+'\'+darklistfile readcol,dark_list_path,darkfiles,format='a' darkfiles=darkfiles(sort(darkfiles)) darkfiles=['0',darkfiles] ;Open the Output_file that will contain the statistics ;This file will have the following columns ;XPixel YPixel Radius Files used for Difference Output_stats_file=outdir+strcompress(string(THRESHOLD,format='(I3)'),/remove_all)+'_Threshold_Star.txt' openw,1,Output_stats_file,/append for dkf_index=1, (size(darkfiles,/n_elements)-2) do begin ;Split the entires with the underscore dark_file_parts1=strsplit(darkfiles(dkf_index),'_',/extract) dark_file_parts2=strsplit(darkfiles(dkf_index+1),'_',/extract) ;Determine whether format is Dark_[temp]_[read_num]_min_1_[ramp_number] ; or Dark_[temp]_[read_num}_min_[ramp_numer] if N_elements(dark_file_parts1) eq 5 then begin ramp_index=4 voltage='no bias' endif if N_elements(dark_file_parts1) eq 6 then begin ramp_index=5 voltage='no bias' endif if N_elements(dark_file_parts1) eq 7 then begin ramp_index=6 voltage=dark_file_parts1(5) endif ;get temperatures and the corresponding ramp numbers for use in ;obtaining difference images down the line file1=indir+'\'+darkfiles(dkf_index) file2=indir+'\'+darkfiles(dkf_index+1) temp1=dark_file_parts1(1) temp2=dark_file_parts2(1) read_num1_str=dark_file_parts1(2) read_num2_str=dark_file_parts2(2) reads,read_num1_str,read_num ramp_num1_plus_fits=dark_file_parts1(ramp_index) ramp_num2_plus_fits=dark_file_parts2(ramp_index) ramp_num1_parts=strsplit(ramp_num1_plus_fits,'.',/extract) ramp_num2_parts=strsplit(ramp_num2_plus_fits,'.',/extract) ramp_num1=ramp_num1_parts(0) ramp_num2=ramp_num2_parts(0) Index_string=temp1+read_num1_str+ramp_num1+ramp_num2 ;only do differencing of ramps if the temperatures are the same and the ;1st ramp is not included. This is because the 1st ramp has unusually high ;dark current if ((temp1 eq temp2) and (ramp_num1_plus_fits ne '01.fits') and $ (read_num1_str eq read_num2_str) and (file_test(file1) ne 0) and (file_test(file2) ne 0)) then begin print,'doable',temp1,temp2,ramp_num1,ramp_num2 fits_read,file1,x1,first=long((read_num-1)*numpixrd),last=long((read_num)*numpixrd)-1 fits_read,file2,x2,first=long((read_num-1)*numpixrd),last=long((read_num)*numpixrd)-1 ;For last read of two ramps, take difference, and set negative values to zero ;This should be a good way to get rid of bad pixels im1=reform(float(x1),2048.,2048.) im2=reform(float(x2),2048.,2048.) diff=float(im2-im1) diff(where(diff lt 0))=0. total_diff=double(N_elements(where(diff gt 300))) ;Only execute if the difference array contains reasonable values. This will not be the case if ;one image has significantly higher dark current than the other if ((N_elements(diff) gt 0) and (total_diff lt double(2000000))) then begin ;Begin by creating a fits image of the difference between the last reads for later reference filename=outdir+temp1+'_'+read_num1_str+'_'+voltage+'_'+ramp_num1+'-'+ramp_num2_plus_fits writefits,filename,diff for radius=max_radius,min_radius,-1 do begin gt_thresh=where(diff gt THRESHOLD,length_1) print,radius, size(gt_thresh) for i=double(0),(length_1-1) do begin ;Avoid the edges of the detector by only referencing pixels that are valid if ((gt_thresh(i) gt radius*array_dimension) and (gt_thresh(i) lt (array_dimension-radius)*array_dimension) $ and ((gt_thresh(i) mod array_dimension) gt radius) and ((gt_thresh(i) mod array_dimension) lt (array_dimension-radius))) then begin ;Use Boolean value of found_less here. ;found_less=0 A pixel with count less than THRESHOLD has not been found ;found_less=1 A pixel with count less than THRESHOLD has been found. In this case, break out of the loop ; and move onto the next value in the gt_threshold array found_less=0 ;These nested for loops cover the region of max_radius for xy_radius=(-radius),radius do begin for diag_radius=(-radius+abs(xy_radius)),(radius-abs(xy_radius)) do begin if ( (diff(long(gt_thresh(i)+long(xy_radius*array_dimension)+diag_radius)) lt THRESHOLD) $ or (diff(long(gt_thresh(i)+long(xy_radius*array_dimension)+diag_radius)) gt diff(gt_thresh(i)))) then begin found_less=1 break endif endfor if (found_less eq 1) then begin break endif endfor ;If the entire region contained only pixels greater than THRESHOLD, print values to Output_file if (found_less eq 0) then begin act_radius=radius+1 star_indices=array_indices(diff,gt_thresh(i)) print,'act radius',act_radius printf,1,FORMAT='(%"%d\t\t%d\t\t%d\t\t%s\t\t%s")',act_radius,star_indices(0),star_indices(1),voltage,Index_string ;remove the whole region so that the pixels are not double counted for xy_radius=(-radius),radius do begin for diag_radius=(-radius+abs(xy_radius)),(radius-abs(xy_radius)) do begin diff(long(gt_thresh(i)+long(xy_radius*array_dimension)+diag_radius))=0 endfor endfor endif endif endfor endfor endif endif endfor close,1 end