Skip to content

Tutorials

Mike Jarvis edited this page Feb 22, 2016 · 16 revisions

The examples directory contains demo files that essentially amount to tutorials on how to use the GalSim code.

There are versions of each demo in both Python (demo*.py) and YAML (demo*.yaml). The demo scripts start fairly simple and progress to more sophisticated simulations, adding a modest number of new features each time with copious documentation about the new features being introduced.

The YAML files are run using the galsim executable, which parses the YAML file into a Python dict and runs this through the config parsing module in GalSim. For complicated simulations, we generally recommend using config files such as these, since they tend to be more quickly readable than the Python scripts, which makes it easy to see how to modify them to effect some desired change in the simulation. For more information about running the galsim executable, see the main Config Documentation page.

Both versions of each demo produce identical output files. Internally, this serves as a useful unit test of the config parsing code. But it also serves as a kind of implicit documentation about how some of the config features are handled by GalSim.

Demo 1

demo1.py demo1.yaml

This first demo is about as simple as it gets. We draw an image of a single galaxy convolved with a PSF and write it to disk. We use a circular Gaussian profile for both the PSF and the galaxy. And we add a constant level of Gaussian noise to the image.

New features in the Python file:

  • obj = galsim.Gaussian(flux, sigma)
  • obj = galsim.Convolve([list of objects])
  • image = obj.drawImage(scale)
  • image.added_flux (Only present after a drawImage command.)
  • noise = galsim.GaussianNoise(sigma)
  • image.addNoise(noise)
  • image.write(file_name)
  • image.FindAdaptiveMom()

New features in the YAML file:

  • top level fields gal, psf, image, output
  • obj type : Gaussian (flux, sigma)
  • image : pixel_scale
  • image : noise
  • noise type : Gaussian (sigma)
  • output : dir, file_name