desihub / specsim

Quick simulations of spectrograph response
2 stars 9 forks source link

Issue with camera.get_output_resolution_matrix #126

Closed julienguy closed 1 year ago

julienguy commented 1 year ago

camera.get_output_resolution_matrix is returning the resolution matrix of spectra for the output wavelength grid. It is deriving it from the input resolution matrix and the input wavelength grid that is finer than the output. I do not understand the result from this routine that does a complex treatment of indices to average some elements of the sparse matrix.

I think we should expect an output resolution with rms_out close to sqrt( rms_in^2 + bin_width_out^2/12 - bin_width_in^2/12 )which is resulting frm the convolution of the input resolution and a bin of given width (after subtracting the contribution of the input bin size)

In $DESIMODEL/data/specpsf/psf-quicksim.fits , at 4000A, fwhm_wave = 1.718A , giving sigma = 1.718/(2 * np.sqrt(2 * np.log(2)) = 1.718 / 2.35 = 0.731 A. The output wavelength grid of quickspectra is 0.8 A , so I would expect the output resolution to have a rms ~= sqrt(0.731**2+0.8**2/12.-0.2**2/12.) = 0.764 A.

But the function camera.get_output_resolution_matrix returns a resolution with a rms of 0.795A which looks like the rebinning has been performed twice ...

Screenshot from 2023-05-04 11-05-54

julienguy commented 1 year ago

There is another ambiguity because the input resolution in the code is directly a Gaussian of FWHM given in $DESIMODEL/data/specpsf/psf-quicksim.fits which ignores the input bin size (which is 0.2A by default). This effect is however smaller than the one mentioned above.

julienguy commented 1 year ago

I ran a simulation test with a delta function at 4000A as input and confirm the above. I measure a output line sigma=0.769A.

p-slash commented 1 year ago

@julienguy I had this simple change some weeks ago, which you can now find on this branch. The changes are minor. I shift every row of the input resolution matrix to the center of the coarse grid.

This gives a one-smoothed resolution matrix, but it does not work like spectro-perfectionism, i.e. Obs != NewResoMat x model.

dkirkby commented 1 year ago

Just catching up now. The resolution matrix computed by this function is not used internally in specsim, so any problems here should not affect the simulated spectra. Does the simulation test you ran at 4000A contradict this assertion @julienguy ?

julienguy commented 1 year ago

It is used in desispec in quickspectra. https://github.com/desihub/desisim/blob/50998bfa41c5ebfc61930d352a455ea0f913584c/py/desisim/scripts/quickspectra.py#L242 Naim's correction is working fine (I validated it with my 4000A line test), we indeed have recenter the resolution before averaging in one direction. More details will be given in the PR to come.

julienguy commented 1 year ago

Solved with PR #128.