Skip to content
Snippets Groups Projects
Commit 335f72d5 authored by Roberto Susino's avatar Roberto Susino
Browse files

Minor improvements and optimizations

parent a7656a07
No related branches found
No related tags found
No related merge requests found
pro fix_fits_header, filename
fits_info, filename, n_ext = n_ext, /silent
for ext = 0, n_ext do begin
data = readfits(filename, header, exten_no = ext, /silent)
data = readfits(filename, header, exten_no = ext, /noscale, /silent)
for k = 0, n_elements(header) - 1 do begin
while header[k].matches('\/ +') do begin
header[k] = header[k].replace('/ ', '/ ')
endwhile
endfor
fits_add_checksum, header, data
modfits, filename, 0, header, exten_no = ext
endfor
end
\ No newline at end of file
......@@ -121,6 +121,14 @@ pro metis_l2_prep_uv
end
endcase
; make rotations and compute absolute error
if not ref_detector then data = metis_rectify(data, 'UV')
if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'UV')
if not ref_detector then error = metis_rectify(error, 'UV')
error_matrix = data * sqrt(error)
; definitions for the primary header
; version of the fits file
......@@ -145,6 +153,8 @@ pro metis_l2_prep_uv
fxaddpar, primary_header, 'VERS_SW', input.sw_version
fxaddpar, primary_header, 'VERS_CAL', cal_pack.version
fxaddpar, primary_header, 'VERSION', version
fxaddpar, primary_header, 'OBJECT', 'Sun'
fxaddpar, primary_header, 'TARGET', 'Corona'
fxaddpar, primary_header, 'BTYPE', btype
fxaddpar, primary_header, 'BUNIT', bunit
fxaddpar, primary_header, 'DATAMIN', min(data, /nan)
......@@ -197,20 +207,19 @@ pro metis_l2_prep_uv
fxaddpar, primary_header, 'HISTORY', history[k]
fxaddpar, primary_header, 'HISTORY', 'L2 FITS file created on ' + date
if not ref_detector then data = metis_rectify(data, 'UV')
; write the fits file
fits_add_checksum, primary_header, float(data)
mwrfits, float(data), out_file_name, primary_header, /no_comment, /create, /silent
journal, 'Fits file created:'
journal, ' file name = ' + file_basename(out_file_name)
; add the extension with the quality matrix
; quality matrix
base_header = primary_header
sxdelpar, base_header, 'SIMPLE'
sxdelpar, base_header, 'EXTEND'
sxdelpar, base_header, 'DATASUM'
sxdelpar, base_header, 'CHECKSUM'
sxdelpar, base_header, 'COMMENT'
sxdelpar, base_header, 'HISTORY'
......@@ -227,16 +236,16 @@ pro metis_l2_prep_uv
fxaddpar, extension_header, 'COMMENT', ' NaN = saturated or null L0 pixel counts'
fxaddpar, extension_header, 'COMMENT', ' 0 = unreliable pixel value'
fxaddpar, extension_header, 'COMMENT', ' 1 = good pixel'
if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'UV')
; add the extension to the fits file
fits_add_checksum, extension_header, float(quality_matrix)
mwrfits, float(quality_matrix), out_file_name, extension_header, /no_comment, /silent
journal, 'Quality-matrix extension correctly added.'
; add the extension with the error matrix
; error matrix
if not ref_detector then error = metis_rectify(error, 'UV')
error_matrix = data * sqrt(error)
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
fxaddpar, extension_header, 'PCOUNT', 0, 'parameter count', before = 'LONGSTRN'
......@@ -246,6 +255,8 @@ pro metis_l2_prep_uv
fxaddpar, extension_header, 'DATAMIN', min(error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(error_matrix, /nan)
; add the extension to the fits file
fits_add_checksum, extension_header, float(error_matrix)
mwrfits, float(error_matrix), out_file_name, extension_header, /no_comment, /silent
......
......@@ -137,6 +137,14 @@ pro metis_l2_prep_vl_generic
end
endcase
; make rotations and compute absolute error
if not ref_detector then data = metis_rectify(data, 'VL')
if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
if not ref_detector then error = metis_rectify(error, 'VL')
error_matrix = data * sqrt(error)
; definitions for the primary header
; version of the fits file
......@@ -160,6 +168,8 @@ pro metis_l2_prep_vl_generic
fxaddpar, primary_header, 'VERS_SW', input.sw_version
fxaddpar, primary_header, 'VERS_CAL', cal_pack.version
fxaddpar, primary_header, 'VERSION', version
fxaddpar, primary_header, 'OBJECT', 'Sun'
fxaddpar, primary_header, 'TARGET', 'Corona'
fxaddpar, primary_header, 'BTYPE', btype
fxaddpar, primary_header, 'BUNIT', bunit
fxaddpar, primary_header, 'DATAMIN', min(data, /nan)
......@@ -232,22 +242,19 @@ pro metis_l2_prep_vl_generic
fxaddpar, primary_header, 'HISTORY', history[k]
fxaddpar, primary_header, 'HISTORY', 'L2 FITS file created on ' + date
; add checksum and datasum to the fits header
; write the fits file
if not ref_detector then data = metis_rectify(data, 'VL')
fits_add_checksum, primary_header, float(data)
mwrfits, float(data), out_file_name, primary_header, /no_comment, /create, /silent
journal, 'Fits file created:'
journal, ' file name = ' + file_basename(out_file_name)
; add the extension with the quality matrix
; quality matrix
base_header = primary_header
sxdelpar, base_header, 'SIMPLE'
sxdelpar, base_header, 'EXTEND'
sxdelpar, base_header, 'DATASUM'
sxdelpar, base_header, 'CHECKSUM'
sxdelpar, base_header, 'COMMENT'
sxdelpar, base_header, 'HISTORY'
......@@ -264,16 +271,16 @@ pro metis_l2_prep_vl_generic
fxaddpar, extension_header, 'COMMENT', ' NaN = saturated or null L0 pixel counts'
fxaddpar, extension_header, 'COMMENT', ' 0 = unreliable pixel value'
fxaddpar, extension_header, 'COMMENT', ' 1 = good pixel'
if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
; add the extension to the fits file
fits_add_checksum, extension_header, float(quality_matrix)
mwrfits, float(quality_matrix), out_file_name, extension_header, /no_comment, /silent
journal, 'Quality-matrix extension correctly added.'
; add the extension with the error matrix
; error matrix
if not ref_detector then error = metis_rectify(error, 'VL')
error_matrix = data * sqrt(error)
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
fxaddpar, extension_header, 'PCOUNT', 0, 'parameter count', before = 'LONGSTRN'
......@@ -282,6 +289,9 @@ pro metis_l2_prep_vl_generic
fxaddpar, extension_header, 'BTYPE', 'Absolute error'
fxaddpar, extension_header, 'DATAMIN', min(error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(error_matrix, /nan)
; add the extension to the fits file
fits_add_checksum, extension_header, float(error_matrix)
mwrfits, float(error_matrix), out_file_name, extension_header, /no_comment, /silent
......
......@@ -72,12 +72,12 @@ pro metis_l2_prep_vl_polariz
header = fits_hdr2struct(primary_header)
; ====================================
; ======================================================================
; for old l1 data
; image = image * header.nbin * header.ndit
; header.xposure = header.dit/1000. * header.ndit
; header.nsumexp = header.ndit
; ====================================
; ======================================================================
; check data type
......@@ -130,14 +130,14 @@ pro metis_l2_prep_vl_polariz
image_subdark = metis_dark_vlda(image, header, error = image_error, quality_matrix = image_quality_matrix, cal_pack, history = tb_history)
; ====================================
; ======================================================================
; for data already subtracted of dark
; file = file_basename(header.parent, '.fits') + '_subdark.fits'
; image_subdark = mrdfits('input/subdark/' + file, 0, /silent)
; image_subdark = rebin(image_subdark, header.naxis1, header.naxis2) * header.nbin
; image_subdark = image_subdark * header.ndit
; tb_history = ['Dark correction: ', ' ' + file]
; ====================================
; ======================================================================
data_subdark = [[[data_subdark]], [[image_subdark]]]
abs_error = [[[abs_error]], [[image_subdark * sqrt(image_error)]]]
......@@ -285,10 +285,9 @@ pro metis_l2_prep_vl_polariz
tb_image = i
tb_error = (i_abs_error / i) ^ 2
tb_quality_matrix = quality_matrix
tb_image = metis_flat_field(tb_image, header, error = tb_error, quality_matrix = tb_quality_matrix, cal_pack, history = tb_history)
tb_image = metis_vignetting(tb_image, header, error = tb_error, quality_matrix = tb_quality_matrix, cal_pack, history = tb_history)
tb_image = metis_rad_cal(tb_image, header, error = tb_error, quality_matrix = tb_quality_matrix, cal_pack, /polarimetric, history = tb_history)
tb_image = metis_flat_field(tb_image, header, error = tb_error, quality_matrix = quality_matrix, cal_pack, history = tb_history)
tb_image = metis_vignetting(tb_image, header, error = tb_error, quality_matrix = quality_matrix, cal_pack, history = tb_history)
tb_image = metis_rad_cal(tb_image, header, error = tb_error, quality_matrix = quality_matrix, cal_pack, history = tb_history, /polarimetric)
; compute the pb from the stokes q and u and apply other calibrations
......@@ -296,25 +295,30 @@ pro metis_l2_prep_vl_polariz
pb_image = sqrt(q ^ 2 + u ^ 2)
pb_error = (q ^ 2 * q_abs_error ^ 2 + u ^ 2 * u_abs_error ^ 2) / pb_image ^ 4
pb_quality_matrix = quality_matrix
pb_image = metis_flat_field(pb_image, header, error = pb_error, quality_matrix = pb_quality_matrix, cal_pack, history = pb_history)
pb_image = metis_vignetting(pb_image, header, error = pb_error, quality_matrix = pb_quality_matrix, cal_pack, history = pb_history)
pb_image = metis_rad_cal(pb_image, header, error = pb_error, quality_matrix = pb_quality_matrix, cal_pack, /polarimetric, history = pb_history)
pb_image = metis_flat_field(pb_image, header, error = pb_error, cal_pack, history = pb_history)
pb_image = metis_vignetting(pb_image, header, error = pb_error, cal_pack, history = pb_history)
pb_image = metis_rad_cal(pb_image, header, error = pb_error, cal_pack, history = pb_history, /polarimetric)
; ====================================
; ==========================================================================
; for simple radiometric calibration
; cal_pack.vl_channel.cal_units = 'DN/s'
; ====================================
; ==========================================================================
; compute the polarization angle from the stokes q and u
pol_angle = 0.5d0 * atan(stokes[*, *, 2], stokes[*, *, 1])
pol_angle_error = (q ^ 2 * u_abs_error ^ 2 + u ^ 2 * q_abs_error ^ 2) / (2d0 * pb_image ^ 4) / pol_angle ^ 2
; convert pol. angle to degrees
pol_angle = pol_angle * !radeg
journal, 'Polarization angle correctly computed.'
; rotate the quality matrix if necessary
if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
; definitions for the primary header
; version of the fits file
......@@ -332,6 +336,8 @@ pro metis_l2_prep_vl_polariz
fxaddpar, primary_header, 'VERS_SW', input.sw_version
fxaddpar, primary_header, 'VERS_CAL', cal_pack.version
fxaddpar, primary_header, 'VERSION', version
fxaddpar, primary_header, 'OBJECT', 'Sun'
fxaddpar, primary_header, 'TARGET', 'Corona'
fxaddpar, primary_header, 'DATE', date, 'date and time of FITS file creation'
fxaddpar, primary_header, 'DATE-BEG', header.date_beg, 'start time of observation'
fxaddpar, primary_header, 'DATE-OBS', header.date_obs, 'same as DATE-BEG'
......@@ -409,6 +415,17 @@ pro metis_l2_prep_vl_polariz
out_file_name = strarr(4)
; ==========================================================================
; polarized brightness
; ==========================================================================
; make rotations and compute absolute error
if not ref_detector then pb_image = metis_rectify(pb_image, 'VL')
if not ref_detector then pb_error = metis_rectify(pb_error, 'VL')
pb_error_matrix = pb_image * 0. ; pb_image * sqrt(pb_error)
; keywords specific for polarized brightness images
primary_pb_header = primary_header
......@@ -429,22 +446,19 @@ pro metis_l2_prep_vl_polariz
for k = 0, n_elements(pb_history) - 1 do fxaddpar, primary_pb_header, 'HISTORY', pb_history[k]
fxaddpar, primary_pb_header, 'HISTORY', 'L2 FITS file created on ' + date
; add checksum and datasum to the fits header
; write the fits file
if not ref_detector then pb_image = metis_rectify(pb_image, 'VL')
fits_add_checksum, primary_pb_header, float(pb_image)
mwrfits, float(pb_image), out_file_name[0], primary_pb_header, /no_comment, /create, /silent
journal, 'Polarized-brightness FITS file created:'
journal, ' file name = ' + file_basename(out_file_name[0])
; add the extension with the quality matrix
; quality matrix
base_header = primary_pb_header
sxdelpar, base_header, 'SIMPLE'
sxdelpar, base_header, 'EXTEND'
sxdelpar, base_header, 'DATASUM'
sxdelpar, base_header, 'CHECKSUM'
sxdelpar, base_header, 'COMMENT'
sxdelpar, base_header, 'HISTORY'
......@@ -461,26 +475,29 @@ pro metis_l2_prep_vl_polariz
fxaddpar, extension_header, 'COMMENT', ' NaN = saturated or null L0 pixel counts'
fxaddpar, extension_header, 'COMMENT', ' 0 = unreliable pixel value'
fxaddpar, extension_header, 'COMMENT', ' 1 = good pixel'
if not ref_detector then pb_quality_matrix = metis_rectify(pb_quality_matrix, 'VL')
fits_add_checksum, extension_header, float(pb_quality_matrix)
mwrfits, float(pb_quality_matrix), out_file_name[0], extension_header, /no_comment, /silent
; add the extension to the fits file
fits_add_checksum, extension_header, float(quality_matrix)
mwrfits, float(quality_matrix), out_file_name[0], extension_header, /no_comment, /silent
journal, 'Quality-matrix extension correctly added.'
; add the extension with the error matrix
; error matrix
if not ref_detector then pb_error = metis_rectify(pb_error, 'VL')
error_matrix = pb_image * 0. ; pb_image * sqrt(pb_error)
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
fxaddpar, extension_header, 'PCOUNT', 0, 'parameter count', before = 'LONGSTRN'
fxaddpar, extension_header, 'GCOUNT', 1, 'group count', before = 'LONGSTRN'
fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'extension name', before = 'LONGSTRN'
fxaddpar, extension_header, 'BTYPE', 'Absolute error'
fxaddpar, extension_header, 'DATAMIN', min(error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(error_matrix, /nan)
fits_add_checksum, extension_header, float(error_matrix)
mwrfits, float(error_matrix), out_file_name[0], extension_header, /no_comment, /silent
fxaddpar, extension_header, 'DATAMIN', min(pb_error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(pb_error_matrix, /nan)
; add the extension to the fits file
fits_add_checksum, extension_header, float(pb_error_matrix)
mwrfits, float(pb_error_matrix), out_file_name[0], extension_header, /no_comment, /silent
journal, 'Error-matrix extension correctly added.'
......@@ -488,6 +505,17 @@ pro metis_l2_prep_vl_polariz
fix_fits_header, out_file_name[0]
; ==========================================================================
; total brightness
; ==========================================================================
; make rotations and compute absolute error
if not ref_detector then tb_image = metis_rectify(tb_image, 'VL')
if not ref_detector then tb_error = metis_rectify(tb_error, 'VL')
tb_error_matrix = tb_image * 0. ; tb_image * sqrt(tb_error)
; keywords specific for total brightness images
primary_tb_header = primary_header
......@@ -508,22 +536,19 @@ pro metis_l2_prep_vl_polariz
for k = 0, n_elements(tb_history) - 1 do fxaddpar, primary_tb_header, 'HISTORY', tb_history[k]
fxaddpar, primary_tb_header, 'HISTORY', 'L2 FITS file created on ' + date
; add checksum and datasum to the fits header
; write the fits file
if not ref_detector then tb_image = metis_rectify(tb_image, 'VL')
fits_add_checksum, primary_tb_header, float(tb_image)
mwrfits, float(tb_image), out_file_name[1], primary_tb_header, /no_comment, /create, /silent
journal, 'Total-brightness FITS file created:'
journal, ' file name = ' + file_basename(out_file_name[1])
; add the extension with the quality matrix
; quality matrix
base_header = primary_tb_header
sxdelpar, base_header, 'SIMPLE'
sxdelpar, base_header, 'EXTEND'
sxdelpar, base_header, 'DATASUM'
sxdelpar, base_header, 'CHECKSUM'
sxdelpar, base_header, 'COMMENT'
sxdelpar, base_header, 'HISTORY'
......@@ -534,32 +559,35 @@ pro metis_l2_prep_vl_polariz
fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'extension name', before = 'LONGSTRN'
fxaddpar, extension_header, 'BTYPE', 'Pixel quality'
fxaddpar, extension_header, 'BUNIT', 'None'
fxaddpar, extension_header, 'DATAMIN', min(tb_quality_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(tb_quality_matrix, /nan)
fxaddpar, extension_header, 'DATAMIN', min(quality_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(quality_matrix, /nan)
fxaddpar, extension_header, 'COMMENT', 'Quality matrix values:'
fxaddpar, extension_header, 'COMMENT', ' NaN = saturated or null L0 pixel counts'
fxaddpar, extension_header, 'COMMENT', ' 0 = unreliable pixel value'
fxaddpar, extension_header, 'COMMENT', ' 1 = good pixel'
if not ref_detector then tb_quality_matrix = metis_rectify(tb_quality_matrix, 'VL')
fits_add_checksum, extension_header, float(tb_quality_matrix)
mwrfits, float(tb_quality_matrix), out_file_name[1], extension_header, /no_comment, /silent
; add the extension to the fits file
fits_add_checksum, extension_header, float(quality_matrix)
mwrfits, float(quality_matrix), out_file_name[1], extension_header, /no_comment, /silent
journal, 'Quality-matrix extension correctly added.'
; add the extension with the error matrix
; error matrix
if not ref_detector then tb_error = metis_rectify(tb_error, 'VL')
error_matrix = tb_image * 0. ; tb_image * sqrt(tb_error)
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
fxaddpar, extension_header, 'PCOUNT', 0, 'parameter count', before = 'LONGSTRN'
fxaddpar, extension_header, 'GCOUNT', 1, 'group count', before = 'LONGSTRN'
fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'extension name', before = 'LONGSTRN'
fxaddpar, extension_header, 'BTYPE', 'Absolute error'
fxaddpar, extension_header, 'DATAMIN', min(error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(error_matrix, /nan)
fits_add_checksum, extension_header, float(error_matrix)
mwrfits, float(error_matrix), out_file_name[1], extension_header, /no_comment, /silent
fxaddpar, extension_header, 'DATAMIN', min(tb_error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(tb_error_matrix, /nan)
; add the extension to the fits file
fits_add_checksum, extension_header, float(tb_error_matrix)
mwrfits, float(tb_error_matrix), out_file_name[1], extension_header, /no_comment, /silent
journal, 'Error-matrix extension correctly added.'
......@@ -567,6 +595,17 @@ pro metis_l2_prep_vl_polariz
fix_fits_header, out_file_name[1]
; ==========================================================================
; polarization angle
; ==========================================================================
; make rotations and compute absolute error
if not ref_detector then pol_angle = metis_rectify(pol_angle, 'VL')
if not ref_detector then pol_angle_error = metis_rectify(pol_angle_error, 'VL')
pol_angle_error_matrix = pol_angle * 0. ; pol_angle * sqrt(pol_angle_error)
; keywords specific for polarization-angle images
primary_polangle_header = primary_header
......@@ -587,22 +626,19 @@ pro metis_l2_prep_vl_polariz
for k = 0, n_elements(pb_history) - 1 do fxaddpar, primary_polangle_header, 'HISTORY', pb_history[k]
fxaddpar, primary_polangle_header, 'HISTORY', 'L2 FITS file created on ' + date
; add checksum and datasum to the fits header
; write the fits file
if not ref_detector then pol_angle = metis_rectify(pol_angle, 'VL')
fits_add_checksum, primary_polangle_header, float(pol_angle)
mwrfits, float(pol_angle), out_file_name[2], primary_polangle_header, /no_comment, /create, /silent
journal, 'Polarization-angle FITS file created:'
journal, ' file name = ' + file_basename(out_file_name[2])
; add the extension with the quality matrix
; quality matrix
base_header = primary_polangle_header
sxdelpar, base_header, 'SIMPLE'
sxdelpar, base_header, 'EXTEND'
sxdelpar, base_header, 'DATASUM'
sxdelpar, base_header, 'CHECKSUM'
sxdelpar, base_header, 'COMMENT'
sxdelpar, base_header, 'HISTORY'
......@@ -619,26 +655,29 @@ pro metis_l2_prep_vl_polariz
fxaddpar, extension_header, 'COMMENT', ' NaN = saturated or null L0 pixel counts'
fxaddpar, extension_header, 'COMMENT', ' 0 = unreliable pixel value'
fxaddpar, extension_header, 'COMMENT', ' 1 = good pixel'
if not ref_detector then pol_angle_quality_matrix = metis_rectify(quality_matrix, 'VL')
fits_add_checksum, extension_header, float(pol_angle_quality_matrix)
mwrfits, float(pol_angle_quality_matrix), out_file_name[2], extension_header, /no_comment, /silent
; add the extension to the fits file
fits_add_checksum, extension_header, float(quality_matrix)
mwrfits, float(quality_matrix), out_file_name[2], extension_header, /no_comment, /silent
journal, 'Quality-matrix extension correctly added.'
; add the extension with the error matrix
; error matrix
if not ref_detector then pol_angle_error = metis_rectify(pol_angle_error, 'VL')
error_matrix = pol_angle * 0. ; pol_angle * sqrt(pol_angle_error)
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
fxaddpar, extension_header, 'PCOUNT', 0, 'parameter count', before = 'LONGSTRN'
fxaddpar, extension_header, 'GCOUNT', 1, 'group count', before = 'LONGSTRN'
fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'extension name', before = 'LONGSTRN'
fxaddpar, extension_header, 'BTYPE', 'Absolute error'
fxaddpar, extension_header, 'DATAMIN', min(error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(error_matrix, /nan)
fits_add_checksum, extension_header, float(error_matrix)
mwrfits, float(error_matrix), out_file_name[2], extension_header, /no_comment, /silent
fxaddpar, extension_header, 'DATAMIN', min(pol_angle_error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(pol_angle_error_matrix, /nan)
; add the extension to the fits file
fits_add_checksum, extension_header, float(pol_angle_error_matrix)
mwrfits, float(pol_angle_error_matrix), out_file_name[2], extension_header, /no_comment, /silent
journal, 'Error-matrix extension correctly added.'
......@@ -646,7 +685,9 @@ pro metis_l2_prep_vl_polariz
fix_fits_header, out_file_name[2]
; management of stokes images
; ==========================================================================
; stokes parameters
; ==========================================================================
journal, 'Calibrating Stokes parameter I...'
......@@ -669,6 +710,12 @@ pro metis_l2_prep_vl_polariz
u = metis_vignetting(u, header, cal_pack)
u = metis_rad_cal(u, header, cal_pack, /polarimetric)
; make rotations
if not ref_detector then i = metis_rectify(i, 'VL')
if not ref_detector then q = metis_rectify(q, 'VL')
if not ref_detector then u = metis_rectify(u, 'VL')
; keywords specific for stokes images
primary_stokes_header = primary_header
......@@ -689,8 +736,8 @@ pro metis_l2_prep_vl_polariz
for k = 0, n_elements(tb_history) - 1 do fxaddpar, primary_stokes_header, 'HISTORY', tb_history[k]
fxaddpar, primary_stokes_header, 'HISTORY', 'L2 FITS file created on ' + date
; add checksum and datasum to the fits header
if not ref_detector then i = metis_rectify(i, 'VL')
; write the fits file
fits_add_checksum, primary_stokes_header, float(i)
mwrfits, float(i), out_file_name[3], primary_stokes_header, /no_comment, /create, /silent
......@@ -702,8 +749,6 @@ pro metis_l2_prep_vl_polariz
base_header = primary_stokes_header
sxdelpar, base_header, 'SIMPLE'
sxdelpar, base_header, 'EXTEND'
sxdelpar, base_header, 'DATASUM'
sxdelpar, base_header, 'CHECKSUM'
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
......@@ -714,8 +759,9 @@ pro metis_l2_prep_vl_polariz
fxaddpar, extension_header, 'BUNIT', cal_pack.vl_channel.cal_units
fxaddpar, extension_header, 'DATAMIN', min(q, /nan)
fxaddpar, extension_header, 'DATAMAX', max(q, /nan)
sxdelpar, extension_header, 'EXTEND'
if not ref_detector then q = metis_rectify(q, 'VL')
; add the extension to the fits file
fits_add_checksum, extension_header, float(q)
mwrfits, float(q), out_file_name[3], extension_header, /no_comment, /silent
......@@ -732,8 +778,9 @@ pro metis_l2_prep_vl_polariz
fxaddpar, extension_header, 'BUNIT', cal_pack.vl_channel.cal_units
fxaddpar, extension_header, 'DATAMIN', min(u, /nan)
fxaddpar, extension_header, 'DATAMAX', max(u, /nan)
sxdelpar, extension_header, 'EXTEND'
if not ref_detector then u = metis_rectify(u, 'VL')
; add the extension to the fits file
fits_add_checksum, extension_header, float(u)
mwrfits, float(u), out_file_name[3], extension_header, /no_comment, /silent
......@@ -742,7 +789,7 @@ pro metis_l2_prep_vl_polariz
sxdelpar, base_header, 'COMMENT'
sxdelpar, base_header, 'HISTORY'
; add the extension with the quality matrix
; quality matrix
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
......@@ -757,26 +804,29 @@ pro metis_l2_prep_vl_polariz
fxaddpar, extension_header, 'COMMENT', ' NaN = saturated or null L0 pixel counts'
fxaddpar, extension_header, 'COMMENT', ' 0 = unreliable pixel value'
fxaddpar, extension_header, 'COMMENT', ' 1 = good pixel'
if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
; add the extension to the fits file
fits_add_checksum, extension_header, float(quality_matrix)
mwrfits, float(quality_matrix), out_file_name[3], extension_header, /no_comment, /silent
journal, 'Quality-matrix extension correctly added.'
; add the extension with the error matrix
; error matrix
if not ref_detector then error_matrix = metis_rectify(error_matrix, 'VL')
error_matrix = tb_image * 0. ; tb_image * sqrt(tb_error)
extension_header = base_header
fxaddpar, extension_header, 'XTENSION', 'IMAGE', 'image extension', before = 'BITPIX'
fxaddpar, extension_header, 'PCOUNT', 0, 'parameter count', before = 'LONGSTRN'
fxaddpar, extension_header, 'GCOUNT', 1, 'group count', before = 'LONGSTRN'
fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'extension name', before = 'LONGSTRN'
fxaddpar, extension_header, 'BTYPE', 'Absolute error'
fxaddpar, extension_header, 'DATAMIN', min(error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(error_matrix, /nan)
fits_add_checksum, extension_header, float(error_matrix)
mwrfits, float(error_matrix), out_file_name[3], extension_header, /no_comment, /silent
fxaddpar, extension_header, 'DATAMIN', min(tb_error_matrix, /nan)
fxaddpar, extension_header, 'DATAMAX', max(tb_error_matrix, /nan)
; add the extension to the fits file
fits_add_checksum, extension_header, float(tb_error_matrix)
mwrfits, float(tb_error_matrix), out_file_name[3], extension_header, /no_comment, /silent
journal, 'Error-matrix extension correctly added.'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment