Open Borlaff opened 9 months ago
Thanks a lot @Borlaff for the issue! I have not yet looked into the example in detail, but my suspicion here is that this might be due to the boundary handling of the PSF convolution. I remember when I worked with the code, the flux of the point source in the center was recovered correctly.
Can you please add this check? Integrate the flux in a given circle around the test source. You can use for example photutils.aperture.CircularAperture for this.
You could also try to correct the exposure for the boundary effect along the lines of:
from pylira.utils.convolution import fftconvolve
from pylira.data import point_source_gauss_psf
import numpy as np
data = point_source_gauss_psf()
psf = data["psf"] / np.sum(data["psf"])
weights = fftconvolve(np.ones(data["exposure"].shape), psf)
data["exposure"] /= weights
Maybe this resolves the difference already.
Dear pyLIRA developers,
I am running some experiments with LIRA and I am finding a problem related to the conservation of flux before and after deconvolution.
I found that the total flux before (sum of all initial counts) and after (sum of the posterior traces) the deconvolution in LIRA is not preserved. The output seems to be about 95% lower than the expected. I am unable to explain this difference. I tried using different number of simulations, setting fit_background_scale to True and False, different initial backgrounds, different initial fluxes, without any different result.
I made a minimal reproducible example in case that you can provide with assistance. The code is attached to the end of this issue. The fits file required can be accessed here:
https://drive.google.com/file/d/1eqvFbofKg6OgdctiXCBZWTjAeVdveiVD/view?usp=sharing
The example reads the attached image (obs_events.fits), generates the initial conditions for the pyLIRA deconvolver, adds the PSF from another example and runs the statistics to check the flux.
These are the input image and the PSF:
And this is the histogram of flux conservation, measured as:
Flux post-LIRA deconvolution / Flux pre-LIRA deconvolution (Technically it should be one).
The division between the total flux of the posterior_trace and the input image should be equal to 1, but rather it is closer to 0.95 (95%). I am already adding the background flux as recorded in the bkgScale column in result.parameter_trace. At first I thought that that was the problem, but after checking it, it seems that even after adding bkgScale to the sum of all the flux in the posterior, it is impossible to recover the 100% of the input flux. I must be missing something in the process.
I hope that you can point us in the right direction. Thank you so much, Alex