Skip to content

Commit 4952ae5

Browse files
committed
Series lazy decompose A
(#628)
1 parent 2ebdb62 commit 4952ae5

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

galsim/series.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -306,36 +306,41 @@ def rotate(self, theta):
306306
return self._applyMatrix(R)
307307

308308
def _decomposeA(self):
309-
A = self._A
310-
a = A[0,0]
311-
b = A[0,1]
312-
c = A[1,0]
313-
d = A[1,1]
314-
mu = math.sqrt(a*d-b*c)
315-
phi0 = math.atan2(c-b, a+d)
316-
beta = math.atan2(b+c, a-d)+phi0
317-
eta = math.acosh(0.5*((a-d)**2 + (b+c)**2)/mu**2 + 1.0)
318-
319-
# print "mu: {}".format(mu)
320-
# print "phi0: {}".format(phi0)
321-
# print "beta: {}".format(beta)
322-
# print "eta: {}".format(eta)
323-
324-
ellip = galsim.Shear(eta1=eta).e1
325-
r0 = mu/np.sqrt(1.0 - ellip**2)
326-
# find the nearest r_i:
327-
f, i = np.modf(np.log(r0)/self.dlnr)
328-
# deal with negative logs
329-
if f < 0.0:
330-
f += 1.0
331-
i -= 1
332-
# if f > 0.5, then round down from above
333-
if f > 0.5:
334-
f -= 1.0
335-
i += 1
336-
scale_radius = np.exp(self.dlnr*i)
337-
Delta = 1.0 - (r0/scale_radius)**2
338-
return ellip, phi0+beta/2, scale_radius, Delta
309+
if not hasattr(self, 'ellip'):
310+
A = self._A
311+
a = A[0,0]
312+
b = A[0,1]
313+
c = A[1,0]
314+
d = A[1,1]
315+
mu = math.sqrt(a*d-b*c)
316+
phi0 = math.atan2(c-b, a+d)
317+
beta = math.atan2(b+c, a-d)+phi0
318+
eta = math.acosh(0.5*((a-d)**2 + (b+c)**2)/mu**2 + 1.0)
319+
320+
# print "mu: {}".format(mu)
321+
# print "phi0: {}".format(phi0)
322+
# print "beta: {}".format(beta)
323+
# print "eta: {}".format(eta)
324+
325+
ellip = galsim.Shear(eta1=eta).e1
326+
r0 = mu/np.sqrt(np.sqrt(1.0 - ellip**2))
327+
# find the nearest r_i:
328+
f, i = np.modf(np.log(r0)/self.dlnr)
329+
# deal with negative logs
330+
if f < 0.0:
331+
f += 1.0
332+
i -= 1
333+
# if f > 0.5, then round down from above
334+
if f > 0.5:
335+
f -= 1.0
336+
i += 1
337+
scale_radius = np.exp(self.dlnr*i)
338+
Delta = 1.0 - (r0/scale_radius)**2
339+
self.ellip = ellip
340+
self.phi0 = phi0+beta/2
341+
self.scale_radius = scale_radius
342+
self.Delta = Delta
343+
return self.ellip, self.phi0, self.scale_radius, self.Delta
339344

340345

341346
class Spergelet(galsim.GSObject):

0 commit comments

Comments
 (0)