Skip to content

Commit

Permalink
Add gsparams capabilities to demo7
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Apr 23, 2013
1 parent a43282f commit 51a7135
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 18 deletions.
62 changes: 47 additions & 15 deletions examples/demo7.py
Expand Up @@ -43,6 +43,7 @@
- dev = galsim.PoissonDeviate(rng, mean)
= noise = galsim.DeviateNoise(dev)
- writeCube(..., compress='gzip')
- gsparams = galsim.GSParams(...)
"""

import sys
Expand Down Expand Up @@ -91,29 +92,60 @@ def main(argv):

psf_fwhm = 0.65 # arcsec

# This script is set up as a comparison between using FFTs for doing the convolutions and
# shooting photons. The two methods have trade-offs in speed and accuracy which vary
# with the kind of profile being drawn and the S/N of the object, among other factors.
# In addition, for each method, there are a number of parameters GalSim uses that control
# aspects of the calculation that further affect the speed and accuracy.
#
# We encapsulate these parameters with an object called GSParams. The default values
# are intended to be accurate enough for normal precision shear tests, without sacrificing
# too much speed.
#
# Any PSF or galaxy object can be given a gsparams argument on construction that can
# have different values to make the calculation more or less accurate (typically trading
# off for speed or memory).
#
# In this script, we adjust some of the values slightly, just to show you how it works.
# You could play around with these values and see what effect they have on the drawn images.
# Usually, it requires a pretty drastic change in these parameters for you to be able to
# notice the difference by eye. But subtle effects that may impact the shapes of galaxies
# can happen well before then.

# Type help(galsim.GSParams) for the complete list of parameters and more detailed docs.
gsparams = galsim.GSParams(
alias_threshold=1.e-2, # maximum fractionalr flux that may be aliased around edge of FFT
maxk_threshold=2.e-3, # k-values less than this may be excluded off edge of FFT
xvalue_accuracy=1.e-4, # approximations in real space aim to be this accurate
kvalue_accuracy=1.e-4, # approximations in fourier space aim to be this accurate
shoot_accuracy=1.e-4, # approximations in photon shooting aim to be this accurate
minimum_fft_size=64) # minimum size of ffts

This comment has been minimized.

Copy link
@rmandelb

rmandelb Apr 24, 2013

Member

worth saying how these differ from defaults?

This comment has been minimized.

Copy link
@rmjarvis

rmjarvis Apr 24, 2013

Author Member

How about just adding above: "...and more detailed docs, including what the default values are for each parameter."

This comment has been minimized.

Copy link
@rmandelb

rmandelb Apr 24, 2013

Member

okay


logger.info('Starting demo script 7')

# Make the pixel:
pix = galsim.Pixel(xw = pixel_scale)

# Make the PSF profiles:
psf1 = galsim.Gaussian(fwhm = psf_fwhm)
psf2 = galsim.Moffat(fwhm = psf_fwhm, beta = 2.4)
psf3_inner = galsim.Gaussian(fwhm = psf_fwhm, flux = 0.8)
psf3_outer = galsim.Gaussian(fwhm = 2*psf_fwhm, flux = 0.2)
psf1 = galsim.Gaussian(fwhm = psf_fwhm, gsparams=gsparams)
psf2 = galsim.Moffat(fwhm = psf_fwhm, beta = 2.4, gsparams=gsparams)
psf3_inner = galsim.Gaussian(fwhm = psf_fwhm, flux = 0.8, gsparams=gsparams)
psf3_outer = galsim.Gaussian(fwhm = 2*psf_fwhm, flux = 0.2, gsparams=gsparams)
psf3 = psf3_inner + psf3_outer
atmos = galsim.Gaussian(fwhm = psf_fwhm)
atmos = galsim.Gaussian(fwhm = psf_fwhm, gsparams=gsparams)
optics = galsim.OpticalPSF(
lam_over_diam = 0.6 * psf_fwhm,
obscuration = 0.4,
defocus = 0.1,
astig1 = 0.3, astig2 = -0.2,
coma1 = 0.2, coma2 = 0.1,
spher = -0.3)
psf4 = galsim.Convolve([atmos,optics])
spher = -0.3, gsparams=gsparams)
psf4 = galsim.Convolve([atmos,optics]) # Convolve inherits the gsparams from the first
# item in the list. (Or you can supply a gsparams
# argument explicitly if you want to override this.
#atmos = galsim.AtmosphericPSF(fwhm = psf_fwhm)
atmos = galsim.Kolmogorov(fwhm = psf_fwhm)
optics = galsim.Airy(lam_over_diam = 0.3 * psf_fwhm)
atmos = galsim.Kolmogorov(fwhm = psf_fwhm, gsparams=gsparams)
optics = galsim.Airy(lam_over_diam = 0.3 * psf_fwhm, gsparams=gsparams)
psf5 = galsim.Convolve([atmos,optics])
psfs = [psf1, psf2, psf3, psf4, psf5]
psf_names = ["Gaussian", "Moffat", "Double Gaussian", "OpticalPSF", "Kolmogorov * Airy"]
Expand All @@ -122,12 +154,12 @@ def main(argv):
psf_phot_times = [0,0,0,0,0]

# Make the galaxy profiles:
gal1 = galsim.Gaussian(half_light_radius = 1)
gal2 = galsim.Exponential(half_light_radius = 1)
gal3 = galsim.DeVaucouleurs(half_light_radius = 1)
gal4 = galsim.Sersic(half_light_radius = 1, n = 2.5)
bulge = galsim.Sersic(half_light_radius = 0.7, n = 3.2)
disk = galsim.Sersic(half_light_radius = 1.2, n = 1.5)
gal1 = galsim.Gaussian(half_light_radius = 1, gsparams=gsparams)
gal2 = galsim.Exponential(half_light_radius = 1, gsparams=gsparams)
gal3 = galsim.DeVaucouleurs(half_light_radius = 1, gsparams=gsparams)
gal4 = galsim.Sersic(half_light_radius = 1, n = 2.5, gsparams=gsparams)
bulge = galsim.Sersic(half_light_radius = 0.7, n = 3.2, gsparams=gsparams)
disk = galsim.Sersic(half_light_radius = 1.2, n = 1.5, gsparams=gsparams)
gal5 = 0.4*bulge + 0.6*disk # Net half-light radius is only approximate for this one.
gals = [gal1, gal2, gal3, gal4, gal5]
gal_names = ["Gaussian", "Exponential", "Devaucouleurs", "n=2.5 Sersic", "Bulge + Disk"]
Expand Down
21 changes: 21 additions & 0 deletions examples/demo7.yaml
Expand Up @@ -41,6 +41,7 @@
# - image type : Tiled (..., stamp_size, xborder, yborder)
# - image : draw_method (fft or phot)
# - output : file_name with .gz, .bz2 or .fz extension automatically uses compression.
# - image : gsparams


# Define the PSF profiles
Expand Down Expand Up @@ -155,6 +156,26 @@ image :
# two times, so the fft and phot images get the same values for the random parameters.
random_seed : { type : Sequence , first : 553728 , repeat : 2 }

# This script is set up as a comparison between using FFTs for doing the convolutions and
# shooting photons. The two methods have trade-offs in speed and accuracy which vary
# with the kind of profile being drawn and the S/N of the object, among other factors.
# In addition, for each method, there are a number of parameters GalSim uses that control
# aspects of the calculation that further affect the speed and accuracy.
#
# These parametsrs can be adjusted from the defaults with a gsparams item, either in
# image (in which case the values apply to all objects) or in the gal or psf layer
# in which case the values apply to just that object. For this script, we just apply a
# global change to some of the values, just to demonstrate how it works.
#
# See the config documentation for the complete list of parameters and more detailed
# documentation.
gsparams :
alias_threshold : 1.0e-2 # maximum fractionalr flux that may be aliased around edge of FFT
maxk_threshold : 2.0e-3 # k-values less than this may be excluded off edge of FFT
xvalue_accuracy : 1.0e-4 # approximations in real space aim to be this accurate
kvalue_accuracy : 1.0e-4 # approximations in fourier space aim to be this accurate
shoot_accuracy : 1.0e-4 # approximations in photon shooting aim to be this accurate
minimum_fft_size : 64 # minimum size of ffts

# Define the name and format of the output file
output :
Expand Down
36 changes: 33 additions & 3 deletions examples/json/demo7.json
Expand Up @@ -23,6 +23,7 @@
"#" : "- image type : Tiled (..., stamp_size, xborder, yborder)",
"#" : "- image : draw_method (fft or phot)",
"#" : "- output : file_name with .gz, .bz2 or .fz extension automatically uses compression.",
"#" : "- image : gsparams",


"#" : "Define the PSF profiles",
Expand Down Expand Up @@ -67,8 +68,8 @@

"index" : {
"type" : "Sequence",
"first" : 0,
"last" : 4,
"first" : 0,
"last" : 4,

"#" : "How many times to repeat the same value before moving on:",
"repeat" : 40
Expand Down Expand Up @@ -149,7 +150,36 @@
"#" : "The usual case is to just set a single number, which really means that each object",
"#" : "gets a sequential value starting with this number. In this case we repeat each value",
"#" : "two times, so the fft and phot images get the same values for the random parameters.",
"random_seed" : { "type" : "Sequence" , "first" : 553728 , "repeat" : 2 }
"random_seed" : { "type" : "Sequence" , "first" : 553728 , "repeat" : 2 },

"#" : "This script is set up as a comparison between using FFTs for doing the convolutions and",
"#" : "shooting photons. The two methods have trade-offs in speed and accuracy which vary",
"#" : "with the kind of profile being drawn and the S/N of the object, among other factors.",
"#" : "In addition, for each method, there are a number of parameters GalSim uses that control",
"#" : "aspects of the calculation that further affect the speed and accuracy.",

"#" : "These parametsrs can be adjusted from the defaults with a gsparams item, either in",
"#" : "image (in which case the values apply to all objects) or in the gal or psf layer",
"#" : "in which case the values apply to just that object. For this script, we just apply a",
"#" : "global change to some of the values, just to demonstrate how it works.",

"#" : "See the config documentation for the complete list of parameters and more detailed",
"#" : "documentation.",
"gsparams" : {
"#" : "maximum fractionalr flux that may be aliased around edge of FFT",
"alias_threshold" : 1.0e-2,
"#" : "k-values less than this may be excluded off edge of FFT",
"maxk_threshold" : 2.0e-3,
"#" : "approximations in real space aim to be this accurate",
"xvalue_accuracy" : 1.0e-4,
"#" : "approximations in fourier space aim to be this accurate",
"kvalue_accuracy" : 1.0e-4,
"#" : "approximations in photon shooting aim to be this accurate",
"shoot_accuracy" : 1.0e-4,
"#" : "minimum size of ffts",
"minimum_fft_size" : 64
}

},

"#" : "Define the name and format of the output file",
Expand Down

0 comments on commit 51a7135

Please sign in to comment.