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

Add management of errors

parent 84140d2e
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -45,9 +45,9 @@ function metis_dark_uvda, data, header, cal_pack, history = history
	endfor

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

		goto, jump
		journal, 'Error 12: UV applicable dark file not found.'
		journal
		exit, status = 12
	endif

	delta_obt = min(abs(obt_beg - obt_available), j)
@@ -78,7 +78,15 @@ function metis_dark_uvda, data, header, cal_pack, history = history
	jump:

	if ~ isa(history) then history = !null
	history = [history, 'Dark correction: ', '  ' + dark_file]
	history = [history, 'Dark-current correction: ', '  ' + dark_file]

	journal, 'Dark-current correction:'
	journal, '  dit = ' + string(dit, format = '(F0)') + ' s'
	journal, '  ndit1 = ' + string(ndit1, format = '(I0)')
	journal, '  ndit2 = ' + string(ndit2, format = '(I0)')
	journal, '  obj_cnt = ' + string(obj_cnt, format = '(I0)')
	journal, '  tsensor = ' + string(tsensor, format = '(F0)') + ' degC'
	journal, '  dark file = ' + dark_file

	return, data
end
+14 −5
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ function metis_dark_vlda, data, header, cal_pack, history = history

	dit = header.dit/1000.D0
	ndit = header.ndit
	xposure = dit * ndit
	nbin = sqrt(header.nbin)
	tsensor = header.tsensor
	obt_beg = header.obt_beg/1000.D0 ; check why obt_beg must be divided by 1000.
@@ -38,8 +39,9 @@ function metis_dark_vlda, data, header, cal_pack, history = history
		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'
		journal, 'Error 02: VL applicable bias file not found.'
		journal
		exit, status = 2
	endelse

	dark_obt_available = !null
@@ -53,15 +55,16 @@ function metis_dark_vlda, data, header, cal_pack, history = history
		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']
		journal, 'Error 03: VL applicable dark file not found.'
		journal
		exit, status = 3
	endelse

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

	mask = where(data eq 0.)
	data = data - (bias_image * ndit + header.xposure * dark_image)
	data = data - (bias_image * ndit + dark_image * xposure)
	data[mask] = 0.

	jump:
@@ -69,5 +72,11 @@ function metis_dark_vlda, data, header, cal_pack, history = history
	if ~ isa(history) then history = !null
	history = [history, 'Bias and dark-current corrections: ', '  ' + dark_file]

	journal, 'Bias and dark-current correction:'
	journal, '  dit = ' + string(dit, format = '(F0)') + ' s'
	journal, '  ndit = ' + string(ndit, format = '(I0)')
	journal, '  xposure = ' + string(xposure, format = '(F0)') + ' s'
	journal, '  tsensor = ' + string(tsensor, format = '(F0)') + ' degC'
	journal, '  bias/dark file = ' + dark_file
	return, data
end
+6 −0
Original line number Diff line number Diff line
function metis_flat_field, data, header, cal_pack, history = history

	journal, 'Flat-field correction:'

	if header.filter.contains('VL', /fold) then begin
		ff_info = cal_pack.vl_channel.flat_field

@@ -9,6 +11,8 @@ function metis_flat_field, data, header, cal_pack, history = history
		first_row = header.ref_rows eq 'Included' ? 2 : 0
		detector_size = cal_pack.vl_channel.detector_size.value
		ff_image = ff_image[*, first_row : first_row + detector_size - 1]

		journal, '  VL ref. rows = ' + header.ref_rows.tolower()
	endif

	if header.filter.contains('UV', /fold) then begin
@@ -30,5 +34,7 @@ function metis_flat_field, data, header, cal_pack, history = history
	if ~ isa(history) then history = !null
	history = [history, 'Flat-field correction: ', '  ' + ff_file]

	journal, '  flat-field file = ' + ff_file

	return, data
end
+38 −14
Original line number Diff line number Diff line
@@ -12,10 +12,15 @@ pro metis_l2_prep_uv

	input = json_parse('input/contents.json', /toarray, /tostruct)

	journal, 'File ' + file_basename(input.file_name)

	; load the spice kernels

	load_spice_kernels, input.spice_kernels, kernel_list = kernel_list, kernel_version = kernel_version

	journal, 'SPICE kernel files correctly loaded:'
	journal, '  SDK version= ' + kernel_version

	; read the calibration package index

	cal_pack = json_parse(input.cal_pack_path + '/index.json', /toarray, /tostruct)
@@ -24,6 +29,10 @@ pro metis_l2_prep_uv

	cal_pack = create_struct('path', input.cal_pack_path + path_sep(), cal_pack)

	journal, 'Calibration package correctly imported:'
	journal, '  version = ' + cal_pack.version
	journal, '  validity range = ' + string(cal_pack.validity_range.start, cal_pack.validity_range._end, format = '(A, "-", A)')

	; read the primary hdu

	data = mrdfits(input.file_name, 0, primary_header, /silent)
