; Given an array of fieuvmes, assemble an mpeg from gifs, set the ; colortable by using the colors from the first gif file. FUNCTION mpeg_myeuvgifs, f, OUTDIR=OUTDIR, DEBUG=DEBUG, QL=QL if keyword_set(DEBUG) then print,'INFO>mpeg_myeuvgifs>Opening mpeg...' id = mpeg_open([140,140]) ; open a new mpeg file idat = bytarr(3,140,140) ; 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_euv_'+p(0)+p(1)+p(2)+p(3)+'_v01.mpg' $ else fname = 'im_k0_euv_'+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_myeuvgifs>'+fname+' completed.' return,0 end ; Given a mega-structure, make image by image gifs of the data FUNCTION gifplot_myeuvimages, a, OUTDIR=OUTDIR, DEBUG=DEBUG ; verify that the input mega-structure is valid if ami_mystruct(a) ne 1 then begin print, 'ERROR>plot_myeuvimages>Invalid input!' & return,-1 endif ; initialize output directory if keyword_set(OUTDIR) then outd = OUTDIR $ else outd = '/mission/image/sci/incoming/' ; ; Extract needed variables from the structure etimes = get_mydata(a,'EPOCH') imgdat = get_mydata(a,'IMAGE') 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' gname = outd + gname if keyword_set(DEBUG) then print,'INFO>gifplot_myeuvimages>Making ',gname s = plot_enaflux(etimes(i),imgdat(*,*,i),84.0,0.6,scpos(*,i),spinaxis(*,i),1,$ GIF=gname,/nocolorbar,/noborder,/nocircles,/nodipole,/reverseorder,$ wsize=[200,200]) if s ne -1 then begin ; gif file was generated if ami_defined(gnames) eq 0 then gnames=gname else gnames=[gnames,gname] endif endfor return,gnames end ; Given start and stop times, in cdf-epoch timetags, create the euv cdf ; for that timespan. Ftype should be 1 for a daily cdf and 0 for ; quicklook FUNCTION make_myEUVcdf, 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_myEUVcdf>estart=',decode_cdfepoch(estart) if keyword_set(DEBUG) then print,'INFO>make_myEUVcdf>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 EUV cdfs from /burley/src f = '' & f = findfile('/mission/image/burley/src/IME*.cdf') if f(0) ne '' then begin if keyword_set(DEBUG) then print,'INFO>make_myEUVcdf>Removing old Intermediate cdfs...' for i=0,n_elements(f)-1 do begin if keyword_set(DEBUG) then print,'INFO>make_myEUVcdf>rm -f ',f(i) spawn,'rm -f '+f(i) endfor endif ; ; before proceeding with the creation of the intermediate EUV 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_myEUVcdf>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 template1 = '/mission/image/sci/data/master/EUV1_UDFCDF_Q ' template2 = '/mission/image/sci/data/master/EUV2_UDFCDF_Q ' template3 = '/mission/image/sci/data/master/EUV3_UDFCDF_Q ' master = '/mission/image/sci/data/master/im_ql_euv_00000000_v01.cdf' end 1 : begin ; daily template1 = '/mission/image/sci/data/master/EUV1_UDFCDF ' template2 = '/mission/image/sci/data/master/EUV2_UDFCDF ' template3 = '/mission/image/sci/data/master/EUV3_UDFCDF ' master = '/mission/image/sci/data/master/im_k0_euv_00000000_v01.cdf' end else : begin ; unknown ftype print,'ERROR>make_myEUVcdf>UNKNOWN FTYPE = ',ftype return,-1 end endcase ; ; construct the UdfCdf command calls c = '/mission/image/software/UDFTools/bin/UdfCdf ' c = c + template1 + 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) print,'INFO>make_myEUVcdf>spawning ',c spawn,c ; create the ugly cdf with the UdfCdf translator c = '/mission/image/software/UDFTools/bin/UdfCdf ' c = c + template2 + 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) print,'INFO>make_myEUVcdf>spawning ',c spawn,c ; create the ugly cdf with the UdfCdf translator c = '/mission/image/software/UDFTools/bin/UdfCdf ' c = c + template3 + 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) print,'INFO>make_myEUVcdf>spawning ',c spawn,c ; create the ugly cdf with the UdfCdf translator ; locate the newly created cdf files f = '' & f = findfile('/mission/image/burley/src/IME*.cdf') if n_elements(f) ne 3 then begin print,'ERROR>make_myEUVcdf>Number of intermediate EUV cdfs not equal to 3!' return,-1 endif else begin ; verify that all of the intermediate cdfs are not named as masters for i=0,2 do f(i) = check_myuglycdfname(f(i)) endelse ; Read the needed data from the cdfs in order to find the number of frames ; which the outgoing cdf has to hold, then create the data arrays needed ; to hold all of the data. print,'INFO>make_myEUVcdf>Reading ',f(0) !quiet=1 & a = read_mycdf('EPOCH,SENSOR1',f(0),/nodatastruct) & !quiet=0 na = n_elements(get_mydata(a,'EPOCH')) print,'INFO>make_myEUVcdf>Reading ',f(1) !quiet=1 & b = read_mycdf('EPOCH,SENSOR1',f(1),/nodatastruct) & !quiet=0 nb = n_elements(get_mydata(b,'EPOCH')) print,'INFO>make_myEUVcdf>Reading ',f(2) !quiet=1 & c = read_mycdf('EPOCH,SENSOR1',f(2),/nodatastruct) & !quiet=0 nc = n_elements(get_mydata(c,'EPOCH')) nframes = min([na,nb,nc]) if nframes gt 0 then begin d = make_array(140,600,nframes,/float,value=a.sensor1.fillval) t = make_array(nframes,/double,value=-1.0d0) endif else begin print,'WARNING>make_myEUVcdf>Number of image frames = 0!' print,' >Unable to proceed.' return,-1 endelse ; ; Read the image data out of the structures into local variables ; to be merged into the combined image of all three cameras... euvt = get_mydata(a,'EPOCH') & cam0 = get_mydata(a,'SENSOR1') cam1 = get_mydata(b,'SENSOR1') & cam2 = get_mydata(c,'SENSOR1') for i=0,nframes-1 do begin ; combine frame by frame d( 0:46,*,i) = cam2(3:49,*,i) d( 47,*,i) = (cam2( 47,*,i) + cam1(2,*,i))/2.0 d( 48:91,*,i) = cam1(3:46,*,i) d( 92,*,i) = (cam1( 47,*,i) + cam0(2,*,i))/2.0 d(93:139,*,i) = cam0(0:46,*,i) endfor d = d(*,275:414,*) ; slice out the earth-centered square ; ; Reverse the order of the images to reflect that EUV stores its ; images [time,spinangle] instead of [spinangle,time] for i=0,nframes-1 do d(*,*,i) = reverse(d(*,*,i),1) help,d ; ; ; Release the data to free up memory delete_myhandles,a & a=0 & cam0=0 delete_myhandles,b & b=0 & cam1=0 delete_myhandles,c & c=0 & cam2=0 ; ; Scrub out any frames with no image data in them at all. If no ; frames contain any image data then exit the function with an error. counts = dblarr(nframes) & for i=0,nframes-1 do counts(i)=total(d(*,*,i)) w = where(counts ne 0.0d0,wc) if wc le 1 then begin print,'WARNING>make_myEUVcdf>LESS THAN 2 FRAMES CONTAIN ANY IMAGE DATA!' return,-1 endif else begin print,'INFO>make_myEUVcdf>scrubbing ',n_elements(w),' empty frames out of ',nframes d = d(*,*,w) & euvt = euvt(w) endelse ; ; Read the EUV master cdf and plug in the time and image data print,'INFO>make_myEUVcdf>reading EUV master cdf...' !quiet=1 & m = read_mycdf('',master,/all,/nodatastruct) & !quiet=0 m.EPOCH.handle = handle_create(value=euvt) m.IMAGE.handle = handle_create(value=d) ; ; Find and Read the cdfs which have the required ancillary orbit data print,'INFO>make_myEUVcdf>generating ancillary data...' offset = 1000.0d0 * 1800.0d0 ; compute a 30 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_myEUVcdf>matching orbit cdf files not found!' & return,-1 endif !quiet=1 & orb = read_mycdf('',f,/all) & !quiet=0 if ami_mystruct(orb) ne 1 then begin print,'ERROR>make_myEUVcdf>Eror reading orbit data from cdf!' & return,-1 endif ; ; Compute the interpolation points using the euv image times p = compute_interpolation_points( orb.epoch.dat, euvt ) ; ; Populate the m structure with orbit data interpolated to euv image times px = interpolate( reform( orb.gci_pos.dat(0,*)),p ) py = interpolate( reform( orb.gci_pos.dat(1,*)),p ) pz = interpolate( reform( orb.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) ; ; Convert each of the GCI positions to GEO and populate the m structure geo_pos = dblarr(3,n_elements(euvt)) for i = 0,n_elements(euvt)-1 do begin recalc,year,day,hour,min,sec,epoch=euvt(i) ; setup conversion values xgci=px(i) & ygci=py(i) & zgci=pz(i) & xgeo=0 & ygeo=0 & zgeo=0 geigeo,xgci,ygci,zgci,xgeo,ygeo,zgeo,1,epoch=euvt(i) geo_pos(0,i)=xgeo & geo_pos(1,i)=ygeo & geo_pos(2,i)=zgeo endfor m.GEO_POS.handle = handle_create(value=geo_pos) ; ; Populate the m structure with orbit data interpolated to euv image times px = interpolate( reform( orb.gsm_pos.dat(0,*)),p ) py = interpolate( reform( orb.gsm_pos.dat(1,*)),p ) pz = interpolate( reform( orb.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(euvt,/QL) $ else spin = find_myspinaxis(euvt) ; use daily files if amia_structure(spin) ne 1 then begin print,'WARNING>make_myEUVcdf>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) ; ; Manufacture data for 'roll_data' until I can get the real stuff m.ROLL_ANGLE.handle = handle_create(value=findgen(nframes)) ; ; create the new cdf if keyword_set(OUTDIR) then outd = OUTDIR $ else outd = '/mission/image/sci/incoming/' ; verify that final structure starts and ends at requested times a = timeslice_mystruct(m,estart,estop) print,'INFO>make_myEUVcdf>Creating output cdf...' s = write_mycdf(a,'',/autoname,/lowercase,OUTDIR=outd) delete_myhandles,m & m=0 ; release memory space return,s end ; Read the Cam0 cdf and walk through the data, moving frames of data from ; the input cdf to the correct location in the output array 'd'. ;if keyword_set(DEBUG) then print,'INFO>make_myEUVcdf>Moving Cam0 data...' ;euvt = get_mydata(a,'EPOCH') & euvd = get_mydata(a,'SENSOR1') ;for i=0,nframes-1 do begin ; t(i) = euvt(i) ; get the timetag from camera 0 ; d(100:149,*,i) = euvd(*,*,i) ; copy the camera 0 image ;endfor ;delete_myhandles,a & a=0 ; release the data space ; ; Walk through the sensor 1 data, moving frames of data from ; the input cdf to the correct location in the output array 'd', ; sync'ing them by time. Note that the image times for head1 are ; offset from the image times for head0 by approximately one spin. ;approx_two_minutes = (120.0d0 * 1000.0d0) + (10.0d0 * 1000.0d0) ;euvt = get_mydata(b,'EPOCH') & euvd = get_mydata(b,'SENSOR1') ;if keyword_set(DEBUG) then print,'INFO>make_myEUVcdf>Moving Cam1 data...' ;for i=0,nframes-1 do begin ; w = where(abs(euvt - t(i)) lt approx_two_minutes,wc) ; if wc gt 0 then d(50:99,*,i) = euvd(*,*,w(0)) ;endfor ;delete_myhandles,b & b=0 ; release the data space ; ; Walk through the sensor 2 data, moving frames of data from ; the input cdf to the correct location in the output array 'd', ; sync'ing them by time. Note that the image times for head1 are ; offset from the image times for head0 by approximately one spin. ;approx_four_minutes = (240.0d0 * 1000.0d0) + (10.0d0 * 1000.0d0) ;euvt = get_mydata(c,'EPOCH') & euvd = get_mydata(c,'SENSOR1') ;if keyword_set(DEBUG) then print,'INFO>make_myEUVcdf>Moving Cam2 data...' ;for i=0,nframes-1 do begin ; w = where(abs(euvt - t(i)) lt approx_four_minutes,wc) ; if wc gt 0 then d(0:49,*,i) = euvd(*,*,w(0)) ;endfor ;delete_myhandles,c & c=0 ; release the data space ; Plug the merged data into the master cdf structure. ; Note, before saving the data I may want to search for frames ; which are completely empty, (i.e. full of fillvals) and ; eliminate these to save filespace. ; Initialize some EUV parameters ; print,'INFO>make_myEUVcdf>Reading ',master ; m = read_mycdf('',master,/all,/nodatastruct) ; handle_value,m.epoch.handle,t,/set ; handle_value,m.image.handle,d,/set ; s = write_mycdf(m,'',/autoname,/lowercase) ; return,s ;return,0 ;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_myEUVproducts, my_times, OUTDIR=OUTDIR, DEBUG=DEBUG for i=0,n_elements(my_times.tstart)-1 do begin print,'INFO>make_myEUVproducts>Tstart=',decompute_cdfepoch(my_times.tstart(i)) print,'INFO>make_myEUVproducts>Tstop =',decompute_cdfepoch(my_times.tstop(i)) print,'INFO>make_myEUVproducts>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(0),my_times.tstop(0),$ /day,/def) ; removed nofirstbefore keyword if orb(0) eq '' then begin print,'INFO>make_myEUVproducts>Insufficient orbit data for this timerange.' abort = 1 endif endif ; ; Set the output directory to /incoming if the outdir keyword isn't set 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_myEUVcdf(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_euvproducts>Insufficient data to make EUV mpeg!' endif else begin ; make image by image gifs gnames = gifplot_myeuvimages(a,OUTDIR=d,DEBUG=DEBUG) 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) ; make single gif s = mpeg_myeuvgifs(gnames, OUTDIR=d,$ /QL, /DEBUG) ; make mpeg from gifs endif else begin s = make_mybiggif(gnames,OUTDIR=d,$ DEBUG=DEBUG) ; make single gif s = mpeg_myeuvgifs(gnames, OUTDIR=d,$ DEBUG=DEBUG) ; make mpeg from gifs endelse endif endelse endif a = 0 ; release the memory endif endif endfor return,0 end