xpsi-group / xpsi

X-PSI: X-ray Pulse Simulation and Inference
Other
34 stars 21 forks source link

Background upper limit not forced to be always non-zero #350

Closed thjsal closed 7 months ago

thjsal commented 9 months ago

Using the default module generator code, the background upper limit can remain zero for those channels for which there are no higher energy channels with a non-zero upper limit. According to documentation, zero should not be provided as an upper limit. However, the code does not crash even though one does it.

The solution would be to check channels in both directions when searching for the nearest non-zero value. I.e., replacing this for-loop: https://github.com/xpsi-group/xpsi/blob/1dfb38f7a598f4dc9b2cd5d507c52018cdcbd492/xpsi/module_generator.py#L1630 with something like this:

for i in range(support.shape[0]):
    if support[i,1] == 0.0:
        for j in range(1, support.shape[0]):
            if i+j < support.shape[0] and support[i+j,1] > 0.0:
                support[i,1] = support[i+j,1]
                break
            elif i-j >= 0 and support[i-j,1] > 0.0:
                support[i,1] = support[i-j,1]
                break

This should work, except if having initially zero upper limits everywhere.