pro Puffy_Events_06 ;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 ;CONSTANTS******************************************************. ;Force some to be floating point integers numpixrd=2048.*2048. ;Size of device threshold=1000 ;Threshold to flag pixel as Cosmic Ray Gauss_width=14 ;Width of Area to use for Gaussian Fitting min_sig=float(.6) ;Minimum standard deviation required to flag event read_num=123 ;FILENAMES****************************************************** file_number_1=1 file_number_str_1=string(file_number_1,format='(I1)') file_number_2=5 file_number_str_2=string(file_number_2,format='(I1)') read_num_tot=125 readsstr=string(read_num_tot,format='(I3)') file_name_1='dark_37K_'+readsstr+'_min_1_0'+file_number_str_1+'.fits' file_name_2='dark_37K_'+readsstr+'_min_1_0'+file_number_str_2+'.fits' ;************************************************************ ;Open the file that statistics will be written to and make table header openw,1,'c:\H2RG_15_EVENTS\PSF'+file_number_str_1+'_'+file_number_str_2+'.txt',/append printf,1 ,"Data for difference between final reads in images" printf,1,FORMAT='(%"%s\n%s\n")',file_name_1,file_name_2 printf,1,FORMAT='(%"Background\tAmplitude\tX Pixel\t\tY Pixel\t\tSigmax\t\tSigmay\t\tSigmar\t\tFile_No")' printf,1 ,"-----------------------------------------------------------------------------------------------------------------------------" ;Enter the directory that holds the dark current files for the device cd,'\\Rabbit\raid1\Rockwell4\H2RG-015-5.0mu\cold1\dktest.16May03' ;If the absolute value of the difference between two images is greater than ;Threshold, flag it is a possible cosmic ray. This method will hopefully eliminate ;hot pixels. The array_indices will be returned ;Vectors for successive reads for first image fits_read,file_name_1,x11,first=long(read_num*numpixrd),last=long((read_num+1)*numpixrd)-1 ;Vectors for successive reads for second image fits_read,file_name_2,x21,first=long(read_num*numpixrd),last=long((read_num+1)*numpixrd)-1 ;For last read, generate image to use for overall events ;if read_num eq (read_num_tot-3) then begin im1=reform(float(x11),2048.,2048.) im2=reform(float(x21),2048.,2048.) diff=float(im2-im1) filename='C:\H2RG_15_EVENTS\dktest.16May03\final_read_diff_'+file_number_str_1+file_number_str_2+'.fits' writefits,filename,diff ;Difference vectors for first and second images. Subtract first read twice; once for each read ;diff1_vec=float(x12-x11) ;diff2_vec=float(x22-x21) ;Get difference between image differentials ;diff_ramp_vec=float(diff2_vec-diff1_vec) ;diff_ramp_arr=reform(float(diff_ramp_vec),2048.,2048.) diff(where(diff lt 0))=0. ;writefits,'C:\dif12.fits',diff_ramp_arr ;tv,bytscl(congrid(diff_ramp_arr,1024,1024),min=-1000,max=1000) ;Try doing math with vectors and then finally making an array poss_cosm_vector=where(diff gt threshold) if poss_cosm_vector(0) ne -1 then begin poss_cosm_indices=array_indices(diff,poss_cosm_vector) poss_cosm_size=size(poss_cosm_indices) print,poss_cosm_size ;print,diff(poss_cosm_indices(0),poss_cosm_indices(1)) if poss_cosm_size(0) eq 1 then begin length=0 endif else begin length=poss_cosm_size(2)-1 endelse for j=0,length do begin ;Define the Area With which to fit the Gaussian around (x_pix,y_pix) ;Deal with Left Border, Center values, then Right Border x_pix=poss_cosm_indices(0,j) ;Left Border if x_pix lt 5 then begin xstart=0 xfinish=xstart+Gauss_width x=findgen(Gauss_width+1)+xstart endif ;Center Values if ((x_pix ge 5) and (x_pix le 2043)) then begin xstart=poss_cosm_indices(0,j)-(Gauss_width/2+1) xfinish=xstart+Gauss_width x=findgen(Gauss_width+1)+xstart endif ;Right Border if x_pix gt 2044 then begin xfinish=2047 xstart=xfinish-Gauss_width x=findgen(Gauss_width+1)+xstart endif ;Deal with Upper Border, Center Values, then Lower Border y_pix=poss_cosm_indices(1,j) ;Upper Border if y_pix lt 5 then begin ystart=0 yfinish=ystart+Gauss_width y=findgen(Gauss_width+1)+ystart endif ;Center Values if ((y_pix ge 5) and (y_pix le 2043)) then begin ystart=poss_cosm_indices(1,j)-(Gauss_width/2+1) yfinish=ystart+Gauss_width y=findgen(Gauss_width+1)+ystart endif ;Lower Border if ystart gt 2044 then begin yfinish=2047 ystart=yfinish-Gauss_width y=findgen(Gauss_width+1)+ystart endif gauss_area=diff(xstart:xfinish,ystart:yfinish) my_gauss_elip=mpfit2dpeak(gauss_area,gauss_elip_params,x,y) my_gauss_circ=mpfit2dpeak(gauss_area,gauss_circ_params,x,y,/circular) if ((gauss_elip_params(2) gt min_sig) and (gauss_elip_params(3) gt min_sig) and (gauss_elip_params(1) gt 0)) then begin ;printf,1,gauss_elip_params(0),gauss_elip_params(1),gauss_elip_params(2),gauss_elip_params(3),gauss_circ_params(2),read_num, FORMAT='(3F0)' printf,1,FORMAT='(%"%d\t\t%d\t\t%5.0f\t\t%5.0f\t\t%6.4f\t\t%6.4f\t\t%6.4f\t\t%4.0f")',gauss_elip_params(0),gauss_elip_params(1),gauss_elip_params(4),gauss_elip_params(5),gauss_elip_params(2),gauss_elip_params(3),gauss_circ_params(2),read_num print,gauss_elip_params ;read_num_str=string(read_num,format='(I3)') ;print,read_num_str ;filename='C:\H2RG_15_EVENTS\dktest.16May03\diff_'+file_number_str_1+file_number_str_2+'_'+read_num_str+'.fits' ;writefits,filename,diff_ramp_arr endif ;print,gauss_elip_params,read_num ;print,gauss_circ_params endfor endif ;At this point I can use the following commented commands to see what ;im1 and im2 look like ;tv,bytscl(congrid(im2,1024,1024)) ;tv,bytscl(congrid(im,1024,1024)) ; ;and their difference ;tv,bytscl(congrid(im-im2,1024,1024),min=-100,max=100) ; ;writefits,'C:\H2RG_015_Events\bif16.fits',im-im2 ;Once we find a good pixel with an event, we should look at how the charge evolved ;over the reads. The following commented code will allow that: ; ;imcube6=readfits('dark_37K_125_min_1_06.fits') ;tv,bytscl(im(*,*,0),min=-100,max=100) ;just for a look ;tv,bytscl(im(*,*,0),min=-100,max=100) ;Plot history of one pixel over time close,1 ;Since x and x2 are one-dimensional vectors, we need to turn them into 2-dimensional ;arrays where the size of each dimension is 2048 end