Coverage for examples/monotonic.py: 0%
89 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-09 03:39 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-09 03:39 -0700
1#!/usr/bin/env python
2try:
3 import matplotlib
4 matplotlib.use('Agg') # noqa E402
5 import pylab as plt
6except ImportError:
7 plt = None
9import numpy as np
11import lsst.afw.detection as afwDet
12import lsst.afw.image as afwImg
13import lsst.meas.deblender as measDeblend
16def makePeak(x, y):
17 peakTable = afwDet.PeakTable.make(afwDet.PeakTable.makeMinimalSchema())
18 peak = peakTable.makeRecord()
19 peak.setFx(x)
20 peak.setFy(y)
21 peak.setIx(x)
22 peak.setIy(y)
23 return peak
26def main000():
27 butils = measDeblend.BaselineUtilsF
28 S = 20
29 mim = afwImg.MaskedImageF(S, S)
30 x0, y0 = S/2, S/2
31 im = mim.getImage().getArray()
32 peak = makePeak(x0, y0)
34 im[:, :] = 5.
35 im[y0, x0] = 10.
36 im[y0, x0 + 2] = 1.
38 if plt:
39 plt.clf()
40 plt.imshow(im, origin='lower', interpolation='nearest')
41 plt.savefig('im2.png')
42 butils.makeMonotonic(mim, peak)
43 plt.clf()
44 plt.imshow(mim.getImage().getArray(), origin='lower', interpolation='nearest')
45 plt.savefig('mono2.png')
48def randoms(S=10, N=1, GA=10, GS=10):
49 butils = measDeblend.BaselineUtilsF
50 mim = afwImg.MaskedImageF(S, S)
51 x0, y0 = S/2, S/2
52 peak = makePeak(x0, y0)
53 im = mim.getImage().getArray()
55 for i in range(N):
57 X, Y = np.meshgrid(np.arange(S), np.arange(S))
58 R2 = (X-x0)**2 + (Y-y0)**2
60 im[:, :] = np.random.normal(10, 1, size=im.shape) + GA * np.exp(-0.5 * R2 / GS**2)
62 if plt:
63 plt.clf()
64 ima = dict(vmin=im.min(), vmax=im.max(), origin='lower', interpolation='nearest')
65 plt.imshow(im, **ima)
66 plt.gray()
67 plt.savefig('Rim%i.png' % i)
68 butils.makeMonotonic(mim.getImage(), peak)
69 plt.clf()
70 plt.imshow(mim.getImage().getArray(), **ima)
71 plt.gray()
72 plt.savefig('Rim%im.png' % i)
75def cardinal():
76 butils = measDeblend.BaselineUtilsF
78 S = 20
79 mim = afwImg.MaskedImageF(S, S)
80 x0, y0 = S/2, S/2
82 im = mim.getImage().getArray()
83 peak = makePeak(x0, y0)
85 R = 2
86 xx, yy = [], []
87 x, y = R, -R
88 for dx, dy in [(0, 1), (-1, 0), (0, -1), (1, 0)]:
89 xx.extend(x + dx * np.arange(2*R))
90 yy.extend(y + dy * np.arange(2*R))
91 x += dx*2*R
92 y += dy*2*R
94 for i, (dx, dy) in enumerate(zip(xx, yy)):
95 im[:, :] = 5.
96 im[y0, x0] = 10.
97 im[y0 + dy, x0 + dx] = 1.
98 mn, mx = im.min(), im.max()
99 plota = dict(origin='lower', interpolation='nearest', vmin=mn, vmax=mx)
101 if plt:
102 plt.clf()
103 plt.imshow(im, **plota)
104 plt.savefig('im%i.png' % i)
105 butils.makeMonotonic(mim.getImage(), peak)
106 plt.clf()
107 plt.imshow(mim.getImage().getArray(), **plota)
108 plt.savefig('im%im.png' % i)
111if __name__ == '__main__':
112 cardinal()
113 # main000()
114 # randoms(S=100, N=10)
115 randoms(S=100, N=1)