I am fitting to galaxies in galsim and receive the following errors:
File "/home/luis/Documents/SRC2014/galsim_work/noiseLibrary.py", line 50, in create_galaxy
gal = gal.shear(g1=e1, g2=e2)
File "/usr/lib/python2.7/dist-packages/galsim/base.py", line 572, in shear
shear = galsim.Shear(**kwargs)
File "/usr/lib/python2.7/dist-packages/galsim/shear.py", line 111, in __init__
raise ValueError("Requested shear exceeds 1: %f"%g)
ValueError: Requested shear exceeds 1: 1.007171
I've attempted to remedy this by checking for values of e1 and e2 and the magnitude in my program that creates galaxies by the following:
if e1 > 1:
print "The e1 component of ellipticity is greater than 1."
e1 = 0.99
elif e1 < -1:
print "The e1 component of ellipticity is less than -1."
e1 = -0.99
if e2 > 1:
print "The e2 component of ellipticity is greater than 1."
e2 + 0.99
elif e2 < -1:
print "The e2 component of ellipticity is less than -1."
e2 = -0.99
if np.sqrt(e1**2 + e2**2) > 1:
return create_galaxy(flux, hlr, e1*0.5, e2*0.5, galtype_gal=galtype_gal, sersic_index=sersic_index,
psf_flag=psf_flag, psf_type=psf_type, beta=beta, size_psf=size_psf, flux_psf=flux_psf,
x_len=x_len, y_len=y_len, scale=scale, method=method,seed=seed)
while this solution works for the individual components, I suspect the recursive call is creating the following error:
File "/usr/lib/python2.7/dist-packages/galsim/base.py", line 1196, in drawImage
image.added_flux = prof.SBProfile.draw(imview.image, gain, wmult)
MemoryError
Any recommendations on how to go about this? Note that I am bounding e1 and e2 to be between -1 and 1 for my fitting parametrization. I suspect that I should be bounding the magnitude of my ellipticity (to bound according to the unit circle), not the unit square.
Thanks!
You are correct that the ellipticity must be bounded within the unit circle, so separate bounds on each component will not do the job. That is the reason for the ValueError about the requested shear exceeding 1.
However, the memory error is difficult to diagnose in the absence of more specifics. Does this happen all the time or just once in a while? Can you give us a short script that reproduces this error, including specific values for all galaxy and PSF parameters and the commands you're using to make the object that is being drawn?