Commit 5f6290e3 authored by Roberto Susino's avatar Roberto Susino
Browse files

Manage processing of temp.-noise and CR-log mat.

parent ae959234
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -80,15 +80,22 @@ pro metis_l2_prep_uv
		; history = [history, '  additional cal. factor from stars = 3.4']
		; ====================================
		
		if not ref_detector then data = metis_rectify(data, header.filter)
		btype = 'UV Lyman-alpha intensity'
		bunit = cal_pack.uv_channel.cal_units
	endif

	if header.datatype eq 4 then begin
		; calibration of temporal noise images
		btype = 'UV temporal standard deviation'
		bunit = 'DN'
		history = !null
	endif

	if header.datatype eq 6 then begin
		; calibration of cr/sep log matrices
		btype = 'UV cosmic-ray matrix'
		bunit = 'DN'
		history = !null
	endif

	; definitions for the primary header
@@ -115,8 +122,8 @@ pro metis_l2_prep_uv
	fxaddpar, primary_header, 'CREATOR', 'metis_l2_prep_uv.pro'
	fxaddpar, primary_header, 'VERS_SW', input.sw_version
	fxaddpar, primary_header, 'VERS_CAL', cal_pack.version, after = 'VERS_SW'
	fxaddpar, primary_header, 'BTYPE', 'UV Lyman-alpha intensity'
	fxaddpar, primary_header, 'BUNIT', cal_pack.uv_channel.cal_units
	fxaddpar, primary_header, 'BTYPE', btype
	fxaddpar, primary_header, 'BUNIT', bunit
	fxaddpar, primary_header, 'DATAMIN', min(data, /nan)
	fxaddpar, primary_header, 'DATAMAX', max(data, /nan)
	fxaddpar, primary_header, 'XPOSURE', header.xposure
@@ -140,7 +147,8 @@ pro metis_l2_prep_uv

	; add the history keyword

	for k = 0, n_elements(history) - 1 do fxaddpar, primary_header, 'HISTORY', history[k]
	for k = 0, n_elements(history) - 1 do $
	fxaddpar, primary_header, 'HISTORY', history[k]
	fxaddpar, primary_header, 'HISTORY', 'L2 FITS file created on ' + date

	; add checksum and datasum to the fits header
@@ -149,29 +157,36 @@ pro metis_l2_prep_uv

	; add keywords for file history

	data = float(data)
	if not ref_detector then data = metis_rectify(data, 'UV')
	fits_add_checksum, primary_header, data
	mwrfits, data, out_file_name, primary_header, /no_comment, /create, /silent

	; add the extension with the quality matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'Extension name'
	if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'UV')
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the error matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'Extension name'
	fits_add_checksum, extension_header, intarr(header.naxis1, header.naxis2)
	mwrfits, intarr(header.naxis1, header.naxis2), out_file_name, extension_header, /no_comment, /silent
	error_matrix = intarr(header.naxis1, header.naxis2)
	if not ref_detector then error_matrix = metis_rectify(error_matrix, 'UV')
	fits_add_checksum, extension_header, error_matrix
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	; write the auxiliary information file

	output = { $
		file_name: out_file_name, $
		l2_file_name: input.file_name, $
		l1_file_name: input.file_name, $
		log_file_name: 'output/metis_l2_prep_log.txt' $
	}

+31 −21
Original line number Diff line number Diff line
@@ -65,19 +65,31 @@ pro metis_l2_prep_vl_generic

		data = metis_flat_field(data, header, cal_pack, history = history)
		data = metis_vignetting(data, header, cal_pack, history = history)
		data = metis_rad_cal(data, header, cal_pack, history = history)

		if header.pol_id ge 1 and header.pol_id le 4 then polarimetric = 1 else polarimetric = 0
		data = metis_rad_cal(data, header, cal_pack, polarimetric = polarimetric, history = history)
		if header.pol_id eq 0 then begin
			btype = 'VL fixed-polarization intensity'
		endif else if header.pol_id ge 1 and header.pol_id le 4 then begin
			btype = 'VL fixed-polarization intensity'
		endif else begin
			btype = 'VL total brightness'
		endelse
		
		if not ref_detector then data = rotate(data, 1)
		bunit = cal_pack.vl_channel.cal_units
	endif

	if header.datatype eq 3 then begin
		; calibration of temporal noise images
		btype = 'VL temporal standard deviation'
		bunit = 'DN'
		history = !null
	endif

	if header.datatype eq 5 then begin
		; calibration of cr/sep log matrices
		btype = 'VL cosmic-ray matrix'
		bunit = 'DN'
		history = !null
	endif

	; definitions for the primary header
