Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

#!/usr/bin/env python 

try: 

import matplotlib 

matplotlib.use('Agg') # noqa E402 

import pylab as plt 

except ImportError: 

plt = None 

 

import numpy as np 

 

import lsst.afw.detection as afwDet 

import lsst.afw.image as afwImg 

import lsst.meas.deblender as measDeblend 

 

 

def makePeak(x, y): 

peakTable = afwDet.PeakTable.make(afwDet.PeakTable.makeMinimalSchema()) 

peak = peakTable.makeRecord() 

peak.setFx(x) 

peak.setFy(y) 

peak.setIx(x) 

peak.setIy(y) 

return peak 

 

 

def main000(): 

butils = measDeblend.BaselineUtilsF 

S = 20 

mim = afwImg.MaskedImageF(S, S) 

x0, y0 = S/2, S/2 

im = mim.getImage().getArray() 

peak = makePeak(x0, y0) 

 

im[:, :] = 5. 

im[y0, x0] = 10. 

im[y0, x0 + 2] = 1. 

 

if plt: 

plt.clf() 

plt.imshow(im, origin='lower', interpolation='nearest') 

plt.savefig('im2.png') 

butils.makeMonotonic(mim, peak) 

plt.clf() 

plt.imshow(mim.getImage().getArray(), origin='lower', interpolation='nearest') 

plt.savefig('mono2.png') 

 

 

def randoms(S=10, N=1, GA=10, GS=10): 

butils = measDeblend.BaselineUtilsF 

mim = afwImg.MaskedImageF(S, S) 

x0, y0 = S/2, S/2 

peak = makePeak(x0, y0) 

im = mim.getImage().getArray() 

 

for i in range(N): 

 

X, Y = np.meshgrid(np.arange(S), np.arange(S)) 

R2 = (X-x0)**2 + (Y-y0)**2 

 

im[:, :] = np.random.normal(10, 1, size=im.shape) + GA * np.exp(-0.5 * R2 / GS**2) 

 

if plt: 

plt.clf() 

ima = dict(vmin=im.min(), vmax=im.max(), origin='lower', interpolation='nearest') 

plt.imshow(im, **ima) 

plt.gray() 

plt.savefig('Rim%i.png' % i) 

butils.makeMonotonic(mim.getImage(), peak) 

plt.clf() 

plt.imshow(mim.getImage().getArray(), **ima) 

plt.gray() 

plt.savefig('Rim%im.png' % i) 

 

 

def cardinal(): 

butils = measDeblend.BaselineUtilsF 

 

S = 20 

mim = afwImg.MaskedImageF(S, S) 

x0, y0 = S/2, S/2 

 

im = mim.getImage().getArray() 

peak = makePeak(x0, y0) 

 

R = 2 

xx, yy = [], [] 

x, y = R, -R 

for dx, dy in [(0, 1), (-1, 0), (0, -1), (1, 0)]: 

xx.extend(x + dx * np.arange(2*R)) 

yy.extend(y + dy * np.arange(2*R)) 

x += dx*2*R 

y += dy*2*R 

 

for i, (dx, dy) in enumerate(zip(xx, yy)): 

im[:, :] = 5. 

im[y0, x0] = 10. 

im[y0 + dy, x0 + dx] = 1. 

mn, mx = im.min(), im.max() 

plota = dict(origin='lower', interpolation='nearest', vmin=mn, vmax=mx) 

 

if plt: 

plt.clf() 

plt.imshow(im, **plota) 

plt.savefig('im%i.png' % i) 

butils.makeMonotonic(mim.getImage(), peak) 

plt.clf() 

plt.imshow(mim.getImage().getArray(), **plota) 

plt.savefig('im%im.png' % i) 

 

 

if __name__ == '__main__': 

cardinal() 

# main000() 

# randoms(S=100, N=10) 

randoms(S=100, N=1)