Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ stx_scenario_*

.vscode

# macOS metadata
.DS_Store

14 changes: 14 additions & 0 deletions stix/dbase/grid/real_bkg_grid_transmission.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;Real transmission factors for on-axis grid transmission in BGK detector pixels MZS - 18-Jun-24
;N.B. tranmission for fully covered pixels is currently set to 0
0.1341096
0.0010084
0.0115397
0.0000000
0.0000000
0.0113317
0.0009876
0.1393076
0.0000000
0.0000000
0.0000000
0.0000000
32 changes: 29 additions & 3 deletions stix/idl/demo/stx_imaging_demo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,39 @@ aux_data = stx_create_auxiliary_data(aux_fits_file, time_range)

stop

;************************************* DOWNLOAD CALIBRATION FITS FILE *********************************

; This file is used for creating a structure containing daily calibration data to be used for ELUT
; correction (see next section)
path_calib_file = stx_get_calibration_file(time_range[0], time_range[1], out_dir=out_dir)

stop

;;********************************** CONSTRUCT CALIBRATION DATA STRUCTURE *****************************

; Create a structure containing daily calibration data to use for ELUT correction:
; - TIME_START: start time of the calibration file which is used to derive gain/offset values
; - TIME_END: end time of the calibration file which is used to derive gain/offset values
; - T_MEAN: mid point of the time range of the calibration file which is used to derive gain/offset values
; - ENERGY_BIN_LOW: actual lower energy edges (in keV) of the science channels for each pixel
; - ENERGY_BIN_HIGH: actual higher energy edges (in keV) of the science channels for each pixel
; - GAIN: gain value for each pixel
; - OFFSET: offset value for each pixel
; - LIVE_TIME: live time of the calibration file
; - ELUT_NAME: name of the ELUT that was utilized onboard when the calibration file was recorded

stx_read_calibration_data, path_calib_file, calib_data=calib_data

stop

;*************************************** ESTIMATE FLARE LOCATION **************************************

; Returns the coordinates of the estimated flare location (arcsec, Helioprojective Cartesian coordinates
; from Solar Orbiter vantage point) in the 'flare_loc' keyword. These coordinates are used for setting the
; center of the maps to be reconstructed

stx_estimate_flare_location, path_sci_file, time_range, aux_data, flare_loc=flare_loc, $
path_bkg_file=path_bkg_file
path_bkg_file=path_bkg_file, calib_data=calib_data

stop

Expand All @@ -102,7 +127,7 @@ xy_flare = mapcenter
; '6a','6b','6c','5a','5b','5c','4a','4b','4c','3a','3b','3c'])

vis=stx_construct_calibrated_visibility(path_sci_file, time_range, energy_range, mapcenter, subc_index=subc_index, $
path_bkg_file=path_bkg_file, xy_flare=xy_flare)
path_bkg_file=path_bkg_file, xy_flare=xy_flare, calib_data=calib_data)

stop

Expand Down Expand Up @@ -178,7 +203,8 @@ stop

; Expectation Maximization algorithm from STIX counts (see Massa P. et al (2019) for details). Takes as input a
; summed pixel data structure
pixel_data_summed = stx_construct_pixel_data_summed(path_sci_file, time_range, energy_range, path_bkg_file=path_bkg_file, /silent)
pixel_data_summed = stx_construct_pixel_data_summed(path_sci_file, time_range, energy_range, path_bkg_file=path_bkg_file, $
calib_data=calib_data, /silent)

em_map = stx_em(pixel_data_summed, aux_data, imsize=imsize, pixel=pixel, xy_flare=xy_flare, mapcenter=mapcenter)

Expand Down
7 changes: 4 additions & 3 deletions stix/idl/io/stx_fits_info_params.pro
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@
;
; :history:
; 17-Aug-2022 - ECMD (Graz), initial release
; 05-Apr-2023 - ECMD (Graz), fix issue with taking header distance as default
; 05-Apr-2023 - ECMD (Graz), fix issue with taking header distance as default
; 07-May-2026 - Massa P. (FHNW), print warning if generate_fits = 0 (regardless of 'specfile' or 'srmfile' are defined)
;
;-
function stx_fits_info_params, fits_path_data = fits_path_data, data_level = data_level, $
distance = distance, time_shift = time_shift, fits_path_bk = fits_path_bk, uid = uid, $
generate_fits = generate_fits, specfile = specfile, srmfile = srmfile, elut_file = elut_file, silent = silent

