GalSim-developers / GalSim

The modular galaxy image simulation toolkit. Documentation:
http://galsim-developers.github.io/GalSim/
Other
224 stars 106 forks source link

Improve the speed and quality of the Roman PSFs #1089

Closed rmjarvis closed 4 years ago

rmjarvis commented 4 years ago

This PR fixes a number of problems with the Roman PSFs in GalSim noticed by @matroxel in his recent simulations of the Roman telescope.

  1. Most importantly, the approximate_struts option doesn't really look at all like the 12-spike PSF that we expect. In other words, just putting in 6 radial struts is a bad approximation to the pupil plane mask.
  2. Very bright stars are noticeably boxy, with evident reflections in the diffraction spikes.
  3. There are also apparent FFT ringing artifacts when approximate_struts=False, along the x and y axes of the star.
  4. Setting high_accuracy=True just takes forever and doesn't improve anything.
  5. Setting folding_threshold lower helps with the boxiness and folding, but also takes a vv long time.

The fixes implemented here are as follows:

  1. Don't do approximate struts. Instead for an approximate version, take the real pupil plane image and down sample it (using the Image.bin method) to get a smaller image that is as correct as possible at that resolution.
  2. Don't increase oversampling or pad_factor for high_accuracy. Instead lower folding_threshold to get rid of the folding as per the normal meaning of that parameter.
  3. Deprecate both high_accuracy and approximate_struts. To replace the former, suggest that users lower folding_threshold in the normal way. To replace the latter, let users set the pupil plane binning with the new pupil_bin parameter. (Default is 4.)
  4. Added a workaround for a weird anomaly in the Roman pupil plane images. There is a square around the main pupil image with amplitude ~0.03. This eventually gets turned into 1 when cast as a boolean, so it leads to significant ringing in the rendered PSF image. I deal with it by simply taking everything <0.5 => 0.0, which seems to work.
  5. Make it easier to set individual GSParams by writing e.g. obj.withGSParams(folding_threshold=2.e-3) rather than obj.withGSParams(galsim.GSParams(folding_threshold=2.e-3)), which is almost equivalent. However, the latter syntax isn't always safe, since it loses any other non-default GSParams that obj might already have had set. The new syntax will preserve any non-default values that aren't explicitly overridden in the kwargs.
  6. Change the default ii_pad_factor for PhaseScreenPSFs from 4 to 1.5. I realized when working on this that there was no point to setting it to 4. The whole reason for InterpolatedImage's pad_factor is to accurately render sheared interpolated images. PSFs are vv rarely sheared and not much if at all. So the analysis that led us to recommend pad_factor=4 for (galaxies using) InterpolatedImage doesn't apply. I think 1.0 would be fine, but I chose 1.5 in case there was some need for a little bit of padding.
  7. Cache the apertures that get created. Since the approximate_struts replacement now does a little more work, reading in a non-trivial file, fixing the 0.03 artifact, and then rebinning, there's a bit more overhead than there used to be. So now I save the resulting Aperture in a cache indexed by the relevant parameters. In the normal case where the user makes different PSFs with different aberrations, but otherwise the same bandpass, wavelength, gsparams, then it will be able to use the cache.
rmjarvis commented 4 years ago

Some comparisons between old and new. These are a magnitude 10 star drawn with a typical Roman noise level. The script that made these is in devel/test_roman_psfs.py.

Old (master branch):

old_roman_psf

New (this branch):

new_roman_psf

The four choices of folding_threshold and pupil_bin are what the corresponding high_accuracy and approximate_struts get converted into along with a deprecation warning. The lower left is the most accurate, and that looks quite good I think. In all cases, the new version is (usually much!) faster and looks better.

rmjarvis commented 4 years ago

Note that the central pixel of this star has a value of more than 1.e8. And the flux near the box edges, even in the upper right case is <1000, so the relative accuracy is always better than 1.e-5, which is usually the level that we shoot for with these kinds of things. So the variation among these options is mostly a cosmetic issue for extremely bright things. The usual faint galaxies we mostly care about will be just fine with even the 8x8 binning and normal folding_threshold.

rmjarvis commented 4 years ago

@rmandelb I'm still waiting on responses from project re filter throughputs. I'm still not positive which ones are the really official ones. I had thought to update those on this PR too, but if you have time to take a look at what's here, we can go ahead and finish this PR up and I'll make another one for the other cycle 8 updates that need to happen, once I figure out what the right values are.

rmjarvis commented 4 years ago

Also, one update since I wrote the overview above: I updated the pupil plane images we had here with the new Cycle 8 ones from the project. They now have separate images for each SCA, so I use that. (We already had SCA as a parameter for the getPSF function, so I didn't need any API change to allow this.) They also don't have the weird 0.03 artifact, so I was able to remove that bit of code to fix that up.

rmandelb commented 4 years ago

@rmjarvis - I got eaten up by other things this week, and have a full-afternoon Zoom commitment Thurs+Fri. Realistically I can't do a deep dive into this until the weekend. Just wanted to let you know in case that affects your thinking about what to include in this versus punting. Sorry -

rmjarvis commented 4 years ago

That's fine. I think this is a good set of work to review for now. There'll be more Roman prs this summer with other bits, but we should get this one merged I think.

rmjarvis commented 4 years ago

Thanks Rachel! I reworked parts of the doc string to clear things up. And I took your other suggestions as well. Thanks for the review.