; Given an array of filenames, assemble an mpeg from gifs FUNCTION mpeg_myhenagifs, f id = mpeg_open([200,200]) ; open a new mpeg file tvlct, r,g,b, /get ; get the current color table idat = bytarr(3,200,200) ; allocate one frame of memory ; construct mpeg frame by frame from the gif files for i=0,n_elements(f)-1 do begin ; process each gif image read_gif, f(i),a ; read the gif file idat(0,*,*) = r[a] ; extract red data idat(1,*,*) = g[a] ; extract green data idat(2,*,*) = b[a] ; extract blue data mpeg_put, id, frame=i, image=idat, order=1 ; write frame to file endfor ; construct a name for the mpeg fole based on the datatime of first gif e = get_mytimefromfilename( f(0) ) p = parse_mystring( decode_cdfepoch(e) ) fname = 'im_k0_hena_' + p(0) + p(1) + p(2) + p(3) + '.mpg' ; close the mpeg and exit mpeg_save,id,filename=fname mpeg_close,id return,0 end ; Given an array of filenames, assemble an mpeg from gifs, set the ; colortable by using the colors from the first gif file. FUNCTION mpeg_myhenagifs2, f, OUTDIR=OUTDIR, DEBUG=DEBUG, QL=QL if keyword_set(DEBUG) then print,'INFO>mpeg_myhenagifs>Opening mpeg...' id = mpeg_open([200,200]) ; open a new mpeg file idat = bytarr(3,200,200) ; allocate one frame of memory read_gif,f(0),a,r,g,b ; get colortable from first gif tvlct, r,g,b ; load the color table ; construct mpeg frame by frame from the gif files for i=0,n_elements(f)-1 do begin ; process each gif image read_gif, f(i),a ; read the gif file idat(0,*,*) = r[a] ; extract red data idat(1,*,*) = g[a] ; extract green data idat(2,*,*) = b[a] ; extract blue data mpeg_put, id, frame=i, image=idat, order=1 ; write frame to file endfor ; construct a name for the mpeg file based on the datatime of first gif e = get_mytimefromfilename( f(0) ) p = parse_mystring( decode_cdfepoch(e) ) if keyword_set(QL) then fname = 'im_ql_hena_'+p(0)+p(1)+p(2)+p(3)+'_v01.mpg' $ else fname = 'im_k0_hena_'+p(0)+p(1)+p(2)+p(3)+'_v01.mpg' if keyword_set(OUTDIR) then fname = OUTDIR+fname ; close the mpeg and exit mpeg_save,id,filename=fname mpeg_close,id if keyword_set(DEBUG) then print,'INFO>mpeg_myhenagifs>'+fname+' completed.' return,0 end ; Given a mega-structure, make image by image gifs of the data FUNCTION gifplot_myhenaimages, a, OUTDIR=OUTDIR, DEBUG=DEBUG ; verify that the input mega-structure is valid if ami_mystruct(a) ne 1 then begin print, 'ERROR>plot_myhenaimages>Invalid input!' & return,-1 endif ; Extract needed variables from the structure etimes = get_mydata(a,'EPOCH') imgdat = get_mydata(a,'IMAGE3') scpos = get_mydata(a,'GCI_POS') spinaxis = get_mydata(a,'GCI_SPINAXIS') ; Make a gif of every image in the structure for i=0,n_elements(etimes)-1 do begin ; determine the name of the gif file p = parse_mystring( decode_cdfepoch( etimes(i) ) ) gname = a.(0).logical_source + '_' + p(0) + p(1) + p(2) + p(3) + p(4) + p(5) + '.gif' if keyword_set(OUTDIR) then gname=OUTDIR+gname else gname='/mission/image/sci/incoming/'+gname ; Smooth the image data (changed 0:19 to 19:38) to try to center the images. idat = smooth(imgdat(19:38,*,i),5) s = plot_enaflux(etimes(i),idat,120.0,6.0,scpos(*,i),spinaxis(*,i),1,$ GIF=gname,/nocolorbar,/noborder,wsize=[200,200],DEBUG=DEBUG) if i eq 0 then gnames = gname else gnames = [gnames,gname] endfor return,gnames end FUNCTION extract_myhenaimages, a ; Compute the number of images which must be moved into ; the cdf file. The first record in the 'a' structure is ; guaranteed to be the start of a complete image, and a ; complete image occupies 60 records. Note that the ; for loop variable j uses the variable number, the cdf ; should be read with /all nrecs = long(n_elements(a.epoch.dat)/60) ; initialize the variables which hold the remolded images. hi0 = fltarr(60,20,nrecs) & hi1=hi0 hi2 = hi0 & hi3=hi0 & hi4=hi0 & hi5=hi0 & itimes=dblarr(nrecs) for i=0,nrecs-1 do begin ; for each complete image b = 60L*i & c = b+59L ; compute start/stop points for j=3,22 do begin ; for each hena column i.e. 'sensor itimes(i) = a.EPOCH.dat(b) ; get image starttime hi0(0:59,(j-3),i) = a.(j).dat(0,b:c) ; move data hi1(0:59,(j-3),i) = a.(j).dat(1,b:c) ; move data hi2(0:59,(j-3),i) = a.(j).dat(2,b:c) ; move data hi3(0:59,(j-3),i) = a.(j).dat(3,b:c) ; move data hi4(0:59,(j-3),i) = a.(j).dat(4,b:c) ; move data hi5(0:59,(j-3),i) = a.(j).dat(5,b:c) ; move data endfor endfor return,{itimes:itimes,hi0:hi0,hi1:hi1,hi2:hi2,hi3:hi3,hi4:hi4,hi5:hi5} end FUNCTION extract_myhenaimages2, a ; extract the hena images from the input structure. HENA uses a ; floating reference point, so in order to keep the location of ; the earth at a consistant location within the image, the start ; of each spin must be located. Note that the for loop variable j ; uses the variable number, the cdf should be read with /all nrecs = long(n_elements(a.epoch.dat)/60) ; compute number of records w = where( abs(a.(4).dat - 180.0) lt 3.0,wc) ; locate anti-nadir from spin phase ; initialize the variables which hold the remolded images. hi0 = fltarr(60,20,nrecs) & hi1=hi0 hi2 = hi0 & hi3=hi0 & hi4=hi0 & hi5=hi0 & itimes=dblarr(nrecs) for i=0,nrecs-1 do begin ; for each complete image b = w(i) & c = b+59L ; compute start/stop points if c lt n_elements(a.epoch.dat) then begin ; whole image exists for j=1,20 do begin ; for each hena column i.e. 'sensor' itimes(i) = a.EPOCH.dat(b) ; get image starttime hi0(0:59,j-1,i) = a.(j*3).dat(0,b:c) ; move data hi1(0:59,j-1,i) = a.(j*3).dat(1,b:c) ; move data hi2(0:59,j-1,i) = a.(j*3).dat(2,b:c) ; move data hi3(0:59,j-1,i) = a.(j*3).dat(3,b:c) ; move data hi4(0:59,j-1,i) = a.(j*3).dat(4,b:c) ; move data hi5(0:59,j-1,i) = a.(j*3).dat(5,b:c) ; move data endfor endif ; else I might have one image to many? endfor return,{itimes:itimes,hi0:hi0,hi1:hi1,hi2:hi2,hi3:hi3,hi4:hi4,hi5:hi5} end FUNCTION extract_myhenaimages3, a ; extract the hena images from the input structure. HENA uses a ; floating reference point, so in order to keep the location of ; the earth at a consistant location within the image, the start ; of each spin must be located. Note that the for loop variable j ; uses the variable number, the cdf should be read with /all nrecs = long(n_elements(a.epoch.dat)/60) - 1 ; compute number of records w = where( abs(a.(4).dat - 180.0) lt 3.0,wc) ; locate anti-nadir from spin phase ; initialize the variables which hold the remolded images. hi0 = fltarr(60,20,nrecs) & hi1=hi0 hi2 = hi0 & hi3=hi0 & hi4=hi0 & hi5=hi0 & itimes=dblarr(nrecs) for i=0,nrecs-1 do begin ; for each complete image b = w(i) & c = b+59L ; compute start/stop points if c lt n_elements(a.epoch.dat) then begin ; whole image exists for j=1,20 do begin ; for each hena column i.e. 'sensor' itimes(i) = a.EPOCH.dat(b) ; get image starttime hi0(0:59,j-1,i) = a.(j*3).dat(0,b:c) ; move data hi1(0:59,j-1,i) = a.(j*3).dat(1,b:c) ; move data hi2(0:59,j-1,i) = a.(j*3).dat(2,b:c) ; move data hi3(0:59,j-1,i) = a.(j*3).dat(3,b:c) ; move data hi4(0:59,j-1,i) = a.(j*3).dat(4,b:c) ; move data hi5(0:59,j-1,i) = a.(j*3).dat(5,b:c) ; move data endfor endif ; else I might have one image to many? endfor for i=0,nrecs-1 do hi0(*,*,i) = rotate(hi0(*,*,i),2) ; rotate 180 degrees for i=0,nrecs-1 do hi1(*,*,i) = rotate(hi1(*,*,i),2) ; rotate 180 degrees for i=0,nrecs-1 do hi2(*,*,i) = rotate(hi2(*,*,i),2) ; rotate 180 degrees for i=0,nrecs-1 do hi3(*,*,i) = rotate(hi3(*,*,i),2) ; rotate 180 degrees for i=0,nrecs-1 do hi4(*,*,i) = rotate(hi4(*,*,i),2) ; rotate 180 degrees for i=0,nrecs-1 do hi5(*,*,i) = rotate(hi5(*,*,i),2) ; rotate 180 degrees return,{itimes:itimes,hi0:hi0,hi1:hi1,hi2:hi2,hi3:hi3,hi4:hi4,hi5:hi5} end ; Given start and stop times, in cdf-epoch timetags, create the hena cdf for that ; timespan. Ftype should be 'D' for a daily cfd and 'Q' for quicklook FUNCTION make_myHENAcdf, estart, estop, ftype, OUTDIR=OUTDIR, DEBUG=DEBUG ; convert the start and stop times into integers for UdfCdf call if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>estart=',decode_cdfepoch(estart) if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>estop =',decode_cdfepoch(estop) cdf_epoch,estart,y0,m0,d0,h0,n0,s0,/break & monday,y0,doy0,m0,d0,/yearday cdf_epoch,estop ,y1,m1,d1,h1,n1,s1,/break & monday,y1,doy1,m1,d1,/yearday ; ; remove any intermediate HENA cdfs from /burley/src f = '' & f = findfile('/mission/image/burley/src/IMHIMCPL*.cdf') if f(0) ne '' then begin if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf.pro>Rm old Intermediate cdfs.' for i=0,n_elements(f)-1 do spawn,'rm -f '+f(i) endif ; ; before proceeding with the creation of the intermediate HENA cdf, which ; takes a long time to create, verify that definitive orbit data exists ; if this is a definitive data generation run. if ftype eq 1 then begin go_ahead = do_i_have_definitive_orbitdata(estart,estop,DEBUG=DEBUG) if go_ahead eq 0 then begin print,'INFO>make_myHENAcdf>Insufficient definitive orbit data for daily' return,0 endif endif ; ; select the correct UdfCdf template and cdf master given the level zero ftype case ftype of 0 : begin ; quicklook template = '/mission/image/sci/data/master/HENA_UDFCDF_Q ' master = '/mission/image/sci/data/master/im_ql_hena_00000000_v01.cdf' end 1 : begin ; daily template = '/mission/image/sci/data/master/HENA_UDFCDF ' master = '/mission/image/sci/data/master/im_k0_hena_00000000_v01.cdf' end else : begin ; unknown ftype print,'ERROR>make_myHENAcdf>UNKNOWN FTYPE = ',ftype return,-1 end endcase ; ; construct the UdfCdf command call c = '/mission/image/software/UDFTools/bin/UdfCdf ' c = c + template + strtrim(string(y0),2) + $ ' ' + strtrim(string(doy0),2) + ' ' + strtrim(string(h0),2) + ' ' + strtrim(string(n0),2) + $ ' ' + strtrim(string(s0),2) + ' ' + strtrim(string(y1),2) + ' ' + strtrim(string(doy1),2) + $ ' ' + strtrim(string(h1),2) + ' ' + strtrim(string(n1),2) + ' ' + strtrim(string(s1),2) if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>spawning ',c spawn,c ; create the ugly cdf with the UdfCdf translator ; Locate the cdf that was just created, if it was created, and read it f = findfile('/mission/image/burley/src/IMHIMCPL*.cdf') if f(0) eq '' then begin print,'WARNING>make_myHENAcdf>NO HENA CDF WAS CREATED!' & return,-1 endif else begin f(0) = check_myuglycdfname(f(0)) ; verify cdf won't be treated as a 'master' by read_mycdf !quiet=1 & a = read_mycdf('',f(0),/all) & !quiet=0 ; read the cdf file if ami_mystruct(a) ne 1 then begin print,'ERROR>make_myHENAcdf>read_mycdf did not return a structure!' & return,-1 endif ; The HENA PIDF can force UDFCDF to include an image which starts ; before the requested tstart/tstop. For example, if a 2 minute ; image starts at 30 seconds before end of day, it will be included ; in the file, and when write_mycdf autonames the file, it will be ; named using this first time. Therefore, these early images need ; to be filtered out. if a.epoch.dat(0) lt estart then begin if keyword_set(DEBUG) then print,'WARNING>make_myHENAcdf>TimeFiltering 1st image.' a = timeslice_mystruct(a,estart,estop) endif ; validate that enough data exists in the ugly cdf to make a usable cdf. In the ugly-cdf ; each scanline of the image is saved as a separate variable, at 2 second resolution. In ; the full cdf, this data must be combined into a 2 minute image. Thus, to have > 1 complete ; image in the good cdf, you must have at least 120 records in the ugly cdf. e = get_mydata(a,'EPOCH') ; get the epoch data from the structure if n_elements(e) lt 120 then begin print,'WARNING>make_henaproducts>Insufficient hena data to make HENA cdf!' spawn,'rm -f '+f(0) ; delete the ugly cdf return,-1 endif endelse ; Read the HENA master cdf if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>reading HENA master cdf...' !quiet=1 & m = read_mycdf('',master,/all,/nodatastruct) & !quiet=0 if ami_mystruct(m) ne 1 then begin print,'ERROR>make_myHENAcdf>read_mycdf could not read the master!' & return,-1 endif ; Extract and descramble the images from the ugly cdf if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>descrambling HENA images.' henaimages = extract_myhenaimages3(a) ; Find and Read the cdfs which have the required ancillary orbit data if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>generating ancillary data.' offset = 1000.0d0 * 360.0d0 ; compute a 6 minute offset in millisecs if ftype eq 1 then f = find_myorbitcdfs(estart - offset, estop + offset, /DAY,/DEF) if ftype eq 0 then f = find_myorbitcdfs(estart - offset, estop + offset, /QL,/PRED) if f(0) eq '' then begin print,'WARNING>make_myHENAcdf>matching orbit cdf files not found!' & return,-1 endif !quiet=1 & d = read_mycdf('',f,/all) & !quiet=0 if ami_mystruct(d) ne 1 then begin print,'ERROR>make_myHENAcdf>Eror reading orbit data from cdf!' & return,-1 endif ; Compute the interpolation points using the hena image times p = compute_interpolation_points( d.epoch.dat, henaimages.itimes ) ; Populate the m structure with orbit data interpolated to hena image times px = interpolate( reform( d.gci_pos.dat(0,*)),p ) py = interpolate( reform( d.gci_pos.dat(1,*)),p ) pz = interpolate( reform( d.gci_pos.dat(2,*)),p ) pv = dblarr( 3,n_elements(px) ) & pv(0,*)=px & pv(1,*)=py & pv(2,*)=pz m.GCI_POS.handle = handle_create(value=pv) px = interpolate( reform( d.gse_pos.dat(0,*)),p ) py = interpolate( reform( d.gse_pos.dat(1,*)),p ) pz = interpolate( reform( d.gse_pos.dat(2,*)),p ) pv = dblarr( 3,n_elements(px) ) & pv(0,*)=px & pv(1,*)=py & pv(2,*)=pz m.GSE_POS.handle = handle_create(value=pv) px = interpolate( reform( d.gsm_pos.dat(0,*)),p ) py = interpolate( reform( d.gsm_pos.dat(1,*)),p ) pz = interpolate( reform( d.gsm_pos.dat(2,*)),p ) pv = dblarr( 3,n_elements(px) ) & pv(0,*)=px & pv(1,*)=py & pv(2,*)=pz m.GSM_POS.handle = handle_create(value=pv) ; Locate spacecraft spin axis data covering the requested time span if ftype eq 0 then spin = find_myspinaxis(henaimages.itimes,/QL) $ else spin = find_myspinaxis(henaimages.itimes) ; quicklook or daily if amia_structure(spin) ne 1 then begin print,'WARNING>make_myHENAcdf>Unable to get spinaxis data.' & return,-1 endif spinv = dblarr( 3,n_elements(spin.spinx) ) & spinv(0,*) = spin.spinx spinv(1,*) = spin.spiny & spinv(2,*) = spin.spinz m.GCI_SPINAXIS.handle = handle_create(value=spinv) ; ; Perform TBD manipulation of the images ; ; Insert the images into the m_structure m.epoch.handle = handle_create( value=henaimages.itimes ) m.image0.handle = handle_create( value=henaimages.hi0 ) m.image1.handle = handle_create( value=henaimages.hi1 ) m.image2.handle = handle_create( value=henaimages.hi2 ) m.image3.handle = handle_create( value=henaimages.hi3 ) m.image4.handle = handle_create( value=henaimages.hi4 ) m.image5.handle = handle_create( value=henaimages.hi5 ) ; create the new cdf if keyword_set(OUTDIR) then d = OUTDIR else d = '/mission/image/sci/incoming/' if keyword_set(DEBUG) then print,'INFO>make_myHENAcdf>Creating output cdf.' s = write_mycdf(m,'',/autoname,/lowercase,OUTDIR=d) delete_myhandles,m & m=0 ; release memory space return,s end ; Given the input structure 'my_times' which includes tstart and tstop and ; filetype, generate all of the level-1 HENA science data products. FUNCTION make_myHENAproducts, my_times, OUTDIR=OUTDIR, DEBUG=DEBUG for i=0,n_elements(my_times.tstart)-1 do begin print,'INFO>make_henaproducts>Tstart=',decompute_cdfepoch(my_times.tstart(i)) print,'INFO>make_henaproducts>Tstop =',decompute_cdfepoch(my_times.tstop(i)) print,'INFO>make_henaproducts>Ftype =',my_times.ftype(i) ; ; verify that ancillary orbit data exists for the time, if its a day file abort = 0 ; initialize abort flag if my_times.ftype(i) eq 1 then begin orb = find_myorbitcdfs(my_times.tstart(i),my_times.tstop(i),$ /day,/def) ; removed nofirstbefore keyword if orb(0) eq '' then begin print,'INFO>make_myHENAproducts>Insufficient orbit data for this timerange.' abort = 1 endif endif ; ; set output directory based on default and keyword if keyword_set(OUTDIR) then d = OUTDIR else d = '/mission/image/sci/incoming/' ; ; make a CDF file from UDF data for the time range if abort eq 0 then begin s = make_myhenacdf(my_times.tstart(i),my_times.tstop(i),$ my_times.ftype(i),OUTDIR=d,DEBUG=DEBUG) ; ; if CDF creation was succesfull, then make HENA gif's and MPEG if (amia_string(s)) then begin !quiet=1 & a = read_mycdf('',s(0),/all,DEBUG=DEBUG) & !quiet=0 if amia_structure(a) then begin ; read was succesfull ; validate that enough data exists in the cdf to make a usable mpegs e = get_mydata(a,'EPOCH') ; get the epoch data from the structure if n_elements(e) lt 10 then begin print,'WARNING>make_henaproducts>Insufficient data to make HENA mpeg!' endif else begin gnames = gifplot_myhenaimages(a,OUTDIR=d,DEBUG=DEBUG) ; make image-by-image gifs if n_elements(gnames) gt 1 then begin if my_times.ftype(i) eq 0 then begin s = make_mybiggif(gnames,OUTDIR=d,/QL, DEBUG=DEBUG) ; make single gif s = mpeg_myhenagifs2(gnames, OUTDIR=d,/QL, DEBUG=DEBUG) ; make mpeg from gifs endif else begin s = make_mybiggif(gnames,OUTDIR=d,DEBUG=DEBUG) ; make single gif s = mpeg_myhenagifs2(gnames, OUTDIR=d,DEBUG=DEBUG) ; make mpeg from gifs endelse endif endelse endif a = 0 ; release the memory endif endif endfor return,0 end