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

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

# 

# LSST Data Management System 

# Copyright 2015 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

import unittest 

import math 

 

import numpy as np 

 

import lsst.utils.tests 

import lsst.geom 

import lsst.afw.geom as afwGeom 

import lsst.afw.math as afwMath 

import lsst.afw.table as afwTable 

from lsst.meas.base import SingleFrameMeasurementTask 

import lsst.meas.astrom as measAstrom 

from functools import reduce 

 

 

class TestAstrometricSolver(lsst.utils.tests.TestCase): 

 

def setUp(self): 

# make a nominal match list where the distances are 0; test can then modify 

# source centroid, reference coord or distance field for each match, as desired 

self.wcs = afwGeom.makeSkyWcs(crpix=lsst.geom.Point2D(1500, 1500), 

crval=lsst.geom.SpherePoint(215.5, 53.0, lsst.geom.degrees), 

cdMatrix=afwGeom.makeCdMatrix(scale=5.1e-5*lsst.geom.degrees)) 

self.bboxD = lsst.geom.Box2D(lsst.geom.Point2D(10, 100), lsst.geom.Extent2D(1000, 1500)) 

self.numMatches = 25 

 

sourceSchema = afwTable.SourceTable.makeMinimalSchema() 

# add centroid (and many other unwanted fields) to sourceSchema 

SingleFrameMeasurementTask(schema=sourceSchema) 

self.sourceCentroidKey = afwTable.Point2DKey(sourceSchema["slot_Centroid"]) 

self.sourceCat = afwTable.SourceCatalog(sourceSchema) 

 

refSchema = afwTable.SourceTable.makeMinimalSchema() 

self.refCoordKey = afwTable.CoordKey(refSchema["coord"]) 

self.refCat = afwTable.SourceCatalog(refSchema) 

 

self.matchList = [] 

 

np.random.seed(5) 

pixPointList = [lsst.geom.Point2D(pos) for pos in 

np.random.random_sample([self.numMatches, 2])*self.bboxD.getDimensions() + 

self.bboxD.getMin()] 

for pixPoint in pixPointList: 

src = self.sourceCat.addNew() 

src.set(self.sourceCentroidKey, pixPoint) 

ref = self.refCat.addNew() 

ref.set(self.refCoordKey, self.wcs.pixelToSky(pixPoint)) 

 

match = afwTable.ReferenceMatch(ref, src, 0) 

self.matchList.append(match) 

 

def tearDown(self): 

del self.wcs 

del self.bboxD 

del self.sourceCentroidKey 

del self.sourceCat 

del self.refCoordKey 

del self.refCat 

del self.matchList 

 

def testMakeMatchStatistics(self): 

"""Test makeMatchStatistics 

""" 

np.random.seed(47) 

distList = list((np.random.random_sample([self.numMatches]) - 0.5) * 10) 

for dist, match in zip(distList, self.matchList): 

match.distance = dist 

itemList = (afwMath.MEDIAN, afwMath.MEANCLIP, afwMath.STDEV) 

itemMask = reduce(lambda a, b: a | b, itemList) 

distStats = measAstrom.makeMatchStatistics(self.matchList, itemMask) 

directStats = afwMath.makeStatistics(distList, itemMask) 

for item in itemList: 

self.assertAlmostEqual(distStats.getValue(item), directStats.getValue(item)) 

 

def testMakeMatchStatisticsInRadians(self): 

"""Test makeMatchStatisticsInRadians 

""" 

np.random.seed(164) 

offLenList = [val*lsst.geom.radians for val in np.random.random_sample([self.numMatches])] 

offDirList = [val*lsst.geom.radians for val in np.random.random_sample([self.numMatches])*math.pi*2] 

for offLen, offDir, match in zip(offLenList, offDirList, self.matchList): 

coord = match.first.get(self.refCoordKey) 

offsetCoord = coord.offset(offDir, offLen) 

match.first.set(self.refCoordKey, offsetCoord) 

itemList = (afwMath.MEDIAN, afwMath.MEANCLIP, afwMath.IQRANGE) 

itemMask = reduce(lambda a, b: a | b, itemList) 

distStats = measAstrom.makeMatchStatisticsInRadians(self.wcs, self.matchList, itemMask) 

distRadiansList = [val.asRadians() for val in offLenList] 

directStats = afwMath.makeStatistics(distRadiansList, itemMask) 

for item in itemList: 

self.assertAlmostEqual(distStats.getValue(item), directStats.getValue(item)) 

 

def testMakeMatchStatisticsInPixels(self): 

"""Test testMakeMatchStatisticsInPixels 

""" 

np.random.seed(164) 

offList = [lsst.geom.Extent2D(val) for val in (np.random.random_sample([self.numMatches, 2])-0.5)*10] 

for off, match in zip(offList, self.matchList): 

centroid = match.second.get(self.sourceCentroidKey) 

offCentroid = centroid + off 

match.second.set(self.sourceCentroidKey, offCentroid) 

itemList = (afwMath.MEDIAN, afwMath.MEAN, afwMath.STDEVCLIP) 

itemMask = reduce(lambda a, b: a | b, itemList) 

distStats = measAstrom.makeMatchStatisticsInPixels(self.wcs, self.matchList, itemMask) 

distList = [math.hypot(*val) for val in offList] 

directStats = afwMath.makeStatistics(distList, itemMask) 

for item in itemList: 

self.assertAlmostEqual(distStats.getValue(item), directStats.getValue(item)) 

 

 

class MemoryTester(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

140 ↛ 141line 140 didn't jump to line 141, because the condition on line 140 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()