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

1from __future__ import with_statement 

2from __future__ import print_function 

3from builtins import zip 

4from builtins import range 

5import numpy as np 

6import tempfile 

7 

8import os 

9import unittest 

10import lsst.utils.tests 

11from lsst.sims.utils import ObservationMetaData 

12from lsst.sims.catalogs.utils import (myTestGals, myTestStars, 

13 makeStarTestDB, makeGalTestDB, getOneChunk) 

14 

15from lsst.utils import getPackageDir 

16from lsst.sims.utils.CodeUtilities import sims_clean_up 

17from lsst.sims.utils import defaultSpecMap 

18from lsst.sims.photUtils.Bandpass import Bandpass 

19from lsst.sims.photUtils.Sed import Sed 

20from lsst.sims.photUtils import BandpassDict 

21from lsst.sims.photUtils import LSSTdefaults 

22from lsst.sims.catUtils.utils import (cartoonStars, cartoonGalaxies, testStars, testGalaxies, 

23 cartoonStarsOnlyI, cartoonStarsIZ, 

24 cartoonGalaxiesIG, galaxiesWithHoles) 

25from lsst.sims.catUtils.mixins import PhotometryGalaxies 

26 

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

28 

29 

30def setup_module(module): 

31 lsst.utils.tests.init() 

32 

33 

34class variabilityUnitTest(unittest.TestCase): 

35 

36 @classmethod 

37 def setUpClass(cls): 

38 # Create test databases 

39 cls.testDB = tempfile.mktemp(dir=ROOT, prefix='PhotometryTestDatabase-', suffix='.db') 

40 

41 makeStarTestDB(filename=cls.testDB, size=100000, seedVal=1) 

42 makeGalTestDB(filename=cls.testDB, size=100000, seedVal=1) 

43 

44 @classmethod 

45 def tearDownClass(cls): 

46 sims_clean_up() 

47 if os.path.exists(cls.testDB): 

48 os.unlink(cls.testDB) 

49 

50 def setUp(self): 

51 self.obs_metadata = ObservationMetaData(mjd=52000.7, 

52 boundType = 'circle', 

53 pointingRA=200.0, pointingDec=-30.0, 

54 boundLength=1.0, 

55 m5=[23.9, 25.0, 24.7, 24.0, 23.3, 22.1], 

56 bandpassName=['u', 'g', 'r', 'i', 'z', 'y']) 

57 

58 self.galaxy = myTestGals(database=self.testDB) 

59 self.star = myTestStars(database=self.testDB) 

60 

61 def tearDown(self): 

62 del self.galaxy 

63 del self.star 

64 del self.obs_metadata 

65 

66 def testGalaxyVariability(self): 

67 

68 galcat = testGalaxies(self.galaxy, obs_metadata=self.obs_metadata) 

69 results = self.galaxy.query_columns(['varParamStr'], obs_metadata=self.obs_metadata, 

70 constraint='VarParamStr is not NULL') 

71 result = getOneChunk(results) 

72 ct = 0 

73 for row in result: 

74 # apply variability to make sure that it does not fall down 

75 galcat.applyVariability([row['varParamStr']]) 

76 ct += 1 

77 self.assertGreater(ct, 0) # to make sure that the test was actually performed 

78 

79 def testStarVariability(self): 

80 starcat = testStars(self.star, obs_metadata=self.obs_metadata) 

81 results = self.star.query_columns(['varParamStr'], obs_metadata=self.obs_metadata, 

82 constraint='VarParamStr is not NULL') 

83 result = getOneChunk(results) 

84 ct = 0 

85 for row in result: 

86 ct += 1 

87 # apply variability to make sure it doesn't fall down 

88 starcat.applyVariability([row['varParamStr']]) 

89 self.assertGreater(ct, 0) # to make sure that the test was actually performed 

90 

91 

92class photometryUnitTest(unittest.TestCase): 

93 

94 @classmethod 

95 def setUpClass(cls): 

96 # Create test databases 

97 cls.testDB = tempfile.mktemp(dir=ROOT, prefix='PhotometryTestDatabase-', suffix='.db') 

