GalSim
GalSim copied to clipboard
#1148 Fix PhotonDCR config layer bugs, along with a number of other edge cases it turned up.
@jmeyers314 noticed some clear typos in the PhotonDCR opt_params class variable, which made it obvious that we don't have any unit tests testing the various ways to make a PhotonDCR object in the config layer. So this PR adds some.
Along the way, I discovered the following minor bugs and a few features I thought we should have, so I fixed them as well:
- There was no way to specify the dtype of the image made by config processing. Usually float32 is fine, but we should be able to specify something else if we want. So now, the image field takes an optional
dtype, which can be e.g. `np.float64', 'int', 'float', 'numpy.uint32', etc. Basically all the types that images can be using either np or numpy prefixes where appropriate. - When testing that feature with int images, I discovered that (completely unrelated to config-based usage) sometimes int images would have values 1 less than what they should be, even when photon shooting, so everything should be integer values. This turned out to be due to numpy's
astypenot rounding when casting to integers as I think I always assumed. Some bits of the calculation go through floats, so they could be e.g. 29.99999999999974, which became 29, not 30. So now GalSim.Image has a_safe_castmethod that rounds if casting to an integer value before doingastype. - Image type Single had a non-standard usage of world_pos, which I think used to have a rationale a long time ago, but the reason for it has been superseded by
sky_pos. This "feature" also wasn't documented anywhere other than in a unit test that confirms it works in that non-standard way. So I considered it a bug, and I fixed it to work the normal way. - I wanted to set a flux for an object with an SED, which wasn't (easily) possible in config. So I added a feature that if you set both flux and sed, it will apply the SED and then call
withFlux(flux, bandpass)to normalize to that flux value, which seems intuitive. - I discovered that for image type=Single, sometimes the wcs in the final image would be a Jacobian at the local image pos, rather than the intended wcs. So I fixed that.
- Finally, there were the typos Josh noticed for PhotonDCR, and also it assumed sky_pos always exists when using it for obj_coord, which isn't true, so now I check for it.