function uly_lsfconvol_1D, lsf_file, data, start, step, QUIET=quiet
compile_opt idl2, hidden
velscale = 299792.458d * step
if file_test(lsf_file) eq 0 then begin
message, /CONT, 'LSF file not found '+lsf_file
return, 0
endif
rlsf = uly_lsf_read(lsf_file)
nlsf = n_elements(rlsf.v)
if nlsf eq 0 then begin
message, /CONT, 'Invalid LSF file '+lsf_file
return, 0
endif
s = size(data)
npx = s[1]
alsf=replicate({wl:1d,conv:dblarr(npx)},nlsf)
alsf.wl = rlsf.centrWL
for k=0,nlsf-1 do begin
uly_slit, rlsf.v[k], rlsf.sig[k], rlsf.h3[k], rlsf.h4[k], velscale, lsf
lsf = lsf/total(lsf)
alsf[k].conv = convol(data, lsf, /EDGE_TRUNCATE)
endfor
wl = exp([start + step*lindgen(npx)])
limits = where(alsf.wl ge wl[0] and alsf.wl le wl[n_elements(wl)-1])
alsf = alsf[min(limits, MAX=mxl):mxl]
nlsf = n_elements(alsf.wl)
px = findgen(n_elements(wl))
alsf.wl = (alog(alsf.wl)-start) / step
minPX = min((alsf.wl)[0:n_elements(alsf.wl)-1], MAX=maxPX)
n1 = WHERE(px lt minPX)
n3 = WHERE(px ge maxPX)
(data)[n1] = alsf[0].conv[n1]
(data)[n3] = alsf[nlsf-1].conv[n3]
for k = 0, nlsf-2 do begin
n2 = WHERE((px ge alsf[k].wl) and (px lt alsf[k+1].wl), nn2)
ff = rebin((n2-alsf[k].wl) / (alsf[k+1].wl-alsf[k].wl ), nn2)
(data)[n2] = alsf[k].conv[n2] + $
ff * (alsf[k+1].conv[n2]-alsf[k].conv[n2])
endfor
return, data
end
function uly_lsfconvol_2D, lsf_file, data, start, step, QUIET=quiet
compile_opt idl2, hidden
velscale = 299792.458d * step
rlsf = uly_lsf_read(lsf_file)
nlsf = n_elements(rlsf.v)
if nlsf eq 0 then begin
message, /CONT, 'Invalid LSF file '+lsf_file
return, 0
endif
s = size(data)
npx = s[1]
n2d = s[2]
alsf = replicate({wl:1d,conv:dblarr(npx,n2d)},nlsf)
alsf.wl = rlsf.centrWL
for k=0,nlsf-1 do begin
uly_slit, rlsf.v[k], rlsf.sig[k], rlsf.h3[k], rlsf.h4[k], velscale, lsf
lsf = lsf/total(lsf)
alsf[k].conv = convol(data, lsf, /EDGE_TRUNCATE)
endfor
wl = exp([start + step*lindgen(npx)])
limits = where(alsf.wl ge wl[0] and alsf.wl le wl[n_elements(wl)-1])
alsf = alsf[min(limits, MAX=mxl):mxl]
nlsf = n_elements(alsf.wl)
px = findgen(n_elements(wl))
alsf.wl = (alog(alsf.wl)-start) / step
minPX = min((alsf.wl)[0:n_elements(alsf.wl)-1], MAX=maxPX)
n1 = WHERE(px lt minPX)
n3 = WHERE(px ge maxPX)
(data)[n1,*] = alsf[0].conv[n1,*]
(data)[n3,*] = alsf[nlsf-1].conv[n3,*]
for k = 0, nlsf-2 do begin
n2 = WHERE((px ge alsf[k].wl) and (px lt alsf[k+1].wl), nn2)
ff = rebin((n2-alsf[k].wl) / (alsf[k+1].wl-alsf[k].wl ), nn2, n2d)
(data)[n2,*] = alsf[k].conv[n2,*] + $
ff * (alsf[k+1].conv[n2,*]-alsf[k].conv[n2,*])
endfor
return, data
end
pro uly_spect_lsfconvol, lsf_file, spec, QUIET=quiet
if n_elements(lsf_file) eq 0 then begin
print, 'Usage: uly_spect_lsfconvol, <lsf_file>, <spec>'
message, 'Missing argument <lsf_file>', /INFO
return
endif
if file_test(lsf_file) ne 1 then begin
f = ''
if size(lsf_file, /TYPE) eq 7 then f = ' ('+lsf_file+')'
message, 'No valid input LSF file: '+f, /INFO
return
endif
if n_elements(spec) eq 0 then begin
print, 'Usage: uly_spect_lsfconvol, <lsf_file>, <spec>'
message, 'Missing argument <spec>'
return
endif
if size(spec, /TYPE) ne 8 then begin
spec = uly_spect_read(spec, /QUIET)
endif
s = size(*spec.data)
type = ''
if size(spec, /TYPE) eq 8 then begin
case s[0] of
0: message, 'No valid input spectrum data'
1: type = '1D'
2: type = '2D'
else: type = '>2D'
endcase
endif
if spec.sampling ne 1 then $
message, 'The input spectrum should be sampled in log-wave'
if type eq '1D' then begin
*spec.data = uly_lsfconvol_1D(lsf_file, *spec.data, spec.start, spec.step, QUIET=quiet)
return
endif
if type eq '2D' then begin
*spec.data = uly_lsfconvol_2D(lsf_file, *spec.data, spec.start ,spec.step, QUIET=quiet)
return
endif
if type eq '>2D' then begin
ndim = size(*spec.data, /N_DIM)
data = *spec.data
start = spec.start
step = spec.step
dim = size(*spec.data, /DIM)
if ndim ge 3 then begin
tot = 1
for i = 1, ndim-1 do tot *= dim[i]
data = reform(data, dim[0], tot, /OVER)
endif
(*spec.data) = reform(uly_lsfconvol_2D(lsf_file, data, start, step, $
/QUIET), dim, /OVER)
endif
end
Part of