pro movy_driver,year,week=week,strt_date=strt_date,decaday=decaday,$ end_date=end_date,nfils=nfils,bgst=bgst,clip=clip,$ al_only=al_only,dg_only=dg_only,grid=grid,$ sst=sst,debug=debug,outdir=outdir,$ append=append,name=name,mk_fits=mk_fits,$ prefixx=prefixx,indir=indir,$ depit=depit,noroll=noroll,one_big_movy=one_big_movy ;+ ; NAME: movy_driver ; ; PURPOSE: Front end program to read and process SSC ; files for purpose of eliminating bad ones and creating ; SXT movie files (i.e., what we used to call SSS files). ; The default is to produce one file per image. Set keyword ; /one_big_movy to put entire movy in one big file. ; ; CALLING EXAMPLE: ; movy_driver,year,strt_date=strt_date,decaday=decaday,$ ; end_date=end_date,nfils=nfils,bgst=bgst,clip=clip,$ ; al_only=al_only,dg_only=dg_only,grid=grid,$ ; sst=sst,debug=debug,outdir=outdir,$ ; append=append,name=name,mk_fits=mk_fits,$ ; prefixx=prefixx,indir=indir,$ ; depit=depit,noroll=noroll,one_big_movy=one_big_movy ; ; INPUT: ; year, year to be analyzed (Note: year is ALWAYS required.) ; ; SEMI-OPTIONAL KEYWORD INPUT: ; prefixx, if not specified then prefix is sxtf. ; E.g., prefixx='sx2m_' for doublets ; prerixx='sx3m_' for triplets ; ; OPTIONAL KEYWORD INPUT: ; indir, directory to find the SSCs. ; Default: /yla/ssc20 ; nfils, vector of files to be analyzed ; Default: all available files for that year. ; bgst, Alog10 of brightest feature for use in max=bgst in bytscl. ; Default bgst (set in mk_movy.pro) is alog10(1.2e5). ; clip, lower cutoff in final bytscl step. ; Default clip (set in mk_movy.pro) is 12. ; strt_date, day to begin the movie, e.g., '12-jun-96' ; end_date, day to end the movie, e.g., '30-aug-98' ; Note: If strt_date and no end_date code proceeds on in time. ; decaday, month_10day triplet, i.e., '092' ; /al_only, do only Al.1 images ; /dg_only, do only AlMg images ; sst, use Triplet composites (Default is to make doublets.) ; outdir, default for xda output is current directory, ; default for FITS files is /yla/sscmov18. ; grid, use to create desired image cadence (units: minutes) ; /append, append output to an pre-existing file. ; /mk_fits, skip the sda writing and write Legacy fits images. ; name, name for file, default = e.g., 'SSCmv1994' or 'SSTmv1995' ; Note: If /mk_fits then yo_xda2legacy creates name. ; For /name filename of format sx2m_19911001_133212_121.xda is created. ; /depit, Check for and remove cases where compositing with ; sxt_decon has produced negative "pits" around short-exposure ; features that are substantially brighter than the same ; feature in the long exposure, perhaps because of a flare ; in the up to 11 minutes between the long and short exposures ; of the SSC. ; /noroll, make movie without roll correction. ; /one_big_movy, entire movie in a single file (Default: one file/image) ; ; OUTPUT: ; Movie and index structures created by mk_movy.pro or ; mk_movy_noroll.pro. ; ; RESTRICTIONS: ; Beware of hardwired directories! ; ; HISTORY: ; 13-Oct-2004 LWA ; 15-Oct-2004 LWA Updates to use sxt_fix_index. ; 18-Oct-2004 LWA Savegen output one day at a time. ; 19-Oct-2004 LWA Created badimg array and added badimg test. ; 9-Nov-2004 LWA Debug and switch to /SynSFC/ssc6. ; 24-Mar-2005 LWA Update header. Update for current mk_movy.pro. ; Convert to access /disk/yl1/ssc7b (special run). ; Add mk_fits keyword. ; 24-Apr-2005 LWA Revert to /disk/yl1/ssc7, update badimg. ; 25-Apr-2005 LWA Corrected strt_date & end_date bugs. ; Corrected input to yo_xda2legacy call. ; 8-Jul-2005 LWA Clarify header re/ name and outfile. ; 17-Jul-2005 LWA Added SST option for FITS output. ; 2-Aug-2005 LWA Added strt_date and end_date tests. ; 30-Sep-2005 LWA/AKT Added prefixx and safe_log10 keywords. ; Changed dir to /yl2/ssc8 and /yl2/sst8. ; 4-Oct-2005 LWA Clarified keywords in header. ; Output to /disk/yl2/sx2mov8 and sx3mov8. ; 20-Oct-2005 LWA Changed usage of outdir and eliminated ; keywords outfile and ssc. ; 16-Dec-2005 LWA Deleted /safe_log10 keyword. ; Replaced findfile with file_search. ; 25-Jan-2006 LWA Added keyword indir. ; 11-May-2006 LWA Corrected PURPOSE in header. ; Changed to outdir='/disk/yl2/sx2mov9', 'sx3mov9'. ; Read in badimg from ; file='/disk/hl2/pd1/acton/fix_att/att_rej/att_reject_all' ; 8-Jun-2006 LWA Badimg now a table. Added 10-Oct-2000 image times. ; Changed indir to SSC9 and SST9. ; 16-Jun-2006 LWA Incorporated depit option. ; 20-Jun-2006 LWA Direct output to outdir='/disk/yl1/sx2...' ; 26-Jun-2006 LWA Initialized keyword depit. ; 29-Jun-2006 LWA Added 30-Jun-94 badimg. ; 24-Jul-2006 LWA Added keyword noroll. ; 10-Aug-2006 LWA Include keyword depit in call to mk_movy_noroll. ; Update header. ; 31-Jan-2007 LWA Removed 10-Oct-2000 images from badimg list. ; 16-Mar-2007 LWA Added dates to badimg list. ; 20-Mar-2007 LWA Udated directories for version 10 runs. ; 4-Apr-2007 LWA Changed to .3, i.e., fil=file_search(dir+'/*.3'). ; 30-May-2007 LWA Changed to .4, i.e., fil=file_search(dir+'/*.4'). ; 6-Jun-2007 LWA Fits output to '/disk/hl1/ylegacy/sxtmov10'. ; Set up prefixx definition. ; 29-Jun-2007 LWA Made file_search independent of version number. ; 11-Jul-2007 LWA Liberalized handling of strt and end dates. ; 28-Jul-2007 LWA Added 6 badimg in Dec-91. ; 10-Aug-2007 LWA end-date note in header. ; Added badimg '22_Aug-1998 09:01:05'. ; 14-Aug-2007 LWA Added 19 bad images for '1-Mar-2001i'. ; 28-Aug-2007 LWA Inserted missing commas in badimg array. ; 16-Oct-2007 LWA Added badimg '23-Nov-1994 17:09:57'. ; 15-Nov-2007 LWA Handle case of no file for end_date but files ; after end_date. ; 3-Jan-2008 LWA Updated default indir and outdir. ; Updated badimg list. ; 28-Jan-2008 LWA Moved location of definition of aas. ; 6-Feb-2008 LWA Added 2 times to badimg vector. ; 19-Feb-2008 LWA Added some Oct-95 Al.1s to badimg vector. ; 29-Feb-2008 LWA Now read in the badimg list from 'badimg.txt'. ; 31-May-2008 LWA Now can move beyond strt_dates with no data. ; 4-Aug-2008 LWA Fixed fem/cal week problem in file selection. ; 5-Aug-2008 LWA Major logic change, iterate on index rather than files. ; 15-Oct-2008 LWA Add another time test on bbi (hope it is correct!). ; 16-Oct-2008 LWA Fixed yesterday's mistake. ; 25-Jan-2009 LWA Defined keyword week. ; Deleted unused goto shiftforward:. ; Defined strt_date & end_date if only inputting year. ; 27-Jan-2009 LWA Set up indir & outdir for running on sunbeam. ; Added comments throughout program. ; Added keyword one_big_movy to permit YLA usage. ; 24-Mar-2009 LWA Default indir '/yla/ssc18/'. ; Now add year to indir to create dir if indir input. ; 10-apr-2009 LWA Default outdir '/yla/sxtmov18' ; 20-Apr-2009 LWA badimg=rd_tfile('/yla/ssc_work/bad.txt') ; 22-Apr-2009 LWA badimg=rd_tfile('/disk/sb1/ssc_work/badimg.txt') ; for running on helicity. ; 28-Apr-2009 LWA Added keyword sst=sst to call to mk_movy. ; 6-Aug-2009 LWA Made dir='/yla/ssc19/'+strtrim(year,2) and ; outdir='/disk/sb1/sxtmov24' and ; badimg=rd_tfile('/yla/ssc_work/badimg.txt') ; 2-Sep-2009 LWA Default indir='/yla/ssc20 ; 15-Dec-2009 LWA Default indir=/disk/hl3/ylegacy/ssc21 ; Default outdir=/yla/sxtmov26 ; 5-Apr-2010 LWA Deleted obolete debug comments. ; Default indir=/disk/hl3/ylegacy/ssc24 ; Default outdir=/yla/sxtmov30 ; Generalized xda-format file naming. ;- start_time = systime(1) run_time = 0. one_big_movy=keyword_set(one_big_movy) mk_fits=keyword_set(mk_fits) sst=keyword_set(sst) noroll=keyword_set(noroll) al_only = keyword_set(al_only) dg_only = keyword_set(dg_only) depit = keyword_set(depit) appnd=keyword_set(append) if sst then prefixx='sx3m_' else prefixx='sx2m_' ; ---- List of reject image times. ---- badimg=rd_tfile('/yla/ssc_work/badimg.txt') ; ---- Set up I/O stuff. --- if not keyword_set(indir) then begin dir='/disk/hl3/ylegacy/ssc29/'+strtrim(year,2) endif else begin dir=indir+strtrim(year,2) endelse if keyword_set(outdir) then outdir=outdir else begin if not mk_fits then outdir=curdir() else $ outdir='/yla/sxtmov30' endelse if keyword_set(week) then week=week else week=0 if NOT keyword_set(name) then begin if keyword_set(sst) then begin nam='SSTmv'+strtrim(year,2)+'.sda' endif else begin nam='SSCmv'+strtrim(year,2)+'.sda' endelse endif else begin nam=name endelse ; ---- Obtain files and roadmap for desired interval. ---- if keyword_set(decaday) then begin if keyword_set(sst) then $ fil=file_search(dir+'/sst'+strtrim(year,2)+decaday+'*0.1') else $ fil=file_search(dir+'/ssc'+strtrim(year,2)+decaday+'*0.1') endif else begin ;Get the sst or ssc file names for the entire year. if keyword_set(sst) then $ fil=file_search(dir+'/sst'+'*') else $ fil=file_search(dir+'/ssc'+'*') unc=strwhere(fil,'*_unc') if unc(0) ne -1 then begin nunc=delind(indgen(n_elements(fil)),unc) fil=fil(nunc) endif rd_roadmap,fil,rdm ;Determine strt_date and end_date if not input. ---- if not keyword_set(strt_date) then strt_date=fmt_tim(rdm(0)) if not keyword_set(end_date) then $ end_date=fmt_tim(rdm(n_elements(rdm)-1)) help,dir help,fil print,'strt_date = ',strt_date print,'end_date = ',end_date endelse if fil(0) eq '' then goto,nofils ; ---- Redefine strt_date & end_date if week is input. ---- if keyword_set(week) then pr_week2tim,week,strt_date,end_date end_date=anytim(end_date)+(24.*60.*60.) end_date=anytim(end_date,/yoh) ; ---- Determine the beginning image from strt_date. ---- if keyword_set(strt_date) and NOT keyword_set(decaday) then begin help,strt_date rd_roadmap,fil,road aas=anytim(strt_date) beg=where(anytim(road) ge aas,nbeg) endif if nbeg eq 0 then begin print,'*** All data before STRT_DATE. Returning.***' return endif ; ---- Determine the last image from end_date. ---- if keyword_set(end_date) and NOT keyword_set(decaday) then begin help,end_date aae=anytim(end_date) eed=where(anytim(road) le aae,need) endif if need eq 0 then begin print,'*** All data after END_DATE. Returning.***' return endif ; ---- Get indices of all images within strt/end time interval. ---- bend=lindgen(n_elements(eed))+beg(0) bbx=lindgen(n_elements(road)) bbi=where(bbx ge beg(0) and bbx le eed(n_elements(eed)-1),nbbi) if nbbi le 0 then begin print,'*** No data match time constraints. Returning. ***' return endif ; ---- Down-select to get only the desired images in interval. ---- bend=bbx(bbi) rdm=road(bend) fmt_timer,road fmt_timer,rdm gg=indgen(n_elements(rdm)) bb=tim2dset(rdm,badimg,delta_sec=off) bbx=where(off lt 5,nbbx) if nbbx gt 0 then gg=kill_index(gg,bb(bbx)) if gg(0) eq -1 then goto,skipit case 1 of al_only eq 0 and dg_only eq 0 : gg=gg al_only : begin ff=where(gt_filtb(rdm(gg)) eq 2,nff) case 1 of nff le 0 : goto,skipit nff gt 0 : gg=gg(ff) endcase end dg_only : begin ff=where(gt_filtb(rdm(gg)) eq 3,nff) case 1 of nff le 0 : goto,skipit nff gt 0 : gg=gg(ff) endcase end endcase print print,'Total number of images to be processed =',n_elements(gg) if one_big_movy then begin ; ---- Go thrugh the images 100 at a time and create the movie. ---- nn=fix((n_elements(gg)/100.01)+1) ; Credit: AkT, 8/2/05. for i=0,nn-1 do begin if ((i+1)*100-1 lt n_elements(gg)-1) then $ oo=(i+1)*100-1 else oo=n_elements(gg)-1 if oo lt (i+1)*100-1 then $ hh=indgen(oo-(i*100-1))+(i*100) else hh=indgen(100)+i*100 rd_xda,fil,bend(gg(hh)),index,data help,i print,'Images to be processed: ',min(hh),max(hh) fmt_timer,index ;Make the movie, Include roll correction or not. if noroll then begin moov=mk_movy_noroll(index,data,ioutoo,clip=clip, $ rasho=rasho,bgst=bgst,grid=grid,junk=junk, $ udata=udata,uthresh=uthresh,depit=depit,sst=sst) endif else begin moov=mk_movy(index,data,ioutoo,clip=clip, $ rasho=rasho,bgst=bgst,grid=grid,junk=junk, $ udata=udata,uthresh=uthresh,depit=depit,sst=sst) endelse if i eq 0 and junk then goto,skipit if n_elements(moovy) eq 0 then begin moovy=moov iout=ioutoo endif else begin moovy=[[[moovy]],[[moov]]] iout=merge_struct(iout,ioutoo) endelse endfor if not mk_fits then begin sav_sda,outdir+'/'+nam,iout,moovy,append=appnd appnd=1 endif else begin yo_xda2legacy,iout,moovy,prefixx=prefixx,outdir=outdir endelse endif else begin nj=0 ;Make the movie one SSC at a time. for j=0,n_elements(gg)-1 do begin rd_xda,fil,bend(gg(j)),index,data mj=j/100 if mj eq nj then begin print,'Processing image '+strtrim(j,2) print,get_info(index,/non) nj=mj+1 endif ;Include roll correction or not. if noroll then begin moov=mk_movy_noroll(index,data,ioutoo,clip=clip, $ rasho=rasho,bgst=bgst,grid=grid,junk=junk, $ udata=udata,uthresh=uthresh,depit=depit,sst=sst) endif else begin moov=mk_movy(index,data,ioutoo,clip=clip, $ rasho=rasho,bgst=bgst,grid=grid,junk=junk, $ udata=udata,uthresh=uthresh,depit=depit,sst=sst) endelse if junk then goto,junk_img if not mk_fits then begin if name and data_type(nam) eq 2 then begin nam=sxt_index2filename(ioutoo) if sst then nam=strmid(nam,0,2)+'3m'+strmid(nam,4,21)+'xda' $ else nam=strmid(nam,0,2)+'2m'+strmid(nam,4,21)+'xda' endif sav_sda,outdir+'/'+nam,ioutoo,moov endif else begin yo_xda2legacy,ioutoo,moov,prefixx=prefixx,outdir=outdir endelse junk_img : endfor endelse skipit: nofils : end_time = systime(1) run_time = (end_time-start_time)/60. print, 'MOVY_DRIVER: ', run_time, ' minutes to process your request' end