PRO maxdn,year,month,day ; ; This procedure scans any 'ilists' for the specified date, and ; for each 'ilist', outputs a list of the useful maximum DN necessary ; to represent each listed image. The output lists can be used to ; set full-scale DN's for image plots in advance. ; ; Algorithm: ; for each ilist: ; read ilist ; scan list and identify needed dark frames ; read in needed dark frames a la ql.pro ; for each 1- or 10-second image in list ; read in each image in list ; subtract appropriate dark frame ; determine useful upper limit DN a la ql.pro ; write DN entry to vector of max DN's ; open output file ; write out max DN and file name (similar format to 'ilist' files) ; mask=BYTARR(256,256) s='' ; define mask for images, with fixed horizon at 150 superpixels prad=150 d256=SHIFT(dist(256),128,128) & base=WHERE(d256 GT 150) wprad=WHERE(d256 LE prad) & mask(wprad)=1 ; make lists of available files of desired type hr=0B & min=hr & sec=hr rdilist,0,year,month,day,hr,min,sec,n0,t0,files0 maxDN0=INTARR(n0) rdilist,1,year,month,day,hr,min,sec,n1,t1,files1 maxDN1=INTARR(n1) ; read in or generate required dark frames dkt=0 dkim=INTARR(1,512) dkpair=INTARR(256,512) FOR i=0,n0-1 DO BEGIN exp0=FIX(STRMID(files0(i),STRLEN(files0(i))-7,3)) we=WHERE(exp0 EQ dkt,nwe) IF nwe EQ 0 THEN BEGIN ; haven't got this exposure time yet rdmeandk,0,exp0,dk0 rdmeandk,1,exp0,dk1 dkpair(*,0:255)=dk0 dkpair(*,256:511)=dk1 dkt=[dkt,exp0] dkim=[dkim,dkpair] ENDIF ENDFOR FOR i=0,n1-1 DO BEGIN ; repeat above process for camera 1 exp1=FIX(STRMID(files1(i),STRLEN(files1(i))-7,3)) we=WHERE(exp1 EQ dkt,nwe) IF nwe EQ 0 THEN BEGIN ; haven't got this exposure time yet rdmeandk,0,exp1,dk0 rdmeandk,1,exp1,dk1 dkpair(*,0:255)=dk0 dkpair(*,256:511)=dk1 dkt=[dkt,exp1] dkim=[dkim,dkpair] ENDIF ENDFOR dkt=dkt(1:*) ; drop dummy entry at start of array dkim=dkim(1:*,*) ; drop dummy column ... ; read in each image, rebin to 256x256 if necessary, subtract dark ; frame, compute histogram of exposed part of image, and find DN ; > 99.9% of exposed pixels ; ; camera 0 images first ; FOR i=0,n0-1 DO BEGIN s=files0(i) exp=FIX(STRMID(s,STRLEN(s)-7,3)) IF exp LE 10 THEN BEGIN rdkimg,s,h,im IF N_ELEMENTS(im) NE 65536L THEN BEGIN im=REBIN(im,256,256) ; ensure counts are actually summed if a 512x512 image is compressed cfac=512/(256*KIh.exp.sbin) rfac=512/(256*KIh.exp.pbin) im=im*cfac*rfac ENDIF ; subtract appropriate dark frame dp=WHERE(dkt EQ exp) im=(im-dkim(256*dp(0):256*dp(0)+255,0:255))>0 ; identify useful min and max values for byte-scaling ih=HISTOGRAM(im(wprad),MIN=0,BIN=1) ; histogram of exposed image cih=ih ; next line computes cumulative pixel value pdf FOR jj=1,N_ELEMENTS(cih)-1 DO cih(jj)=cih(jj)+cih(jj-1) cih=cih/FLOAT(MAX(cih)) ; normalize to unity maxDN0(i)=MAX(WHERE(cih LE .999)) ; top 0.1% of pixels saturate IF (i+1) MOD 50 EQ 0 THEN PRINT,STRTRIM(i+1,2)+' images processed' ENDIF ENDFOR ww=WHERE(maxDN0) files0=files0(ww) maxDN0=maxDN0(ww) outname='/jasper/cnsr3_data1/ilist/'+ $ STRING(year,month,day,FORMAT='(3I2.2,".0.maxDN")') OPENW,u0,outname,/GET_LUN FOR i=0,N_ELEMENTS(ww)-1 DO $ PRINTF,u0,maxDN0(i),files0(i),FORMAT='(I5,3X,A45)' CLOSE,u0 FREE_LUN,u0 ; then camera 1 ; FOR i=0,n1-1 DO BEGIN s=files1(i) exp=FIX(STRMID(s,STRLEN(s)-7,3)) IF exp LE 10 THEN BEGIN rdkimg,s,h,im IF N_ELEMENTS(im) NE 65536L THEN BEGIN im=REBIN(im,256,256) ; ensure counts are actually summed if a 512x512 image is compressed cfac=512/(256*KIh.exp.sbin) rfac=512/(256*KIh.exp.pbin) im=im*cfac*rfac ENDIF ; subtract appropriate dark frame dp=WHERE(dkt EQ exp) im=(im-dkim(256*dp(0):256*dp(0)+255,256:511))>0 ; identify useful min and max values for byte-scaling ih=HISTOGRAM(im(wprad),MIN=0,BIN=1) ; histogram of exposed image cih=ih ; next line computes cumulative pixel value pdf FOR jj=1,N_ELEMENTS(cih)-1 DO cih(jj)=cih(jj)+cih(jj-1) cih=cih/FLOAT(MAX(cih)) ; normalize to unity maxDN1(i)=MAX(WHERE(cih LE .999)) ; top 0.1% of pixels saturate IF (i+1) MOD 50 EQ 0 THEN PRINT,STRTRIM(i+1,2)+' images processed' ENDIF ENDFOR ww=WHERE(maxDN1) files1=files1(ww) maxDN1=maxDN1(ww) outname='/jasper/cnsr3_data1/ilist/'+ $ STRING(year,month,day,FORMAT='(3I2.2,".1.maxDN")') OPENW,u1,outname,/GET_LUN FOR i=0,N_ELEMENTS(ww)-1 DO $ PRINTF,u1,maxDN1(i),files1(i),FORMAT='(I5,3X,A45)' CLOSE,u1 FREE_LUN,u1 END