pro mk_ssc, week, outdir=outdir, loud=loud, $ noscatter=noscatter, scatter=scatter, nodeka=nodeka, nokleen=nokleen, $ vignette=vignette, novignette=novignette, $ nodestreak=nodestreak, destreak=destreak, $ noclean=noclean, noleak=noleak, no_second_order_leak=no_second_order_leak, $ prefix=prefix, ss=ss, triplet=triplet, nonormalize=nonormalize, $ saa_state=saa_state, ifiles=ifiles, $ subdir=subdir, yyyy=yyyy, filename_only=filename_only, _extra=_extra, $ uncert=uncert, synsfc=synsfc, debug=debug, nuden_ok=nuden_ok, $ strtdate=strtdate,ndays=ndays,indx=indx,dat=dat,$ timg=timg,cindex=cindex,cdata=cdata,cunc=cunc,outfile=outfile ;+ ; Name: mk_ssc ; ; Purpose: make SXT "Final" science composite movie - de-spagetti mk_sfd ; ; Input Parameters: ; week - the week to process ; ifiles - explicit filelist (in lieu of WEEK string) ; BEWARE! This program is designed to be driven by go_ssc_batch ; which causes SFR files to be ingested one day at a time. ; This program reads ALL files in ifiles=ifiles, or for an ; entire week if the input week is used. Thus, one can readily ; exceed the memory capacity of the computer if discretion ; is not used. ; NOTE: To deal with this problem without having to use ifiles ; I've added the keywords strtdate and ndays. ; ; Keyword Output ; cindex, cdata, cunc: Returned if timg is input. ; ; Keyword Parameters: ; timg, time (anytim format) of the sole long exposure to process ; 'week' is generated internally when using timg. ; indx, dat - permit readin of data to process ; strtdate - for less than the whole week you can specify ; a starting date. E.g., '7-Oct-2001' ; ndays - if you use strtdate then ndays can be used to specify ; the number of days to process. (default ndays=1) ; nodeka - dont deka normalize (default) ; vignette - call sxt_off_axis to correct for vignetting. ; novignette - dont vignette correct (default) ; noleak - don't do straylight correction (default is to do it) ; no_second_order_leak - don't do 2nd straylight (default is to do it) ; noclean or nokleen - dont call sxt_clean (default is to clean) ; noscatter - dont call sxt_scatter (default) ; scatter - call sxt_scatter ; triplet - make 3-image composite SSTs ; prefix - output file prefix (default='ssc' (pair), 'sst' implies triple ; outdir - output directory ; subdir - optional subdirectory ; filename_only - if set, just derive planned filename and return in OUTFILE ; ss - Set ss to limit the number of composites made to ss (saves time) ; debug - Stop before return for debugging ; loud - Print out some messages. ; destreak - call sxt_xsaa to remove cosmic ray streaks. ; nodestrak - don't call sxt_xsaa (default) ; nonormalize - don't normalize to 1 sec exposure (default is to do it) ; yyyy - Put the output in a specified yyyy subdirectory (normally automatic) ; uncert - Create uncertainty arrays (default not to do it) ; synsfc - Use SynSFCs, override internal guidelines ; saa_state - choose where to make SSCs w/t SAA (default is off) ; SAA_STATE = undefined => don't care about SAA (ie, all) ; SAA_STATE = 1 => ONLY include SAA images ; SAA_STATE = 0 => Only include NON-SAA images ; nuden_ok - Eliminates rejection of images using ND filter. ; ; Side Effects: ; generates an 'ssc' file - floating point, normalized to counts/sec/pix ; ; Rules for choice of Synthetic or Terminator SFCs. ; -------- Set up Syn/Term SFC boundaries ---------- ; ent(0) - 24 Jul 93 use TermSFC ; 24 Jul 93 - 16 Sep 94 use SynSFC ; 16 Sep 94 - ent(3) use TermSFC ; ent(3) - ent(5) use SynSFC ; ent(5) - ent(7) use TermSFC ; ent(7) - ent(9) use SynSFC ; NOTE: Syn/Term choice is based upon time of first index ; record and that selection is used for that SSC or SST. ; ------------------------------------------------- ; ; History: ; 29-Feb-2007 - LWA - Created from mk_ssc.pro ; 3-Apr-2007 - LWA - Changed version to '.3' ; 22-May-2007 - LWA - Got rid of extraneous mk_sff_pair_91 call. ; 29-May-2007 - LWA - Mod. for early months. version now '.4'. ; Changed non-saturated flag to -2. ; 30-May-2007 - LWA - Don't read FR data to save memory space. ; 31_May-2007 - LWA - Created from mk_ssc_91.pro. ; 8-Jun-2007 - LWA - Cleared common mk_ssc_blk2. ; 17-Aug-2007 - LWA - Enabled quiet keyword for mk_sff_pair. ; 21-Aug-2007 - LWA - if loud then help,nlong,ssl,ssm,sss. ; made fmt_timer printout subject to /loud. ; 22-Aug-2007 - LWA - Incorporated keyword quiet in call to sxt_prep. ; 22-Jan-2008 - LWA - Incorporated timg, cindex, cdata, cunc. ; 24-Jan-2008 - LWA - Set up to NOT do dc_orbit_correct or ; second_order_leak for 14-Nov to 8-Dec-1992. ; 25-Jan_2008 - LWA - Defined week for timg use. ; 27-Jan-2008 - LWA - Corrected 25-Jan fix. ; 31-Jan-2008 - LWA - Corrected old notfr bug (ouch!) ; Added timg test to save reading so much data. ; 7-Feb-2008 - LWA - Auto generation of week if strtdate and not timg. ; 8-Feb-2008 - LWA - Don't do sxt_decon on uncertainty array. ; Moved first definition of skip2nd=0 & dcorb=1. ; 10-Feb-2008 - LWA - Moved if/else def of skip2nd=0 & dcorb=1 earlier. ; 16-Jun-2008 - LWA - Replaced missing cindex=scatindex. ; 22-Jan-2009 - LWA - Changed maxdt to 1200 for use in 24-Oct-95 eclipse. ; Changed maxdt back to 660. ; 9-Mar-2009 - LWA - Changed misleading "roadmap" to xindex throughout. ; Changed maxdt back to 660. ; 23-Mar-2009 - LWA - Reject images more than half off of CCD. ; 21-Jul-2009 - LWA - Moved file name definition to end in order to ; pick up synsfc flag correctly. ; Added keyword outfile. ; 27-Jul-2009 - LWA - Test for eclipse special leak handling. ; 30-Jul-2009 - LWA - Delete special leak handling, done in leak_sub.pro. ; 19-Aug-2009 - LWA - Reversed 24-Jan-2008 change. Now DO dc_orbit_correct or ; second_order_leak from ent(1) to 4-Dec-1992. ; 29-Jun-2012 - LWA - Force soleak=0 before 1st ent failure. ;- common mk_ssc_blk1, lweek, files, xindex, xdata common mk_ssc_blk2, chang delvarx,chang mk_ssc_version='.4' loud=keyword_set(loud) if not loud then sffquiet=1 else sffquiet=0 noleak=keyword_set(noleak) triplet=keyword_set(triplet) debug=keyword_set(debug) if keyword_set(strtdate) and not keyword_set(timg) then begin week=anytim2weekinfo(strtdate) endif if keyword_set(timg) then begin week=anytim2weekinfo(timg(0)) endif skip2nd=0 & dcorb=1 ;if keyword_set(loud) then begin ; box_message,'McKenzie''s hack of MK_SSC' ; To allow output of uncert, 11-dec-01 ; box_message,'FORCING UNCERT PROCESSING' ;endif ; My hacks are on lines 197, 232, 241, 248, 264. (McKenzie) ; Processing Flags (boolean in file name of form xxxx (0=>off,1=>on) ; ORDER>> SCATTER | VIGNETTE | CLEAN | DESTREAK | NORMALIZE | 2ndLEAK | synsfc scatter=keyword_set(scatter) ; Default OFF vignette=keyword_set(vignette) ; Default OFF destreak=keyword_set(destreak) ; Default OFF soleak=1-keyword_set(no_second_order_leak) ; Default ON clean=(1-keyword_set(noclean)) or destreak ; Default ON synsfc=keyword_set(synsfc) ; Default OFF ;synsfc=(keyword_set(synsfc)) or $ ; get_logenv('sxt_syn_sfc') eq '1' ; Default OFF deka=0 ; S.L.F 18-dec-1998 Default Changed normalize=1-keyword_set(nonormalize) ; Default ON ; ------------ define output directory ---------------- defdir=get_logenv('DIR_SXT_SSC') case 1 of data_chk(outdir,/string,/scalar): ; user supplied file_exist(defdir): outdir =defdir ; online else: outdir=curdir() ; current directory endcase if not keyword_set(outdir) then outdir=curdir() case 1 of data_chk(prefix,/string,/scalar): ; user supplied keyword_set(triplet): prefix='sst' ; triplet movie else: prefix='ssc' ; default (pair) movie endcase case 1 of keyword_set(saa_state): prefix=prefix + 'saa' ; saa only n_elements(saa_state) eq 1: prefix=prefix + 'nosaa' else: endcase loud=keyword_set(loud) if n_elements(lweek) eq 0 then lweek='' if keyword_set(indx) then goto,skipread ; -------- read xindex ------------ case 1 of data_chk(week,/string): begin box_message,'Checking CDROM for associated week files...' files=cdrom_files(week=week,/sfr,mag_disk='/disk/hl2/pd1/weekdirs') froot=week endcase data_chk(ifiles,/string): begin box_message,'Using user supplied filelist...' files=ifiles froot=time2file(file2time(ifiles(0))) case 1 of keyword_set(yyyy): subdir=strmid(froot,0,4) ; prepend ../YYYY/... data_chk(subdir,/string): sub=subdir else: subdir='' endcase outdir=concat_dir(outdir,subdir) box_message,'Using parent directory: ' + outdir week='' endcase ; keyword_set(timg) : else: begin box_message,'Need to supply either week (YYYY_WW), file list '$ +'(IFILES=filelisti), or timg' return endcase endcase if keyword_set(timg) then begin tfil=anytim(strmid(files,23,4)+'-'+strmid(files,36,2)+'-'+$ strmid(files,38,2)+'T'+strmid(files,41,2)+':'+strmid(files,43,2)) lfil=where(tfil le anytim(timg)) files=files(n_elements(lfil)-1) if loud then print,files endif rd_roadmap,files,frchk notfr=where(gt_res(frchk) eq 1 or gt_res(frchk) eq 2) if loud then help,files,frchk rd_xda,files,notfr,xindex,xdata skipread: if keyword_set(indx) then begin xindex=indx xdata=dat froot=anytim2weekinfo(indx(0)) endif if loud then help,indx,xindex,dat,xdata if keyword_set(strtdate) then begin sd=anytim(strtdate,/ints) sde=sd if keyword_set(ndays) then sde.day=sde.day+ndays else $ sde.day=sde.day+1 ;Default is to do one day. ff=sel_timrange(xindex,sd,sde,/between) if loud then begin print,'START = ',fmt_tim(sd) print,'END = ',fmt_tim(sde) endif rd_xda,files,notfr(ff),xindex,xdata ; Fixed LWA 1/31/08. endif ; Set soleak=0 if before 1st ent failure. 29-Jun-2012 LWA. firstleak=get_yo_dates(/ent) ; Test for first entrance failure. tt=int2secarr(anytim(xindex(0),/yohkoh),anytim(firstleak(1),/yohkoh)) - $ int2secarr(anytim(firstleak(1),/yohkoh)) if tt lt 0 then soleak=0 ; OFF before 1st ent failure. mnr_frm_fix,xindex,xdata ;Set missing minor frames to zero. if loud then fmt_timer,xindex ; -------- make LONG/SHORT pariings ---------- if loud then box_message,'Calling image-pairing routine...' mk_sff_pair,xindex,indat=xdata,$ ssl,ssm,sss,count=count,triplet=triplet, $ saa_state=saa_state,_extra=_extra,maxdt=660, $ ; saa_state=saa_state,_extra=_extra,maxdt=1200, $ nuden_ok=nuden_ok,debug=debug,quiet=sffquiet if loud then fmt_timer,xindex nlong=n_elements(ssl) if n_elements(ss) ne 0 then nlong=ss if count eq 0 then nlong=0 ; Process only a single composite. if keyword_set(timg) then begin jj=tim2dset(xindex(ssl),anytim(timg,/yohkoh)) ssl=ssl(jj) ssm=ssm(jj) sss=sss(jj) nlong=1 endif if loud then help,nlong,ssl,ssm,sss if debug then print,'STOP before compositing.' if debug then stop for i=0,nlong(0) -1 do begin print,'COMPOSITE # ',strtrim(i,2) delvarx, data, fillmap if triplet then begin case 1 of ;LWA 1/24/04 ssm(i) ne -2 and sss(i) ne -2 : ssx=[ssl(i),ssm(i),sss(i)] ssm(i) ne -2 and sss(i) eq -2 : ssx=[ssl(i),ssm(i)] ssm(i) eq -2 : ssx=ssl(i) endcase index=xindex(ssx) data=xdata(*,*,ssx) endif else begin case 1 of ;LWA 1/24/04 sss(i) ne -2 : ssx=[ssl(i),sss(i)] sss(i) eq -2 : ssx=ssl(i) endcase index=xindex(ssx) data=xdata(*,*,ssx) endelse ; Check for image totally out of CCD FOV. att=sxt_cen(index(0)) cc=where(att lt 0. or att gt 1024.,ncc) if ncc gt 0 then begin print print,'&&&& Skipping ',i,' ',fmt_tim(index(0)) print,'&&&& ATT = ',att print goto,local endif ; ---- Print out the images chosen for composites ---- if loud then begin if keyword_set(triplet) then begin case 1 of ssm(i) eq -2 and sss(i) eq -2 : begin box_message,['SST "Triplet" comprises:', $ get_info(index(0),/non)] end ssm(i) gt -2 and sss(i) eq -2 : begin box_message,['SST "Triplet" comprises:', $ get_info(index(0),/non), $ get_info(index(1),/non)] end ssm(i) gt -2 and sss(i) gt -2 : begin box_message,['SST "Triplet" comprises:', $ get_info(index(0),/non), $ get_info(index(1),/non), $ get_info(index(2),/non)] end endcase endif else begin case 1 of sss(i) eq -2 : begin box_message,['SSC "Doublet" comprises:', $ get_info(index(0),/non)] end sss(i) gt -2 : begin box_message,['SSC "Doublet" comprises:', $ get_info(index(0),/non), $ get_info(index(1),/non)] end endcase endelse endif ; -------- Set up Syn/Term SFC boundaries ---------- 19-Nov-04 ; ent(0) - 24 Jul 93 use TermSFC ; 24 Jul 93 - 16 Sep 94 use SynSFC ; 16 Sep 94 - ent(3) use TermSFC ; ent(3) - ent(5) use SynSFC ; ent(5) - ent(7) use TermSFC ; ent(7) - ent(9) use SynSFC ; NOTE: Syn/Term choice is based upon time of first index record and ; that selection is used for the SSC or SST. ; ------------------------------------------------- if not synsfc then begin ent=get_yo_dates(/ent) braks=[ent(0),'24-Jul-93 00:00','16-Sep-94 00:00',ent(3),ent(5), ent(7),ent(9)] btt0=int2secarr(braks,index(0)) bii0=where(btt0 ge 0) case 1 of bii0(0) eq 1 : choose_sfc,/term bii0(0) eq 2 : begin choose_sfc,/syn synsfc=1 end bii0(0) eq 3 : choose_sfc,/term bii0(0) eq 4 : begin choose_sfc,/syn synsfc=1 end bii0(0) eq 5 : choose_sfc,/term bii0(0) eq 6 : begin choose_sfc,/syn synsfc=1 end else : choose_sfc,/term endcase endif ; ent=get_yo_dates(/ent) ; lk1=anytim(ent(1)) & lk2=anytim('4-dec-1992') & lk0=anytim(index(0)) ; if ((lk0 ge lk1) and (lk0 le lk2)) then begin ; dcorb=0 ; skip2nd=1 ; endif else begin dcorb=1 skip2nd=0 ; endelse ; Set skip2nd=1 for certain eclipse situations. ; if (anytim(index(0)) gt anytim('24-OCT-95 03:22:00') and anytim(index(0)) $ ; lt anytim('24-OCT-95 03:48:00')) or (anytim(index(0)) gt $ ; anytim('24-OCT-95 05:34:00') and anytim(index(0)) lt $ ; anytim('24-OCT-95 05:53:00')) or (anytim(index(0)) gt $ ; anytim('17-Apr-96 22:04') and anytim(index(0)) lt $ ; anytim('18-Apr-96 00:08')) then skip2nd=1 if n_elements(ssx) gt 1 then begin ;LWA 1/24/04 ; ---- Call compositing routine (calls sxt_prep internally) --- ; /Uncert choice for compositing, next 7 lines; 11-dec-01, DMcK sonuden=soleak and max(gt_filta(index) eq 6) ;LWA 9/25/04 / SLF 18-nov-04 ; Note: sonuden is 0 unless soleak eq 1 and the nuden filter is ; in place. Therefore, sonuden is usually 0 and second_order_leak ; isn't done in the sxt_sff_composite calls. Keyword dcorb has ; been added to control use of dc_orbit_correct. LWA 1/24/08 if keyword_set(uncert) then sxt_sff_composite,index,data,cindex,cdata,$ vignette=0, sxt_cleanx=clean, destreak=destreak, noleak=noleak, $ fillmap=fillmap, unc_out=cunc, second_order_leak=sonuden,$ dcorb=dcorb if not(keyword_set(uncert)) then sxt_sff_composite,index,data,cindex,cdata,$ vignette=0, sxt_cleanx=clean, destreak=destreak, noleak=noleak, $ fillmap=fillmap, second_order_leak=sonuden,dcorb=dcorb endif else begin ; ----- No compositing needed - just call sxt_prep --------- sonuden=0 sxt_prep, index(0),data(*,*,0), cindex, cdata, cunc, $ /float,dc_orbit_correct=dcorb,vignette=0, $ sxt_cleanx=clean, destreak=destreak, noleak=noleak, $ quiet=1-loud if keyword_set(uncert) then cunc=sxt_dn_unc(cindex,cdata,temporary(cunc)) fillmap=bytarr(data_chk(data,/nx),data_chk(data,/ny)) endelse if skip2nd then goto,skip2 ; ----------- Next do 2nd order leak ------ tt=int2secarr(anytim(cindex,/yohkoh),anytim(firstleak(1),/yohkoh)) - $ int2secarr(anytim(firstleak(1),/yohkoh)) help,soleak,tt if soleak and tt gt 0 then begin raw=tim2dset(index,cindex) second_done=0 ; assume not applied (sxt_deleak "failure") cdata=sxt_deleak(cindex,cdata,xdata=data(*,*,raw),yn=second_done) qleak=cindex.his.q_leak_sub ; get current .HIS value his_index,cindex,0,'q_leak_sub', $ qleak+(2^15*((second_done ne 0) and (1-sonuden))) ; endif skip2: ; --------------- scatter correction ------------------ if scatter then begin if loud then box_message,'Scatter; deconvolving using sxt_decon...' if loud then sxt_decon,cindex,cdata,scatindex,scatdata else $ sxt_decon,cindex,cdata,scatindex,scatdata,/noverbose ; << data array cdata=temporary(scatdata) cindex=scatindex ; Do not deconvolute uncert array, this violates the actual statistical ; uncertainty in any give pixel. 2/8/2008 LWA and DMcK. ; if keyword_set(uncert) then begin ; sxt_decon,cindex,cunc,scatindunc,scatatunc ; << uncertainty array ; cunc=temporary(scatatunc) ; endif ; cindex=scatindex endif ; ----------- Finally, do vignette correction --------- if vignette then begin box_message,'Devignette with sxt_off_axis.' vigdata=sxt_off_axis(cindex,cdata,vigindex) cdata=temporary(vigdata) if keyword_set(uncert) then begin vigdataunc=sxt_off_axis(cindex,cunc,vigindexunc) cunc=vigdataunc endif cindex=vigindex endif ; ----------- normalization --------------- case 1 of normalize: begin ; -> counts/sec/pixel box_message,'Normalizing to CTS/Sec/Pixl' for j=0,data_chk(cdata,/nimage)-1 do $ cdata(0,0,j) = 1.e3*cdata(*,*,j)/gt_expdur(cindex(j)) if keyword_set(uncert) then begin for j=0,data_chk(cdata,/nimage)-1 do $ cunc(0,0,j) = 1.e3*cunc(*,*,j)/gt_expdur(cindex(j)) endif his_index, cindex, -1, 'expdur', 1000. ; history his_index, cindex, -1, 'q_exp_norm', 2 ; algorithm end deka: begin box_message,'DEKA-Normalizing' cdata=deka_norm(cindex, cdata, deka=cindex) if keyword_set(uncert) then cunc=deka_norm(cindex, cunc, deka=cindex) end else: box_messge,'Not Normalizing data' endcase ; ------- make the processing flags part of the file name ------------ flagstring=strcompress(string(scatter)+ $ string(vignette)+string(clean)+string(destreak)+string(normalize) + $ string(soleak) + string(synsfc),/remove) outfile=concat_dir(outdir,prefix+froot+'_'+flagstring+ mk_ssc_version) if keyword_set(filename_only) then begin box_message,'Just returing filename in OUTFILE...' return endif if loud then begin box_message,'Number of useful LONGS found: ' + strtrim(nlong,2) states=(['DISABLED','ENABLED']) status=['Output File Name: ' + outfile, $ 'Processing Options:' , $ ' Scattered Light: ' + states(scatter), $ ' Vignette Correction :' + states(vignette),$ ' SXT_Clean (despike) :' + states(clean), $ ' SXT_XSAA (destreak):' + states(destreak), $ ' Normal->Cts/Sec/Pix: ' + states(normalize), $ ' 2nd Order Leak Corr: ' + states(soleak) , $ ' Synthetic SFC Corr: ' + states(synsfc) ] if noleak then begin box_message,'LEAK SUBTRACTION INHIBITED!',btext=txt,/quiet status=[txt,status] endif box_message,status endif ; For timg case don't write files. Simply return cindex,cdata and cunc. if keyword_set(timg) then goto,local ; ----------- Save the SSC and go on to next case ------ sav_sda,outfile,cindex,cdata,append=(i ne 0) ; Finally, save the uncert; 11-dec-01, DMcK if keyword_set(uncert) then $ sav_sda,outfile+'_unc',cindex,cunc,append=(i ne 0) local: endfor if debug then stop end