@@ -104,16 +116,8 @@ pro metis_l2_prep_vl_generic
	fxaddpar, primary_header, 'CREATOR', 'metis_l2_prep_vl_generic.pro'
	fxaddpar, primary_header, 'VERS_SW', input.sw_version
	fxaddpar, primary_header, 'VERS_CAL', cal_pack.version, after = 'VERS_SW'
	case header.pol_id of
		0: fxaddpar, primary_header, 'BTYPE', 'VL fixed-polarization intensity'
		1: fxaddpar, primary_header, 'BTYPE', 'VL fixed-polarization intensity'
		2: fxaddpar, primary_header, 'BTYPE', 'VL fixed-polarization intensity'
		3: fxaddpar, primary_header, 'BTYPE', 'VL fixed-polarization intensity'
		4: fxaddpar, primary_header, 'BTYPE', 'VL fixed-polarization intensity'
		5: fxaddpar, primary_header, 'BTYPE', 'VL total brightness'
		6: fxaddpar, primary_header, 'BTYPE', 'VL total brightness'
	endcase
	fxaddpar, primary_header, 'BUNIT', cal_pack.vl_channel.cal_units
	fxaddpar, primary_header, 'BTYPE', btype
	fxaddpar, primary_header, 'BUNIT', bunit
	fxaddpar, primary_header, 'DATAMIN', min(data, /nan)
	fxaddpar, primary_header, 'DATAMAX', max(data, /nan)
	fxaddpar, primary_header, 'XPOSURE', header.xposure
@@ -122,7 +126,6 @@ pro metis_l2_prep_vl_generic
	; append wcs keywords

	wcs = metis_wcs(header, cal_pack, ref_detector = ref_detector)

	foreach element, wcs do fxaddpar, primary_header, element.name, element.value, element.comment, before = 'DATATYPE'

	; append solar ephemeris keywords
@@ -138,35 +141,42 @@ pro metis_l2_prep_vl_generic

	; add the history keyword

	for k = 0, n_elements(history) - 1 do fxaddpar, primary_header, 'HISTORY', history[k]

	for k = 0, n_elements(history) - 1 do $
	fxaddpar, primary_header, 'HISTORY', history[k]
	fxaddpar, primary_header, 'HISTORY', 'L2 FITS file created on ' + date

	; add checksum and datasum to the fits header

	data = float(data)
	if not ref_detector then data = metis_rectify(data, 'VL')
	fits_add_checksum, primary_header, data
	mwrfits, data, out_file_name, primary_header, /no_comment, /create, /silent

	; add the extension with the quality matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'Extension name'
	if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the error matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'Extension name'
	error_matrix = intarr(header.naxis1, header.naxis2)
	if not ref_detector then data = metis_rectify(error_matrix, 'VL')
	fits_add_checksum, extension_header, intarr(header.naxis1, header.naxis2)
	mwrfits, intarr(header.naxis1, header.naxis2), out_file_name, extension_header, /no_comment, /silent
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	; write the auxiliary information file

	output = { $
		file_name: out_file_name, $
		l2_file_name: input.file_name, $
		l1_file_name: input.file_name, $
		log_file_name: 'output/metis_l2_prep_log.txt' $
	}

+58 −33
Original line number Diff line number Diff line
@@ -188,8 +188,6 @@ pro metis_l2_prep_vl_polariz
	tb_image = metis_vignetting(tb_image, header, cal_pack, history = tb_history)
	tb_image = metis_rad_cal(tb_image, header, cal_pack, /polarimetric, history = tb_history)

	if not ref_detector then tb_image = rotate(tb_image, 1)

	; compute the pb from the stokes q and u and apply other calibrations

	pb_image = sqrt(reform(stokes[*, *, 1])^2 + reform(stokes[*, *, 2])^2)