98 

99 makeStarTestDB(filename=cls.testDB, size=100000, seedVal=1) 

100 makeGalTestDB(filename=cls.testDB, size=100000, seedVal=1) 

101 

102 @classmethod 

103 def tearDownClass(cls): 

104 sims_clean_up() 

105 if os.path.exists(cls.testDB): 

106 os.unlink(cls.testDB) 

107 

108 def setUp(self): 

109 defaults = LSSTdefaults() 

110 bandpassName = ['u', 'g', 'r', 'i', 'z', 'y'] 

111 self.obs_metadata = ObservationMetaData(mjd=52000.7, 

112 bandpassName=bandpassName, 

113 m5=[defaults.m5(mm) for mm in bandpassName], 

114 boundType='circle', 

115 pointingRA=200.0, pointingDec=-30.0, 

116 boundLength=1.0) 

117 

118 self.galaxy = myTestGals(database=self.testDB) 

119 self.star = myTestStars(database=self.testDB) 

120 

121 def tearDown(self): 

122 del self.galaxy 

123 del self.star 

124 del self.obs_metadata 

125 

126 def testStarCatalog(self): 

127 test_cat = testStars(self.star, obs_metadata=self.obs_metadata) 

128 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

129 test_cat.write_catalog(catName) 

130 with open(catName) as cat: 

131 lines = cat.readlines() 

132 self.assertGreater(len(lines), 1) # to make sure we did not write an empty catalog 

133 results = self.star.query_columns(obs_metadata=self.obs_metadata) 

134 result = getOneChunk(results) 

135 self.assertGreater(len(result), 0) # to make sure some results are returned 

136 

137 def testGalaxyCatalog(self): 

138 test_cat = testGalaxies(self.galaxy, obs_metadata=self.obs_metadata) 

139 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

140 test_cat.write_catalog(catName) 

141 with open(catName) as cat: 

142 lines = cat.readlines() 

143 self.assertGreater(len(lines), 1) # to make sure we did not write an empty catalog 

144 results = self.galaxy.query_columns(obs_metadata=self.obs_metadata) 

145 result = getOneChunk(results) 

146 self.assertGreater(len(result), 0) # to make sure some results are returned 

147 

148 def test_m5_exceptions(self): 

149 """ 

150 Test that the correct exception is raised when you ask for a photometric 

151 uncertainty but do not define the required m5 value 

152 """ 

153 obs = ObservationMetaData(pointingRA=25.0, pointingDec=-14.0, 

154 boundType='circle', boundLength=0.1, 

155 bandpassName=['u', 'g', 'r', 'z', 'y'], 

156 m5 = [24.0] * 5, 

157 mjd=57388.0) 

158 

159 with self.assertRaises(KeyError) as context: 

160 cat = testStars(self.star, obs_metadata=obs) 

161 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

162 cat.write_catalog(catName) 

163 

164 self.assertIn('Is it possible your ObservationMetaData does not have the proper\nm5 values defined?', 

165 context.exception.args[0]) 

166 

167 with self.assertRaises(KeyError) as context: 

168 cat = testGalaxies(self.galaxy, obs_metadata=obs) 

169 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

170 cat.write_catalog(catName) 

171 

172 self.assertIn('Is it possible your ObservationMetaData does not have the proper\nm5 values defined?', 

173 context.exception.args[0]) 

174 

175 def testSumMagnitudes(self): 

176 """ 

177 Test that the method sum_magnitudes in PhotometryGalaxies handles 

178 NaNs correctly. Test it both in the vectorized and non-vectorized form. 

179 """ 

180 mm_0 = 22.0 

181 

182 bulge = 15.0*np.ones(8) 

183 

184 disk = 15.2*np.ones(8) 

185 

186 agn = 15.4*np.ones(8) 

187 

188 bulge[0] = np.NaN 

189 disk[1] = np.NaN 

190 agn[2] = np.NaN 

191 

192 bulge[3] = np.NaN 

193 disk[3] = np.NaN 

194 

195 bulge[4] = np.NaN 

