;+ ; NAME: ; smei_mksky ; PURPOSE: ; Create skymaps from most recent SMEI data ; CATEGORY: ; ucsd/camera/idl/toolbox ; CALLING SEQUENCE: PRO smei_mksky, $ camera = camera , $ ignore_block= ignore_block , $ force = force , $ make_mask = make_mask , $ make_www = make_www , $ remote = remote , $ boss = boss ; OPTIONAL INPUTS: ; camera scalar or array; type: integer; default: [1,2,3] ; camera numbers ; /ignore_block if the SMEI pipeline is blocked (by putting a 1 in ; file $SSWDB_SMEI/cat/sts/block/block_pipeline.txt) ; this procedure will abort by default. ; Setting this keyword will ignore this block. ; /force if set then the "overwrite" flag is set for the "skyd" ; daemon (resulting in overwriting existing skymaps) ; /make_mask if set then the "msk" daily skymasks are calculated ; and written to $SSWDB_SMEI/msk ; /make_www creates html tables for available SMEI skymaps ; (see href=smei_www_skymaps=) ; remote=remote scalar; type: string: default: soft@smei ; if /make_mask is SET, and this procedure has no write ; access to $SSWDB_SMEI, then remote should be set to a ; username/host on a machine that does have write ; access. The "msk" files are copied using scp. ; boss scalar; type: string: default: smeidb.smei.ucsd.edu ; set hostname of 'boss'. previously only ran on sun ; this should let it run on any machine, use with ; caution ; INCLUDE: @compile_opt.pro ; CALLS: ; skyd_cat, hide_env, InitVar, txt_read, smei_filepath ; TimeUnit, FindAllFiles, smei_filename, TimeOp, TimeSet ; boost, smei_orbit_get, TimeGet, smei_www_skymaps, IsType ; smei_last_tle ; RESTRICTIONS: ; -Can only be run on smei.smei.ucsd.edu on the "skyd" account. ; unless boss is specified ; Depends on the collection of "status" files in $SSWDB_SMEI/cat/sts. ; - Will not run if a skyd daemon is already running. ; - To update the sts files on the smei server over ssh login using ; public/private key pair needs to be set up. ; PROCEDURE: ; Processes days for which the sts files has flag "summary" ON ; (i.e. pedestal/dark current have been calcalate and the header ; files have been updated); and (camera 3 only) the flag "orb" is ; ON (i.e. "on-the-fly" orbital patterns are available; the flag ; "sky" of OFF (i.e. no skymaps have been made yet. ; ; - skyd_cat is called to create the catalogues in $SKYD/list. ; - the cf file $SKYD/cf/skyd_sun.cf is modified ; - launches the skyd daemon ; - sets the flag "sky" in the appropriate sts files. ; MODIFICATION HISTORY: ; MAR-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, camera , [1,2,3] InitVar, force , /key InitVar, make_mask , /key InitVar, make_www , /key InitVar, remote , 'soft@smei' InitVar, boss , 'smeidb.smei.ucsd.edu' IF getenv('HOSTNAME') NE boss THEN BEGIN message, /info, 'HOSTNAME does not match boss=',boss RETURN ENDIF IF getenv('USER') NE 'skyd' AND getenv('USER') NE 'soft' THEN BEGIN message, /info, 'run only on the "skyd" or "soft" account' RETURN ENDIF skyd_root = getenv('SKYD') pid_file = filepath(root=skyd_root,subdir='run','skyd_'+(strsplit(boss,'.', /extract))[0]+'.pid') IF skyd_root EQ '' THEN BEGIN message, /info, 'env var "SKYD" not defined' RETURN ENDIF ; Check whether the skyd daemon is running ; Quit if there already is a copy running. IF txt_read(pid_file,skyd_pid,/silent) THEN BEGIN skyd_pid = skyd_pid[0] spawn, 'ps '+skyd_pid+' > /dev/null', exit_status=exit_status IF exit_status EQ 0 THEN BEGIN message, /info, '"skyd" daemon already running' RETURN ENDIF ENDIF IF smei_blocked(ignore_block=ignore_block) THEN $ RETURN sts_dir = smei_filepath(mode='sts' ) uday = TimeUnit(/day) uhour = TimeUnit(/hour) umin = TimeUnit(/min) usec = TimeUnit(/sec) ; 5 groups in skyd_sun.cf type = ['c1m2 ','c2m2 ','c3m1 ','c3m2 ','c3m1s'] istart = replicate(-1,5) istop = replicate(-1,5) done = replicate( 1,5) tt = replicate(!TheTime,2,5) last_tle = TimeGet(/_ydoy,smei_last_tle(),upto=uday) ; Time of last Coriolis TLM ncam = n_elements(camera) FOR icam=0,ncam-1 DO BEGIN ; Loop over selected cameras cam_int = camera[icam] cam_str = strcompress(cam_int,/rem) ; Find all c*sts files in $SSWDB_SMEI/cat/sts sts_files = FindAllFiles('c'+cam_str+'sts_*.txt',paths=sts_dir, count=count) IF count EQ 0 THEN $ ; No files; do next camera continue group = cam_int-1 FOR ists=count-1,0,-1 DO BEGIN sts_file = sts_files[ists] sts_hide = hide_env(sts_file) IF txt_read(sts_file,txt,/silent) NE 1 THEN $ continue cstr = 'sky :' sky_ok = fix( strmid( txt[where( strpos(txt,cstr) EQ 0 )], strlen(cstr) ) ) IF sky_ok THEN $ break cstr = 'summary :' summary_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF NOT summary_ok THEN $ continue IF cam_int EQ 3 THEN BEGIN cstr = 'orb :' orb_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF NOT orb_ok THEN $ continue ENDIF IF TimeGet(/_ydoy,smei_filename(sts_file),upto=uday) GE last_tle THEN BEGIN message, /info, sts_hide+', TLM not yet past this day' continue ; TLM not yet past this day ENDIF message, /info, sts_hide ; Most recent day run through smei_orbit_stats IF istop[group] EQ -1 THEN istop[group] = ists istart[group] = ists ENDFOR IF istop[group] EQ -1 THEN BEGIN message, /info, 'no sts file with "summary" flag "on" and "sky" flag "off" found for cam '+cam_str continue ENDIF done[group] = 0 tt[*,group] = smei_filename(sts_files[[istart[group],istop[group]]]) tt[0,group] = TimeOp(/subtract,tt[0,group],TimeSet(/diff,110,umin)) ; Pick up last orbit of previous day tt[1,group] = TimeOp(/add ,tt[1,group],TimeSet(/diff, 1,uday)) ; Up to end of day boost, sts_done, sts_files[istart[group]+indgen(istop[group]-istart[group]+1)] skyd_cat, tt[*,group] , $ camera = cam_int , $ destination = filepath(root=skyd_root,'list'), $ /reverse IF cam_int EQ 3 THEN BEGIN done [4] = done [group] istart[4] = istart[group] istop [4] = istop [group] tt [*,4] = tt [*,group] skyd_cat, tt[*,4] , $ camera = cam_int , $ destination = filepath(root=skyd_root,'list'), $ /smoothdark , $ /reverse ENDIF ENDFOR not_done = where(1-done) IF not_done[0] EQ -1 THEN $ RETURN cf_file = filepath(root=skyd_root,subdir='cf','skyd_'+(strsplit(boss,'.', /extract))[0]+'.cf') IF NOT txt_read(cf_file,txt) THEN $ RETURN done = strcompress(done,/rem) txt[where(strpos(txt,'_done=') EQ 0)] = '_done='+done type = type[not_done] tt = tt[*,not_done] orbs = smei_orbit_get(TimeGet(/smei,tt),/number) orbs[1,*] -= 1 orbs = strcompress(orbs,/rem) txt[(where(strpos(txt,'_min_orbit=') EQ 0))[not_done]] = '_min_orbit='+orbs[0,*] txt[(where(strpos(txt,'_max_orbit=') EQ 0))[not_done]] = '_max_orbit='+orbs[1,*] txt[(where(strpos(txt,'_checkversion=') EQ 0))[not_done]] = '_checkversion='+strcompress(1-force,/rem) txt[(where(strpos(txt,'_overwrite=' ) EQ 0))[not_done]] = '_overwrite=' +strcompress( force,/rem) message, /info, 'update '+hide_env(cf_file) openw, /get_lun, iu, cf_file FOR i=0,n_elements(txt)-1 DO printf, iu, txt[i] free_lun, iu print print message, /info, 'launching "skyd" daemon to process:' FOR i=0,n_elements(type)-1 DO $ print, type[i]+': ' + $ strjoin(TimeGet(/_ydoy,tt[*,i],upto=uday),' - ') + $ ', orbits '+strjoin(strcompress(orbs[*,i]),' - ') spawn, 'skyd start' ; Wait 10 seconds, this should be more than enough for the skyd daemon to start message, /info, 'waiting 10 seconds for "skyd" to start"' wait, 10.0 ; Check to make sure that skyd is really running IF NOT txt_read(pid_file,skyd_pid,/silent) THEN BEGIN message, /info, 'could not read "skyd" pid file '+hide_env(pid_file) RETURN ENDIF skyd_pid = skyd_pid[0] spawn, 'ps '+skyd_pid+' > /dev/null', exit_status=exit_status IF exit_status NE 0 THEN BEGIN message, /info, '"skyd" daemon not running' RETURN ENDIF ; Now keep waiting until the skyd daemon has finished. tstart = TimeSystem(/silent) message, /info, '"skyd" daemon is running on '+TimeGet(/_ydoy,tstart,upto=usec)+'(pid '+skyd_pid+')' skyd_finished = 0 ; Wait until the next whole hour wait_a_sec = TimeOp(/subtract,TimeGet(tstart,/eot,uhour),tstart,usec) REPEAT BEGIN message, /info, 'wait for it to finish ..........'+strcompress(wait_a_sec,/rem) wait, wait_a_sec spawn, 'ps '+skyd_pid+' > /dev/null', exit_status=exit_status skyd_finished = exit_status NE 0 IF NOT skyd_finished THEN BEGIN tstop = TimeSystem(/silent) message, /info, '"skyd" daemon is still running on '+TimeGet(/_ydoy,tstop,upto=usec) dtstart = TimeOp(/subtract,tstop,tstart,uhour) IF dtstart GT 24 THEN BEGIN message, /info, '"skyd" daemon has been running for more than 24 hours' spawn, 'skyd stop' message, /info, '.... something wrong ....???.... stop daemon and abort !!!.......' RETURN ENDIF IF dtstart GT 20 THEN BEGIN message, /info, '"skyd" daemon has been running for more than 20 hours; SIG_USR1 signal sent' spawn, 'kill -10 '+skyd_pid ENDIF wait_a_sec = TimeOp(/subtract,TimeGet(tstop,/eot,uhour),tstop,usec) IF wait_a_sec EQ 0 THEN wait_a_sec = 3600 ENDIF ENDREP UNTIL skyd_finished tstop = TimeSystem(/silent) message, /info, '"skyd" daemon has finished on '+TimeGet(/_ydoy,tstop,upto=usec) IF IsType(sts_done,/defined) THEN BEGIN ; Create the daily masks (combines skymaps for all three cameras) IF make_mask THEN BEGIN tt = TimeGet(/_ydoy,smei_filename(sts_done),upto=uday) tt = tt[uniq(tt,sort(tt))] FOR i=0,n_elements(tt)-1 DO smei_mkmask, tt[i], /to_smeidb, remote=remote, silent=1 ENDIF ; Update the online catalogue of available skymaps IF make_www THEN $ smei_www_skymaps, lastmonths=1, /update, remote=remote, silent=1 ENDIF ; Now that "skyd" has completed, Set "sky" flag in status files FOR i=0,n_elements(sts_done)-1 DO BEGIN sts_file = sts_done[i] sts_hide = hide_env(sts_file) IF NOT txt_read(sts_file,txt,/silent) THEN $ continue txt[where(strpos(txt,'sky :') EQ 0)] = 'sky : 1' CASE make_mask OF 0: message, /info, sts_hide+', set "sky" field' 1: BEGIN txt[where(strpos(txt,'msk :') EQ 0)] = 'msk : 1' message, /info, sts_hide+', set "sky" and "msk" field' END ENDCASE txt = strjoin(txt,string(10B)) ; 10B = new line spawn, 'echo "'+txt+'" | ssh soft@smei "cat - > '+sts_file+'"' ENDFOR IF IsType(sts_done,/undefined) THEN $ message, /info, '"sky" field nowhere updated' RETURN & END