if n_elements(generate_fits) ne 0 then begin
if generate_fits eq 0 and keyword_set(specfile) || keyword_set(srmfile) then begin
message, 'FITS file generation has been set to 0 but an output filename has been specified.'
if generate_fits eq 0 then begin
message, [" ", " ", 'FITS file generation has been set to 0.', " ", " "], /continue
endif
endif

Expand Down
211 changes: 211 additions & 0 deletions stix/idl/io/stx_get_calibration_file.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
;+
;
; name:
; stx_get_calibration_file
;
; :description:
; This procedure checks the STIX data archive for a given observation time and finds any
; STIX CAL calibration file. If no file is present for the input date, the procedure searches for
; the calibration file which is closest in time. If multiple files are present for that date,
; this procedure downloads the one with largest duration.
;
; :categories:
; template, example
;
; :params:
; start_time : in, required, type="string"
; the start time of the observation
; end_time : in, required, type="string"
; the end time of the observation
;
; :keywords
; out_dir: path of the folder where the STIX calibration FITS files are saved. Default is the current directory
;
; clobber: 0 or 1. If set to 0, the code does not download the file again if it is already present in 'out_dir'.
;
; :returns:
; Path of the downloaded STIX calibration FITS file
;
; :examples:
; out_file = stx_get_calibration_file('09-May-23 06:14:37.094', '09-May-23 06:36:12.194')
;
; :history:
; 24-Mar-2026 - Massa P. (FHNW), first release
; 13-Apr-2026 - Massa P. (FHNW), updated to search for calibration files the day before or after the input date (in case there are no files for the input date)
;-
function stx_get_calibration_file, start_time, end_time, out_dir=out_dir, clobber=clobber

cd, current=current

default, out_dir, current
default, clobber, 0

day_in_s = 86400.d ;; Number of seconds in a day. To be used later to identify the most appropriate calibration file

site = 'http://dataarchive.stix.i4ds.net'
date_path = get_fid(start_time,end_time,/full,delim='/')

;; Concatenate files from the input date and from the day before/after
type_path = '/fits/CAL/'
filter = '*stix-cal-energy*.fits'

;; Load the ELUT file for the iput time (it is used later for checks)
elut_input_time = stx_date2elut_file(start_time)


found_files_array=[]

;; Input day
path = type_path + date_path[0] +'/CAL'
found_files=sock_find(site,filter,path=path,count=count)

if count gt 0 then found_files_array=[found_files_array, found_files]

;; Day before
this_start_time_before = anytim(anytim(start_time) - day_in_s, /vms)
this_end_time_before = anytim(anytim(end_time) - day_in_s, /vms)

path_before = get_fid(this_start_time_before,this_end_time_before,/full,delim='/')

path = type_path + path_before[0] +'/CAL'
found_files=sock_find(site,filter,path=path,count=count)

if count gt 0 then found_files_array=[found_files_array, found_files]

;; Day after
this_start_time_after = anytim(anytim(start_time) + day_in_s, /vms)
this_end_time_after = anytim(anytim(end_time) + day_in_s, /vms)

path_after = get_fid(this_start_time_after,this_end_time_after,/full,delim='/')

path = type_path + path_after[0] +'/CAL'
found_files=sock_find(site,filter,path=path,count=count)

if count gt 0 then found_files_array=[found_files_array, found_files]


;;*********

len_path = STRLEN(site+path)

if n_elements(found_files_array) eq 0 then begin

message, $
[" ", " ", "No STIX calibration file was found within 1 day before or after " +date_path[0]+". Please, download an appropriate calibration file manually.", " ", " "]

endif else begin