@@ -197,14 +195,10 @@ pro metis_l2_prep_vl_polariz
	pb_image = metis_vignetting(pb_image, header, cal_pack, history = pb_history)
	pb_image = metis_rad_cal(pb_image, header, cal_pack, /polarimetric, history = pb_history)

	if not ref_detector then pb_image = rotate(pb_image, 1)

	; compute the polarization angle from the stokes q and u

	pol_angle = 0.5d0 * atan(stokes[*, *, 2], stokes[*, *, 1]) * !radeg

	if not ref_detector then pol_angle = rotate(pol_angle, 1)

	; definitions for the primary header
	; version of the fits file

@@ -238,7 +232,6 @@ pro metis_l2_prep_vl_polariz
	; append wcs keywords

	wcs = metis_wcs(header, cal_pack, ref_detector = ref_detector)

	foreach element, wcs do fxaddpar, primary_header, element.name, element.value, element.comment, before = 'DATATYPE'

	; append solar ephemeris keywords
@@ -291,29 +284,36 @@ pro metis_l2_prep_vl_polariz

	; add the history keyword

	for k = 0, n_elements(pb_history) - 1 do fxaddpar, primary_pb_header, 'HISTORY', pb_history[k]

	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

	if not ref_detector then pb_image = metis_rectify(pb_image, 'VL')
	fits_add_checksum, primary_pb_header, pb_image

	mwrfits, pb_image, out_file_name, primary_pb_header, /no_comment, /create, /silent

	; add the extension with the quality matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'Extension name'
	if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the error matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'Extension name'
	fits_add_checksum, extension_header, intarr(header.naxis1, header.naxis2)
	mwrfits, intarr(header.naxis1, header.naxis2), out_file_name, extension_header, /no_comment, /silent
	error_matrix = intarr(header.naxis1, header.naxis2)
	if not ref_detector then error_matrix = metis_rectify(error_matrix, 'VL')
	fits_add_checksum, extension_header, error_matrix
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	; keywords specific for total brightness images

@@ -333,29 +333,36 @@ pro metis_l2_prep_vl_polariz

	; add the history keyword

	for k = 0, n_elements(tb_history) - 1 do fxaddpar, primary_tb_header, 'HISTORY', tb_history[k]

	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

	if not ref_detector then tb_image = metis_rectify(tb_image, 'VL')
	fits_add_checksum, primary_tb_header, tb_image

	mwrfits, tb_image, out_file_name, primary_tb_header, /no_comment, /create, /silent

	; add the extension with the quality matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'Extension name'
	if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the error matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'Extension name'
	fits_add_checksum, extension_header, intarr(header.naxis1, header.naxis2)
	mwrfits, intarr(header.naxis1, header.naxis2), out_file_name, extension_header, /no_comment, /silent
	error_matrix = intarr(header.naxis1, header.naxis2)
	if not ref_detector then error_matrix = metis_rectify(error_matrix, 'VL')
	fits_add_checksum, extension_header, error_matrix
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	; keywords specific for polarization-angle images

