LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | List of all members
lsst.shapelet.tests.ShapeletTestCase Class Reference
Inheritance diagram for lsst.shapelet.tests.ShapeletTestCase:

Public Member Functions

def compareShapeletFunctions (self, a, b, rtolEllipse=1E-13, rtolCoeff=1E-13, atolEllipse=1E-14, atolCoeff=1E-14)
 
def simplifyMultiShapeletFunction (self, msf)
 
def compareMultiShapeletFunctions (self, a, b, simplify=True, rtolEllipse=1E-13, rtolCoeff=1E-13, atolEllipse=1E-14, atolCoeff=1E-14)
 
def checkMoments (self, function, x, y, z)
 
def checkConvolution (self, f1, f2)
 

Static Public Member Functions

def makeUnitVector (i, n)
 
def makeImage (function, x, y)
 
def makeRandomShapeletFunction (order=2, zeroCenter=False, ellipse=None, scale=1.0)
 
def makeRandomMultiShapeletFunction (nComponents=3, ellipse=None)
 

Detailed Description

Definition at line 38 of file tests.py.

Member Function Documentation

◆ checkConvolution()

def lsst.shapelet.tests.ShapeletTestCase.checkConvolution (   self,
  f1,
  f2 
)

Definition at line 140 of file tests.py.

140  def checkConvolution(self, f1, f2):
141  bbox = lsst.geom.Box2I(lsst.geom.Point2I(-50, -50), lsst.geom.Point2I(50, 50))
142  i1 = lsst.afw.image.ImageD(bbox)
143  f1.evaluate().addToImage(i1)
144  self.assertFloatsAlmostEqual(i1.getArray().sum(), f1.evaluate().integrate(), rtol=1E-3)
145  i2 = lsst.afw.image.ImageD(bbox)
146  f2.evaluate().addToImage(i2)
147  self.assertFloatsAlmostEqual(i2.getArray().sum(), f2.evaluate().integrate(), rtol=1E-3)
148  fc1 = f1.convolve(f2)
149  fc2 = f2.convolve(f1)
150  ic1 = lsst.afw.image.ImageD(bbox)
151  fc1.evaluate().addToImage(ic1)
152  ic2 = lsst.afw.image.ImageD(bbox)
153  fc2.evaluate().addToImage(ic2)
154  self.assertFloatsAlmostEqual(ic1.getArray(), ic2.getArray())
155  out = lsst.afw.image.ImageD(bbox)
156  if scipy is None:
157  print("Skipping convolution test; scipy could not be imported.")
158  return
159  # I'm using scipy.ndimage to convolve test images, because I can't figure
160  # out how to make afw do it (afw can convolve images with kernels, but two similarly-sized
161  # are apparently another matter; if I try to make a FixedKernel from one of the images,
162  # I can't even make the operation commutative, let alone correct.
163  scipy.ndimage.convolve(i1.getArray(), i2.getArray(), output=out.getArray(),
164  mode="constant", cval=0.0)
165  self.assertFloatsAlmostEqual(out.getArray(), ic1.getArray(), rtol=1E-4, atol=1E-5)
166  self.assertFloatsAlmostEqual(out.getArray(), ic2.getArray(), rtol=1E-4, atol=1E-5)
167  return fc1, fc2
An integer coordinate rectangle.
Definition: Box.h:55
auto integrate(UnaryFunctionT func, Arg const a, Arg const b, double eps=1.0e-6)
The 1D integrator.
Definition: Integrate.h:767
void addToImage(std::shared_ptr< afw::image::Image< double >> image, std::vector< std::shared_ptr< afw::image::Image< double >>> const &imgVector, std::vector< double > const &weightVector)
Definition: CoaddPsf.cc:201

◆ checkMoments()

def lsst.shapelet.tests.ShapeletTestCase.checkMoments (   self,
  function,
  x,
  y,
  z 
)

Definition at line 114 of file tests.py.

114  def checkMoments(self, function, x, y, z):
115  gx, gy = numpy.meshgrid(x, y)
116  m = z.sum()
117  dipole = lsst.geom.Point2D((gx * z).sum() / m, (gy * z).sum() / m)
118  gx -= dipole.getX()
119  gy -= dipole.getY()
121  (gx**2 * z).sum() / m,
122  (gy**2 * z).sum() / m,
123  (gx * gy * z).sum() / m
124  )
125  imageMoments = lsst.afw.geom.ellipses.Ellipse(quadrupole, dipole)
126  shapeletMoments = function.evaluate().computeMoments()
127  self.assertFloatsAlmostEqual(imageMoments.getCenter().getX(),
128  shapeletMoments.getCenter().getX(), rtol=1E-3)
129  self.assertFloatsAlmostEqual(imageMoments.getCenter().getY(),
130  shapeletMoments.getCenter().getY(), rtol=1E-3)
131  self.assertFloatsAlmostEqual(imageMoments.getCore().getIxx(),
132  shapeletMoments.getCore().getIxx(), rtol=1E-3)
133  self.assertFloatsAlmostEqual(imageMoments.getCore().getIyy(),
134  shapeletMoments.getCore().getIyy(), rtol=1E-3)
135  self.assertFloatsAlmostEqual(imageMoments.getCore().getIxy(),
136  shapeletMoments.getCore().getIxy(), rtol=1E-3)
137  integral = numpy.trapz(numpy.trapz(z, gx, axis=1), y, axis=0)
138  self.assertFloatsAlmostEqual(integral, function.evaluate().integrate(), rtol=1E-3)
139 
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47

