Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions examples/demo8.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

New features introduced in this demo:

- galsim.config.Process(config, logger)
- galsim.config.ProcessInput(config, logger)
- galsim.config.BuildFile(config, file_num, logger)
- image = galsim.config.BuildImage(config, image_num, logger)
- galsim.config.Process(config)
- galsim.config.ProcessInput(config)
- galsim.config.BuildFile(config, file_num)
- image = galsim.config.BuildImage(config, image_num)
- galsim.fits.read(file_name)
"""

Expand Down Expand Up @@ -153,19 +153,13 @@ def main(argv):
#
# image = galsim.config.BuildImage(config, image_num)
#
# All of the above functions also have an optional kwarg, logger, which can take a
# logger object to output diagnostic information if desired. We'll use that option here
# to output the progress of the build as we go. Our logger is set with level=logging.INFO
# which means it will output a modest amount of text along the way. Using level=logging.DEBUG
# will output a lot of text, useful when diagnosing a mysterious crash. And using
# level=logging.WARNING or higher will be pretty silent unless there is a problem.

t1 = time.time()

# Build the image.
# In this case, there is only a single image, so image_num=0. This is the default, so we
# can actually omit this parameter for brevity.
image = galsim.config.BuildImage(config, logger=logger)
image = galsim.config.BuildImage(config)

# At this point you could do something interesting with the image in memory.
# After all, that was kind of the point of using BuildImage rather than the other higher
Expand Down Expand Up @@ -202,7 +196,7 @@ def main(argv):
'file_name' : multi_file_name
}
# Again, we are just building one file, so use the default value of file_num=0.
galsim.config.BuildFile(config, logger=logger)
galsim.config.BuildFile(config)

t3 = time.time()

Expand Down
54 changes: 26 additions & 28 deletions examples/des/blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Define the Blend stamp type
#

def BuildBlendProfiles(self, config, base, psf, gsparams, logger):
def BuildBlendProfiles(self, config, base, psf, gsparams):
"""
Build a list of galaxy profiles, each convolved with the psf, to use for the blend image.

Expand All @@ -38,7 +38,7 @@ def BuildBlendProfiles(self, config, base, psf, gsparams, logger):

self.neighbor_gals = []
for i in range(n_neighbors):
gal = galsim.config.BuildGSObject(base, 'gal', gsparams=gsparams, logger=logger)[0]
gal = galsim.config.BuildGSObject(base, 'gal', gsparams=gsparams)[0]
self.neighbor_gals.append(gal)
# Remove the current stuff from base['gal'] so we don't get the same galaxy
# each time.
Expand All @@ -55,8 +55,7 @@ def BuildBlendProfiles(self, config, base, psf, gsparams, logger):
pos = galsim.config.ParseValue(config_pos, 'pos', base, galsim.PositionD)[0]
self.neighbor_pos.append(pos)

self.main_gal = galsim.config.BuildGSObject(base, 'gal', gsparams=gsparams,
logger=logger)[0]
self.main_gal = galsim.config.BuildGSObject(base, 'gal', gsparams=gsparams)[0]

profiles = [ self.main_gal ]
profiles += [ gal.shift(pos) for gal, pos in zip(self.neighbor_gals, self.neighbor_pos) ]
Expand All @@ -68,7 +67,7 @@ def BuildBlendProfiles(self, config, base, psf, gsparams, logger):

class BlendBuilder(galsim.config.StampBuilder):

def setup(self, config, base, xsize, ysize, ignore, logger):
def setup(self, config, base, xsize, ysize, ignore):
"""Do the appropriate setup for a Blend stamp.
"""
self.first = None # Mark that we don't have anything stored yet.
Expand All @@ -80,19 +79,19 @@ def setup(self, config, base, xsize, ysize, ignore, logger):
# Now farm off to the regular stamp setup function the rest of the work of parsing
# the size and position of the stamp.
ignore = ignore + ['n_neighbors', 'min_sep', 'max_sep']
return super(BlendBuilder,self).setup(config, base, xsize, ysize, ignore, logger)
return super(BlendBuilder,self).setup(config, base, xsize, ysize, ignore)

def buildProfile(self, config, base, psf, gsparams, logger):
return BuildBlendProfiles(self, config, base, psf, gsparams, logger)
def buildProfile(self, config, base, psf, gsparams):
return BuildBlendProfiles(self, config, base, psf, gsparams)

def draw(self, profiles, image, method, offset, config, base, logger):
def draw(self, profiles, image, method, offset, config, base):
"""
Draw the profiles onto the stamp.
"""
n_neighbors = len(profiles)-1

# Draw the central galaxy using the basic draw function.
image = galsim.config.DrawBasic(profiles[0], image, method, offset, config, base, logger)
image = galsim.config.DrawBasic(profiles[0], image, method, offset, config, base)

