Coverage for tests/testCompoundCatalogs.py : 32%

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
1import unittest
2import os
3import shutil
4import tempfile
5import lsst.utils.tests
7from lsst.sims.utils import ObservationMetaData
8from lsst.sims.catUtils.baseCatalogModels import (GalaxyBulgeObj, GalaxyDiskObj,
9 GalaxyAgnObj, GalaxyTileCompoundObj,
10 StarObj)
12from lsst.sims.catalogs.definitions import InstanceCatalog, CompoundInstanceCatalog
14_testCompoundCatalogs_is_connected = True
15try:
16 _example_db = GalaxyBulgeObj()
17except:
18 _testCompoundCatalogs_is_connected = False
21def setup_module(module):
22 lsst.utils.tests.init()
25class BulgeDiskCatalog(InstanceCatalog):
26 catalog_type = __file__ + 'bulge_disk_catalog'
27 cannot_be_null = ['sedFilename']
28 column_outputs = ['galtileid', 'raJ2000', 'decJ2000',
29 'componentra', 'componentdec',
30 'magNorm', 'sedFilename',
31 'majorAxis', 'minorAxis',
32 'positionAngle',
33 'halfLightRadius',
34 'internalExtinctionModel',
35 'internalAv', 'internalRv']
38class AgnCatalog(InstanceCatalog):
39 catalog_type = __file__ + 'agn_catalog'
40 cannot_be_null = ['sedFilename']
41 column_outputs = ['galtileid', 'raJ2000', 'decJ2000',
42 'componentra', 'componentdec',
43 'magNorm', 'sedFilename',
44 'variabilityParameters']
47class StarCatalog(InstanceCatalog):
48 catalog_type = __file__ + 'star_catalog'
49 cannot_be_null = ['sedFilename']
50 column_outputs = ['id', 'raJ2000', 'decJ2000',
51 'glon', 'glat', 'magNorm',
52 'properMotionRa', 'properMotionDec',
53 'parallax', 'galacticAv', 'radialVelocity',
54 'variabilityParameters', 'sedFilename']
57ROOT = os.path.abspath(os.path.dirname(__file__))
59class CompoundCatalogTest(unittest.TestCase):
61 def setUp(self):
62 self.baseDir = tempfile.mkdtemp(dir=ROOT, prefix='compoundCatalogTest-')
64 def tearDown(self):
65 if os.path.exists(self.baseDir):
66 shutil.rmtree(self.baseDir, ignore_errors=True)
68 @unittest.skipIf(not _testCompoundCatalogs_is_connected,
69 "We are not connected to fatboy")
70 def testGalaxyCatalog(self):
71 """
72 Test GalaxyTileCompoundObj by creating a catalog of galaxy bulges, disks,
73 and agns using both the 'old fashioned way' (one catalog at a time), and
74 using CompoundInstanceCatalog
75 """
76 controlFileName = os.path.join(self.baseDir, 'gal_compound_control.txt')
77 testFileName = os.path.join(self.baseDir, 'gal_compound_test.txt')
79 if os.path.exists(controlFileName):
80 os.unlink(controlFileName)
81 if os.path.exists(testFileName):
82 os.unlink(testFileName)
84 obs = ObservationMetaData(pointingRA=25.0, pointingDec=-45.0,
85 boundType='circle', boundLength=0.05)
87 dbBulge = GalaxyBulgeObj()
88 dbDisk = GalaxyDiskObj()
89 dbAgn = GalaxyAgnObj()
91 catBulge = BulgeDiskCatalog(dbBulge, obs_metadata=obs)
92 catDisk = BulgeDiskCatalog(dbDisk, obs_metadata=obs)
93 catAgn = AgnCatalog(dbAgn, obs_metadata=obs)
95 catBulge.write_catalog(controlFileName, write_header=False, chunk_size=10000)
96 catDisk.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
97 catAgn.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
99 totalCat = CompoundInstanceCatalog([BulgeDiskCatalog, BulgeDiskCatalog, AgnCatalog],
100 [GalaxyDiskObj, GalaxyBulgeObj, GalaxyAgnObj],
101 obs_metadata=obs,
102 compoundDBclass=GalaxyTileCompoundObj)
104 totalCat.write_catalog(testFileName, write_header=False, chunk_size=10000)
106 with open(controlFileName, 'r') as controlFile:
107 control = controlFile.readlines()
109 with open(testFileName, 'r') as testFile:
110 test = testFile.readlines()
112 for line in control:
113 self.assertIn(line, test)
115 for line in test:
116 self.assertIn(line, control)
118 @unittest.skipIf(not _testCompoundCatalogs_is_connected,
119 "We are not connected to fatboy")
120 def testGalaxyAndStarCatalog(self):
121 """
122 Test GalaxyTileCompoundObj by creating a catalog of galaxy bulges, disks,
123 agns, and stars using both the 'old fashioned way' (one catalog at a time), and
124 using CompoundInstanceCatalog
125 """
126 controlFileName = os.path.join(self.baseDir, 'galStar_compound_control.txt')
127 testFileName = os.path.join(self.baseDir, 'galStar_compound_test.txt')
129 if os.path.exists(controlFileName):
130 os.unlink(controlFileName)
131 if os.path.exists(testFileName):
132 os.unlink(testFileName)
134 obs = ObservationMetaData(pointingRA=25.0, pointingDec=-45.0,
135 boundType='circle', boundLength=0.05)
137 dbBulge = GalaxyBulgeObj()
138 dbDisk = GalaxyDiskObj()
139 dbAgn = GalaxyAgnObj()
140 dbStar = StarObj()
142 catBulge = BulgeDiskCatalog(dbBulge, obs_metadata=obs)
143 catDisk = BulgeDiskCatalog(dbDisk, obs_metadata=obs)
144 catAgn = AgnCatalog(dbAgn, obs_metadata=obs)
145 catStar = StarCatalog(dbStar, obs_metadata=obs)
147 catBulge.write_catalog(controlFileName, write_header=False, chunk_size=10000)
148 catDisk.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
149 catAgn.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
150 catStar.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
152 totalCat = CompoundInstanceCatalog([BulgeDiskCatalog, BulgeDiskCatalog, StarCatalog, AgnCatalog],
153 [GalaxyBulgeObj, GalaxyDiskObj, StarObj, GalaxyAgnObj],
154 obs_metadata=obs,
155 compoundDBclass=GalaxyTileCompoundObj)
157 totalCat.write_catalog(testFileName, write_header=False, chunk_size=10000)
159 with open(controlFileName, 'r') as controlFile:
160 control = controlFile.readlines()
162 with open(testFileName, 'r') as testFile:
163 test = testFile.readlines()
165 for line in control:
166 self.assertIn(line, test)
168 for line in test:
169 self.assertIn(line, control)
172class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
173 pass
175if __name__ == "__main__": 175 ↛ 176line 175 didn't jump to line 176, because the condition on line 175 was never true
176 lsst.utils.tests.init()
177 unittest.main()