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
6from lsst.utils import getPackageDir
8from lsst.sims.utils import ObservationMetaData
9from lsst.sims.catUtils.baseCatalogModels import (GalaxyBulgeObj, GalaxyDiskObj,
10 GalaxyAgnObj, GalaxyTileCompoundObj,
11 StarObj)
13from lsst.sims.catalogs.definitions import InstanceCatalog, CompoundInstanceCatalog
15_testCompoundCatalogs_is_connected = True
16try:
17 _example_db = GalaxyBulgeObj()
18except:
19 _testCompoundCatalogs_is_connected = False
22def setup_module(module):
23 lsst.utils.tests.init()
26class BulgeDiskCatalog(InstanceCatalog):
27 catalog_type = __file__ + 'bulge_disk_catalog'
28 cannot_be_null = ['sedFilename']
29 column_outputs = ['galtileid', 'raJ2000', 'decJ2000',
30 'componentra', 'componentdec',
31 'magNorm', 'sedFilename',
32 'majorAxis', 'minorAxis',
33 'positionAngle',
34 'halfLightRadius',
35 'internalExtinctionModel',
36 'internalAv', 'internalRv']
39class AgnCatalog(InstanceCatalog):
40 catalog_type = __file__ + 'agn_catalog'
41 cannot_be_null = ['sedFilename']
42 column_outputs = ['galtileid', 'raJ2000', 'decJ2000',
43 'componentra', 'componentdec',
44 'magNorm', 'sedFilename',
45 'variabilityParameters']
48class StarCatalog(InstanceCatalog):
49 catalog_type = __file__ + 'star_catalog'
50 cannot_be_null = ['sedFilename']
51 column_outputs = ['id', 'raJ2000', 'decJ2000',
52 'glon', 'glat', 'magNorm',
53 'properMotionRa', 'properMotionDec',
54 'parallax', 'galacticAv', 'radialVelocity',
55 'variabilityParameters', 'sedFilename']
58ROOT = os.path.abspath(os.path.dirname(__file__))
60class CompoundCatalogTest(unittest.TestCase):
62 def setUp(self):
63 self.baseDir = tempfile.mkdtemp(dir=ROOT, prefix='compoundCatalogTest-')
65 def tearDown(self):
66 if os.path.exists(self.baseDir):
67 shutil.rmtree(self.baseDir)
69 @unittest.skipIf(not _testCompoundCatalogs_is_connected,
70 "We are not connected to fatboy")
71 def testGalaxyCatalog(self):
72 """
73 Test GalaxyTileCompoundObj by creating a catalog of galaxy bulges, disks,
74 and agns using both the 'old fashioned way' (one catalog at a time), and
75 using CompoundInstanceCatalog
76 """
77 controlFileName = os.path.join(self.baseDir, 'gal_compound_control.txt')
78 testFileName = os.path.join(self.baseDir, 'gal_compound_test.txt')
80 if os.path.exists(controlFileName):
81 os.unlink(controlFileName)
82 if os.path.exists(testFileName):
83 os.unlink(testFileName)
85 obs = ObservationMetaData(pointingRA=25.0, pointingDec=-45.0,
86 boundType='circle', boundLength=0.05)
88 dbBulge = GalaxyBulgeObj()
89 dbDisk = GalaxyDiskObj()
90 dbAgn = GalaxyAgnObj()
92 catBulge = BulgeDiskCatalog(dbBulge, obs_metadata=obs)
93 catDisk = BulgeDiskCatalog(dbDisk, obs_metadata=obs)
94 catAgn = AgnCatalog(dbAgn, obs_metadata=obs)
96 catBulge.write_catalog(controlFileName, write_header=False, chunk_size=10000)
97 catDisk.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
98 catAgn.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
100 totalCat = CompoundInstanceCatalog([BulgeDiskCatalog, BulgeDiskCatalog, AgnCatalog],
101 [GalaxyDiskObj, GalaxyBulgeObj, GalaxyAgnObj],
102 obs_metadata=obs,
103 compoundDBclass=GalaxyTileCompoundObj)
105 totalCat.write_catalog(testFileName, write_header=False, chunk_size=10000)
107 with open(controlFileName, 'r') as controlFile:
108 control = controlFile.readlines()
110 with open(testFileName, 'r') as testFile:
111 test = testFile.readlines()
113 for line in control:
114 self.assertIn(line, test)
116 for line in test:
117 self.assertIn(line, control)
119 @unittest.skipIf(not _testCompoundCatalogs_is_connected,
120 "We are not connected to fatboy")
121 def testGalaxyAndStarCatalog(self):
122 """
123 Test GalaxyTileCompoundObj by creating a catalog of galaxy bulges, disks,
124 agns, and stars using both the 'old fashioned way' (one catalog at a time), and
125 using CompoundInstanceCatalog
126 """
127 controlFileName = os.path.join(self.baseDir, 'galStar_compound_control.txt')
128 testFileName = os.path.join(self.baseDir, 'galStar_compound_test.txt')
130 if os.path.exists(controlFileName):
131 os.unlink(controlFileName)
132 if os.path.exists(testFileName):
133 os.unlink(testFileName)
135 obs = ObservationMetaData(pointingRA=25.0, pointingDec=-45.0,
136 boundType='circle', boundLength=0.05)
138 dbBulge = GalaxyBulgeObj()
139 dbDisk = GalaxyDiskObj()
140 dbAgn = GalaxyAgnObj()
141 dbStar = StarObj()
143 catBulge = BulgeDiskCatalog(dbBulge, obs_metadata=obs)
144 catDisk = BulgeDiskCatalog(dbDisk, obs_metadata=obs)
145 catAgn = AgnCatalog(dbAgn, obs_metadata=obs)
146 catStar = StarCatalog(dbStar, obs_metadata=obs)
148 catBulge.write_catalog(controlFileName, write_header=False, chunk_size=10000)
149 catDisk.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
150 catAgn.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
151 catStar.write_catalog(controlFileName, write_mode='a', write_header=False, chunk_size=10000)
153 totalCat = CompoundInstanceCatalog([BulgeDiskCatalog, BulgeDiskCatalog, StarCatalog, AgnCatalog],
154 [GalaxyBulgeObj, GalaxyDiskObj, StarObj, GalaxyAgnObj],
155 obs_metadata=obs,
156 compoundDBclass=GalaxyTileCompoundObj)
158 totalCat.write_catalog(testFileName, write_header=False, chunk_size=10000)
160 with open(controlFileName, 'r') as controlFile:
161 control = controlFile.readlines()
163 with open(testFileName, 'r') as testFile:
164 test = testFile.readlines()
166 for line in control:
167 self.assertIn(line, test)
169 for line in test:
170 self.assertIn(line, control)
173class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
174 pass
176if __name__ == "__main__": 176 ↛ 177line 176 didn't jump to line 177, because the condition on line 176 was never true
177 lsst.utils.tests.init()
178 unittest.main()