GalSim-developers/GalSim — pull request #403 by rmjarvis (2013-04-22 03:00:30+00:00)
Title: #380 Change default centering convention for image drawing to be the true center of the image.

This pull request is mostly about changing the centering convention as we discussed on #380. For even sized images, the drawn profiles had been centered on the pixel just up and to the right of the actual center of the postage stamp, rather than the true center of the image. The reasons for this were clear -- when using FFTs, it is natural to have a particular pixel be considered 0. However, we decided that it was sufficiently confusing to merit switching to the actual image center instead.

The implementation (thanks to Barney for this suggestion) is pretty much all in the python layer. On the C++ side, we still have a pixel that is considered 0 for the above reason. In the python layer, the draw and drawShoot functions now check if they should apply a half-pixel shift in either or both x and y directions.

I also took Rachel's suggestion to have a keyword the sets whether or not to do this, called use_true_center, which defaults to True. This was mostly to make it easier to get some of the unit tests to pass, so in test_SBProfile.py, most of the tests use use_true_center = False. Especially the tests that compare to a reference image that was drawn off-center.

Finally, I found and fixed a pretty important (although subtle) bug in the FFT drawing routine. Because we make even-sized images for the FFT, and one of the indices is 0, this means there is another index for either +N/2 or -N/2, but not both. The code had arbitrarily picked one of them. (I think +N/2.) This asymmetry meant that a shift (say by 1/2 a pixel) induced a spurious shear of order 1.e-3 or so in addition to the shift, which is more than the precision we want to test the shear measurement algorithms, so that seemed like a bad thing. Anyway, the solution was to build both the +N/2 and -N/2 values and then take the average. When I did this, the spurious shear effect completely vanished, so I think it's working correctly now.

Other more minor changes on this PR:
- Added bounds.trueCenter() to return actual c enter, which doesn't have to be an integer position for integer bounds
- Added 0-based indexing option in config with image.index_convention item. The choices are (0, 'C', 'python') for the 0-based indexing, or (1, 'Fortran', 'FITS') for the 1-based indexing. The default is 1.
- Use index_convention = 0 in demo11.yaml
- Demo image.setOrigin(0,0) in demo11.py to produce same behavior.
- Made the InterpolatedImage class work the same way as draw, but in reverse. Namely, there is a use_true_center option (default=True), which determines whether the profile center is taken to be the true image center or the nominal integer pixel center, which may be 1/2 pixel from the true center.
- Fixed a bug in NFWHalo.getShear where the return value was the wrong type if the input is PositionD. I think this happened as part of the improvements in branch #304, and no one noticed the error until now.