GalSim-developers/GalSim — pull request #202 by barnabytprowe (2012-06-23 08:33:51+00:00)
Title: #163 - Fixups and enhancements for photon shooting

Thanks to much help from Mike and others, we've completed the following tasks identified for Issue #163:

1. Have the drawShoot() method return the fraction of photons that fell inside the Image.

2. Improved the shuffling of photons by `Convolve` (especially for `Add` objects)

3. Added code that will let drawShoot() add Poisson variation to the total flux of the drawn object.

4. Added a `noise` parameter to `drawShoot()` to allow GalSim to calculate the number of photons required based on a tolerance value of Poisson noise deemed acceptable in the output.

5. Investigated and documented findings regarding possibility that use of BinomialDeviate in SBAdd is very slow, perhaps calling UniformDeviate many times. This seems to be fine (see #163).

6. Seen whether the Newton-Raphson method of SBExponential is really faster than the OneDimensionalDeviate routine that you get when you request SBSersic with n=1. It seems not to be. See also...

7. Performed efficiency testing where there are multiple ways to do the same thing (unit-circle randoms vs sin/cos and the 1D deviate method described above for Exponential).

For 7., the impacted profiles are the Gaussian, Moffat and Exponential, and timing tests scripts can be found in the directory `devutils/external/time_photon_shooting/`.

The results are as follows:
```
Results of photon shooting timing tests for GalSim Issue #163
(see https://github.com/GalSim-developers/GalSim/issues/163)

Excecuted using the code at the repository commit: 1d8627904508c6727eac389e03dcf9072dbff18f

Testing scripts:
devutils/external/time_photon_shooting/time_gaussian.py
devutils/external/time_photon_shooting/time_moffat.py
devutils/external/time_photon_shooting/time_exponential.py

Test system info:
MacbookPro8,2: 4 core 2.2 GHz Intel Core i7, 8GB RAM
OSX 10.7.4, Darwin Kernel Version 11.4.0, gcc 4.2.1 (i686-apple-darwin11 build)

--Gaussian results--

USE_COS_SIN: on
time_gaussian_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 43.769228 sec
time_gaussian_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 43.845985 sec
time_gaussian_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 43.759112 sec

USE_COS_SIN: off
time_gaussian_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 41.460453 sec
time_gaussian_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 41.458574 sec
time_gaussian_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 41.389149 sec

--Moffat results--

USE_COS_SIN: on
time_moffat_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 81.330360 sec
time_moffat_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 81.366816 sec
time_moffat_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 81.526213 sec

USE_COS_SIN: off
time_moffat_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 70.426707 sec
time_moffat_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 70.504782 sec
time_moffat_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 70.456211 sec

--Exponential results--

USE_COS_SIN: on
USE_1D_DEVIATE_EXPONENTIAL: on
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 69.313235 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 69.781120 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 69.329941 sec

USE_COS_SIN: off
USE_1D_DEVIATE_EXPONENTIAL: on
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 69.009877 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 69.070312 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 69.083846 sec

USE_COS_SIN: on
USE_1D_DEVIATE_EXPONENTIAL: off
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 114.169648 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 114.104397 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 114.024346 sec

USE_COS_SIN: off
USE_1D_DEVIATE_EXPONENTIAL: off
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 118.740515 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 118.716056 sec
time_exponential_shoot: NIMAGES = 1000, NPHOTONS = 500000, total time = 118.701256 sec
```

To replicate these results on your system, it is merely necessary to comment out the relevant lines
```
#define USE_COS_SIN
#define USE_1D_DEVIATE_EXPONENTIAL
```
which can be found at lines 15 and 19 of `galsim/include/SBProfile.h`.

I think this motivates disabling `USE_SIN_COS` by default and enabling `USE_1D_DEVIATE_EXPONENTIAL`.

Comments / suggestions welcomed. There are a couple of final resolutions made in #163, regarding making issues for further work. These are some what independent of this pull request, but I won't close #163 until they are complete (that would be cheating... ;)