Skip to content

Commit

Permalink
Deal with case when time range runs over two consecutive days (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
FredSchuller committed Oct 13, 2023
1 parent 367bf44 commit c134e39
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 12 additions & 2 deletions stix/idl/processing/aux_data/stx_create_auxiliary_data.pro
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
; 2022-09-23, FSc: keyword 'silent' added; if not set, now displays messages about the pointing correction used
; 2022-09-28, FSc: displays a warning if dispersion in pointing > 3 arcsec
; 2023-05-25, A. F. Battaglia (FHNW, Switzerland): added a few keywords for returing header informations of the FITS file
; 2023-10-06, FSc (AIP): also allow input fits_path to be a list of (two) strings, to deal with cases where a change of day
; in the time range requires to read two files
;-
function stx_create_auxiliary_data, fits_path, time_range, force_sas=force_sas, no_sas=no_sas, silent=silent, $
primary_header = primary_header, data_header = data_header, control_header= control_header, idb_version_header = idb_version_header
Expand All @@ -48,8 +50,15 @@ function stx_create_auxiliary_data, fits_path, time_range, force_sas=force_sas,
if keyword_set(force_sas) and keyword_set(no_sas) then $
message, 'WARNING: keywords force_sas and no_sas both set, will not use SAS.', /info, /cont

stx_read_aux_fits, fits_path, aux_data=aux_data_str, primary_header = primary_header, data_header = data_header, $
control_header= control_header, idb_version_header = idb_version_header
n_files = n_elements(fits_path)
if n_files eq 2 then begin
stx_read_aux_fits, fits_path[0], aux_data=aux_data_str_1, primary_header = primary_header, data_header = data_header, $
control_header= control_header, idb_version_header = idb_version_header
stx_read_aux_fits, fits_path[1], aux_data=aux_data_str_2, primary_header = primary_header, data_header = data_header, $
control_header= control_header, idb_version_header = idb_version_header
aux_data_str = [aux_data_str_1, aux_data_str_2]
endif else stx_read_aux_fits, fits_path, aux_data=aux_data_str, primary_header = primary_header, data_header = data_header, $
control_header= control_header, idb_version_header = idb_version_header

;************** Get the indices corresponding to the considered time range
this_time_range = anytim(time_range)
Expand All @@ -62,6 +71,7 @@ if this_time_range[1] lt min(time_data) or $
message, "The aux fits file does not contain information for the considered time range."

time_ind = where((time_data ge this_time_range[0]) and (time_data le this_time_range[1]), nb_within)

; if time range is too short to contain any measurement, interpolate between nearest values
if ~nb_within then begin
if ~silent then print, " + STX_CREATE_AUXILIARY_DATA : no measurement found, doing interpolation."
Expand Down
22 changes: 17 additions & 5 deletions stix/idl/processing/imaging/stx_imaging_pipeline.pro
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function stx_imaging_pipeline, stix_uid, time_range, energy_range, bkg_uid=bkg_u

; Input directories - TO BE ADAPTED depending on local installation - FIX ME!
aux_data_folder = '/net/galilei/store/data/STIX/L2_FITS_AUX/'
; l1a_data_folder = '/store/data/STIX/L1A_FITS/L1/'
l1a_data_folder = '/net/galilei/store/data/STIX/L1_FITS_SCI/'

default, imsize, [128, 128]
Expand All @@ -61,16 +60,30 @@ function stx_imaging_pipeline, stix_uid, time_range, energy_range, bkg_uid=bkg_u
;;;;

; Extract pointing and other ancillary data from auxiliary file covering the input time_range.
; First, find out the date from time_range[0]
; FIX-ME (issue #162): special case when time range runs over two consecutive days
; First, find out the starting date from time_range[0]:
time_0 = anytim2utc(anytim(time_range[0], /tai), /ccsds)
day_0 = strmid(str_replace(time_0,'-'),0,8)

aux_fits_file = aux_data_folder + 'solo_L2_stix-aux-ephemeris_'+day_0+'*.fits'
aux_file_list = file_search(aux_fits_file, count=nb_aux)
if nb_aux gt 0 then begin
aux_fits_file = aux_file_list[-1] ; this should be the highest version, since FILE_SEARCH sorts the list of files returned
print, " STX_IMAGING_PIPELINE - INFO: Found AUX file " + aux_fits_file
endif else message,"Cannot find auxiliary data file " + aux_fits_file

; Check if the time range runs over two consecutive days (fixes issue #162)
time_end = anytim2utc(anytim(time_range[1], /tai), /ccsds)
day_end = strmid(str_replace(time_end,'-'),0,8)
if day_end ne day_0 then begin
aux_fits_file_1 = aux_fits_file
aux_fits_file_2 = aux_data_folder + 'solo_L2_stix-aux-ephemeris_'+day_end+'*.fits'
aux_file_list_2 = file_search(aux_fits_file_2, count=nb_aux)
if nb_aux gt 0 then begin
aux_fits_file_2 = aux_file_list_2[-1]
print, " STX_IMAGING_PIPELINE - INFO: Found AUX file " + aux_fits_file_2
endif else message,"Cannot find auxiliary data file " + aux_fits_file_2
aux_fits_file = [aux_fits_file_1, aux_fits_file_2]
endif

; Extract data at requested time
; If an aspect solution is given as input, then use that one:
Expand All @@ -81,8 +94,7 @@ function stx_imaging_pipeline, stix_uid, time_range, energy_range, bkg_uid=bkg_u
aux_data.stx_pointing[0] = x_ptg
aux_data.stx_pointing[1] = y_ptg
endif else aux_data = stx_create_auxiliary_data(aux_fits_file, time_range, force_sas=force_sas, no_sas=no_sas)



;;;;
; Read and process STIX L1A data
l1a_file_list = file_search(l1a_data_folder + '*' + stix_uid + '*.fits')
Expand Down

0 comments on commit c134e39

Please sign in to comment.