196 agn[4] = np.NaN 

197 

198 disk[5] = np.NaN 

199 agn[5] = np.NaN 

200 

201 bulge[7] = np.NaN 

202 disk[7] = np.NaN 

203 agn[7] = np.NaN 

204 

205 bulge_flux = np.power(10.0, -0.4*(bulge-mm_0)) 

206 disk_flux = np.power(10.0, -0.4*(disk-mm_0)) 

207 agn_flux = np.power(10.0, -0.4*(agn-mm_0)) 

208 

209 answer = np.zeros(8) 

210 answer[0] = -2.5*np.log10(disk_flux[0]+agn_flux[0]) + mm_0 

211 answer[1] = -2.5*np.log10(bulge_flux[1]+agn_flux[1]) + mm_0 

212 answer[2] = -2.5*np.log10(bulge_flux[2]+disk_flux[2]) + mm_0 

213 answer[3] = -2.5*np.log10(agn_flux[3]) + mm_0 

214 answer[4] = -2.5*np.log10(disk_flux[4]) + mm_0 

215 answer[5] = -2.5*np.log10(bulge_flux[5]) + mm_0 

216 answer[6] = -2.5*np.log10(bulge_flux[6]+disk_flux[6]+agn_flux[6]) + mm_0 

217 answer[7] = np.NaN 

218 

219 phot = PhotometryGalaxies() 

220 test = phot.sum_magnitudes(bulge=bulge, disk=disk, agn=agn) 

221 

222 np.testing.assert_array_almost_equal(test, answer, decimal=10) 

223 

224 for ix, (bb, dd, aa, truth) in enumerate(zip(bulge, disk, agn, answer)): 

225 test = phot.sum_magnitudes(bulge=bb, disk=dd, agn=aa) 

226 if ix < 7: 

227 self.assertAlmostEqual(test, truth, 10) 

228 self.assertFalse(np.isnan(test), msg='test is NaN; should not be') 

229 else: 

230 np.testing.assert_equal(test, np.NaN) 

231 np.testing.assert_equal(truth, np.NaN) 

232 

233 def testSumMagnitudesCatalog(self): 

234 """ 

235 test that sum_magnitudes handles NaNs correctly in the context 

236 of a catalog by outputting a catalog of galaxies with NaNs in 

237 different component magnitudes, reading that catalog back in, 

238 and then calculating the summed magnitude by hand and comparing 

239 """ 

240 

241 obs_metadata = ObservationMetaData(mjd=50000.0, 

242 boundType='circle', 

243 pointingRA=0.0, pointingDec=0.0, 

244 boundLength=10.0) 

245 

246 test_cat = galaxiesWithHoles(self.galaxy, obs_metadata=obs_metadata) 

247 dtype = np.dtype([('raJ2000', np.float), 

248 ('decJ2000', np.float), 

249 ('u', np.float), ('g', np.float), ('r', np.float), 

250 ('i', np.float), ('z', np.float), ('y', np.float), 

251 ('ub', np.float), ('gb', np.float), ('rb', np.float), 

252 ('ib', np.float), ('zb', np.float), ('yb', np.float), 

253 ('ud', np.float), ('gd', np.float), ('rd', np.float), 

254 ('id', np.float), ('zd', np.float), ('yd', np.float), 

255 ('ua', np.float), ('ga', np.float), ('ra', np.float), 

256 ('ia', np.float), ('za', np.float), ('ya', np.float)]) 

257 

258 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

259 test_cat.write_catalog(catName) 

260 data = np.genfromtxt(catName, dtype=dtype, delimiter=', ') 

261 self.assertGreater(len(data), 16) 

262 phot = PhotometryGalaxies() 

263 

264 test = phot.sum_magnitudes(bulge=data['ub'], disk=data['ud'], agn=data['ua']) 

265 np.testing.assert_array_almost_equal(test, data['u'], decimal=10) 

266 

267 test = phot.sum_magnitudes(bulge=data['gb'], disk=data['gd'], agn=data['ga']) 

268 np.testing.assert_array_almost_equal(test, data['g'], decimal=10) 

