pro nis_c_div,sequence,sequence_avg, dark_mode, obs_target, sourcedir, verbose, head,satflag ; SUB-PROGRAM of nis_proc ; ; ABSTRACT ; Goes through sequence of NIS data and divides each spectrum by its exposure ; time (number of spectra at 1 sec per spectra), returning a sequence of ; average spectra. ; Also Reads from table the intrinsic noise of NIS. ; intrinsic noise is derived from 300 spectra-long darks. ; ; INPUTS ; sequence - Sequence of NIS spectra. It does not matter what the target is. ; sourcedir - source directory for NISCAL programs and data. ; verbose - Toggle description of events std output. ; ; USES - nis_default_noise.dat ; ; OUTPUTS ; sequence_avg - sequence1 with each spectra divided by exposure time. ; with table-derived nis detector noise, one for each ; spectrum inserted. ; ; HISTORY ; Created 9/12/97 by N. R. Izenberg ; Modified 11/24/97 (NRI) to include NIS detector stdevs ; 01/19/98 (NRI) v1.2 directory structure ; 07/14/98 (NRI) v2.0 compliant - "error" changed to "noise" and ; incorporated into CNFF format ; 11/11/98 (NRI) Fix single spectrum glitch ; 04/05/99 (NRI) Add MET fix (signed to unsigned) ; 05/04/00 (NRI) v4.1 Replace sz with NAX (= sxpar(head,'NAXIS2')) ; Add saturation detection - modify header and DQI. ; Fix incorrect signed/unsigned adjustment. ; 07/19/01 (NRI) v5.0 Make sure DQI mod is PDS compliant ; ; ; NOTES ; CNISF 5.0 NIS sequence data: (IDL column) 25 = # of spectra coadded ; CNISF 5.0 Data is 67:130 for Raw ; CNISF 5.0 Data is 131:194 for Calibration ; CNISF 5.0 Data is 195:258 for Noise ; Default Detector noise file from August 8 1997 calibration run ;------------------------------------------------------------------------------ ; Main ;Get standard per-detector ;error derived from 300 individual spectra ;----------------------------------------- noiz=fltarr(64) openr,unit,sourcedir+'lib_tables/nis_default_noise.dat',/get_lun readf,unit,noiz close,unit,/all ; Loop thourgh sequence, averaging each spectrum (each row) by the number of ; spectra summed for that row. ; Insert standard error for each sequence NAX=sxpar(head,'NAXIS2') ; sequence elngth DQI=sxpar(head,'NIS-023') ; sequence DQI if n_elements(verbose) ne 0 then $ print," >>>> Number of observations = ",NAX if NAX eq 1 then begin ; if number of observations is only 1 sequence_avg = sequence sequence_avg(195:258)=noiz if verbose eq 1 then print,' STEP 2: Single spectrum needs no average' goto, kickout endif sequence_avg=sequence satflag=0 ; column 25 is # of coadded spectra ; column 27 (or 25+2) is # of coadded darks scds = (sequence(6,*) ge 2)*2 ;shutter-closed dark spectrum smspec = shift(scds ne 0,-1)*(sequence(26,*)+sequence(27,*)) divisor=fltarr(1,nax) For i=0,NAX-1 do begin divisor(i)=sequence(25+scds(i),i)-smspec(i) endfor divisor2=fltarr(1,nax) For i=0,NAX-1 do begin divisor2(i)=sequence(25,i) endfor ;for dark_separated calibrations, where the entire file is dark if (dark_mode eq 1 or dark_mode eq 2) and (obs_target eq "C") or (obs_target eq "S") then begin scds=scds*0. smspoec=smspec*0. endif For i=0,NAX-1 do begin ; Divide calibrated data by number of coadded spectra ; If spectrum is shutter-closed dark, divide by coadded darks. divisor=sequence(25+scds(i),i)-smspec(i) ; Fix Kluged Earth swingby sequence if sequence(26,i) eq 3 and sequence(27,i) eq 4 and scds(i) eq 0 then begin divisor=10. print,'!!!!!!!!!!!!!!!!!!!!!!!!!!!' print,"LUNAR BD SEQUENCE TYPO FLAG" print,'!!!!!!!!!!!!!!!!!!!!!!!!!!!' endif ;interleaved darks take observations from the data spectra, so ;if the shutter closes, the previous spectrum has fewer ;coadded spectra. divisor in this case is # coadded spcs - rest ; seconds - secs of co-added darks. sequence_avg(131:194,i)=sequence(67:130,i)/divisor ;INSERT Noise ;NOISE of each spectrum can't be determined directly, since all we have ;is the total signal. We put in a proxy noise wich is the standard ;deviation of 300 individual 1 second observations. sequence_avg(195:258,i)=noiz ;fix signed integers to unsigned if sequence(0,i) lt 0 then sequence_avg(0,i)=65536.+sequence(0,i) if sequence(1,i) lt 0 then sequence_avg(1,i)=65536.+sequence(1,i) if sequence(2,i) lt 0 then sequence_avg(2,i)=65536.+sequence(2,i) sat1=total(sequence_avg(131:194,i) ge 4095.) ge 1 sat2=total(sequence(67:130,i) ge 65535.) ge 1 if sat1 ne 0 or sat2 ne 0 then begin satflag=satflag+1 sequence_avg(0,i)=long(sequence_avg(0,i)+2.*sat1+4*sat2) ;DQ (wich are zero unless a DQ issue is raised) is ;incremented by 2 for Saturation and 4 for rollover, ;resulting in a DQI value=result of: ;0=No DQ problems ;1=Data missing/interrupted ;2=Saturation ;3=Sat+missing ;4=rollover ;5=rollover+missing ;6=rollover+sat ;7=rollover+sat+missing endif endfor if satflag ne 0 then sxaddpar, head, 'NIS-023', DQI+10, $ 'DQI: sat data (lft #) or missing data (rt)' ;print,satflag if verbose eq 1 then begin print,' STEP 2: spectra averaged' if total(satflag) gt 0 then print,' >>>> FLAG: ',fix(total(satflag)), $ ' observations have saturated channels. endif kickout: end