43 """Register the pickled profiles in the data directory with the RadialProfile
46 This should only be called at import time by this module; it's only a function to
47 avoid polluting the module namespace with all the local variables used here.
49 regex = re.compile(
r"([a-z]+\d?)_K(\d+)_MR(\d+)\.pickle")
53 with importlib.resources.as_file(
54 importlib.resources.files(
"lsst.shapelet").joinpath(
"resources",
"data")
56 for filename
in os.listdir(dataDir):
57 match = regex.match(filename)
61 nComponents = int(match.group(2))
62 maxRadius = int(match.group(3))
64 profile = RadialProfile.get(name)
66 _LOG.warning(
"No C++ profile for multi-Gaussian pickle file '%s'", filename)
68 with open(os.path.join(dataDir, filename),
'rb')
as stream:
69 array = pickle.load(stream, encoding=
'latin1')
70 amplitudes = array[:nComponents]
71 amplitudes /= amplitudes.sum()
72 variances = array[nComponents:]
73 if amplitudes.shape != (nComponents,)
or variances.shape != (nComponents,):
74 _LOG.warning(
"Unknown format for multi-Gaussian pickle file '%s'", filename)
77 for amplitude, variance
in zip(amplitudes, variances):
78 radius = variance**0.5
79 matrix = numpy.array([[amplitude / ShapeletFunction.FLUX_FACTOR]], dtype=float)
80 basis.addComponent(radius, 0, matrix)
81 profile.registerBasis(basis, nComponents, maxRadius)
153 """Plot all the profiles defined in this module together.
155 Plot all the profiles defined in this module together: true exp and dev,
156 the SDSS softened/truncated lux and luv, and the multi-Gaussian approximations
161 doComponents : `bool`, optional
162 True, to plot the individual Gaussians that form the multi-Gaussian approximations.
166 figure : `matplotlib.figure.Figure`
167 Figure that contains the plot.
168 axes : `numpy.ndarray` of `matplotlib.axes.Axes`
169 A 2x4 NumPy array of matplotlib axes objects.
171 from matplotlib
import pyplot
172 fig = pyplot.figure(figsize=(9, 4.7))
173 axes = numpy.zeros((2, 4), dtype=object)
174 r1 = numpy.logspace(-3, 0, 1000, base=10)
175 r2 = numpy.linspace(1, 10, 1000)
179 axes[i, j] = fig.add_subplot(2, 4, i*4+j+1)
180 profiles = {name: RadialProfile.get(name)
for name
in (
"exp",
"lux",
"dev",
"luv")}
181 basis = {name: profiles[name].getBasis(8)
for name
in profiles}
182 z = numpy.zeros((2, 4), dtype=object)
183 colors = (
"k",
"g",
"b",
"r")
184 fig.subplots_adjust(wspace=0.025, hspace=0.025, bottom=0.15, left=0.1, right=0.98, top=0.92)
185 centers = [
None,
None]
187 for j
in range(0, 4, 2):
188 bbox0 = axes[i, j].get_position()
189 bbox1 = axes[i, j+1].get_position()
190 bbox1.x0 = bbox0.x1 - 0.06
192 centers[j//2] = 0.5*(bbox0.x0 + bbox1.x1)
193 axes[i, j].set_position(bbox0)
194 axes[i, j+1].set_position(bbox1)
195 for j
in range(0, 2):
196 z[0, j] = [
evaluateRadial(basis[k], r[j], sbNormalize=
True, doComponents=doComponents)
197 for k
in (
"exp",
"lux")]
198 z[0, j][0:0] = [profiles[k].evaluate(r[j])[numpy.newaxis, :]
for k
in (
"exp",
"lux")]
199 z[0, j+2] = [
evaluateRadial(basis[k], r[j], sbNormalize=
True, doComponents=doComponents)
200 for k
in (
"dev",
"luv")]
201 z[0, j+2][0:0] = [profiles[k].evaluate(r[j])[numpy.newaxis, :]
for k
in (
"dev",
"luv")]
202 methodNames = [[
"loglog",
"semilogy"], [
"semilogx",
"plot"]]
203 for j
in range(0, 4):
204 z[1, j] = [(z[0, j][0][0, :] - z[0, j][i][0, :])/z[0, j][0][0, :]
for i
in range(0, 4)]
206 method0 = getattr(axes[0, j], methodNames[0][j%2])
207 method1 = getattr(axes[1, j], methodNames[1][j%2])
210 handles.append(method0(r[j%2], y0[0, :], color=colors[k])[0])
212 for ll
in range(1, y0.shape[0]):
213 method0(r[j%2], y0[ll, :], color=colors[k], alpha=0.25)
214 method1(r[j%2], z[1, j][k], color=colors[k])
215 axes[0, j].set_xticklabels([])
216 axes[0, j].set_ylim(1E-6, 1E3)
217 axes[1, j].set_ylim(-0.2, 1.0)
218 for i, label
in enumerate((
"profile",
"relative error")):
219 axes[i, 0].set_ylabel(label)
220 for t
in axes[i, 0].get_yticklabels():
222 for j
in range(1, 4):
223 axes[0, j].set_yticklabels([])
224 axes[1, j].set_yticklabels([])
225 xticks = [[
'$\\mathdefault{10^{%d}}$' % i
for i
in range(-3, 1)],
226 [str(i)
for i
in range(1, 11)]]
229 for j
in range(0, 4):
230 axes[1, j].set_xticklabels(xticks[j%2])
231 for t
in axes[1, j].get_xticklabels():
233 fig.legend(handles, [
"exp/dev",
"lux/luv",
"approx exp/dev",
"approx lux/luv"],
234 loc=
'lower center', ncol=4)
235 fig.text(centers[0], 0.95,
"exponential", ha=
'center', weight=
'bold')
236 fig.text(centers[1], 0.95,
"de Vaucouleur", ha=
'center', weight=
'bold')