Permalink
Browse files

Mike's BuildX stuff now working.

  • Loading branch information...
1 parent 9f6ad10 commit 7b1a991d8b27f2b2d2e7729f8f5fc7d60c9478d0 @rmjarvis rmjarvis committed May 10, 2012
Showing with 39 additions and 27 deletions.
  1. +21 −10 examples/MultiObjectDemo.py
  2. +18 −17 galsim/frontend.py
@@ -274,10 +274,12 @@ def Script2():
random_seed = 8241573
sky_level = 1.e6 # ADU
- pixel_scale = 0.2 # arcsec
+ pixel_scale = 0.3 # arcsec
gal_flux = 2000 #
gal_g1 = -0.009 #
gal_g2 = 0.011 #
+ image_xmax = 64 # pixels
+ image_ymax = 64 # pixels
logger.info('Starting multi-object script 2 using:')
logger.info(' - parameters taken from catalog %r',cat_file_name)
@@ -336,39 +338,48 @@ def Script2():
# Read the catalog
input_cat = galsim.io.ReadInputCat(config,cat_file_name)
+ logger.info('Read %d objects from catalog',input_cat.nobjects)
# Build the images
all_images = []
for i in range(input_cat.nobjects):
+ if i is not input_cat.current:
+ raise ValueError('i is out of sync with current.')
+
+ logger.info('Start work on image %d',input_cat.current)
+
psf = galsim.BuildGSObject(config.psf, input_cat, logger)
- logger.info('Made PSF profile')
+ logger.info(' Made PSF profile')
pix = galsim.BuildGSObject(config.pix, input_cat, logger)
- logger.info('Made pixel profile')
+ logger.info(' Made pixel profile')
gal = galsim.BuildGSObject(config.gal, input_cat, logger)
- logger.info('Made galaxy profile')
-
- # increment the row of the catalog that we should use
- input_cat.current += 1
+ logger.info(' Made galaxy profile')
final = galsim.Convolve(psf,pix,gal)
- im = final.draw()
+ #im = final.draw(dx=pixel_scale) # It makes these as 768 x 768 images. A bit big.
+ im = galsim.ImageF(image_xmax, image_ymax)
+ final.draw(im, dx=pixel_scale)
+ logger.info(' Drew image: size = %d x %d',im.xMax-im.xMin+1, im.yMax-im.yMin+1)
# Add Poisson noise
im += sky_level
im.addNoise(galsim.CCDNoise(rng))
im -= sky_level
- logger.info('Drew image')
+ logger.info(' Added noise')
# Store that into the list of all images
all_images += [im]
+ # increment the row of the catalog that we should use for the next iteration
+ input_cat.current += 1
+
logger.info('Done making images of galaxies')
# Now write the image to disk.
# TODO: This function doesn't exist yet.
- galsim.fits.writeCube(out_file_name, all_images, clobber=True)
+ #galsim.fits.writeCube(out_file_name, all_images, clobber=True)
logger.info('Wrote image to %r',out_file_name) # using %r adds quotes around filename for us
print
View
@@ -109,36 +109,36 @@ def BuildSimple(config, req=[], size_opt=[], opt=[], input_cat=None, logger=None
@param opt A list of optional attributes
In addition to what is listed, the flux is always optional.
"""
- print 'Start BuildSimple for ',config.type
+ #print 'Start BuildSimple for ',config.type
# All simple builders have an optional flux attribute so add that to opt
opt += ['flux']
# Make the argument list for the constructor
kwargs = {}
for key in req:
- print 'req key = ',key
+ #print 'req key = ',key
if not config.hasattr(key):
if logger != None:
logger.info("Error: %s requires the following attributes: %s",config.type,req)
raise AttributeError()
value = Generate(eval("config." + key),input_cat,logger)
- print 'value = ',value
+ #print 'value = ',value
kwargs[key] = value
for key in opt:
if config.hasattr(key):
- print 'opt key = ',key
+ #print 'opt key = ',key
value = Generate(eval("config." + key),input_cat,logger)
- print 'value = ',value
+ #print 'value = ',value
kwargs[key] = value
# Make sure one and only one size is present
found = False
for key in size_opt:
- print 'size key = ',key
+ #print 'size key = ',key
if config.hasattr(key):
value = Generate(eval("config." + key),input_cat,logger)
- print 'value = ',value
+ #print 'value = ',value
if (found):
if logger != None:
logger.info("Error: %s requires exactly one of the following attributes: %s",
@@ -177,7 +177,7 @@ def BuildAiry(config, input_cat=None, logger=None):
return galsim.BuildSimple(config, [], ['D'], ['obs'], input_cat, logger)
def BuildPixel(config, input_cat=None, logger=None):
- print 'Start BuildPixel'
+ #print 'Start BuildPixel'
for key in ['xw','yw']:
if not config.hasattr(key):
@@ -200,7 +200,7 @@ def BuildPixel(config, input_cat=None, logger=None):
return galsim.Pixel(**kwargs)
def BuildSquarePixel(config, input_cat=None, logger=None):
- print 'Start BuildSquarePixel'
+ #print 'Start BuildSquarePixel'
if not config.hasattr('size'):
if logger != None:
@@ -213,7 +213,7 @@ def BuildSquarePixel(config, input_cat=None, logger=None):
return galsim.Pixel(**kwargs)
def BuildSum(config, input_cat=None, logger=None):
- print 'Start BuildSum'
+ #print 'Start BuildSum'
if not config.hasattr('items'):
if logger != None:
@@ -225,7 +225,7 @@ def BuildSum(config, input_cat=None, logger=None):
return galsim.Add(list)
def BuildConvolve(config, input_cat=None, logger=None):
- print 'Start BuildConvolve'
+ #print 'Start BuildConvolve'
if not config.hasattr('items'):
if logger != None:
@@ -240,7 +240,7 @@ def BuildConvolve(config, input_cat=None, logger=None):
def Generate(config, input_cat=None, logger=None):
- print 'Start Generate with config = ',config
+ #print 'Start Generate with config = ',config
try:
if config.hasattr('type'):
return eval('galsim.GenerateFrom' + config.type + '(config, input_cat, logger)')
@@ -250,7 +250,7 @@ def Generate(config, input_cat=None, logger=None):
return config
def GenerateFromInputCatalog(config, input_cat, logger=None):
- print 'Start GenerateFromInputCatalog'
+ #print 'Start GenerateFromInputCatalog'
if input_cat is None:
raise ValueError("Use of InputCatalog requested, but no input_cat given")
@@ -259,11 +259,11 @@ def GenerateFromInputCatalog(config, input_cat, logger=None):
logger.info("Error: InputCatalog requires col attribute",config.type)
raise AttributeError("No col specified for InputCatalog")
col = config.col
- print 'col = ',col
+ #print 'col = ',col
# input_cat stores the current row to use.
current = input_cat.current
- print 'current = ',current
+ #print 'current = ',current
if current >= input_cat.nobjects:
raise ValueError("Trying to access past the end of the catalog data.")
@@ -272,8 +272,9 @@ def GenerateFromInputCatalog(config, input_cat, logger=None):
if input_cat.type is 'ASCII':
try:
- value = input_cat.data[current,col]
- print 'value = ',value
+ # config values are 1-based, but we access is 0-based, so use col-1
+ value = input_cat.data[current,col-1]
+ #print 'value = ',value
except TypeError:
if logger != None:
logger.info("Error: col should be an integer, but is %s",col)

0 comments on commit 7b1a991

Please sign in to comment.