Commit ae959234 authored by Roberto Susino's avatar Roberto Susino
Browse files

Fix bugs in dark file selection

parent 4e3758f8
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -10,12 +10,16 @@ function metis_dark_uvda, data, header, cal_pack, history = history
	obj_cnt = header.obj_cnt
	obt_beg = header.obt_beg

	; WARN - temporary patch to handle local l1 fits files
	; if tsensor eq 0. then tsensor = -25.

	for i = 0, n_elements(dark) - 1 do begin
		if (dark[i].dit eq dit) and (dark[i].nbin eq nbin) and (dark[i].ndit1 eq ndit1) and (dark[i].ndit2 eq ndit2) and (abs(dark[i].tsensor - tsensor) lt 5) and (abs(obt_beg - dark[i].obt_beg) lt (3600 * 24 * 10)) then begin
		if (dark[i].dit eq dit) and (dark[i].ndit1 eq ndit1) and (dark[i].ndit2 eq ndit2) and (abs(dark[i].tsensor - tsensor) lt 5.) and (abs(obt_beg - dark[i].obt_beg) lt (3600. * 24. * 10.)) then begin
			if obj_cnt eq 1 then begin
				dark_file = dark[i].file_name.cnt_1
				dark_image = float(readfits(cal_pack.path + dark[i].file_name.cnt_1, /silent))
				dark_image = float(readfits(cal_pack.path + dark_file, /silent))
				dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin^2

				mask = where(data eq 0., count)
				data = data - dark_image * ndit1 * ndit2
				data[mask] = 0.
@@ -23,8 +27,9 @@ function metis_dark_uvda, data, header, cal_pack, history = history
				goto, jump
			endif else begin
				dark_file = dark[i].file_name.cnt_2
				dark_image = float(readfits(cal_pack.path + dark[i].file_name.cnt_2, /silent))
				dark_image = float(readfits(cal_pack.path + dark_file, /silent))
				dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin^2

				mask = where(data eq 0., count)
				data = data - dark_image * ndit1 * ndit2
				data[mask] = 0.
@@ -36,28 +41,32 @@ function metis_dark_uvda, data, header, cal_pack, history = history

	obt_available = !null
	for i = 0, n_elements(dark) - 1 do begin
		if (dark[i].dit eq dit) and (abs(dark[i].tsensor - tsensor) lt 5) then begin
			obt_available = [obt_available, dark[i].obt_beg]
		endif
		if (dark[i].dit eq dit) and (abs(dark[i].tsensor - tsensor) lt 5.) then obt_available = [obt_available, dark[i].obt_beg]
	endfor

	if not isa(obt_available) then begin
		dark_file = 'applicable file not found - correction not applied'

		goto, jump
	endif

	delta_obt = min(abs(obt_beg - obt_available), j)
	i = where(dark.obt_beg eq obt_available[j])

	if obj_cnt eq 1 then begin
		if (ndit1 eq dark[i].ndit1) and (ndit2 eq dark[i].ndit2) then begin
			dark_image = float(readfits(cal_pack.path + dark[i].file_name.cnt_1, /silent))
			dark_file = dark[i].file_name.cnt_1
			dark_image = float(readfits(cal_pack.path + dark_file, /silent))
		endif else begin
			q = ndit2/dark[i].ndit2
			dark_file = dark[i].file_name.cnt_1 + ' - ' + dark[i].file_name.cnt_2
			dark_1 = float(readfits(cal_pack.path + dark[i].file_name.cnt_1, /silent))
			dark_2 = float(readfits(cal_pack.path + dark[i].file_name.cnt_2, /silent))
			dark_image = (dark_1 + (q - 1) * dark_2)/q
			dark_file = dark[i].file_name.cnt_1 + ' - ' + dark[i].file_name.cnt_2
		endelse
	endif else begin
		dark_image = float(readfits(cal_pack.path + dark[i].file_name.cnt_2, /silent))
		dark_file = dark[i].file_name.cnt_2
		dark_image = float(readfits(cal_pack.path + dark_file, /silent))
	endelse

	dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin^2
+28 −17
Original line number Diff line number Diff line
@@ -8,15 +8,18 @@ function metis_dark_vlda, data, header, cal_pack, history = history
	ndit = header.ndit
	nbin = sqrt(header.nbin)
	tsensor = header.tsensor
	obt_beg = header.obt_beg/1000.D0
	obt_beg = header.obt_beg/1000.D0 ; check why obt_beg must be divided by 1000.

	; WARN - temporary patch to handle local l1 fits files
	; if tsensor eq 0. then tsensor = -30.

	for i = 0, n_elements(bias_dark) - 1 do begin
		if bias_dark[i].dit eq dit and bias_dark[i].nbin eq nbin and abs(bias_dark[i].tsensor - tsensor) lt 5 then begin
			dark_image = float(readfits(cal_pack.path + bias_dark[i].file_name, /silent))
		if bias_dark[i].dit eq dit and bias_dark[i].nbin eq nbin and abs(bias_dark[i].tsensor - tsensor) lt 5. then begin
			dark_file = bias_dark[i].file_name
			dark_image = float(readfits(cal_pack.path + dark_file, /silent))
			dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin^2 * ndit
			
			mask = where(data eq 0.)
			dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin^2 * ndit
			data = data - dark_image
			data[mask] = 0.

@@ -26,25 +29,33 @@ function metis_dark_vlda, data, header, cal_pack, history = history

	bias_obt_available = !null
	for i = 0, n_elements(bias) - 1 do begin
		if abs(bias[i].tsensor - tsensor) lt 5 then $
		bias_obt_available = [bias_obt_available, bias[i].obt_beg]
		if abs(bias[i].tsensor - tsensor) lt 5. then bias_obt_available = [bias_obt_available, bias[i].obt_beg]
	endfor

	if isa(bias_obt_available) then begin
		delta_obt = min(abs(obt_beg - bias_obt_available), j)
		i = where(bias.obt_beg eq bias_obt_available[j])
		bias_image = float(readfits(cal_pack.path + bias[i].file_name, /silent))
		dark_file = bias[i].file_name
	endif else begin
		bias_image = fltarr(header.naxis1, header.naxis2)
		dark_file = 'applicable bias file not found - correction not applied'
	endelse

	dark_obt_available = !null
	for i = 0, n_elements(dark) - 1 do begin
		if abs(dark[i].tsensor - tsensor) lt 5 then $
		dark_obt_available = [dark_obt_available, dark[i].obt_beg]
		if abs(dark[i].tsensor - tsensor) lt 5. then dark_obt_available = [dark_obt_available, dark[i].obt_beg]
	endfor

	if isa(dark_obt_available) then begin
		delta_obt = min(abs(obt_beg - dark_obt_available), j)
		i = where(dark.obt_beg eq dark_obt_available[j])
		dark_image = float(readfits(cal_pack.path + dark[i].file_name, /silent))
		dark_file = [dark_file, dark[i].file_name]
	endif else begin
		dark_image = fltarr(header.naxis1, header.naxis2)
		dark_file =  [dark_file, 'applicable dark file not found - correction not applied']
	endelse

	bias_image = rebin(bias_image, header.naxis1, header.naxis2) * nbin^2
	dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin^2