269 

270 test = phot.sum_magnitudes(bulge=data['rb'], disk=data['rd'], agn=data['ra']) 

271 np.testing.assert_array_almost_equal(test, data['r'], decimal=10) 

272 

273 test = phot.sum_magnitudes(bulge=data['ib'], disk=data['id'], agn=data['ia']) 

274 np.testing.assert_array_almost_equal(test, data['i'], decimal=10) 

275 

276 test = phot.sum_magnitudes(bulge=data['zb'], disk=data['zd'], agn=data['za']) 

277 np.testing.assert_array_almost_equal(test, data['z'], decimal=10) 

278 

279 test = phot.sum_magnitudes(bulge=data['yb'], disk=data['yd'], agn=data['ya']) 

280 np.testing.assert_array_almost_equal(test, data['y'], decimal=10) 

281 

282 # make sure that there were some NaNs for our catalog to deal with (but that they were not 

283 # all NaNs 

284 for line in [data['u'], data['g'], data['r'], data['i'], data['z'], data['y'], 

285 data['ub'], data['gb'], data['rb'], data['ib'], data['zb'], data['yb'], 

286 data['ud'], data['gd'], data['rd'], data['id'], data['zd'], data['yd'], 

287 data['ua'], data['ga'], data['ra'], data['ia'], data['za'], data['ya']]: 

288 

289 ctNans = len(np.where(np.isnan(line))[0]) 

290 self.assertGreater(ctNans, 0) 

291 self.assertLess(ctNans, len(line)) 

292 

293 def testAlternateBandpassesStars(self): 

294 """ 

295 This will test our ability to do photometry using non-LSST bandpasses. 

296 

297 It will first calculate the magnitudes using the getters in cartoonPhotometryStars. 

298 

299 It will then load the alternate bandpass files 'by hand' and re-calculate the magnitudes 

300 and make sure that the magnitude values agree. This is guarding against the possibility 

301 that some default value did not change and the code actually ended up loading the 

302 LSST bandpasses. 

303 """ 

304 

305 obs_metadata_pointed = ObservationMetaData(mjd=2013.23, 

306 boundType='circle', 

307 pointingRA=200.0, pointingDec=-30.0, 

308 boundLength=1.0) 

309 

310 test_cat = cartoonStars(self.star, obs_metadata=obs_metadata_pointed) 

311 

312 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

313 test_cat.write_catalog(catName) 

314 with open(catName, 'r') as input_file: 

315 lines = input_file.readlines() 

316 self.assertGreater(len(lines), 1) 

317 

318 cartoonDir = os.path.join(getPackageDir('sims_photUtils'), 'tests', 'cartoonSedTestData') 

319 testBandPasses = {} 

320 keys = ['u', 'g', 'r', 'i', 'z'] 

321 

322 bplist = [] 

323 

324 for kk in keys: 

325 testBandPasses[kk] = Bandpass() 

326 testBandPasses[kk].readThroughput(os.path.join(cartoonDir, "test_bandpass_%s.dat" % kk)) 

327 bplist.append(testBandPasses[kk]) 

328 

329 sedObj = Sed() 

330 phiArray, waveLenStep = sedObj.setupPhiArray(bplist) 

331 

332 i = 0 

333 

334 # since all of the SEDs in the cartoon database are the same, just test on the first 

335 # if we ever include more SEDs, this can be something like 

336 # for ss in test_cata.sedMasterList: 

337 ss = test_cat.sedMasterList[0] 

338 ss.resampleSED(wavelen_match = bplist[0].wavelen) 

339 ss.flambdaTofnu() 

340 mags = -2.5*np.log10(np.sum(phiArray*ss.fnu, axis=1)*waveLenStep) - ss.zp 

341 self.assertEqual(len(mags), len(test_cat.cartoonBandpassDict)) 

342 self.assertGreater(len(mags), 0) 

343 for j in range(len(mags)): 

344 self.assertAlmostEqual(mags[j], test_cat.magnitudeMasterList[i][j], 4) 

345 

346 def testAlternateBandpassesGalaxies(self): 