start_time_file = []
end_time_file = []
elut_check = []

;; Extract file names
for i = 0,n_elements(found_files_array)-1 do begin

len_full_path = STRLEN(found_files_array[i])
filename = STRMID(found_files_array[i], len_path+1, len_full_path)

string_dates = STRMID(filename, STRLEN('solo_CAL_stix-cal-energy_'), STRLEN(filename)-STRLEN('solo_CAL_stix-cal-energy_')-9) ;; 9 is the number of characters in the string '_V02.fits'

mid_part = STRPOS(string_dates, '-')

this_start_time_file = STRMID(string_dates, 0, mid_part)
year = STRMID(this_start_time_file, 0, 4)
month = STRMID(this_start_time_file, 4, 2)
day = STRMID(this_start_time_file, 6, 2)
hour = STRMID(this_start_time_file, 9, 2)
min = STRMID(this_start_time_file, 11, 2)
sec = STRMID(this_start_time_file, 13, 2)

this_start_time = anytim(year + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec)
start_time_file = [start_time_file, this_start_time]

this_end_time_file = STRMID(string_dates, mid_part+1, STRLEN(string_dates))
year = STRMID(this_end_time_file, 0, 4)
month = STRMID(this_end_time_file, 4, 2)
day = STRMID(this_end_time_file, 6, 2)
hour = STRMID(this_end_time_file, 9, 2)
min = STRMID(this_end_time_file, 11, 2)
sec = STRMID(this_end_time_file, 13, 2)
end_time_file = [end_time_file, anytim(year + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec)]

elut_check = [elut_check, (elut_input_time eq stx_date2elut_file(this_start_time))]

endfor

;; Compute mid point of the time interval of the calibration file
mid_time_file = (start_time_file + end_time_file) / 2.

;; Compute duration file
duration = end_time_file - start_time_file

;; ELUT check
idx_elut = where(elut_check, n_elut_check)

if n_elut_check eq 0 then begin

message, [" ", " ", "Available STIX calibration files within 1 day before or after " +date_path[0]+" have been registered with an onboard ELUT different from that used during the selected time range and cannot be used. Please, download an appropriate calibration file manually.", " ", " "]

endif else begin

;; Select calibration files recorded with the same ELUT as the one that was onboard during the input time range
found_files = found_files_array[idx_elut]
duration = duration[idx_elut]
start_time_file = start_time_file[idx_elut]
end_time_file = end_time_file[idx_elut]
mid_time_file = mid_time_file[idx_elut]

;; Select calibration file with largest duration
idx_duration = where(duration ge day_in_s / 2., n_duration)

if n_duration eq 0 then begin

message, [" ", " ", "Available STIX calibration files within 1 day before or after " +date_path[0]+" have a duration shorter than half a day and should not be used. Please, download an appropriate calibration file manually.", " ", " "]

endif else begin

found_files = found_files[idx_duration]
duration = duration[idx_duration]
start_time_file = start_time_file[idx_duration]
end_time_file = end_time_file[idx_duration]
mid_time_file = mid_time_file[idx_duration]

;; If multiple files have the largest duration, select the closest one to the input time range
if n_duration gt 1 then begin

;; Select the file closest in time to input time range
mid_time_input = (anytim(start_time) + anytim(end_time)) / 2.
time_diff = abs(mid_time_file - mid_time_input)

idx_time_diff = sort(time_diff)

idx_file = idx_time_diff[0]

selected_file = found_files[idx_file]
selected_file_time_start = start_time_file[idx_file]
selected_file_time_end = end_time_file[idx_file]

endif else begin

selected_file = found_files
selected_file_time_start = start_time_file
selected_file_time_end = end_time_file

endelse

endelse

endelse

endelse

;; Download file
message, [" ", " ", "Download STIX calibration file recorded between " +anytim(selected_file_time_start, /vms)+$
" and "+anytim(selected_file_time_end, /vms), " ", " "], /continue
sock_copy, selected_file, out_name, local_file=out_file, out_dir = out_dir, clobber=clobber

return, out_file



end
Loading