;============================================================================= ; ; NAME: ivm_blong_qnd ; ; DESCRIPTION: ; Function to estimate Blong_qnd from a demodulated Stokes data cube. ; ; CALLING SEQUENCE: ; blqd = ivm_blong_qnd(idats, nn, nframes, nw, lc=lc, err=err, vb=vb) ; ; INPUTS: ; idats = Stokes input: fltarr(nn,nn,nframes,nw) or (nn,nn,nframes*nw) ; ; KEYWORDS: ; lc = Line center; will be computed (output) if not set (input) ; err = Set to 1 if there was a problem, e.g., crazy line center ; vb = Verbosity (0=none, 1=minimal, 2+=lots) ; ; RETURN VALUE: ; fltarr(nn,nn) containing the result at each pixel, or 0 if problems ; ; HISTORY: ; ELW 2011.08.30 - generalized, functionalized form of code from rivmts ; ;============================================================================= function ivm_blong_qnd, idats, nn, nframes, nw, lc=lc, err=err, vb=vb err=0 ; Start out with a clean slate fn='ivm_blong_qnd: ' if (n_elements(vb) ne 1) then vb=0 if (vb gt 1) then print, fn, 'Start: ', systime() if (nw lt 10) then begin print, fn, 'Unexpected value for nw ('+strtrim(nw,2)+'). Returning.' err=1 return, 0 endif ;--------------------------------------- ; Assure a 3D data cube for calculation ;--------------------------------------- if (size(idats, /n_dim) eq 4) then $ demod3D = reform(idats, nn, nn, nw*nframes) $ else $ demod3D = idats ;----------------------------------------------------------------------- ; Find line center if not set - ELW20101001, from KD snippets ;----------------------------------------------------------------------- if (~keyword_set(lc) || (n_elements(lc) ne 1)) then begin if (vb gt 0) then print, fn, 'Computing line center. ', systime() ; spraw = reform(rebin(demod3D, 1,1,30)) ; lc = (lc_find(spraw,5,24,9))[0] spraw = reform(rebin(demod3D, 1, 1, nw)) lc = (lc_find(spraw, 5, nw - 5 - 1, 9))[0] endif else if (vb gt 1) then $ print, fn, 'Using line center passed in via LC keyword.' ;----------------------------------------------------------------------- ; Calculate quick & dirty Blong. First check line center to determine ; which side to use for Blong, or flag an error if it is shifted too ; far to either side. ;----------------------------------------------------------------------- if (lc gt 3*nw/4-1 || lc lt nw/4) then begin ; Extreme LC (was 21, 8 w/nw=30) print, fn, 'Line center is extreme ('+strtrim(lc,2)+'). Data are useless.' err=1 return, 0 endif else if (lc gt nw/2+3) then begin ; Switch sides (was 18) if (vb ge 1) then print,fn,'Line center is '+strtrim(lc,2)+ $ '. Switching sides for Bl_QnD.' Bl_QnD = -1.*total(idats[*,*,3,long(lc)+2:nw-2], 4) ; was 16:28 endif else begin ; Else, normal if (vb ge 1) then print,fn,'Line center is ', +strtrim(lc,2) Bl_QnD = total(idats[*,*,3,0:nw/3+2], 4) ; ELW-20110829 - Was 0:12 endelse if (vb gt 1) then print, fn, 'End: ', systime() return, Bl_Qnd end