347 """ 

348 the same as testAlternateBandpassesStars, but for galaxies 

349 """ 

350 

351 obs_metadata_pointed = ObservationMetaData(mjd=50000.0, 

352 boundType='circle', 

353 pointingRA=0.0, pointingDec=0.0, 

354 boundLength=10.0) 

355 

356 dtype = np.dtype([('galid', np.int), 

357 ('ra', np.float), 

358 ('dec', np.float), 

359 ('uTotal', np.float), 

360 ('gTotal', np.float), 

361 ('rTotal', np.float), 

362 ('iTotal', np.float), 

363 ('zTotal', np.float), 

364 ('uBulge', np.float), 

365 ('gBulge', np.float), 

366 ('rBulge', np.float), 

367 ('iBulge', np.float), 

368 ('zBulge', np.float), 

369 ('uDisk', np.float), 

370 ('gDisk', np.float), 

371 ('rDisk', np.float), 

372 ('iDisk', np.float), 

373 ('zDisk', np.float), 

374 ('uAgn', np.float), 

375 ('gAgn', np.float), 

376 ('rAgn', np.float), 

377 ('iAgn', np.float), 

378 ('zAgn', np.float), 

379 ('bulgeName', str, 200), 

380 ('bulgeNorm', np.float), 

381 ('bulgeAv', np.float), 

382 ('diskName', str, 200), 

383 ('diskNorm', np.float), 

384 ('diskAv', np.float), 

385 ('agnName', str, 200), 

386 ('agnNorm', np.float), 

387 ('redshift', np.float)]) 

388 

389 test_cat = cartoonGalaxies(self.galaxy, obs_metadata=obs_metadata_pointed) 

390 with lsst.utils.tests.getTempFilePath('.txt') as catName: 

391 test_cat.write_catalog(catName) 

392 catData = np.genfromtxt(catName, dtype=dtype, delimiter=', ') 

393 

394 self.assertGreater(len(catData), 0) 

395 

396 cartoonDir = getPackageDir('sims_photUtils') 

397 cartoonDir = os.path.join(cartoonDir, 'tests', 'cartoonSedTestData') 

398 sedDir = getPackageDir('sims_sed_library') 

399 

400 testBandpasses = {} 

401 keys = ['u', 'g', 'r', 'i', 'z'] 

402 

403 for kk in keys: 

404 testBandpasses[kk] = Bandpass() 

405 testBandpasses[kk].readThroughput(os.path.join(cartoonDir, "test_bandpass_%s.dat" % kk)) 

406 

407 imsimBand = Bandpass() 

408 imsimBand.imsimBandpass() 

409 

410 specMap = defaultSpecMap 

411 

412 ct = 0 

413 for line in catData: 

414 bulgeMagList = [] 

415 diskMagList = [] 

416 agnMagList = [] 

417 if line['bulgeName'] == 'None': 

418 for bp in keys: 

419 np.testing.assert_equal(line['%sBulge' % bp], np.NaN) 

420 bulgeMagList.append(np.NaN) 

421 else: 

422 ct += 1 

423 dummySed = Sed() 

424 dummySed.readSED_flambda(os.path.join(sedDir, specMap[line['bulgeName']])) 

425 fnorm = dummySed.calcFluxNorm(line['bulgeNorm'], imsimBand) 

426 dummySed.multiplyFluxNorm(fnorm) 

427 a_int, b_int = dummySed.setupCCM_ab() 

428 dummySed.addDust(a_int, b_int, A_v=line['bulgeAv']) 

429 dummySed.redshiftSED(line['redshift'], dimming=True) 

430 dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen) 

431 for bpName in keys: 

432 mag = dummySed.calcMag(testBandpasses[bpName]) 

433 self.assertAlmostEqual(mag, line['%sBulge' % bpName], 10) 

434 bulgeMagList.append(mag) 

435 

436 if line['diskName'] == 'None': 

437 for bp in keys: 

438 np.assert_equal(line['%sDisk' % bp], np.NaN) 

439 diskMagList.append(np.NaN) 

440 else: 

441 ct += 1 