# We'll want a copy of just the neighbors for the deblend image.
# Otherwise we could have just drawn these on the main image with add_to_image = True
Expand All @@ -101,7 +100,7 @@ def draw(self, profiles, image, method, offset, config, base, logger):

# Draw all the neighbor stamps
for p in profiles[1:]:
galsim.config.DrawBasic(p, self.neighbor_image, method, offset, config, base, logger,
galsim.config.DrawBasic(p, self.neighbor_image, method, offset, config, base,
add_to_image=True)

# Save this in base for the deblend output
Expand All @@ -111,12 +110,12 @@ def draw(self, profiles, image, method, offset, config, base, logger):

return image

def whiten(self, profiles, image, config, base, logger):
def whiten(self, profiles, image, config, base):
"""
Whiten the noise on the stamp according to the existing noise in all the profiles.
"""
total = galsim.Add(profiles)
return super(BlendBuilder,self).whiten(total, image, config, base, logger)
return super(BlendBuilder,self).whiten(total, image, config, base)


galsim.config.RegisterStampType('Blend', BlendBuilder())
Expand All @@ -132,7 +131,7 @@ class BlendSetBuilder(galsim.config.StampBuilder):
# This is the same as the setup function for Blend, so there is a bit of duplicated code
# here, but it was simpler to have BlendSetBuilder derive directly from StampBuilder
# so the super calls go directly to that.
def setup(self, config, base, xsize, ysize, ignore, logger):
def setup(self, config, base, xsize, ysize, ignore):
"""Do the appropriate setup for a Blend stamp.
"""
# Make sure that we start over on the start of a new file.
Expand All @@ -146,9 +145,9 @@ def setup(self, config, base, xsize, ysize, ignore, logger):
# Now farm off to the regular stamp setup function the rest of the work of parsing
# the size and position of the stamp.
ignore = ignore + ['n_neighbors', 'min_sep', 'max_sep']
return super(BlendSetBuilder, self).setup(config, base, xsize, ysize, ignore, logger)
return super(BlendSetBuilder, self).setup(config, base, xsize, ysize, ignore)

def buildProfile(self, config, base, psf, gsparams, logger):
def buildProfile(self, config, base, psf, gsparams):
"""
Build a list of galaxy profiles, each convolved with the psf, to use for the blend image.
"""
Expand All @@ -158,12 +157,12 @@ def buildProfile(self, config, base, psf, gsparams, logger):
return None
else:
# Run the above BuildBlendProfiles function to build the profiles.
self.profiles = BuildBlendProfiles(self, config, base, psf, gsparams, logger)
self.profiles = BuildBlendProfiles(self, config, base, psf, gsparams)
# And mark this as the first object in the set
self.first = base['obj_num']
return self.profiles

def draw(self, profiles, image, method, offset, config, base, logger):
def draw(self, profiles, image, method, offset, config, base):
"""
Draw the profiles onto the stamp.
"""
Expand All @@ -188,8 +187,7 @@ def draw(self, profiles, image, method, offset, config, base, logger):
self.full_images = []
for prof in profiles:
im = galsim.ImageF(bounds=bounds, wcs=wcs)
galsim.config.DrawBasic(prof, im, method, offset-im.true_center, config, base,
logger)
galsim.config.DrawBasic(prof, im, method, offset-im.true_center, config, base)
self.full_images.append(im)

# Figure out what bounds to use for the cutouts.
Expand Down Expand Up @@ -219,7 +217,7 @@ def draw(self, profiles, image, method, offset, config, base, logger):

return image

def whiten(self, profiles, image, config, base, logger):
def whiten(self, profiles, image, config, base):
"""
Whiten the noise on the stamp according to the existing noise in all the profiles.
"""
Expand All @@ -229,7 +227,7 @@ def whiten(self, profiles, image, config, base, logger):
self.current_var = 0
for prof, full_im in zip(self.profiles, self.full_images):
self.current_var += super(BlendSetBuilder,self).whiten(
prof, full_im, config, base, logger)
prof, full_im, config, base)
if self.current_var != 0:
# Then we whitened the noise somewhere. Rebuild the stamp
image.setZero()
Expand All @@ -239,7 +237,7 @@ def whiten(self, profiles, image, config, base, logger):
return self.current_var


def addNoise(self, config, base, image, current_var, logger):
def addNoise(self, config, base, image, current_var):
"""Add the sky and noise"""
# We want the noise realization to be the same for all galaxies in the set,
# so we only generate the noise the first time and save it, pulling out the right cutout
Expand All @@ -251,7 +249,7 @@ def addNoise(self, config, base, image, current_var, logger):
self.full_noise_image = self.full_images[0].copy()
self.full_noise_image.setZero()
self.full_noise_image, self.current_var = super(BlendSetBuilder,self).addNoise(
config, base, self.full_noise_image, current_var, logger)
config, base, self.full_noise_image, current_var)

