GalSim-developers/GalSim — pull request #371 by rmandelb (2013-03-15 01:04:09+00:00)
Title: #304 - magnification from a shear power spectrum

This pull request is for a modification of the lensing engine to include calculation of convergence (magnification) in addition to shears when drawing shears according to a power spectrum, with various bits of work by Joe, Barney, and me. In addition to the changes to the PowerSpectrum class to enable this functionality, here are some other changes:

* there is a new utility to reconstruct kappa based on gridded shears using the Kaiser & Squires method,
* there were small changes to config to use this functionality, and
* the magnifications are applied to the galaxies in demo11 as an example. (Mike, I've never tinkered in config this much, so comments on what I did would be welcome. I know it's not totally wrong because the outputs from demo11.py, .yaml, and .json are identical, but I imagine that there could be details missing or deviations from usual style.)

Here are some notes on the changes, including some issues of design that are up for discussion:

(1) There is some non-parallelism between the NFWHalo and PowerSpectrum classes. For NFWHalo there are analytic expressions for shear and convergence, so it makes sense to have independent getShear and getMag methods. However, for PowerSpectrum, we first have a buildGriddedShears method to make the shears on the grid, so it makes sense to decide at that point whether we want convergence, and calculate it then. At that point, since it is relatively unusual that one would want convergence from a power spectrum WITHOUT knowing the shear as well, I also made the getShear() method return both shear and convergence (with the latter being optional). There is no separate method to just get convergence / magnification. However, this was a design choice that should be up for discussion, and there are many variations one could imagine.

(2) In the context of cosmological theory, people often talk about shear PS and convergence PS, hence I have the code returning the convergence. However, when applying this to simulated data, we want magnification mu. For now, the user is responsible for this conversion to mu, but are people interested in having a get_mu option (parallel to the get_kappa option) that would return the magnification directly?

(3) Because of the coupling between shear and convergence here, the config method to get the magnification is inefficient, since it has to call getShear() even though most users will have already called getShear() to get the convergence. There are, again, many ways this could be done differently (including caching shears or changing around the methods to decouple the calculations), so comments/suggestions are welcome.

(4) The default for now is that the convergence calculation is turned off, partly for speed (it leads to additional FFTs) and partly for backwards compatibility: the return statements have more numbers when convergence is calculated and returned, so all the places in the current code where we get ```g1, g2 = ps.buildGriddedShear(...)``` or ```g1, g2 = ps.getShear(...)``` would have broken. However, since we're still at version <1 it isn't crazy to change the user interface, so if people prefer it to be calculated and returned by default, I could be persuaded that that's the way to go.

A final random idea that I'm not sure about and would like some opinions on: right now users have to get shear and magnification, and apply them separately. Would it make sense to have methods like ```createLensed``` and ```applyLensing``` that would take a shear and magnification, and do both steps at once? It seems a tad silly since it's just saving one line, but having that function around is kind of a nice reminder for users that lensing includes both effects.