GalSim
GalSim copied to clipboard
Add a GalSim deviates (partial) drop-in replacement for numpy.RandomState.
In numpy, if I want a random array uniformly distributed between -0.6 and +0.6 with 100 elements, I'd write:
rng = numpy.random.RandomState(seed)
array = rng.uniform(-0.6, 0.6, 100)
Using GalSim deviates, I'd do something like:
ud = galsim.UniformDeviate(seed)
array = np.empty(100)
ud.generate(array)
array = array*1.2 - 0.6
I find the former easier to read. I don't think it'd be too difficult to create an object based on GalSim deviates with methods like .uniform, .normal=.gaussian, .binomial, .poisson, etc that have the same syntax as numpy. Making a drop-in replacement also means that it's easier for external packages (e.g., imsim, batoid, ...) to switch from numpy random numbers to Galsim random numbers with their stronger guarantee of stability over time.
Sounds good. I wouldn't make a new class for this though. These can be methods of BaseDeviate I think.
I thought about that. The only awkward part is that then UniformDeviate will have an inherited method .poisson and so on. Maybe that's fine though.
Doesn't bother me. :) But either way. If you prefer to make a new subclass of BaseDeviate that would enable these various driver methods, that's also fine.
Done via #1179