@@ -375,49 +382,53 @@ pro metis_l2_prep_vl_polariz

	; add the history keyword

	for k = 0, n_elements(pb_history) - 1 do fxaddpar, primary_polangle_header, 'HISTORY', pb_history[k]

	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

	if not ref_detector then pol_angle = metis_rectify(pol_angle, 'VL')
	fits_add_checksum, primary_polangle_header, pol_angle

	mwrfits, pol_angle, out_file_name, primary_polangle_header, /no_comment, /create, /silent

	; add the extension with the quality matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'Extension name'
	if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the error matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'Extension name'
	fits_add_checksum, extension_header, intarr(header.naxis1, header.naxis2)
	mwrfits, intarr(header.naxis1, header.naxis2), out_file_name, extension_header, /no_comment, /silent
	error_matrix = intarr(header.naxis1, header.naxis2)
	if not ref_detector then error_matrix = metis_rectify(error_matrix, 'VL')
	fits_add_checksum, extension_header, error_matrix
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	; =================== STOKES PARAMETERS ======================
	; management of stokes images

	i = reform(stokes_subdark[*, *, 0])
	i = metis_flat_field(i, header, cal_pack)
	i = metis_vignetting(i, header, cal_pack)
	i = metis_rad_cal(i, header, cal_pack, /polarimetric)
	if not ref_detector then i = rotate(i, 1)

	q = reform(stokes[*, *, 1])
	q = metis_flat_field(q, header, cal_pack)
	q = metis_vignetting(q, header, cal_pack)
	q = metis_rad_cal(q, header, cal_pack, /polarimetric)
	if not ref_detector then q = rotate(q, 1)

	u = reform(stokes[*, *, 2])
	u = metis_flat_field(u, header, cal_pack)
	u = metis_vignetting(u, header, cal_pack)
	u = metis_rad_cal(u, header, cal_pack, /polarimetric)
	if not ref_detector then u = rotate(u, 1)

	; keywords specific for stokes images

@@ -437,15 +448,17 @@ pro metis_l2_prep_vl_polariz

	; add the history keyword

	for k = 0, n_elements(tb_history) - 1 do fxaddpar, primary_stokes_header, 'HISTORY', tb_history[k]

	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')
	fits_add_checksum, primary_stokes_header, i
	mwrfits, i, out_file_name, primary_stokes_header, /no_comment, /create, /silent

	; add the extension with the stokes q image

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
@@ -454,9 +467,12 @@ 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)
	if not ref_detector then q = metis_rectify(q, 'VL')
	fits_add_checksum, extension_header, q
	mwrfits, q, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the stokes u image

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
@@ -465,27 +481,36 @@ 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)
	if not ref_detector then u = metis_rectify(u, 'VL')
	fits_add_checksum, extension_header, u
	mwrfits, u, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the quality matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Quality matrix', 'Extension name'
	if not ref_detector then quality_matrix = metis_rectify(quality_matrix, 'VL')
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	; add the extension with the error matrix

	extension_header = !null
	fxaddpar, extension_header, 'PCOUNT', 0, 'Parameter count'
	fxaddpar, extension_header, 'GCOUNT', 1, 'Group count'
	fxaddpar, extension_header, 'EXTNAME', 'Error matrix', 'Extension name'
	mwrfits, intarr(header.naxis1, header.naxis2), out_file_name, extension_header, /no_comment, /silent
	error_matrix = intarr(header.naxis1, header.naxis2)
	if not ref_detector then error_matrix = metis_rectify(error_matrix, 'VL')
	fits_add_checksum, extension_header, error_matrix
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	; write the auxiliary information file

	output = { $
		file_name: out_file_name, $
		l2_file_name: input.file_name, $
		l1_file_name: input.file_name, $
		log_file_name: 'output/metis_l2_prep_log.txt' $
	}

+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ function metis_rad_cal, data, header, cal_pack, polarimetric = polarimetric, his

		; NOTE - this is to take into account that calibration of polarimetric images or their combination, must not include the pmp efficiency (0.5) since this is included in the demodulation formulae

		if keyword_set(polarimetric) then pmp_factor = 2.d0 else pmp_factor = 1.d0
		if keyword_set(polarimetric) then pmp_factor = 2.D0 else pmp_factor = 1.D0

		angular_pixel = cal_pack.vl_channel.angular_pixel.value * header.nbin
		rad_info = cal_pack.vl_channel.radiometry[0]
@@ -16,7 +16,7 @@ function metis_rad_cal, data, header, cal_pack, polarimetric = polarimetric, his
		angular_pixel = cal_pack.uv_channel.angular_pixel.value * header.nbin
		rad_info = cal_pack.uv_channel.radiometry[0]
		units = cal_pack.uv_channel.cal_units
		pmp_factor = 1.d0
		pmp_factor = 1.D0
		unit_factor = 1.
	endif