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

import unittest 

import os 

import shutil 

import tempfile 

import lsst.utils.tests 

from lsst.utils import getPackageDir 

 

from lsst.sims.utils import ObservationMetaData 

from lsst.sims.catUtils.baseCatalogModels import (GalaxyBulgeObj, GalaxyDiskObj, 

GalaxyAgnObj, GalaxyTileCompoundObj, 

StarObj) 

 

from lsst.sims.catalogs.definitions import InstanceCatalog, CompoundInstanceCatalog 

 

_testCompoundCatalogs_is_connected = True 

try: 

_example_db = GalaxyBulgeObj() 

except: 

_testCompoundCatalogs_is_connected = False 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class BulgeDiskCatalog(InstanceCatalog): 

catalog_type = __file__ + 'bulge_disk_catalog' 

cannot_be_null = ['sedFilename'] 

column_outputs = ['galtileid', 'raJ2000', 'decJ2000', 

'componentra', 'componentdec', 

'magNorm', 'sedFilename', 

'majorAxis', 'minorAxis', 

'positionAngle', 

'halfLightRadius', 

'internalExtinctionModel', 

'internalAv', 'internalRv'] 

 

 

class AgnCatalog(InstanceCatalog): 

catalog_type = __file__ + 'agn_catalog' 

cannot_be_null = ['sedFilename'] 

column_outputs = ['galtileid', 'raJ2000', 'decJ2000', 

'componentra', 'componentdec', 

'magNorm', 'sedFilename', 

'variabilityParameters'] 

 

 

class StarCatalog(InstanceCatalog): 

catalog_type = __file__ + 'star_catalog' 

cannot_be_null = ['sedFilename'] 

column_outputs = ['id', 'raJ2000', 'decJ2000', 

'glon', 'glat', 'magNorm', 

'properMotionRa', 'properMotionDec', 

'parallax', 'galacticAv', 'radialVelocity', 

'variabilityParameters', 'sedFilename'] 

 

 

ROOT = os.path.abspath(os.path.dirname(__file__)) 

 

class CompoundCatalogTest(unittest.TestCase): 

 

def setUp(self): 

self.baseDir = tempfile.mkdtemp(dir=ROOT, prefix='compoundCatalogTest-') 

 

def tearDown(self): 

if os.path.exists(self.baseDir): 

shutil.rmtree(self.baseDir) 

 

@unittest.skipIf(not _testCompoundCatalogs_is_connected, 

"We are not connected to fatboy") 

def testGalaxyCatalog(self): 

""" 

Test GalaxyTileCompoundObj by creating a catalog of galaxy bulges, disks, 

and agns using both the 'old fashioned way' (one catalog at a time), and 

using CompoundInstanceCatalog 

""" 

controlFileName = os.path.join(self.baseDir, 'gal_compound_control.txt') 

testFileName = os.path.join(self.baseDir, 'gal_compound_test.txt') 

 

if os.path.exists(controlFileName): 

os.unlink(controlFileName) 

if os.path.exists(testFileName): 

os.unlink(testFileName) 

 

obs = ObservationMetaData(pointingRA=25.0, pointingDec=-45.0, 

boundType='circle', boundLength=0.05) 

 

dbBulge = GalaxyBulgeObj() 

dbDisk = GalaxyDiskObj() 

dbAgn = GalaxyAgnObj() 

 

catBulge = BulgeDiskCatalog(dbBulge, obs_metadata=obs) 

catDisk = BulgeDiskCatalog(dbDisk, obs_metadata=obs) 

catAgn = AgnCatalog(dbAgn, obs_metadata=obs) 

 

catBulge.write_catalog(controlFileName, write_header=False, chunk_size=10000) 

catDisk.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000) 

catAgn.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000) 

 

totalCat = CompoundInstanceCatalog([BulgeDiskCatalog, BulgeDiskCatalog, AgnCatalog], 

[GalaxyDiskObj, GalaxyBulgeObj, GalaxyAgnObj], 

obs_metadata=obs, 

compoundDBclass=GalaxyTileCompoundObj) 

 

totalCat.write_catalog(testFileName, write_header=False, chunk_size=10000) 

 

with open(controlFileName, 'r') as controlFile: 

control = controlFile.readlines() 

 

with open(testFileName, 'r') as testFile: 

test = testFile.readlines() 

 

for line in control: 

self.assertIn(line, test) 

 

for line in test: 

self.assertIn(line, control) 

 

@unittest.skipIf(not _testCompoundCatalogs_is_connected, 

"We are not connected to fatboy") 

def testGalaxyAndStarCatalog(self): 

""" 

Test GalaxyTileCompoundObj by creating a catalog of galaxy bulges, disks, 

agns, and stars using both the 'old fashioned way' (one catalog at a time), and 

using CompoundInstanceCatalog 

""" 

controlFileName = os.path.join(self.baseDir, 'galStar_compound_control.txt') 

testFileName = os.path.join(self.baseDir, 'galStar_compound_test.txt') 

 

if os.path.exists(controlFileName): 

os.unlink(controlFileName) 

if os.path.exists(testFileName): 

os.unlink(testFileName) 

 

obs = ObservationMetaData(pointingRA=25.0, pointingDec=-45.0, 

boundType='circle', boundLength=0.05) 

 

dbBulge = GalaxyBulgeObj() 

dbDisk = GalaxyDiskObj() 

dbAgn = GalaxyAgnObj() 

dbStar = StarObj() 

 

catBulge = BulgeDiskCatalog(dbBulge, obs_metadata=obs) 

catDisk = BulgeDiskCatalog(dbDisk, obs_metadata=obs) 

catAgn = AgnCatalog(dbAgn, obs_metadata=obs) 

catStar = StarCatalog(dbStar, obs_metadata=obs) 

 

catBulge.write_catalog(controlFileName, write_header=False, chunk_size=10000) 

catDisk.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000) 

catAgn.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000) 

catStar.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000) 

 

totalCat = CompoundInstanceCatalog([BulgeDiskCatalog, BulgeDiskCatalog, StarCatalog, AgnCatalog], 

[GalaxyBulgeObj, GalaxyDiskObj, StarObj, GalaxyAgnObj], 

obs_metadata=obs, 

compoundDBclass=GalaxyTileCompoundObj) 

 

totalCat.write_catalog(testFileName, write_header=False, chunk_size=10000) 

 

with open(controlFileName, 'r') as controlFile: 

control = controlFile.readlines() 

 

with open(testFileName, 'r') as testFile: 

test = testFile.readlines() 

 

for line in control: 

self.assertIn(line, test) 

 

for line in test: 

self.assertIn(line, control) 

 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()