pro makeResistantIRDarks, startDay, endDay, minScanLength, LISTFN=listfn, SIGMA=sigma ;;----------------------------------------------------------------------------- ;; PURPOSE: ;; Generates darks by taking a resistant mean across the scan. The darks ;; Are then added to the Data/dark directory ;; ;; CALLING SEQUENCE: ;; makeResistantIRDarks, startDay, endDay, minScanLength, sigma ;; ;; REQUIRED INPUTS: ;; startDay - The eariliest date to make darks for in (YYYY-MM-DD format) ;; endDay - The last date to to make darks for ;; minScanLength - Minimum numbers of frames in a set to have it considered ;; a scan. A good value is 30 ;; sigma - The sigma value for the resistant mean ;; ;; OUTPUTS: ;; ;; OPTIONAL INPUT KEYWORDS: ;; LISTFN - Set this to the name of an ascii file with five columns ( DOY, ;; Expid, # of frames downloaded, first frame not to use, last ;; frame not to use) that specifies observations desired and ;; where in the scan might be bad for the resistant mean (eg. has ;; the comet in it). This overrides the startDay, endDay and ;; minScanLength parameters ;; ;; EXAMPLE: ;; IDL> makeResistantIRDarks, startDay, endDay, minScanLength, sigma ;; ;; PROCEDURES USED (i.e. called directly!): ;; ;; MODIFICATION HISTORY: ;; 2005-08-04 M. Desnoyer Created ;; ;;----------------------------------------------------------------------------- sig = keyword_set(SIGMA)?sigma:3.0 IF keyword_set(listfn) THEN BEGIN ;; Data are input from a file, so parse it data = read_ascii(listfn) data = data.field1 n = n_elements(data)/5 seq = strarr(3,n) seq[0,*] = strtrim(long(data[1,*]),2) seq[1,*] = strtrim(fix(data[2,*]),2) jd = julday(1,1,2005) + data[0,*] - 1 caldat, jd, mon, day, yr seq[2,*] = strtrim(yr,2)+'-'+string(mon, format='(I2.2)')+'-'+string(day, format='(I2.2)') ENDIF ELSE BEGIN ;; Get all the IR exposure IDs between start and end serv = getSQLserver() db = ( di_scu_missionstruct()).rawdb tbl = 'HRIIR' sel = ['EXPID', 'FNCMMNDD', 'OBSDATE'] cond = 'OBSDATE >= "'+startDay+'" AND OBSDATE <="'+endDay+'" and FNCMMNDD >= '+strtrim(minScanLength,2)+' ' seq = di_sqlquery(serv, db, tbl, sel, cond, dim=dim, /distinct) ENDELSE ;; Cycle through the sequences n = n_elements(seq)/3 for i=0, n-1 do begin ;; Get the jd dateSplit = strsplit(seq[2,i],'-',/extract) jd = julday(dateSplit[1],dateSplit[2], dateSplit[0])-2400000.5 ;; Get the list of files in the sequence, except for the first 3 and any ones the file tells us not to use serv = getSQLserver() db = ( di_scu_missionstruct()).rawdb tbl = 'HRIIR' sel = ['FilePath','NAXIS1','NAXIS2', 'IMGMODE', 'OBSDATE'] cond = 'FNIMGNMB > 3 AND expid ='+strtrim(seq[0,i],2) IF keyword_set(listfn) THEN BEGIN cond = cond+' AND (FNIMGNMB < '+string(data[3,i])+' OR FNIMGNMB > '+string(data[4,i])+$ ') AND abs(FNDOY - '+strtrim(data[0,i],2)+') < 2 ' ENDIF ELSE cond = cond $ + ' AND abs(OBSJD - '+strtrim(string(jd,f='(D20.8)'),2)+') < 2 ' files = di_sqlquery(serv, db, tbl, sel, cond, dim=dim, /distinct) fn = getLocFn(files[0,*]) ;; Make the cube for the scan m = n_elements(fn) IF m EQ 0 THEN message, 'Could not find the files in the scan) cube = fltarr(files[1,0],files[2,0],m) dark = fltarr(files[1,0],files[2,0]) for j=0,m-1 do begin tmp = readfits(fn[j],curhdr) linfn = 'HRIIR_050115_3_'+strtrim(sxpar(curhdr,'IMGMODE'),2)+'.fit' cube[0,0,j] = dical_lineardn(tmp,curhdr, fn='Data/LIN_DN/'+linfn) endfor ;; Do the resistant mean for j=0, files[2,0]-1 do begin for k=0, files[1,0]-1 do begin resistant_mean, cube[k,j,*],sig,tmp dark[k,j] = tmp endfor endfor ;; Get the master dark serv = getSQLServer() db = 'di_calib' sel = ['Filepath'] cond = "Date <= '2005-07-04'" $ +" AND instrument='HRIIR'" $ +" AND Mode = "+strtrim(sxpar(curhdr,'IMGMODE'),2)+$ " order by Date DESC, Version desc limit 1" tblNm = 'DARK_MODEL' fn = DI_sqlQuery(serv, db, tblNm, sel, cond, DIM=dim) IF max(dim) EQ 0 THEN $ message, 'Database contained no valid master dark',/NONAME ;; Get the local filename of the master dark fn = getLocFn(fn, subdir='DARK_MODEL') masterDark = readfits(fn[0]) ;; Scale the master dark by the resistant mean dark = masterDark * mean(dark) / mean(masterDark) ;; Make a header for the dark file mkhdr, hdr, dark cmt = strarr(5) stars= '***********************************************************************' cmt[0] = stars cmt[1] = '** This dark was created by performing a resistant mean in each pixel' cmt[2] = '** across the entire scan. The first three frames and any frames' cmt[3] = '** containing the object are not included in the resistant mean.' cmt[4] = stars sxaddhist, cmt, hdr, /comment sxaddpar, hdr, 'OBJST', keyword_set(listfn)?fix(data[3,i]):-1, ' First frame with object (-1 = no object)' sxaddpar, hdr, 'OBJEND', keyword_set(listfn)?fix(data[4,i]):-1, ' Last frame with object (-1 = no object)' sxaddpar, hdr, 'SIGMA', sig, ' The sigma value used for the resistant mean' sxaddpar, hdr, 'LINFN', linfn, ' File used to linearize the dark frames' cd, 'Data/dark', current=curdir writefits, 'tmp.fit', dark, hdr ;; Make a standard dark frame date = strmid(strjoin(strsplit(files[4,0],'-',/extract),''),2) jd = systime(/julian, /utc) caldat, jd, mon, day, yr curdate = strtrim(yr,2)+'-'+string(mon, format='(I2.2)')+'-'+string(day, format='(I2.2)') standardizedark, 'tmp.fit', 'HRIIR', files[3,0], seq[0,i], 0, seq[0,i], seq[1,i], date, '3', curdate, 'makeResistantIRDarks.pro' cd, curdir endfor end