GalSim-developers/GalSim — pull request #354 by msimet (2013-02-07 20:18:09+00:00)
Title: #306

This branch adds a DistDeviate class to allow users to generate random numbers from a probability distribution other than the galsim builtins. It has all the methods of the other Deviate classes, but (because it's written solely in the Python layer) doesn't satisfy isinstance checks for BaseDeviate.

The class takes one of several kinds of input (filename, two 1d arrays of x and P(x), or a callable function) and builds a table of cumulative probability, then stores a LookupTable of x vs CP(x) and draws from it using a UniformDeviate on successive calls. It quietly renormalizes any input probabilities that don't integrate to 1. To tweak precision, users can pass interpolant types and/or number of points in the LookupTable as kwargs.

It's currently implemented for config as a way to add noise to an image, but not for other places where RNGs are possible inputs. I didn't update the wiki docs yet, since this isn't available on master, but the language I've got currently is:

* 'Distribution' generates noise based on a distribution given as a 2-column ASCII file (first column x, second column P(x)). It uses the following fields:
* filename = str_value (required) The file containing the probability distribution.
* interpolant = str_value (default = linear) Defines the interpolant used to determine intermediate probabilities. Must be one of ceil, floor, linear, or spline.
* npoints = int_value (default=256) Number of points in the deviate's internal LookupTable.