@@ -36,13 +45,15 @@ pro metis_l2_prep_uv

	header = fits_hdr2struct(primary_header)

	; read the house-keeping extension

	hk_table = mrdfits(input.file_name, 'house-keeping', hk_extension_header, /silent)
	journal, 'L1 FITS file correctly read:'
	journal, '  datatype = ' + string(header.datatype, format = '(I0)')
	journal, '  sess_num = ' + header.sess_num
	journal, '  nbin = ' + string(sqrt(header.nbin), format = '(I0)')

	; calibration block

	if header.datatype eq 1 then begin
	case header.datatype of
	1 : begin
		data = double(data)

		; ====================================
@@ -82,21 +93,28 @@ pro metis_l2_prep_uv
		
		btype = 'UV Lyman-alpha intensity'
		bunit = cal_pack.uv_channel.cal_units
	endif
	end

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

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

	else : begin
		journal, 'Error 11: wrong input data product (expected data types 1, 4, or 6).'
		journal
		exit, status = 11
	end
	endcase

	; definitions for the primary header
	; version of the fits file
@@ -162,6 +180,9 @@ pro metis_l2_prep_uv
	fits_add_checksum, primary_header, data
	mwrfits, 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

	extension_header = !null
@@ -172,6 +193,8 @@ pro metis_l2_prep_uv
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	journal, 'Quality-matrix extension correctly added.'

	; add the extension with the error matrix

	extension_header = !null
@@ -183,6 +206,8 @@ pro metis_l2_prep_uv
	fits_add_checksum, extension_header, error_matrix
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	journal, 'Error-matrix extension correctly added.'

	; write the auxiliary information file

	output = { $
@@ -197,13 +222,12 @@ pro metis_l2_prep_uv

	load_spice_kernels, kernel_list = kernel_list, /unload

	journal, 'SPICE kernel files unloaded.'

	; close the log

	journal, 'Exiting without errors.'
	journal
	exit, status = 0
	
	error_handling:
	journal, 'Errors occurred while processing.'
	journal
	exit, status = 1
	exit, status = 0
end
+40 −15
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ pro metis_l2_prep_vl_generic

	load_spice_kernels, input.spice_kernels, kernel_list = kernel_list, kernel_version = kernel_version

	journal, 'SPICE kernel files correctly loaded:'
	journal, '  SDK version= ' + kernel_version

	; read the calibration package

	cal_pack = json_parse(input.cal_pack_path + '/index.json', /toarray, /tostruct)
@@ -24,6 +27,10 @@ pro metis_l2_prep_vl_generic

	cal_pack = create_struct('path', input.cal_pack_path + path_sep(), cal_pack)

	journal, 'Calibration package correctly imported:'
	journal, '  version = ' + cal_pack.version
	journal, '  validity range = ' + string(cal_pack.validity_range.start, cal_pack.validity_range._end, format = '(A, "-", A)')

	; read the primary hdu

	data = mrdfits(input.file_name, 0, primary_header, /silent)
@@ -36,13 +43,18 @@ pro metis_l2_prep_vl_generic

	header = fits_hdr2struct(primary_header)

	; read the house-keeping extension

	hk_table = mrdfits(input.file_name, 'house-keeping', hk_extension_header, /silent)
	journal, 'L1 FITS file correctly read:'
	journal, '  filename = ' + file_basename(input.file_name)
	journal, '  datatype = ' + string(header.datatype, format = '(I0)')
	journal, '  sess_num = ' + header.sess_num
	journal, '  seq_num = ' + string(header.seq_num, format = '(I0)')
	journal, '  pol_id = ' + string(header.pol_id, format = '(I0)')
	journal, '  nbin = ' + string(sqrt(header.nbin), format = '(I0)')

	; calibration block

	if header.datatype eq 0 then begin
	case header.datatype of
	0 : begin
		data = double(data)

		; ====================================
@@ -76,21 +88,28 @@ pro metis_l2_prep_vl_generic
		endelse
		
		bunit = cal_pack.vl_channel.cal_units
	endif
	end

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

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

	else : begin
		journal, 'Error 01: wrong input data product (expected data types 0, 3, or 5).'
		journal
		exit, status = 1
	end
	endcase

	; definitions for the primary header
	; version of the fits file
@@ -152,6 +171,9 @@ pro metis_l2_prep_vl_generic
	fits_add_checksum, primary_header, data
	mwrfits, 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

	extension_header = !null
@@ -162,6 +184,8 @@ pro metis_l2_prep_vl_generic
	fits_add_checksum, extension_header, quality_matrix
	mwrfits, quality_matrix, out_file_name, extension_header, /no_comment, /silent

	journal, 'Quality-matrix extension correctly added.'

	; add the extension with the error matrix

	extension_header = !null
@@ -173,6 +197,8 @@ pro metis_l2_prep_vl_generic
	fits_add_checksum, extension_header, intarr(header.naxis1, header.naxis2)
	mwrfits, error_matrix, out_file_name, extension_header, /no_comment, /silent

	journal, 'Error-matrix extension correctly added.'

	; write the auxiliary information file

	output = { $
@@ -187,13 +213,12 @@ pro metis_l2_prep_vl_generic

	load_spice_kernels, kernel_list = kernel_list, /unload

	journal, 'SPICE kernel files unloaded.'

	; close the log

	journal, 'Exiting without errors.'
	journal
	exit, status = 0
	
	error_handling:
	journal, 'Errors occurred while processing.', /continue
	journal
	exit, status = 1
	exit, status = 0
end
 No newline at end of file
Loading