diff --git a/examples/demo11.py b/examples/demo11.py index 4a62a742517..d6178b3faa6 100644 --- a/examples/demo11.py +++ b/examples/demo11.py @@ -61,6 +61,7 @@ import logging import time import galsim +import astropy.units as u def main(argv): """ @@ -95,7 +96,10 @@ def main(argv): # (This corresponds to 8 galaxies / arcmin^2) grid_spacing = 90.0 # The spacing between the samples for the power spectrum # realization (arcsec) - tel_diam = 4 # Let's figure out the flux for a 4 m class telescope + tel_diam = 4*u.m # Let's figure out the flux for a 4 m class telescope. We'll + # also show how astropy units can be used here (see especially + # the eval_variables section of the yaml version of this + # demo). exp_time = 300 # exposing for 300 seconds. center_ra = 19.3*galsim.hours # The RA, Dec of the center of the image on the sky center_dec = -33.1*galsim.degrees @@ -106,7 +110,7 @@ def main(argv): # is 2.4 but there is obscuration (a linear factor of 0.33). Here, we assume that the telescope # we're simulating effectively has no obscuration factor. We're also ignoring the pi/4 factor # since it appears in the numerator and denominator, so we use area = diam^2. - hst_eff_area = 2.4**2 * (1.-0.33**2) + hst_eff_area = (2.4*u.m)**2 * (1.-0.33**2) flux_scaling = (tel_diam**2/hst_eff_area) * exp_time # random_seed is used for both the power spectrum realization and the random properties diff --git a/examples/demo11.yaml b/examples/demo11.yaml index 2441c1dd5d4..d2449a00930 100644 --- a/examples/demo11.yaml +++ b/examples/demo11.yaml @@ -44,6 +44,7 @@ # - image.noise : symmetrize # - wcs type : Tan(dudx, dudy, dvdx, dvdy, units, origin, ra, dec) # - top level field eval_variables +# - quantity letter type for eval variable. # # - Power spectrum shears and magnifications for non-gridded positions. # - Reading a compressed FITS image (using BZip2 compression). @@ -74,8 +75,10 @@ eval_variables : # An unusual prefix: a = Angle. atheta : &theta 0.17 degrees - # tel_diam = the telescope diameter in meters. - ftel_diam : &tel_diam 4 + # tel_diam = the telescope diameter. Prefixing this with a 'q' means it is an + # astropy.units.Quantity. We'll specify centimeters here, note the interaction with + # meters down below when we use it to calculate the scale_flux. + qtel_diam : &tel_diam 4 m # exp_time = the exposure time in seconds. fexp_time : &exp_time 300 @@ -167,7 +170,7 @@ gal : # noise_pad_size = 40 * sqrt(2) * 0.2 arcsec/pixel = 11.3 arcsec noise_pad_size : 11.3 - # We will select a galaxy at random from the catalog. One could easily do this by setting + # We will select a galaxy at random from the catalog. One could easily do this by setting # index : { type : Random } # but we will instead allow the catalog to choose a random galaxy for us. It will remove any # selection effects involved in postage stamp creation using weights that are stored in the @@ -192,7 +195,7 @@ gal : # second exposures. The COSMOS galaxies have their flux set to be appropriate for HST # (a 2.4 m telescope with a linear obscuration factor of 0.33) with 1 second exposures. # So the flux should be scaled by (4**2/(2.4*(1-0.33**2))) * 300 - "$(tel_diam**2 / (2.4**2*(1.-0.33**2))) * exp_time" + "$(tel_diam**2 / ((2.4*u.m)**2*(1.-0.33**2))) * exp_time" # Define some other information about the images diff --git a/examples/json/demo11.json b/examples/json/demo11.json index 16b856fa3ab..5736f3b52cc 100644 --- a/examples/json/demo11.json +++ b/examples/json/demo11.json @@ -19,7 +19,7 @@ "eval_variables" : { "fpixel_scale" : 0.2, "atheta" : "0.17 degrees", - "ftel_diam" : 4, + "qtel_diam" : "4 m", "fexp_time" : 300, "fimage_size" : 2048, "inobjects" : 288, @@ -44,7 +44,7 @@ "shear" : { "type" : "PowerSpectrumShear" }, "magnification" : { "type" : "PowerSpectrumMagnification" }, "rotation" : { "type" : "Random" }, - "scale_flux" : "$(tel_diam**2 / (2.4**2*(1.-0.33**2))) * exp_time" + "scale_flux" : "$(tel_diam**2 / ((2.4*u.m)**2*(1.-0.33**2))) * exp_time" }, "image" : {