i4Ds / STIX-GSW

STIX Ground-Analysis Software Package
11 stars 16 forks source link

Fixed bug in selection of energy indices of pixel data matrix #185

Closed paolomassa closed 11 months ago

paolomassa commented 11 months ago

There was a potential mismatch between the input energy range and the indices of the energy axis that were selected in the pixel data matrix. The problem raised when e_axis.LOW started from 0 keV (where e_axis is the energy axis structure returned by stx_read_pixel_data_fits_file). Indeed, in that case, the indices corresponding to the input energy interval were selected assuming that the first energy bin was 0-4 keV, while the first energy interval of the pixel data matrix (stored in the counts variable) was systematically discarded before selecting the energy bins. As a consequence, it could happen that the input energy interval was 5-8 keV, but the energy interval that was actually selected by the code was 7-9 keV.

A similar mismatch could also happen when the indices of the ELUT were selected. In that case, the energy correction factors of the first and the last energy interval (which should be between ~0.95 and ~1.05) could take values close to 2 or close to 0 (or even negative!).

I solved this issue in the following way:

paolomassa commented 11 months ago

I have tested the changes I made and they seems to be correct. Also Säm tried out the code and approved the changes.

grazwegian commented 11 months ago
grazwegian commented 11 months ago

It would probably be good to discuss the expectations around stx_read_pixel_data_fits_file at the software meeting in Poland.

samaloney commented 11 months ago
  • The implementation also assumes that both the science and the background fits files contain more that one energy bin (i.e., that the energy_bin_mask contains more than one entry equal to one).

I think it's possible to have only one entry in the energy_bin_edge_mask e.g `0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] is 4-5 keV

paolomassa commented 11 months ago

I think the code crashes if only one energy bin is present. Do you want me to modify it so that it handles also that case?