Skip to content

Commit

Permalink
Added automatic check for energy shift (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
grazwegian committed Aug 4, 2022
1 parent 095d229 commit dea0622
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
50 changes: 50 additions & 0 deletions stix/idl/processing/spectrogram/stx_check_energy_shift.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
;---------------------------------------------------------------------------
;+
; :project:
; STIX
;
; :name:
; stx_check_energy_shift
;
; :description:
;
; This function checks the time of the observation and returns an average energy
; shift if required.
;
; When STIX was switched on during the RSCW of November 2020 the detector settings
; resulted in a shift of energy calibration. For the duration of this RSCW until the
; upload of an ELUT which accounts for this a shift of the energy science channel
; boundaries is needed.
;
; :categories:
; spectroscopy, io
;
; :params:
; start_time : in, required, type="string"
; The start time of the observation being analysed
; :returns:
; expected_energy_shift: the expected energy shift that should be applied in keV
;
; :examples:
; expected_energy_shift = stx_check_energy_shift('2020-11-18T00:00:00')
;
; :history:
; 21-Jul-2022 - ECMD (Graz), initial release
;
;-
function stx_check_energy_shift, start_time

; If time range of observation is during Nov 2020 RSCW apply average energy shift of -1.6 keV by default
expected_energy_shift = (anytim(start_time) gt anytim('2020-11-15T00:00:00') $
and anytim(start_time) lt anytim('2021-12-04T00:00:00')) $
? -1.6 : 0

if expected_energy_shift ne 0 then begin
print, '***********************************************************************'
print, 'Warning: Due to the energy calibration in the selected observation time'
print, 'a shift of -1.6 keV has been applied to all science energy bins.'
print, '************************************************************************'
endif

return, expected_energy_shift
end
1 change: 0 additions & 1 deletion stix/idl/processing/spectrogram/stx_convert_pixel_data.pro
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pro stx_convert_pixel_data, fits_path_data = fits_path_data, fits_path_bk = fit
distance = 1.
endif

default, energy_shift, 0.
default, flare_location, [0.,0.]
default, shift_duration, 0
default, plot, 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pro stx_convert_spectrogram, fits_path_data = fits_path_data, fits_path_bk = fi
distance = 1.
endif

default, energy_shift, 0.
default, flare_location, [0.,0.]
default, plot, 1

Expand Down
16 changes: 10 additions & 6 deletions stix/idl/processing/spectrogram/stx_read_pixel_data_fits_file.pro
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@
; 25-Jan-2021 - ECMD (Graz), initial release
; 19-Jan-2022 - Andrea (FHNW), Added the correction of the duration time array when reading the L1 FITS files for OSPEX
; 22-Feb-2022 - ECMD (Graz), documented, improved handling of alpha and non-alpha files, altered duration shift calculation
; 28-Feb-2022 - ECMD (Graz), fixed issue reading sting rcr values for level 1 files
; 28-Feb-2022 - ECMD (Graz), fixed issue reading sting rcr values for level 1 files
; 05-Jul-2022 - ECMD (Graz), fixed handling of L1 files which don't contain the full set of energy, detector and pixel combinations
;
; 21-Jul-2022 - ECMD (Graz), added automatic check for energy shift
;
;-
pro stx_read_pixel_data_fits_file, fits_path, time_shift, alpha = alpha, primary_header = primary_header, data_str = data, data_header = data_header, control_str = control, $
control_header= control_header, energy_str = energy, energy_header = energy_header, t_axis = t_axis, e_axis = e_axis, $
energy_shift = energy_shift, use_discriminators = use_discriminators, shift_duration = shift_duration

default, alpha, 0
default, time_shift, 0
default, energy_shift, 0
default, use_discriminators, 1

!null = stx_read_fits(fits_path, 0, primary_header, mversion_full = mversion_full)
Expand Down Expand Up @@ -146,13 +146,13 @@ pro stx_read_pixel_data_fits_file, fits_path, time_shift, alpha = alpha, primary


if ~keyword_set(alpha) then begin

rcr = ((data.rcr).typecode) eq 7 ? fix(strmid(data.rcr,0,1,/reverse_offset)) : (data.rcr)
data = rep_tag_value(data, rcr, 'RCR')

detectors_used = where( (data.detector_masks)[*,0] eq 1, ndets)
pixels_used = where( total((data.pixel_masks)[*,*,0],1) eq 1, npix)

full_counts = dblarr(32, 12, 32, n_times)
full_counts[energies_used, pixels_used, detectors_used, *] = counts
counts = full_counts
Expand All @@ -164,7 +164,7 @@ pro stx_read_pixel_data_fits_file, fits_path, time_shift, alpha = alpha, primary
endif else begin
rcr = data.rcr
endelse


if control.energy_bin_mask[0] || control.energy_bin_mask[-1] and ~keyword_set(use_discriminators) then begin

Expand Down Expand Up @@ -206,6 +206,10 @@ pro stx_read_pixel_data_fits_file, fits_path, time_shift, alpha = alpha, primary
t_axis.time_end = t_end
t_axis.duration = duration

; If time range of observation is during Nov 2020 RSCW apply average energy shift by default
expected_energy_shift = stx_check_energy_shift(hstart_time)
default, energy_shift, expected_energy_shift

energies_used = where( control.energy_bin_mask eq 1, nenergies)
energy_edges_2 = transpose([[energy[energies_used].e_low], [energy[energies_used].e_high]])
edge_products, energy_edges_2, edges_1 = energy_edges_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@
; 18-Jun-2021 - ECMD (Graz), initial release
; 22-Feb-2022 - ECMD (Graz), documented, improved handling of alpha and non-alpha files, fixed duration shift issue
; 05-Jul-2022 - ECMD (Graz), fixed handling of L1 files which don't contain the full set of energies
;
; 21-Jul-2022 - ECMD (Graz), added automatic check for energy shift
;
;-
pro stx_read_spectrogram_fits_file, fits_path, time_shift, primary_header = primary_header, data_str = data, data_header = data_header, control_str = control, $
control_header= control_header, energy_str = energy, energy_header = energy_header, t_axis = t_axis, e_axis = e_axis, $
energy_shift = energy_shift, use_discriminators = use_discriminators, keep_short_bins = keep_short_bins, replace_doubles = replace_doubles, $
shift_duration = shift_duration

default, time_shift, 0
default, energy_shift, 0
default, use_discriminators, 1
default, replace_doubles, 0
default, keep_short_bins, 1
Expand All @@ -102,7 +102,6 @@ pro stx_read_spectrogram_fits_file, fits_path, time_shift, primary_header = prim

hstart_time = alpha ? (sxpar(primary_header, 'date_beg')) : (sxpar(primary_header, 'date-beg'))


trigger_zero = (sxpar(data_header, 'TZERO3'))
new_triggers = float(trigger_zero +data.triggers)
data = rep_tag_value(data, 'TRIGGERS', new_triggers)
Expand All @@ -119,6 +118,10 @@ pro stx_read_spectrogram_fits_file, fits_path, time_shift, primary_header = prim
duration_shift_needed = (anytim(hstart_time) lt anytim('2021-12-09T00:00:00')) ? 1 : 0
default, shift_duration, duration_shift_needed

; If time range of observation is during Nov 2020 RSCW apply average energy shift by default
expected_energy_shift = stx_check_energy_shift(hstart_time)
default, energy_shift, expected_energy_shift

if ~keyword_set(keep_short_bins) and (anytim(hstart_time) lt anytim('2020-11-25T00:00:00') ) then $
message, 'Automatic short bin removal should not be attempted on observations before 25-Nov-20'

Expand Down

0 comments on commit dea0622

Please sign in to comment.