442 dummySed = Sed() 

443 dummySed.readSED_flambda(os.path.join(sedDir, specMap[line['diskName']])) 

444 fnorm = dummySed.calcFluxNorm(line['diskNorm'], imsimBand) 

445 dummySed.multiplyFluxNorm(fnorm) 

446 a_int, b_int = dummySed.setupCCM_ab() 

447 dummySed.addDust(a_int, b_int, A_v=line['diskAv']) 

448 dummySed.redshiftSED(line['redshift'], dimming=True) 

449 dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen) 

450 for bpName in keys: 

451 mag = dummySed.calcMag(testBandpasses[bpName]) 

452 self.assertAlmostEqual(mag, line['%sDisk' % bpName], 10) 

453 diskMagList.append(mag) 

454 

455 if line['agnName'] == 'None': 

456 for bp in keys: 

457 np.testing.assert_true(line['%sAgn' % bp], np.NaN) 

458 agnMagList.append(np.NaN) 

459 else: 

460 ct += 1 

461 dummySed = Sed() 

462 dummySed.readSED_flambda(os.path.join(sedDir, specMap[line['agnName']])) 

463 fnorm = dummySed.calcFluxNorm(line['agnNorm'], imsimBand) 

464 dummySed.multiplyFluxNorm(fnorm) 

465 dummySed.redshiftSED(line['redshift'], dimming=True) 

466 dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen) 

467 for bpName in keys: 

468 mag = dummySed.calcMag(testBandpasses[bpName]) 

469 self.assertAlmostEqual(mag, line['%sAgn' % bpName], 10) 

470 agnMagList.append(mag) 

471 

472 totalMags = PhotometryGalaxies().sum_magnitudes(bulge=np.array(bulgeMagList), 

473 disk=np.array(diskMagList), 

474 agn=np.array(agnMagList)) 

475 

476 for testMag, bpName in zip(totalMags, keys): 

477 if np.isnan(line['%sTotal' % bpName]): 

478 np.testing.assert_equal(testMag, np.NaN) 

479 else: 

480 self.assertAlmostEqual(testMag, line['%sTotal' % bpName], 10) 

481 

482 self.assertGreater(ct, 0) 

483 

484 def testStellarPhotometryIndices(self): 

485 """ 

486 A test to make sure that stellar photometry still calculates the right values 

487 even when it is not calculating all of the magnitudes in the getter 

488 """ 

489 

490 baselineDtype = np.dtype([('id', int), 

491 ('raObserved', float), ('decObserved', float), 

492 ('magNorm', float), 

493 ('cartoon_u', float), ('cartoon_g', float), 

494 ('cartoon_r', float), ('cartoon_i', float), 

495 ('cartoon_z', float)]) 

496 

497 testDtype = np.dtype([('id', int), 

498 ('raObserved', float), ('decObserved', float), 

499 ('cartoon_i', float)]) 

500 

501 obs_metadata_pointed = ObservationMetaData(mjd=2013.23, 

502 boundType='circle', 

503 pointingRA=200.0, pointingDec=-30.0, 

504 boundLength=1.0) 

505 

506 baseline_cat = cartoonStars(self.star, obs_metadata=obs_metadata_pointed) 

507 with lsst.utils.tests.getTempFilePath('.txt') as baselineCatName: 

508 baseline_cat.write_catalog(baselineCatName) 

509 baselineData = np.genfromtxt(baselineCatName, dtype=baselineDtype, delimiter=',') 

510 self.assertGreater(len(baselineData), 0) 

511 

512 test_cat = cartoonStarsOnlyI(self.star, obs_metadata=obs_metadata_pointed) 

513 with lsst.utils.tests.getTempFilePath('.txt') as testCatName: 

514 test_cat.write_catalog(testCatName) 

515 testData = np.genfromtxt(testCatName, dtype=testDtype, delimiter=',') 

516 self.assertGreater(len(testData), 0) 

517 

518 for b, t in zip(baselineData, testData): 

519 self.assertAlmostEqual(b['cartoon_i'], t['cartoon_i'], 10) 

520 