image += self.full_noise_image[self.bounds]
return image, self.current_var
Expand All @@ -273,7 +271,7 @@ def addNoise(self, config, base, image, current_var, logger):

class DeblendBuilder(galsim.config.ExtraOutputBuilder):

def processStamp(self, obj_num, config, base, logger):
def processStamp(self, obj_num, config, base):
"""Save the stamps of just the neighbor fluxes. We'll subtract them from the full image
at the end.
"""
Expand All @@ -289,7 +287,7 @@ def processStamp(self, obj_num, config, base, logger):
# Save it in the scratch dict using this obj_num as the key.
self.scratch[obj_num] = im

def processImage(self, index, obj_nums, config, base, logger):
def processImage(self, index, obj_nums, config, base):
"""Copy the full final image over and then subtract off the neighbor-only fluxes.
"""
# Start with a copy of the regular final image.
Expand All @@ -313,7 +311,7 @@ def processImage(self, index, obj_nums, config, base, logger):

class DeblendMedsBuilder(DeblendBuilder):

def finalize(self, config, base, main_data, logger):
def finalize(self, config, base, main_data):
"""Convert from the list of images we've been making into a list of MultiExposureObjects
we can use to write the MEDS file.
"""
Expand All @@ -331,7 +329,7 @@ def finalize(self, config, base, main_data, logger):
k1 = k2
return obj_list

def writeFile(self, file_name, config, base, logger):
def writeFile(self, file_name, config, base):
galsim.des.WriteMEDS(self.final_data, file_name)


Expand Down
4 changes: 2 additions & 2 deletions examples/des/des_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_random_chipnum(ud, bad_ccds):

class DES_SlowLocalWCSBuilder(galsim.config.WCSBuilder):

def buildWCS(self, config, base, logger):
def buildWCS(self, config, base):
"""Build a local WCS from the given location in a DES focal plane, given a directory
with the image files. By default, it will pick a random chipnum and image position,
but these can be optionally specified.
Expand Down Expand Up @@ -144,7 +144,7 @@ def get_chip_wcs(self, chipnum):

class DES_LocalWCSBuilder(galsim.config.WCSBuilder):

def buildWCS(self, config, base, logger):
def buildWCS(self, config, base):
"""Build a local WCS from the given location in a DES focal plane.

This function is used in conjunction with the des_wcs input field, which loads all the
Expand Down
4 changes: 2 additions & 2 deletions examples/great3/noise_free.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class NoiseFreeBuilder(galsim.config.ExtraOutputBuilder):
"""

# The function to call at the end of building each stamp
def processStamp(self, obj_num, config, base, logger):
def processStamp(self, obj_num, config, base):
if base['do_noise_in_stamps']:
noise_free_im = base['current_stamp'].copy()
self.scratch[obj_num] = noise_free_im

# The function to call at the end of building each image
def processImage(self, index, obj_nums, config, base, logger):
def processImage(self, index, obj_nums, config, base):
if len(self.scratch) > 0.:
# If we have been accumulating the stamp images, build the total from them.
image = galsim.ImageF(base['image_bounds'], wcs=base['wcs'], init_value=0.)
Expand Down
13 changes: 8 additions & 5 deletions examples/mixed_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
# and/or other materials provided with the distribution.
#

import logging
import galsim

logger = logging.getLogger(__name__)

class MixedSceneBuilder(galsim.config.StampBuilder):

def setup(self, config, base, xsize, ysize, ignore, logger):
def setup(self, config, base, xsize, ysize, ignore):
if 'objects' not in config:
raise AttributeError('objets field is required for MixedScene stamp type')
objects = config['objects']
Expand Down Expand Up @@ -76,20 +79,20 @@ def setup(self, config, base, xsize, ysize, ignore, logger):
ignore = ignore + ['objects', 'magnify', 'shear', 'obj_type']

# Now go on and do the rest of the normal setup.
return super(MixedSceneBuilder, self).setup(config,base,xsize,ysize,ignore,logger)
return super(MixedSceneBuilder, self).setup(config,base,xsize,ysize,ignore)

def buildProfile(self, config, base, psf, gsparams, logger):
def buildProfile(self, config, base, psf, gsparams):
obj_type = base['current_obj_type']
logger.info('obj %d: Drawing %s', base['obj_num'], obj_type)

# Make the appropriate object using the obj_type field
obj = galsim.config.BuildGSObject(base, obj_type, gsparams=gsparams, logger=logger)[0]
obj = galsim.config.BuildGSObject(base, obj_type, gsparams=gsparams)[0]
# Also save this in case useful for some calculation.
base['current_obj'] = obj

# Only shear and magnify are allowed, but this general TransformObject function will
# work to implement those.
obj, safe = galsim.config.TransformObject(obj, config, base, logger)
obj, safe = galsim.config.TransformObject(obj, config, base)

if psf:
if obj:
Expand Down
Loading