Search code examples
galsim

How to set random seed in Galsim, the modular galaxy image simulation toolkit


How would one go about setting the random seed for functions like the following:

image = galsim.imageD(x_lim,y_lim,scale)
image_gal = gal_obj.drawShoot(image=image)

I need a deterministic seed but am not sure how to set it.


Solution

  • Use the "rng" keyword argument when drawing. So for example, you could do

    image = galsim.ImageD(x_lim, y_lim, scale=scale)
    image_gal = gal_obj.drawShoot(image=image, rng=galsim.BaseDeviate(1234567))
    

    if you want deterministic photon-shooting using the seed 1234567.

    On a more minor note, use of drawShoot is still supported but is discouraged as of GalSim v1.1. Instead, we are encouraging use of a unified drawing method that allows both photon-shooting and DFT rendering. In that case, the last line of the code snippet would become

    image_gal = gal_obj.drawImage(image=image, rng=galsim.BaseDeviate(1234567), method='phot')
    

    (That is, assuming you have GalSim v1.1 installed.)