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

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 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/>. 

# 

 

from __future__ import absolute_import, division, print_function 

import os 

import unittest 

 

import lsst.afw.geom as afwGeom 

import lsst.afw.table as afwTable 

import lsst.afw.image as afwImg 

import lsst.utils.tests 

from astrometry.util import ttime 

from lsst.log import Log 

from lsst.meas.extensions.astrometryNet import AstrometryNetDataConfig, \ 

ANetBasicAstrometryConfig, ANetBasicAstrometryTask 

from lsst.meas.extensions.astrometryNet.multiindex import generateCache 

from test_findAstrometryNetDataDir import setupAstrometryNetDataDir 

 

 

class MultiIndexTest(unittest.TestCase): 

 

def setUp(self): 

self.conf = ANetBasicAstrometryConfig() 

 

# Load sample input from disk 

testDir = os.path.dirname(__file__) 

self.srcCat = afwTable.SourceCatalog.readFits(os.path.join(testDir, "v695833-e0-c000.xy.fits")) 

 

# The .xy.fits file has sources in the range ~ [0,2000],[0,4500] 

self.bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(2048, 4612)) # approximate 

self.exposure = afwImg.ExposureF(os.path.join(testDir, "v695833-e0-c000-a00.sci.fits")) 

 

# Set up local astrometry_net_data 

self.an_data_dir = setupAstrometryNetDataDir('photocal') 

 

def tearDown(self): 

del self.srcCat 

del self.conf 

del self.bbox 

del self.exposure 

 

def getAstrometrySolution(self, andConfig=None, logLevel=Log.INFO): 

astrom = ANetBasicAstrometryTask(self.conf, andConfig=andConfig) 

astrom.log.setLevel(logLevel) 

res = astrom.determineWcs(self.srcCat, self.exposure, bbox=self.bbox) 

del astrom 

return res 

 

def _testGetSolution(self, **kwargs): 

res = self.getAstrometrySolution(logLevel=Log.TRACE, **kwargs) 

self.assertIsNotNone(res) 

self.assertGreater(len(res.getMatches()), 50) 

 

# This is the "vanilla" no-multiIndex setup 

def testMultiIndexA(self): 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig2.py') 

andConfig.load(fn) 

self._testGetSolution(andConfig=andConfig) 

 

# This is a multiIndex setup with two indices 

def testMultiIndexB(self): 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig3.py') 

andConfig.load(fn) 

self._testGetSolution(andConfig=andConfig) 

 

# This is a multiIndex setup with two indices, one that has no star kdtree 

def testMultiIndexC(self): 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig4.py') 

andConfig.load(fn) 

self._testGetSolution(andConfig=andConfig) 

 

# This one has a multiIndex and a normal index. 

def testMultiIndexD(self): 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig5.py') 

andConfig.load(fn) 

self._testGetSolution(andConfig=andConfig) 

 

# This one has a multiIndex with stars-only and index-only parts 

def testMultiIndexE(self): 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig6.py') 

andConfig.load(fn) 

self._testGetSolution(andConfig=andConfig) 

 

# This one uses the cache 

def testCache(self): 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig6.py') 

andConfig.load(fn) 

andConfig.allowCache = True 

cacheName = os.path.join(self.an_data_dir, 'andCache.fits') 

115 ↛ 116line 115 didn't jump to line 116, because the condition on line 115 was never true if os.path.exists(cacheName): 

os.unlink(cacheName) 

try: 

generateCache(andConfig) 

self.assertTrue(os.path.exists(cacheName)) 

self._testGetSolution(andConfig=andConfig) 

finally: 

122 ↛ exitline 122 didn't return from function 'testCache', because the condition on line 122 was never false if os.path.exists(cacheName): 

os.unlink(cacheName) 

 

# Test that creating an Astrometry object with many index files 

# does not use up a lot of memory or file descriptors. 

# FIXME -- there are no tests on memory usage -- not clear exactly 

# what to enforce. 

def testResources(self): 

fd0 = ttime.count_file_descriptors() 

print('Mem0:', end=' ') 

print(ttime.memusage()) 

print('FD0:', fd0) 

 

andConfig = AstrometryNetDataConfig() 

fn = os.path.join(self.an_data_dir, 'andConfig6.py') 

andConfig.load(fn) 

andConfig.multiIndexFiles = andConfig.multiIndexFiles * 100 

print(len(andConfig.multiIndexFiles), 'multi-index files') 

 

astrom = ANetBasicAstrometryTask(self.conf, andConfig=andConfig) 

 

fd1 = ttime.count_file_descriptors() 

print() 

print('Mem1:') 

print(ttime.memusage()) 

print('FD1:', fd1) 

 

# Number of used file descriptors should not grow. Magic 10 

# is just margin from other things going on in the python process 

self.assertLess(fd1, fd0 + 10) 

 

res = astrom.determineWcs(self.srcCat, self.exposure, bbox=self.bbox) 

 

fd2 = ttime.count_file_descriptors() 

print() 

print('Mem2:') 

print(ttime.memusage()) 

print('FD2:', fd2) 

 

# Number of used file descriptors should not grow. Magic 10 

# is just margin from other things going on in the python process 

self.assertLess(fd2, fd0 + 10) 

 

del res 

del astrom 

 

fd3 = ttime.count_file_descriptors() 

print() 

print('Mem3:') 

print(ttime.memusage()) 

print('FD3:', fd3) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()