diff --git a/metis_dark_uvda.pro b/metis_dark_uvda.pro index 71a1e6a1f91fd51c93c82bbdea524a723d633bb7..6a59e680392a6fea33c1e715541c9a0ed6ecd529 100644 --- a/metis_dark_uvda.pro +++ b/metis_dark_uvda.pro @@ -1,3 +1,38 @@ +function m_angle_uv, matrix + + a = mean(matrix[10:45, 10:45]) + b = mean(matrix[980:1014, 10:45]) + c = mean(matrix[10:45, 980:1014]) + d = mean(matrix[980:1014, 980:1014]) + + return, [a, b, c, d] +end + +function m_center_uv, matrix + + a = mean(matrix[454:574, 460:582]) + + return, a +end + +function correzione_uvda, image, dark + + ima_ndit1 = rebin(image, 1024, 1024, /sample) + ima_ndit2 = rebin(dark, 1024, 1024, /sample) + + x = [m_angle_uv(ima_ndit2), m_center_uv(ima_ndit2)] + y = [m_angle_uv(ima_ndit1), m_center_uv(ima_ndit1)] + + r = linfit(x, y, yfit = yfit) + + ima = r[0] + ima_ndit2 * r[1] + + s = size(image) + ima = rebin(ima, s[1], s[2]) + + return, ima +end + function metis_dark_uvda, data, header, cal_pack, error = error, quality_matrix = quality_matrix, history = history dark = cal_pack.uv_channel.dark @@ -24,12 +59,28 @@ function metis_dark_uvda, data, header, cal_pack, error = error, quality_matrix for i = 0, n_elements(dark) - 1 do 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 $ - (dark[i].ndit1 eq ndit1) and (dark[i].ndit2 eq ndit2) and $ - flag_use_notfullset and flag_use_extrapolated then $ + (flag_use_notfullset or dark[i].fullset) and $ + (dark[i].extrapol eq 'False') then $ obt_available = [obt_available, dark[i].obt_beg] endfor + ; if not, search for extrapolated dark matrices with same parameters + if ~ isa(obt_available) and flag_use_extrapolated then begin + for i = 0, n_elements(dark) - 1 do 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 $ + (flag_use_notfullset or dark[i].fullset) and $ + (dark[i].extrapol eq 'True') then $ + obt_available = [obt_available, dark[i].obt_beg] + endfor + endif + ; if not, exit with error code if ~ isa(obt_available) then begin journal, 'Error 02: UV applicable dark file not found.' @@ -48,10 +99,7 @@ function metis_dark_uvda, data, header, cal_pack, error = error, quality_matrix dark_file = dark[i].filename.cnt_1[obj_cnt - 1] else $ dark_file = dark[i].filename.cnt_2 - ; apply normalization if required - if flag_normalize_dark and masking.contains('disabled', /fold) then $ - dark_image = correzione_uvda(data, cal_pack.path + dark_file) else $ - dark_image = float(readfits(cal_pack.path + dark_file, /silent)) + dark_image = float(readfits(cal_pack.path + dark_file, /silent)) dark_nobin = dark_image @@ -59,6 +107,10 @@ function metis_dark_uvda, data, header, cal_pack, error = error, quality_matrix dark_image = rebin(dark_image, header.naxis1, header.naxis2) * nbin dark_image = dark_image * ndit1 * ndit2 + ; apply normalization if required + if flag_normalize_dark and masking.contains('disabled', /fold) then $ + dark_image = correzione_uvda(data, dark_image) + mask = where(data eq 0., count) data = data - dark_image