Skip to content

Commit 9248b0d

Browse files
committed
Update demo7 to use str(obj) in output logger messages
(#218)
1 parent 5612b4e commit 9248b0d

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

examples/demo7.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- obj = galsim.Sersic(n, half_light_radius, trunc)
3838
- psf = galsim.OpticalPSF(..., aberrations=aberrations, ...)
3939
- obj = obj.dilate(scale)
40+
- str(obj)
4041
- image.scale = pixel_scale
4142
- obj.drawImage(image, method='fft')
4243
- obj.drawImage(image, method='phot', max_extra_noise, rng)
@@ -69,6 +70,9 @@ def main(argv):
6970
# To turn off logging:
7071
#logger.propagate = False
7172

73+
# To turn on the debugging messages:
74+
#logger.setLevel(logging.DEBUG)
75+
7276
# Define some parameters we'll use below.
7377

7478
# Make output directory if not already present.
@@ -200,11 +204,23 @@ def main(argv):
200204
for ipsf in range(len(psfs)):
201205
psf = psfs[ipsf]
202206
psf_name = psf_names[ipsf]
207+
logger.info('psf %d: %s',ipsf+1,psf)
208+
# Note that this implicitly calls str(psf). We've made an effort to give all GalSim
209+
# objects an informative but relatively succinct str representation. Some details may
210+
# be missing, but it should look essentially like how you would create the object.
211+
logger.debug('repr = %r',psf)
212+
# The repr() version are a bit more pedantic in form and should be completely informative,
213+
# to the point where two objects that are not identical should never have equal repr
214+
# strings. As such the repr strings may in some cases be somewhat unwieldy. For instance,
215+
# since we set non-default gsparams in these, the repr includes that information, but
216+
# it is omitted from the str for brevity.
203217
for igal in range(len(gals)):
204218
gal = gals[igal]
205219
gal_name = gal_names[igal]
220+
logger.info(' galaxy %d: %s',igal+1,gal)
221+
logger.debug(' repr = %r',gal)
206222
for i in range(4):
207-
logger.debug('Start work on image %d',i)
223+
logger.debug(' Start work on image %d',i)
208224
t1 = time.time()
209225

210226
# Initialize the random number generator we will be using.
@@ -240,7 +256,7 @@ def main(argv):
240256
fft_image = image[galsim.BoundsI(1, nx, 1, ny)]
241257
phot_image = image[galsim.BoundsI(nx+3, 2*nx+2, 1, ny)]
242258

243-
logger.debug(' Read in training sample galaxy and PSF from file')
259+
logger.debug(' Read in training sample galaxy and PSF from file')
244260
t2 = time.time()
245261

246262
# Draw the profile
@@ -252,7 +268,7 @@ def main(argv):
252268
# for illustrative purposes.)
253269
final.drawImage(fft_image, method='fft')
254270

255-
logger.debug(' Drew fft image. Total drawn flux = %f. .flux = %f',
271+
logger.debug(' Drew fft image. Total drawn flux = %f. .flux = %f',
256272
fft_image.array.sum(),final.getFlux())
257273
t3 = time.time()
258274

@@ -285,17 +301,17 @@ def main(argv):
285301
# image, we need to subtract the mean back off when we are done.
286302
phot_image -= sky_level_pixel
287303

288-
logger.debug(' Added Poisson noise. Image fluxes are now %f and %f',
304+
logger.debug(' Added Poisson noise. Image fluxes are now %f and %f',
289305
fft_image.array.sum(), phot_image.array.sum())
290306
t6 = time.time()
291307

292308
# Store that into the list of all images
293309
all_images += [image]
294310

295311
k = k+1
296-
logger.info('%d: %s * %s, flux = %.2e, hlr = %.2f, ellip = (%.2f,%.2f)',
297-
k,gal_name, psf_name, flux, hlr, gal_shape.getE1(), gal_shape.getE2())
298-
logger.debug(' Times: %f, %f, %f, %f, %f',t2-t1, t3-t2, t4-t3, t5-t4, t6-t5)
312+
logger.info(' %d: flux = %.2e, hlr = %.2f, ellip = (%.2f,%.2f)',
313+
k, flux, hlr, gal_shape.getE1(), gal_shape.getE2())
314+
logger.debug(' Times: %f, %f, %f, %f, %f',t2-t1, t3-t2, t4-t3, t5-t4, t6-t5)
299315

300316
psf_times[ipsf] += t6-t1
301317
psf_fft_times[ipsf] += t3-t2

0 commit comments

Comments
 (0)