;+ ;NAME: ; Movie0 ;PURPOSE: ; Data reduction for an m=0 MOSES movie. Extract, dark subtract and ; exposure normalize all the m=0 data. Co-align using fourier_image_shift. ; Save as numbered JPEGs. ; The catalog file 'imageindex.xml' is assumed to be in the current ; working directory. ;CALLING SEQUENCE: ; movie0_aligned [, /restore] ;KEYWORDS: ; restore --- if set, then restore from a save file. This saves ; much time by skipping right up to the point where the image ; cube is scaled and saved as a sequence of images. ;DEPENDNECIES: ; drift_compensate.pro ; fourier_image_shift.pro ;HISTORY: ; 2006-Mar-29 CCK added sub-pixel alignment optimization, improved ; brightness scale. ;- pro movie0_aligned, restore=restore if keyword_set(restore) then begin restore,'movie0_aligned.sav' goto, SCALING endif dt = 250000.0 ;exposure time resolution (microsec) forward_function hist_equal_long ;Set up dataspace Nx = 2048 Ny = 1024 index = mxml('imageindex.xml',curdir()) N_images = n_elements(index.filename) for i=0,N_images-1 do begin ;TALLY DATA IMAGES if (strpos(index.seqname[i],'data') ne -1) then begin print,'Found DATA image ',index.seqname[i] add_element, data_list, i endif ;TALLY DARK IMAGES if (strpos(index.seqname[i],'dark') ne -1) then begin print,'Found DARK image ',index.seqname[i] add_element, dark_list, i endif ;CREATE/UPDATE EXPOSURE LIST, exp_list if n_elements(exp_list) eq 0 then exp_list = [index.exptime[i]] else begin ss = where(abs(exp_list - index.exptime[i]) lt index.exptime[i]/10.0) if ss eq -1 then add_element, exp_list, $ dt*round(index.exptime[i]/dt) endelse endfor ;PROCESS DARK IMAGES Nexptimes = n_elements(exp_list) darks = fltarr(Nx, Ny, Nexptimes) ;array of darks (DN) darkRepeats = intarr(Nexptimes) ;initialized to zero print,'Processing dark images...' Ndark = n_elements(dark_list) for j = 0, Ndark-1 do begin i = dark_list[j] error=0L moses_read, index.filename[i],minus,zero,plus,noise, $ sizes=index.chansize[i,*], /byteorder, directory=curdir(), error=error if error eq 0L then begin print,"Got ",index.filename[i] ;locate exposure time in table s = where(abs(exp_list - index.exptime[i]) lt index.exptime[i]/10.0) if s[0] eq -1 or n_elements(s) ne 1 then message,'Exposure list error.' s = s[0] ;make it into a scalar rather than a 1-element array. ;incorporate zero order image into average dark (DN). darks[*,*,s] = ( darkRepeats[s]*darks[*,*,s] + $ zero ) / (1 + darkRepeats[s]) darkRepeats[s] = darkRepeats[s] + 1 endif endfor ;PROCESS DATA IMAGES Ndata = n_elements(data_list) zcube = fltarr(1024,512,Ndata) for j = 0, Ndata-1 do begin i = data_list[j] error=0L moses_read, index.filename[i],minus,zero,plus,noise, $ sizes=index.chansize[i,*], /byteorder, directory=curdir(), error=error if error eq 0L then begin print,"Got ",index.filename[i] ;locate exposure time in table s = where(abs(exp_list - index.exptime[i]) lt index.exptime[i]/10.0) if s[0] eq -1 or n_elements(s) ne 1 then message,'Exposure list error.' s = s[0] ;make it into a scalar rather than a 1-element array. ;Dark subtract and normalize to 1s exposure image = (zero - darks[*,*,s])/(index.exptime[i]*1e-6) zcube[*,*,j] = rebin(image, 1024, 512)/median(image) endif endfor ;Drift compensation. Align to image 5, the first 24-sec exposure. zcube = drift_compensate(temporary(zcube), offsets=offsets, alignto=5) SCALING: print, "Scaling and saving data..." ;Create scaled data cube maxval = min( zcube[150,190,*] ) minval = min( zcube[1023,450,*] ) ;difference movie! ;foo = bytscl( $ ; (zcube > minval < maxval)[*,*,1:Ndata-1] - $ ; (zcube > minval < maxval)[*,*,0:Ndata-2] $ ; < 1 > (-1) ) ;Alignment check movie! ;foo = bytscl( $ ; (zcube > minval < maxval) - $ ; (zcube > minval < maxval)[*,*,5] $ ; < 1 > (-1) ) ;foo = bytscl( (zcube > minval < maxval)^0.5 ) ;foo = bytscl( (zcube > minval < maxval) ) ;foo = bytscl( hist_equal_long(zcube, max=max)^1.5 ) foo = hist_equal(zcube) ;Crop xlo = round(max(offsets.x)>0) xhi = round(min(offsets.x)<0)+1024-1 ylo = round(max(offsets.y)>0) yhi = round(min(offsets.y)<0)+512-1 foo = foo[xlo:xhi, ylo:yhi, *] ;Save images Nfoo = (size(foo))[3] ;differs from Ndata if a difference movie for j=0, Nfoo-1 do begin filename = '/tmp/'+string(j,format='(i03)')+'.jpg' print,filename write_jpeg, filename, foo[*,*,j] endfor if not keyword_set(restore) then save, filename="movie0_aligned.sav" message,'debug' end