Skip to content

Commit

Permalink
Merge branch 'main' into default
Browse files Browse the repository at this point in the history
* main:
  fixed i4Ds#205 (fix by Dominic Zarro)
  Update VERSION.txt
  Update stx_imaging_demo (i4Ds#203)
  Remove unused keyword from structure
  Add IDL_STARTUP file to stix/setup which will be run every time SSWIDL is started. Currently this only calls stx_check_config_files (i4Ds#196)
  Skip ELUT (i4Ds#182)
  • Loading branch information
grazwegian committed Feb 2, 2024
2 parents 3e4169a + adf4e23 commit 6d2cfc3
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 67 deletions.
2 changes: 1 addition & 1 deletion stix/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.1
v0.5.2
29 changes: 10 additions & 19 deletions stix/idl/demo/stx_imaging_demo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
; 02-september-2021, Massa P., first release
; 23-august-2022, Massa P., made compatible with the up-to-date imaging sofwtare
; 11-september-2023 - ECMD (Graz), allow user to specify output directory
;
; 11-january-2024 - Massa P., use 'stx_get_science_fits_file' and 'stx_get_ephemeris_file' to download fits files
;
;-

Expand All @@ -26,28 +26,13 @@
; Folder in which the files downloaded for this demonstration are stored
default, out_dir, concat_dir( getenv('STX_DEMO_DATA'),'imaging', /d)

; URL of the STIX data center
website_url = 'https://datacenter.stix.i4ds.net/download/fits/bsd/'

; UID of the science fits file to be dowloaded from the website
uid_sci_file = "1178428688"
; Download the science fits file (if not already stored in out_dir)
sock_copy, website_url + uid_sci_file, out_name, status = status, out_dir = out_dir, $
local_file=path_sci_file, clobber=0
path_sci_file = stx_get_science_fits_file(uid_sci_file, out_dir=out_dir)

; UID of the background fits file to be dowloaded from the website
; UID of the background fits file to be dowloaded from the website
uid_bkg_file = "1178082832"
; Download the background fits file (if not already stored in out_dir)
sock_copy, website_url + uid_bkg_file, out_name, status = status, out_dir = out_dir, $
local_file=path_bkg_file, clobber=0

; URL of the server containing the L2 auxiliary fits files
website_url = 'http://dataarchive.stix.i4ds.net/fits/L2/'
; Filename of the auxiliary L2 fits file to be downloaded
file_name = '2020/06/07/AUX/solo_L2_stix-aux-ephemeris_20200607_V01.fits'
; Download the L2 auxiliary fits file (if not already stored in out_dir)
sock_copy, website_url + file_name, out_name, status = status, out_dir = out_dir, $
local_file=aux_fits_file, clobber=0
path_bkg_file = stx_get_science_fits_file(uid_bkg_file, out_dir=out_dir)

stop

Expand All @@ -60,6 +45,12 @@ energy_range = [6,10]

stop

;********************************* DOWNLOAD L2 EPHEMERIS FITS FILE ***********************************

; This file is used for creating a structure with auxiliary data to use for image reconstruction
; (see next section)
aux_fits_file = stx_get_ephemeris_file(time_range[0], time_range[1], out_dir=out_dir)

;;******************************** CONSTRUCT AUXILIARY DATA STRUCTURE ********************************

; Create a structure containing auxiliary data to use for image reconstruction
Expand Down
3 changes: 1 addition & 2 deletions stix/idl/io/stx_read_pixel_data_fits_file.pro
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ pro stx_read_pixel_data_fits_file, fits_path, time_shift, alpha = alpha, primary
pixel_masks:data.pixel_masks,$
detector_masks:data.detector_masks,$
energy_bin_mask: energy_bin_mask,$
num_pixel_sets:data.num_pixel_sets,$
num_energy_groups:data.num_energy_groups }
num_pixel_sets:data.num_pixel_sets}

end
5 changes: 3 additions & 2 deletions stix/idl/processing/spectrogram/stx_check_config_files.pro
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ end
;
; :history:
; 31-Aug-2023 - ECMD (Graz), initial release
; 22-Jan-2024 - Use Dominic Zarro's <idlneturl2> __define in place of out of box IDL idlneturl
;
;-
pro stx_check_config_files, directory, verbose = verbose
Expand All @@ -151,7 +152,7 @@ pro stx_check_config_files, directory, verbose = verbose
version_file = concat_dir(directory, 'stix_conf_version.txt')
find_version_file = loc_file(version_file)

ourl = obj_new('IDLnetURL')
ourl = obj_new('IDLnetURL2') ; S.L.Freeland - use Dominic's IDLnetURL2[__define].pro in place of IDL intrinsic
callback_data = ptr_new({loc:''})
ourl->setproperty, url_scheme='http'
ourl->setproperty, url_host='dataarchive.stix.i4ds.net'
Expand All @@ -174,4 +175,4 @@ pro stx_check_config_files, directory, verbose = verbose
endif
endelse

end
end
50 changes: 31 additions & 19 deletions stix/idl/processing/spectrogram/stx_convert_pixel_data.pro
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pro stx_convert_pixel_data, fits_path_data = fits_path_data, fits_path_bk = fit
time_shift = time_shift, energy_shift = energy_shift, distance = distance, $
aux_fits_file = aux_fits_file, flare_location_hpc = flare_location_hpc, flare_location_stx = flare_location_stx, $
det_ind = det_ind, pix_ind = pix_ind, $
shift_duration = shift_duration, no_attenuation = no_attenuation, sys_uncert = sys_uncert, $
elut_correction = elut_correction, shift_duration = shift_duration, no_attenuation = no_attenuation, sys_uncert = sys_uncert, $
generate_fits = generate_fits, specfile = specfile, srmfile = srmfile,$
background_data = background_data, plot = plot, ospex_obj = ospex_obj

Expand All @@ -112,7 +112,8 @@ pro stx_convert_pixel_data, fits_path_data = fits_path_data, fits_path_bk = fit
default, shift_duration, 0
default, plot, 1
default, det_ind, 'top24'

default, elut_correction, 1

if data_type(det_ind) eq 7 then det_ind = stx_label2det_ind(det_ind)
if data_type(pix_ind) eq 7 then pix_ind = stx_label2pix_ind(pix_ind)

Expand Down Expand Up @@ -188,44 +189,55 @@ pro stx_convert_pixel_data, fits_path_data = fits_path_data, fits_path_bk = fit
endif


stx_read_elut, ekev_actual = ekev_actual, elut_filename = elut_filename

ave_edge = mean(reform(ekev_actual[energy_edges_used-1, pixels_used, detectors_used, 0 ],n_energy_edges, n_pixels, n_detectors), dim= 2)
ave_edge = mean(reform(ave_edge,n_energy_edges, n_detectors), dim= 2)


edge_products, ave_edge, width = ewidth

eff_ewidth = (e_axis.width)/ewidth


counts_in = reform(counts_in,[dim_counts[0:2], n_times])

spec_in = total(reform(counts_in[*,pixels_used,detectors_used,*],[32,n_pixels,n_detectors,n_times]),2)

spec_in = reform(spec_in,[dim_counts[0],n_detectors, n_times])

counts_spec = spec_in[energy_bins,*, *] * reform(reproduce(eff_ewidth, n_detectors*n_times),n_energies, n_detectors, n_times)
counts_spec = spec_in[energy_bins,*, *]

counts_spec = reform(counts_spec,[n_energies, n_detectors, n_times])


counts_err = reform(data_str.counts_err,[dim_counts[0:2], n_times])

counts_err = sqrt(total(reform(counts_err[*,pixels_used,detectors_used,*]^2.,[32,n_pixels,n_detectors,n_times]),2))

counts_err = reform(counts_err,[dim_counts[0],n_detectors, n_times])

counts_err = counts_err[energy_bins,*, *] * reform(reproduce(eff_ewidth, n_detectors*n_times),n_energies, n_detectors, n_times)

counts_err = counts_err[energy_bins,*, *]
counts_err = reform(counts_err,[n_energies, n_detectors, n_times])

triggers = transpose(reform(data_str.triggers,[16, n_times]))

triggers_err = transpose(reform(data_str.triggers_err,[16, n_times]))


rcr = data_str.rcr

if keyword_set(elut_correction) then begin


stx_read_elut, ekev_actual = ekev_actual, elut_filename = elut_filename

ave_edge = mean(reform(ekev_actual[energy_edges_used-1, pixels_used, detectors_used, 0 ],n_energy_edges, n_pixels, n_detectors), dim= 2)
ave_edge = mean(reform(ave_edge,n_energy_edges, n_detectors), dim= 2)

edge_products, ave_edge, width = ewidth

eff_ewidth = (e_axis.width)/ewidth


counts_spec = counts_spec * reform(reproduce(eff_ewidth, n_detectors*n_times),n_energies, n_detectors, n_times)

counts_spec = reform(counts_spec,[n_energies, n_detectors, n_times])


counts_err = counts_err * reform(reproduce(eff_ewidth, n_detectors*n_times),n_energies, n_detectors, n_times)

counts_err = reform(counts_err,[n_energies, n_detectors, n_times])

endif

;insert the information from the telemetry file into the expected stx_fsw_sd_spectrogram structure
spectrogram = { $
Expand Down Expand Up @@ -295,7 +307,7 @@ pro stx_convert_pixel_data, fits_path_data = fits_path_data, fits_path_bk = fit
stx_convert_science_data2ospex, spectrogram = spectrogram, specpar=specpar, time_shift = time_shift, $
data_level = data_level, data_dims = data_dims, fits_path_bk = fits_path_bk, distance = distance, fits_path_data = fits_path_data,$
aux_fits_file = aux_fits_file, flare_location_hpc = flare_location_hpc, flare_location_stx = flare_location_stx, $
eff_ewidth = eff_ewidth, sys_uncert = sys_uncert, plot = plot, background_data = background_data, $
eff_ewidth = eff_ewidth, sys_uncert = sys_uncert, plot = plot, background_data = background_data, elut_correction = elut_correction, $
fits_info_params = fits_info_params, ospex_obj = ospex_obj

end
Expand Down
22 changes: 16 additions & 6 deletions stix/idl/processing/spectrogram/stx_convert_science_data2ospex.pro
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
;-
pro stx_convert_science_data2ospex, spectrogram = spectrogram, specpar = specpar, time_shift = time_shift, data_level = data_level, data_dims = data_dims, fits_path_bk = fits_path_bk,$
distance = distance, fits_path_data = fits_path_data, fits_info_params = fits_info_params, aux_fits_file = aux_fits_file, flare_location_hpc = flare_location_hpc, flare_location_stx = flare_location_stx, $
eff_ewidth = eff_ewidth, sys_uncert = sys_uncert, xspec = xspec, background_data = background_data, plot = plot, generate_fits = generate_fits, pickfile = pickfile, ospex_obj = ospex_obj
eff_ewidth = eff_ewidth, sys_uncert = sys_uncert, xspec = xspec, elut_correction = elut_correction, background_data = background_data, plot = plot, generate_fits = generate_fits, pickfile = pickfile, ospex_obj = ospex_obj

default, plot, 0

Expand Down Expand Up @@ -163,18 +163,25 @@ pro stx_convert_science_data2ospex, spectrogram = spectrogram, specpar = specpar

energy_bins = spectrogram.energy_axis.low_fsw_idx

corrected_counts_bk = corrected_counts_bk[energy_bins,*] * reproduce(eff_ewidth, n_times)
corrected_counts_bk = corrected_counts_bk[energy_bins,*]

if keyword_set(elut_correction) then begin
corrected_counts_bk = corrected_counts_bk * reproduce(eff_ewidth, n_times)
endif

corrected_counts_bk = reform(corrected_counts_bk,[n_elements(energy_bins), n_times])


spec_in_bk = total(reform(spec_in_bk,[dim_counts_bk[0], n_detectors_bk, ntimes_bk ]),2)

spec_in_bk = (total(reform(spec_in_bk, dim_counts_bk[0], ntimes_bk),2)/total(data_str_bk.timedel))#(spectrogram.time_axis.duration)

spec_in_bk = reform(spec_in_bk,dim_counts_bk[0], n_times)

spec_in_bk = spec_in_bk[energy_bins,*] * reproduce(eff_ewidth, n_times)
spec_in_bk = spec_in_bk[energy_bins,*]

if keyword_set(elut_correction) then begin
spec_in_bk = spec_in_bk * reproduce(eff_ewidth, n_times)
endif

spec_in_bk = reform(spec_in_bk,[n_elements(energy_bins), n_times])

Expand All @@ -185,10 +192,13 @@ pro stx_convert_science_data2ospex, spectrogram = spectrogram, specpar = specpar

error_bk = reform(error_bk, dim_counts_bk[0], n_times)

error_bk = error_bk[energy_bins,*] * reproduce(eff_ewidth, n_times)
error_bk = error_bk[energy_bins,*]

error_bk = reform(error_bk,[n_elements(energy_bins), n_times])
if keyword_set(elut_correction) then begin
error_bk = error_bk * reproduce(eff_ewidth, n_times)
endif

error_bk = reform(error_bk,[n_elements(energy_bins), n_times])

spec_in_corr = corrected_counts - corrected_counts_bk

Expand Down
43 changes: 29 additions & 14 deletions stix/idl/processing/spectrogram/stx_convert_spectrogram.pro
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pro stx_convert_spectrogram, fits_path_data = fits_path_data, fits_path_bk = fi
aux_fits_file = aux_fits_file, flare_location_hpc = flare_location_hpc, flare_location_stx = flare_location_stx, $
time_shift = time_shift, energy_shift = energy_shift, distance = distance, $
replace_doubles = replace_doubles, keep_short_bins = keep_short_bins, apply_time_shift = apply_time_shift,$
shift_duration = shift_duration, no_attenuation = no_attenuation, sys_uncert = sys_uncert, $
elut_correction = elut_correction, shift_duration = shift_duration, no_attenuation = no_attenuation, sys_uncert = sys_uncert, $
generate_fits = generate_fits, specfile = specfile, srmfile = srmfile,$
background_data = background_data, plot = plot, ospex_obj = ospex_obj

Expand All @@ -103,7 +103,8 @@ pro stx_convert_spectrogram, fits_path_data = fits_path_data, fits_path_bk = fi


default, plot, 1

default, elut_correction, 1

stx_read_spectrogram_fits_file, fits_path_data, time_shift, primary_header = primary_header, data_str = data_str, data_header = data_header, control_str = control_str, $
control_header= control_header, energy_str = energy_str, energy_header = energy_header, t_axis = t_axis, energy_shift = energy_shift, e_axis = e_axis , use_discriminators = 0,$
replace_doubles = replace_doubles, keep_short_bins = keep_short_bins, shift_duration = shift_duration
Expand Down Expand Up @@ -141,25 +142,16 @@ pro stx_convert_spectrogram, fits_path_data = fits_path_data, fits_path_bk = fi
detector_mask_used[detectors_used] = 1
n_detectors = total(detector_mask_used)

stx_read_elut, ekev_actual = ekev_actual, elut_filename = elut_filename

ave_edge = mean(reform(ekev_actual[energy_edges_used-1, pixels_used, detectors_used, 0 ], n_energy_edges, n_pixels, n_detectors), dim = 2)
ave_edge = mean(reform(ave_edge,n_energy_edges, n_detectors), dim = 2)


edge_products, ave_edge, width = ewidth

eff_ewidth = (e_axis.width)/ewidth

counts_in = reform(counts_in,[dim_counts[0], n_times])

spec_in = counts_in

counts_spec = spec_in[energy_bins, *] * reproduce(eff_ewidth, n_times)
counts_spec = spec_in[energy_bins, *]

counts_spec = reform(counts_spec,[n_energies, n_times])

counts_err = data_str.counts_err[energy_bins,*] * reproduce(eff_ewidth, n_times)
counts_err = data_str.counts_err[energy_bins,*]

counts_err = reform(counts_err,[n_energies, n_times])

Expand All @@ -169,6 +161,29 @@ pro stx_convert_spectrogram, fits_path_data = fits_path_data, fits_path_bk = fi

rcr = data_str.rcr


if keyword_set(elut_correction) then begin
stx_read_elut, ekev_actual = ekev_actual, elut_filename = elut_filename

ave_edge = mean(reform(ekev_actual[energy_edges_used-1, pixels_used, detectors_used, 0 ], n_energy_edges, n_pixels, n_detectors), dim = 2)
ave_edge = mean(reform(ave_edge,n_energy_edges, n_detectors), dim = 2)

edge_products, ave_edge, width = ewidth

eff_ewidth = (e_axis.width)/ewidth

counts_spec = counts_spec * reproduce(eff_ewidth, n_times)

counts_spec = reform(counts_spec,[n_energies, n_times])

counts_err = counts_err * reproduce(eff_ewidth, n_times)

counts_err = reform(counts_err,[n_energies, n_times])
endif




;insert the information from the telemetry file into the expected stx_fsw_sd_spectrogram structure
spectrogram = { $
type : "stx_fsw_sd_spectrogram", $
Expand Down Expand Up @@ -233,7 +248,7 @@ pro stx_convert_spectrogram, fits_path_data = fits_path_data, fits_path_bk = fi
specpar = { sp_atten_state : {time:ut_rcr[index], state:state}, flare_xyoffset : fltarr(2), use_flare_xyoffset:0 }

stx_convert_science_data2ospex, spectrogram = spectrogram, specpar = specpar, time_shift = time_shift, data_level = data_level, data_dims = data_dims, fits_path_bk = fits_path_bk, $
distance = distance, fits_path_data = fits_path_data, eff_ewidth = eff_ewidth, fits_info_params = fits_info_params, sys_uncert = sys_uncert, $
distance = distance, fits_path_data = fits_path_data, elut_correction = elut_correction, eff_ewidth = eff_ewidth, fits_info_params = fits_info_params, sys_uncert = sys_uncert, $
aux_fits_file = aux_fits_file, flare_location_hpc = flare_location_hpc, flare_location_stx = flare_location_stx, $
background_data = background_data, plot = plot, generate_fits = generate_fits, ospex_obj = ospex_obj

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@
;-
function stx_science_data_lightcurve, fits_path, energy_ranges = edges_in, time_min = time_min, $
fits_path_bk = fits_path_bk, plot_obj = plot_obj, time_shift = time_shift, rate = rate, shift_duration = shift_duration, $
det_ind = det_ind, pix_ind = pix_ind, sys_uncert = sys_uncert, time_range = time_range, _extra= _extra
det_ind = det_ind, pix_ind = pix_ind, elut_correction = elut_correction, sys_uncert = sys_uncert, time_range = time_range, _extra= _extra


default, time_min, 20
default, edges_in, [[4.,10.],[10,15],[15,25]]
default, spex_units, 'flux'

default, elut_correction, 0

; If /rate is set, return the rate units
if keyword_set(rate) then spex_units = 'rate'

Expand All @@ -114,10 +115,10 @@ function stx_science_data_lightcurve, fits_path, energy_ranges = edges_in, time

if strpos(orig_filename, 'cpd') gt -1 or strpos(orig_filename, 'xray-l1') gt -1 then begin
stx_convert_pixel_data, fits_path_data = fits_path[this_file], fits_path_bk = fits_path_bk, distance = distance, time_shift = time_shift, ospex_obj = ospex_obj, $
det_ind = det_ind, pix_ind = pix_ind, sys_uncert = sys_uncert, plot = 0, _extra= _extra
det_ind = det_ind, pix_ind = pix_ind, sys_uncert = sys_uncert, elut_correction = elut_correction, plot = 0, _extra= _extra
endif else if strpos(orig_filename, 'spec') gt -1 or strpos(orig_filename, 'spectrogram') gt -1 then begin
stx_convert_spectrogram, fits_path_data = fits_path[this_file], fits_path_bk = fits_path_bk, distance = distance, time_shift = time_shift, ospex_obj = ospex_obj, $
sys_uncert = sys_uncert, plot = 0, _extra= _extra
sys_uncert = sys_uncert, elut_correction = elut_correction, plot = 0, _extra= _extra
if keyword_set(det_ind) or keyword_set(pix_ind) then message, 'ERROR: Detector and pixel selection not possible with spectrogram files.'
endif else begin
message, 'ERROR: the FILENAME field in the primary header should contain either cpd, xray-l1 or spec'
Expand Down
4 changes: 4 additions & 0 deletions stix/setup/IDL_STARTUP
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; STIX idl startup
;----------------------------------------------

stx_check_config_files

0 comments on commit 6d2cfc3

Please sign in to comment.