◆ compareMultiShapeletFunctions()

def lsst.shapelet.tests.ShapeletTestCase.compareMultiShapeletFunctions (   self,
  a,
  b,
  simplify = True,
  rtolEllipse = 1E-13,
  rtolCoeff = 1E-13,
  atolEllipse = 1E-14,
  atolCoeff = 1E-14 
)

Definition at line 104 of file tests.py.

105  atolEllipse=1E-14, atolCoeff=1E-14):
106  if simplify:
107  a = self.simplifyMultiShapeletFunction(a)
108  b = self.simplifyMultiShapeletFunction(b)
109  self.assertEqual(len(a.getComponents()), len(b.getComponents()))
110  for sa, sb in zip(a.getComponents(), b.getComponents()):
111  self.compareShapeletFunctions(sa, sb, rtolEllipse=rtolEllipse, rtolCoeff=rtolCoeff,
112  atolEllipse=atolEllipse, atolCoeff=atolCoeff)
113 

◆ compareShapeletFunctions()

def lsst.shapelet.tests.ShapeletTestCase.compareShapeletFunctions (   self,
  a,
  b,
  rtolEllipse = 1E-13,
  rtolCoeff = 1E-13,
  atolEllipse = 1E-14,
  atolCoeff = 1E-14 
)

Definition at line 82 of file tests.py.

83  atolEllipse=1E-14, atolCoeff=1E-14):
84  self.assertEqual(a.getOrder(), b.getOrder())
85  self.assertEqual(a.getBasisType(), b.getBasisType())
86  self.assertFloatsAlmostEqual(a.getEllipse().getParameterVector(),
87  b.getEllipse().getParameterVector(),
88  rtol=rtolEllipse, atol=atolEllipse)
89  self.assertFloatsAlmostEqual(a.getCoefficients(), b.getCoefficients(),
90  rtol=rtolCoeff, atol=atolCoeff)
91 

◆ makeImage()

def lsst.shapelet.tests.ShapeletTestCase.makeImage (   function,
  x,
  y 
)
static

Definition at line 47 of file tests.py.

47  def makeImage(function, x, y):
48  z = numpy.zeros((y.size, x.size), dtype=float)
49  e = function.evaluate()
50  for i, py in enumerate(y):
51  for j, px in enumerate(x):
52  z[i, j] = e(float(px), float(py))
53  return z
54 

◆ makeRandomMultiShapeletFunction()

def lsst.shapelet.tests.ShapeletTestCase.makeRandomMultiShapeletFunction (   nComponents = 3,
  ellipse = None 
)
static

Definition at line 76 of file tests.py.

76  def makeRandomMultiShapeletFunction(nComponents=3, ellipse=None):
77  components = []
78  for n in range(nComponents):
79  components.append(ShapeletTestCase.makeRandomShapeletFunction(ellipse=ellipse))
80  return lsst.shapelet.MultiShapeletFunction(components)
81 
A multi-scale shapelet function.

◆ makeRandomShapeletFunction()

def lsst.shapelet.tests.ShapeletTestCase.makeRandomShapeletFunction (   order = 2,
  zeroCenter = False,
  ellipse = None,
  scale = 1.0 
)
static

Definition at line 56 of file tests.py.

56  def makeRandomShapeletFunction(order=2, zeroCenter=False, ellipse=None, scale=1.0):
57  center = lsst.geom.Point2D()
58  if not zeroCenter:
59  center = lsst.geom.Point2D(numpy.random.randn(), numpy.random.randn())
60  if ellipse is None:
63  float(numpy.random.uniform(low=1, high=2)),
64  float(numpy.random.uniform(low=1, high=2)),
65  float(numpy.random.uniform(low=0, high=numpy.pi))
66  ),
67  center
68  )
69  coefficients = numpy.random.randn(lsst.shapelet.computeSize(order))
70  result = lsst.shapelet.ShapeletFunction(order, lsst.shapelet.HERMITE, coefficients)
71  result.setEllipse(ellipse)
72  result.getEllipse().scale(scale)
73  return result
74 
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a,...
Definition: Axes.h:47
A 2-d function defined by an expansion onto a Gauss-Laguerre or Gauss-Hermite basis.
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:108
int computeSize(int order)
Return the size of the coefficient vector for the given order.
Definition: constants.h:97

◆ makeUnitVector()

def lsst.shapelet.tests.ShapeletTestCase.makeUnitVector (   i,
  n 
)
static

Definition at line 41 of file tests.py.

41  def makeUnitVector(i, n):
42  v = numpy.zeros(n, dtype=float)
43  v[i] = 1.0
44  return v
45 

◆ simplifyMultiShapeletFunction()

def lsst.shapelet.tests.ShapeletTestCase.simplifyMultiShapeletFunction (   self,
  msf 
)

Definition at line 92 of file tests.py.

92  def simplifyMultiShapeletFunction(self, msf):
93  keep = []
94  for s in msf.getComponents():
95  if not numpy.allclose(s.getCoefficients(), 0.0):
96  params = tuple(s.getEllipse().getParameterVector()) + tuple(s.getCoefficients())
97  keep.append((params, s))
99  keep.sort(key=lambda t: t[0])
100  for params, s in keep:
101  msf.addComponent(s)
102  return msf
103 

The documentation for this class was generated from the following file: