LSSTDESC / descwl-shear-sims

simple simulations for testing weak lensing shear measurement
BSD 3-Clause "New" or "Revised" License
10 stars 9 forks source link

add option for PSF objects to interpolate to offset #147

Closed esheldon closed 2 years ago

esheldon commented 3 years ago

currently offset psfs do so perfectly

real psfs will need to interpolate a centered psf to an offset one

to test the effect of this implement an option to use an InterpolatedImage for offseting

beckermr commented 3 years ago

I don't really follow what's being tested here.

esheldon commented 3 years ago

We need to offset the psf and warp it back to center in order for the psf to have the extra bit of smearing that happens to images when they get warped

But psf codes like psfex and piff create a centered psf and you only get an offset one by interpolating it.

So if we use piff to offset then warp it back we get two smearing effects instead of one: the smearing due to interpolating it to an offset position and the warping back

We can try to mock this up with our galsim based psfs by using an InterpolatedImage to create the offset psf

beckermr commented 3 years ago

But psf codes like psfex and piff create a centered psf and you only get an offset one by interpolating it.

This may be true for PSFex but I don't think it is right for Piff. Piff will use interpolations but those are a part of the actual PSF model, so we don't care about them. Assuming Piff minimizes a chisqr, then its model has been constructed to account for this.

@rmjarvis should confirm.

rmjarvis commented 3 years ago

The underlying model in Piff (for PixelGrid) is already an InterpolatedImage, which you can draw and any position you want.

I don't think it's currently trivial to get a GSObject version of the PSF model directly, but it's been on my TODO list. So if that's a feature you want, I can add it sooner than later.

beckermr commented 3 years ago

The underlying model in Piff (for PixelGrid) is already an InterpolatedImage, which you can draw and any position you want.

Right. My question is really about how the fit is defined.

My understanding is as follows. There is an underlying interpolated image model that is centered at the image center as normal. Then when you compare to an observed star, you use lanczos3 or w/e to interpolate to that star location. Thus the model is adjusted to match that star after interpolation to its subpixel location. Said differently, the PSF model array inside the interpolated image is actually sharper than the real PSF in order to account for the blurring that happens when you draw to a subpixel location.

If the thing I just wrote is correct, then the blurring of the PSF model due to the interpolation is already accounted for in Piff and we do not need to test for the effects of extra blurring here.

rmjarvis commented 3 years ago

Yes, that is basically how the fit works (a little more complicated because interpolation coefficients are fitted at the same time) with one caveat: The model itself may or may not be forced to be centered, depending on the centered parameter of the PixelGrid model. If True (the default, and what the Y6 run used) then it is as you described. If False, then the input positions are trusted and the model at any given location may have a non-zero centroid. We plan to try the latter using Gaia stars with known positions.

rmjarvis commented 3 years ago

In either case, the blurring from the Lanczos kernel is already accounted for.

esheldon commented 3 years ago

What do you mean by "accounted for"?

If I request an off-center PSF reconstruction, is it equivalent to the following if the psf before pixelization was gaussian?

psf = galsim.Gaussian(...)
im = psf.drawImage(..., offset=(offx, offy))

The above would work as it does no interpolation.

this would not because it introduces some small interpolation smearing

psf = galsim.Gaussian(...)
tim = psf.drawImage(..., offset=(offx, offy))
ii = galsim.InterpolatedImage(tim, ...)
im = ii.drawImage(..., offset=(offx, offy))
beckermr commented 3 years ago

Yup. Don't ever do the second thing. I don't do that in the DES codes and we should never do it in the LSST ones. Piff returns to the center we need already.

Edit: What my eyes saw here was reinterpolating a Piff PSF image. That is not what is in the code above! In any case, the general point holds. Let the PSF code do the interpolating.

beckermr commented 3 years ago

If the DM codes are doing this when we ask them for the PSF, they will have to be changed.

rmjarvis commented 3 years ago

The PSF model from Piff is closer to what you call ii here. Not the raw Gaussian. For instance, it already includes the pixel response, so you want to draw it with method='no_pixel'.

But it's fit from a bunch of stars at a variety of offsets. So the mean effect of the Lanzcos kernel is already intrinsic to the fitting process. Drawing it at a new arbitrary location should already be the best estimate of what a star would look like with that sub-pixel position.

esheldon commented 3 years ago

Sounds good if correct. We need to test that.

beckermr commented 3 years ago

Do you have ideas for testing beyond simply checking in the data that for stars not used in the PSF fit, the model is a good fit to them?

I guess we could check in a simulation with a known solution as well. Maybe @rmjarvis has done that before?

rmjarvis commented 3 years ago

Some of the Piff unit tests do that. Rather than reserve stars, compare drawn fits to the same underlying model drawn the same way at new locations. However, they just test image equality a couple decimal places of precision. Not that there is no subtle mean shear imparted by the process or anything like that. So probably you want to do something a bit more tuned to the effect you're worried about.

esheldon commented 3 years ago

I think the test would have to be fitting for the PSF with PIFF and taking it through to shear recovery