521 testDtype = np.dtype([('id', int), 

522 ('raObserved', float), ('decObserved', float), 

523 ('cartoon_i', float), ('cartoon_z', float)]) 

524 

525 test_cat = cartoonStarsIZ(self.star, obs_metadata=obs_metadata_pointed) 

526 with lsst.utils.tests.getTempFilePath('.txt') as testCatName: 

527 test_cat.write_catalog(testCatName) 

528 testData = np.genfromtxt(testCatName, dtype=testDtype, delimiter=',') 

529 self.assertGreater(len(testData), 0) 

530 

531 for b, t in zip(baselineData, testData): 

532 self.assertAlmostEqual(b['cartoon_i'], t['cartoon_i'], 10) 

533 self.assertAlmostEqual(b['cartoon_z'], t['cartoon_z'], 10) 

534 

535 def testGalaxyPhotometricIndices(self): 

536 baselineDtype = np.dtype([('galid', int), 

537 ('raObserved', float), 

538 ('decObserved', float), 

539 ('ctotal_u', float), 

540 ('ctotal_g', float), 

541 ('ctotal_r', float), 

542 ('ctotal_i', float), 

543 ('ctotal_z', float)]) 

544 

545 obs_metadata_pointed = ObservationMetaData(mjd=50000.0, 

546 boundType='circle', 

547 pointingRA=0.0, pointingDec=0.0, 

548 boundLength=10.0) 

549 

550 baseline_cat = cartoonGalaxies(self.galaxy, obs_metadata=obs_metadata_pointed) 

551 with lsst.utils.tests.getTempFilePath('.txt') as baselineCatName: 

552 baseline_cat.write_catalog(baselineCatName) 

553 baselineData = np.genfromtxt(baselineCatName, dtype=baselineDtype, delimiter=',') 

554 self.assertGreater(len(baselineData), 0) 

555 

556 testDtype = np.dtype([('galid', int), 

557 ('raObserved', float), 

558 ('decObserved', float), 

559 ('ctotal_i', float), 

560 ('ctotal_g', float)]) 

561 

562 test_cat = cartoonGalaxiesIG(self.galaxy, obs_metadata=obs_metadata_pointed) 

563 with lsst.utils.tests.getTempFilePath('.txt') as testCatName: 

564 test_cat.write_catalog(testCatName) 

565 testData = np.genfromtxt(testCatName, dtype=testDtype, delimiter=',') 

566 self.assertGreater(len(testData), 0) 

567 

568 for b, t in zip(baselineData, testData): 

569 self.assertAlmostEqual(b['ctotal_i'], t['ctotal_i'], 10) 

570 self.assertAlmostEqual(b['ctotal_g'], t['ctotal_g'], 10) 

571 

572 def testPhotometricIndicesRaw(self): 

573 """ 

574 Use manMagCalc_list with specified indices on an Sed. Make sure 

575 that the appropriate magnitudes are or are not Nan 

576 """ 

577 starName = os.path.join(getPackageDir('sims_sed_library'), defaultSpecMap['km20_5750.fits_g40_5790']) 

578 starPhot = BandpassDict.loadTotalBandpassesFromFiles() 

579 testSed = Sed() 

580 testSed.readSED_flambda(starName) 

581 indices = [1, 3] 

582 mags = starPhot.magListForSed(testSed, indices=indices) 

583 np.testing.assert_equal(mags[0], np.NaN) 

584 self.assertFalse(np.isnan(mags[1]), msg='mags[1] is NaN; should not be') 

585 np.testing.assert_equal(mags[2], np.NaN) 

586 self.assertFalse(np.isnan(mags[3]), msg='mags[3] is NaN; should not be') 

587 np.testing.assert_equal(mags[4], np.NaN) 

588 np.testing.assert_equal(mags[5], np.NaN) 

589 self.assertEqual(len(mags), 6) 

590 

591 

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

593 pass 

594 

595if __name__ == "__main__": 595 ↛ 596line 595 didn't jump to line 596, because the condition on line 595 was never true

596 lsst.utils.tests.init() 

597 unittest.main()