25 sigma2fwhm = 2. * np.sqrt(2. * np.log(2.))
28 basisDegGauss=
None, metadata=
None):
29 """Generate the appropriate Kernel basis based on the Config"""
30 if config.kernelBasisSet ==
"alard-lupton":
32 referenceFwhmPix=referenceFwhmPix,
33 basisDegGauss=basisDegGauss,
35 elif config.kernelBasisSet ==
"delta-function":
36 kernelSize = config.kernelSize
37 return diffimLib.makeDeltaFunctionBasisList(kernelSize, kernelSize)
39 raise ValueError(
"Cannot generate %s basis set" % (config.kernelBasisSet))
42 basisDegGauss=
None, metadata=
None):
43 """Generate an Alard-Lupton kernel basis based upon the Config and
44 the input FWHM of the science and template images"""
46 if config.kernelBasisSet !=
"alard-lupton":
47 raise RuntimeError(
"Cannot generate %s basis within generateAlardLuptonBasisList" % config.kernelBasisSet)
49 kernelSize = config.kernelSize
50 fwhmScaling = config.kernelSizeFwhmScaling
51 basisNGauss = config.alardNGauss
52 basisSigmaGauss = config.alardSigGauss
53 basisGaussBeta = config.alardGaussBeta
54 basisMinSigma = config.alardMinSig
55 if basisDegGauss
is None:
56 basisDegGauss = config.alardDegGauss
58 if len(basisDegGauss) != basisNGauss:
59 raise ValueError(
"len(basisDegGauss) != basisNGauss : %d vs %d" % (len(basisDegGauss), basisNGauss))
60 if len(basisSigmaGauss) != basisNGauss:
61 raise ValueError(
"len(basisSigmaGauss) != basisNGauss : %d vs %d" % (len(basisSigmaGauss), basisNGauss))
62 if (kernelSize % 2) != 1:
63 raise ValueError(
"Only odd-sized Alard-Lupton bases allowed")
65 if (targetFwhmPix
is None)
or (referenceFwhmPix
is None)
or (
not config.scaleByFwhm):
66 if metadata
is not None:
67 metadata.add(
"ALBasisNGauss", basisNGauss)
68 metadata.add(
"ALBasisDegGauss", basisDegGauss)
69 metadata.add(
"ALBasisSigGauss", basisSigmaGauss)
70 metadata.add(
"ALKernelSize", kernelSize)
72 return diffimLib.makeAlardLuptonBasisList(kernelSize//2, basisNGauss, basisSigmaGauss, basisDegGauss)
74 targetSigma = targetFwhmPix / sigma2fwhm
75 referenceSigma = referenceFwhmPix / sigma2fwhm
76 pexLog.Trace(
"lsst.ip.diffim.generateAlardLuptonBasisList", 2,
77 "Generating matching bases for sigma %.2f pix -> %.2f pix" % (targetSigma, referenceSigma))
86 if targetSigma == referenceSigma:
89 elif referenceSigma > targetSigma:
98 kernelSigma = np.sqrt(referenceSigma**2 - targetSigma**2)
99 if kernelSigma < basisMinSigma:
100 kernelSigma = basisMinSigma
104 basisSigmaGauss.append(kernelSigma)
107 if (kernelSigma/basisGaussBeta) > basisMinSigma:
108 basisSigmaGauss.append(kernelSigma/basisGaussBeta)
109 basisSigmaGauss.append(kernelSigma)
112 basisSigmaGauss.append(kernelSigma)
117 for i
in range(nAppended,basisNGauss):
118 basisSigmaGauss.append(basisSigmaGauss[-1]*basisGaussBeta)
120 kernelSize = int(fwhmScaling * basisSigmaGauss[-1])
121 kernelSize += 0
if kernelSize%2
else 1
122 kernelSize = min(config.kernelSizeMax, max(kernelSize, config.kernelSizeMin))
133 basisNGauss = config.alardNGaussDeconv
134 basisMinSigma = config.alardMinSigDeconv
136 kernelSigma = np.sqrt(targetSigma**2 - referenceSigma**2)
137 if kernelSigma < basisMinSigma:
138 kernelSigma = basisMinSigma
141 if (kernelSigma/basisGaussBeta) > basisMinSigma:
142 basisSigmaGauss.append(kernelSigma/basisGaussBeta)
143 basisSigmaGauss.append(kernelSigma)
146 basisSigmaGauss.append(kernelSigma)
149 for i
in range(nAppended,basisNGauss):
150 basisSigmaGauss.append(basisSigmaGauss[-1]*basisGaussBeta)
152 kernelSize = int(fwhmScaling * basisSigmaGauss[-1])
153 kernelSize += 0
if kernelSize%2
else 1
154 kernelSize = min(config.kernelSizeMax, max(kernelSize, config.kernelSizeMin))
157 sig0 = basisSigmaGauss[0]
158 sig1 = basisSigmaGauss[1]
159 sig2 = basisSigmaGauss[2]
161 for n
in range(1, 3):
163 sigma2jn = (n - j) * sig1**2
164 sigma2jn += j * sig2**2
165 sigma2jn -= (n + 1) * sig0**2
166 sigmajn = np.sqrt(sigma2jn)
167 basisSigmaGauss.append(sigmajn)
169 basisSigmaGauss.sort()
170 basisNGauss = len(basisSigmaGauss)
171 basisDegGauss = [config.alardDegGaussDeconv
for x
in basisSigmaGauss]
173 if metadata
is not None:
174 metadata.add(
"ALBasisNGauss", basisNGauss)
175 metadata.add(
"ALBasisDegGauss", basisDegGauss)
176 metadata.add(
"ALBasisSigGauss", basisSigmaGauss)
177 metadata.add(
"ALKernelSize", kernelSize)
179 return diffimLib.makeAlardLuptonBasisList(kernelSize//2, basisNGauss, basisSigmaGauss, basisDegGauss)
def generateAlardLuptonBasisList
limited backward compatibility to the DC2 run-time trace facilities