Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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: 2 additions & 1 deletion stix/idl/io/stx_fits_info_params.pro
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function stx_fits_info_params, fits_path_data = fits_path_data, data_level = dat
default, elut_file, ''
default, fits_background_file, ''
default, detused, ''
default, grid_factor, ''

;if distance is not set use the average value from the fits header
stx_get_header_corrections, fits_path_data, distance = header_distance
Expand All @@ -107,7 +108,7 @@ function stx_fits_info_params, fits_path_data = fits_path_data, data_level = dat


stx_fits_info = {uid:uid, fits_data_file:fits_data_file, data_level:data_level, $
distance:distance, time_shift:time_shift, grid_factor:list(), $
distance:distance, time_shift:time_shift, grid_factor:grid_factor, $
background_subtracted:background_subtracted, fits_background_file:fits_background_file, $
generate_fits:generate_fits, specfile:specfile, srmfile:srmfile, elut_file:elut_file, detused:detused}

Expand Down
9 changes: 5 additions & 4 deletions stix/idl/processing/drm/stx_build_pixel_drm.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
;
;
;-
function stx_build_pixel_drm, ct_energy_edges, pixel_mask, ph_energy_edges = ph_energy_edges,rcr = rcr, grid_factor= grid_factor,dist_factor= dist_factor, _extra = _extra
function stx_build_pixel_drm, ct_energy_edges, pixel_mask, ph_energy_edges = ph_energy_edges, rcr = rcr, $
grid_factor = grid_factor, grid_transparency_correction = grid_transparency_correction, dist_factor = dist_factor, _extra = _extra

default, pixel_mask , intarr(12,32) + 1 ; default pixel mask is all pixels from all detectors
default, grid_factor, 1./4.
Expand Down Expand Up @@ -93,16 +94,16 @@ function stx_build_pixel_drm, ct_energy_edges, pixel_mask, ph_energy_edges = ph_
scale_factor = total_area/drm.area

;scale the relevant parameters
drm.area *= scale_factor*rcr_factor*dist_factor
drm.area *= scale_factor*rcr_factor*dist_factor*grid_factor

det_mask = total(pixel_mask,1) <1
smatrix = drm.smatrix
transmission = stx_transmission(drm.emean, det_mask, attenuator = attenuator)
dim_drm = size(/dim, smatrix) > 1

if n_elements(grid_factor) eq n_elements(ph_in) then grid_factor=10^(interpol(alog10(grid_factor),alog10(ph_in),alog10(drm.emean)))
if n_elements(grid_transparency_correction) eq n_elements(ph_in) then grid_transparency_correction=10^(interpol(alog10(grid_transparency_correction),alog10(ph_in),alog10(drm.emean)))

transmission = transmission*grid_factor
transmission = transmission*grid_transparency_correction

smatrix = smatrix * rebin( transpose(transmission), dim_drm)

Expand Down
20 changes: 10 additions & 10 deletions stix/idl/processing/spectrogram/stx_convert_science_data2ospex.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
; specpar : in, type="float",
; spectrum control and information parameters for OSPEX
;
; time_shift : in, type="float",
; time_shift : in, type="float",
; Applied light travel time correction
;
; data_level : in, type="int", default="1.0"
Expand All @@ -37,14 +37,14 @@
; distance : in, optional, type="float", default taken from FITS header
; The distance between Solar Orbiter and the Sun centre in Astronomical Units needed to correct flux.
;
; flare_location_hpc : in, type=" 2 element float array",
; flare_location_hpc : in, type=" 2 element float array",
; the location of the flare (X,Y) in Helioprojective Cartesian coordinates as seen from Solar Orbiter [arcsec]
; If no location is passed in the on-axis approximation is used to calculate the grid response. In this case
; If no location is passed in the on-axis approximation is used to calculate the grid response. In this case
; a value [Nan, Nan] is passed to the output files.
;
; aux_fits_file : in, required if flare_location_hpc is passed in, type="string"
; the path of the auxiliary ephemeris FITS file to be read."
;
;
; eff_ewidth : in, type="float arr"
; an output float value
;
Expand Down Expand Up @@ -163,12 +163,12 @@ 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,*]
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)
Expand All @@ -177,10 +177,10 @@ pro stx_convert_science_data2ospex, spectrogram = spectrogram, specpar = specpar

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

spec_in_bk = spec_in_bk[energy_bins,*]
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)
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 @@ -192,10 +192,10 @@ 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,*]
error_bk = error_bk[energy_bins,*]

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

error_bk = reform(error_bk,[n_elements(energy_bins), n_times])
Expand Down
18 changes: 13 additions & 5 deletions stix/idl/processing/spectrogram/stx_fsw_sd_spectrogram2ospex.pro
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,29 @@ function stx_fsw_sd_spectrogram2ospex, spectrogram, specpar = specpar, time_shif

if (keyword_set(gtrans32) and n_elements(flare_location_stx) ne 0) then begin
grid_factors_proc = stx_subc_transmission(flare_location_stx, ph_in, /flux, silent = silent)
grid_factors_opaque = stx_subc_transmission(flare_location_stx, ph_in, /flux, silent = silent, /simple_transm)

nph = n_elements(ph_in)
ngrids = n_elements(grids_used)


;05-Oct-2022 - ECMD until fine grid tranmission is ready replace the
;grids not in TOP24 with the on-axis tabulated values
idx_nontop24 = stx_label2det_ind('bkg+cfl+fine')

grid_factors_proc[*,idx_nontop24] = transpose(rebin(grid_factors_file[idx_nontop24],n_elements(idx_nontop24),nph))
grid_factor = average(reform(rebin(grid_factors_proc[*,grids_used], nph, ngrids), nph, ngrids),2)
grid_factor_transparent = average(reform(rebin(grid_factors_proc[*,grids_used], nph, ngrids), nph, ngrids),2)

grid_factors_opaque[*,idx_nontop24] = transpose(rebin(grid_factors_file[idx_nontop24],n_elements(idx_nontop24),nph))
grid_factor_opaque = average(reform(rebin(grid_factors_opaque[*,grids_used], nph, ngrids), nph, ngrids),2)

grid_transparency_correction = f_div(grid_factor_transparent,grid_factor_opaque)
grid_factor = (grid_factor_opaque)[0]

endif else begin
print, 'Using nominal (on axis) grid transmission'
grid_factor = average(grid_factors_file[grids_used])
specpar.flare_xyoffset = [0.,0.]
grid_transparency_correction = 1.
endelse

if max(grid_factor) eq 0 then begin
Expand All @@ -101,6 +108,7 @@ function stx_fsw_sd_spectrogram2ospex, spectrogram, specpar = specpar, time_shif
readcol, grid_transmission_file, bk_grid_factors, format = 'f', skip = 2, silent = silent

grid_factor = average(bk_grid_factors[pixels_used])
grid_transparency_correction = 1.

endif else begin
message, 'Warning: Grid Factor is 0 - transmission for CFL and BKG detectors is not implemented',/info
Expand All @@ -109,7 +117,7 @@ function stx_fsw_sd_spectrogram2ospex, spectrogram, specpar = specpar, time_shif
endif

;make the srm for the appropriate pixel mask and energy edges
srm = stx_build_pixel_drm(ct_edges, pixel_mask, ph_energy_edges = ph_edges, grid_factor = grid_factor, dist_factor = dist_factor,$
srm = stx_build_pixel_drm(ct_edges, pixel_mask, ph_energy_edges = ph_edges, grid_factor = grid_factor, grid_transparency_correction = grid_transparency_correction, dist_factor = dist_factor,$
xspec = xspec, _extra = _extra)

rcr_states = specpar.sp_atten_state.state
Expand All @@ -122,7 +130,7 @@ function stx_fsw_sd_spectrogram2ospex, spectrogram, specpar = specpar, time_shif
;make the srm for the appropriate pixel mask and energy edges
rcr = rcr_states[i]

srm = stx_build_pixel_drm(ct_edges, pixel_mask, rcr = rcr, ph_energy_edges = ph_edges, grid_factor = grid_factor,$
srm = stx_build_pixel_drm(ct_edges, pixel_mask, rcr = rcr, ph_energy_edges = ph_edges, grid_factor = grid_factor, grid_transparency_correction = grid_transparency_correction, $
dist_factor = dist_factor, xspec = xspec, _extra = _extra)
srm_atten[i].srm = srm.smatrix
srm_atten[i].rcr = rcr
Expand Down Expand Up @@ -150,7 +158,7 @@ function stx_fsw_sd_spectrogram2ospex, spectrogram, specpar = specpar, time_shif
specfilename = fits_info_params.specfile
srmfilename = fits_info_params.srmfile

fits_info_params.grid_factor.add, grid_factor
fits_info_params.grid_factor = grid_factor
fits_info_params.detused = detector_label + ', Pixels: ' + pixel_label

if keyword_set(xspec) then begin
Expand Down
26 changes: 13 additions & 13 deletions stix/idl/processing/spectrogram/stx_write_ospex_fits.pro
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,23 @@ pro stx_write_ospex_fits, $

stx_gsw_version, version = version, /silent

fxaddpar, primary_header, 'PARENT', fits_info_params.fits_data_file, "Parent Observation Data File", before='AUTHOR'
fxaddpar, primary_header, 'DATA_LEVEL', stx_data_level2label(fits_info_params.data_level), "Observation Data Compression Level", before='AUTHOR'
fxaddpar, primary_header, 'PARENT', fits_info_params.fits_data_file, 'Parent Observation Data File', before='AUTHOR'
fxaddpar, primary_header, 'DATA_LEVEL', stx_data_level2label(fits_info_params.data_level), 'Observation Data Compression Level', before='AUTHOR'
fxaddpar, primary_header, 'HISTORY', 'STIX GSW Version '+version[0]+ ' was used to process this data'

fxaddpar, specheader, 'REQUEST_ID', fits_info_params.uid, "Unique Request ID for the Observation", before='AUTHOR'
fxaddpar, specheader, 'SUN_DISTANCE', fits_info_params.distance, "Distance in AU to Sun", before='AUTHOR'
fxaddpar, specheader, 'GRID_FACTOR', ((fits_info_params.grid_factor.toarray())[0]), "Total Grid Transmission Factor", before='AUTHOR'
fxaddpar, specheader, 'ELUT_FILENAME', fits_info_params.elut_file, "Filename of ELUT", before='AUTHOR'
fxaddpar, specheader, 'DETUSED', fits_info_params.detused, "Label for detectors used", before='AUTHOR'
fxaddpar, specheader, 'DETNAM', fits_info_params.detused, "Label for detectors used", before='AUTHOR'
fxaddpar, specheader, 'REQUEST_ID', fits_info_params.uid, 'Unique Request ID for the Observation', before='AUTHOR'
fxaddpar, specheader, 'SUN_DISTANCE', fits_info_params.distance, 'Distance in AU to Sun', before='AUTHOR'
fxaddpar, specheader, 'GRID_FACTOR', fits_info_params.grid_factor, 'Total Opaque Grid Transmission Factor', before='AUTHOR'
fxaddpar, specheader, 'ELUT_FILENAME', fits_info_params.elut_file, 'Filename of ELUT', before='AUTHOR'
fxaddpar, specheader, 'DETUSED', fits_info_params.detused, 'Label for detectors used', before='AUTHOR'
fxaddpar, specheader, 'DETNAM', fits_info_params.detused, 'Label for detectors used', before='AUTHOR'
fxaddpar, specheader, 'SUMFLAG', 1, "Detectors are summed", before='AUTHOR'

fxaddpar, srmheader, 'SUN_DISTANCE', fits_info_params.distance, "Distance in AU to Sun", before='AUTHOR'
fxaddpar, srmheader, 'GRID_FACTOR', ((fits_info_params.grid_factor.toarray())[0]), "Total Grid Transmission Factor used", before='AUTHOR'
fxaddpar, srmheader, 'DETUSED', fits_info_params.detused, "Label for detectors used", before='AUTHOR'
fxaddpar, srmheader, 'DETNAM', fits_info_params.detused, "Label for detectors used", before='AUTHOR'
fxaddpar, srmheader, 'SUMFLAG', 1, "Detectors are summed", before='AUTHOR'
fxaddpar, srmheader, 'SUN_DISTANCE', fits_info_params.distance, 'Distance in AU to Sun', before='AUTHOR'
fxaddpar, srmheader, 'GRID_FACTOR', fits_info_params.grid_factor, 'Total Opaque Grid Transmission Factor', before='AUTHOR'
fxaddpar, srmheader, 'DETUSED', fits_info_params.detused, 'Label for detectors used', before='AUTHOR'
fxaddpar, srmheader, 'DETNAM', fits_info_params.detused, 'Label for detectors used', before='AUTHOR'
fxaddpar, srmheader, 'SUMFLAG', 1, 'Detectors are summed', before='AUTHOR'


;make the spectrum file
Expand Down
18 changes: 6 additions & 12 deletions stix/idl/processing/subcollimator/stx_grid_transmission.pro
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ function stx_grid_transmission, x_flare, y_flare, grid_orient, grid_pitch, grid_

default, flux, 1

;; Distance of the flare on the axis perpendicular to the grid orientation
flare_dist = abs(x_flare * cos(grid_orient * !dtor) + y_flare * sin(grid_orient * !dtor))

;; Internal shadowing
shadow_width = grid_thick * tan(flare_dist / 3600. * !dtor)

if ~keyword_set(simple_transm) then begin

bridge_factor = 1.0 - f_div(bridge_width,bridge_pitch)

;; Distance of the flare on the axis perpendicular to the grid orientation
flare_dist = abs(x_flare * cos(grid_orient * !dtor) + y_flare * sin(grid_orient * !dtor))

;; Internal shadowing
shadow_width = grid_thick * tan(flare_dist / 3600. * !dtor)

nenergies = n_elements(linear_attenuation)

slat_optical_depth = grid_thick * linear_attenuation
Expand All @@ -91,12 +91,6 @@ function stx_grid_transmission, x_flare, y_flare, grid_orient, grid_pitch, grid_
return, transmission/2.

endif else begin

;; Distance of the flare on the axis perpendicular to the grid orientation
flare_dist = abs(x_flare * cos(grid_orient * !dtor) + y_flare * sin(grid_orient * !dtor))

;; Internal shadowing
shadow_width = grid_thick * tan(flare_dist / 3600. * !dtor)

return, (grid_slit - shadow_width) / grid_pitch

Expand Down