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

from builtins import zip 

from builtins import range 

import os 

import unittest 

import lsst.utils.tests 

import numpy as np 

import tempfile 

 

from lsst.sims.utils.CodeUtilities import sims_clean_up 

from lsst.sims.utils import ObservationMetaData 

 

from lsst.sims.photUtils import CosmologyObject 

 

from lsst.sims.catalogs.utils import myTestGals, makeGalTestDB 

 

from lsst.sims.catUtils.utils import testGalaxies 

from lsst.sims.catUtils.mixins import CosmologyMixin 

 

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

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class cosmologicalGalaxyCatalog(testGalaxies, CosmologyMixin): 

catalog_type = __file__ + 'cosmo_galaxy_catalog' 

column_outputs = ['galid', 'lsst_u', 'lsst_g', 'lsst_r', 'lsst_i', 'lsst_z', 'lsst_y', 

'uBulge', 'gBulge', 'rBulge', 'iBulge', 'zBulge', 'yBulge', 

'uDisk', 'gDisk', 'rDisk', 'iDisk', 'zDisk', 'yDisk', 

'uAgn', 'gAgn', 'rAgn', 'iAgn', 'zAgn', 'yAgn', 

'redshift', 'cosmologicalDistanceModulus'] 

 

 

class absoluteGalaxyCatalog(testGalaxies): 

catalog_type = __file__ + 'abs_galaxy_catalog' 

column_outputs = ['galid', 'lsst_u', 'lsst_g', 'lsst_r', 'lsst_i', 'lsst_z', 'lsst_y', 

'uBulge', 'gBulge', 'rBulge', 'iBulge', 'zBulge', 'yBulge', 

'uDisk', 'gDisk', 'rDisk', 'iDisk', 'zDisk', 'yDisk', 

'uAgn', 'gAgn', 'rAgn', 'iAgn', 'zAgn', 'yAgn', 

'redshift'] 

 

def get_cosmologicalDistanceModulus(self): 

""" 

Must set this to zero rather than `None` so that PhotometryGalaxies 

does not apply cosmological dimming 

""" 

return np.zeros(len(self.column_by_name('galid'))) 

 

 

class CosmologyMixinUnitTest(unittest.TestCase): 

""" 

This class will test to make sure that our example CosmologyMixin 

(defined in lsst/sims/photUtils/examples/CosmologyMixin.py) 

can produce a catalog 

""" 

 

@classmethod 

def setUpClass(cls): 

cls.dbName = tempfile.mktemp(prefix='cosmologyTestDB-', suffix=".db", dir=ROOT) 

cls.dbSize = 100 

if os.path.exists(cls.dbName): 

os.unlink(cls.dbName) 

makeGalTestDB(size=cls.dbSize, seedVal=1, filename=cls.dbName) 

 

@classmethod 

def tearDownClass(cls): 

sims_clean_up() 

if os.path.exists(cls.dbName): 

os.unlink(cls.dbName) 

 

del cls.dbName 

del cls.dbSize 

 

def setUp(self): 

self.obs = ObservationMetaData(mjd=59580.0) 

 

def testCosmologyCatalog(self): 

""" 

Does a catalog get written? 

""" 

dbObj = myTestGals(database=self.dbName) 

cat = cosmologicalGalaxyCatalog(dbObj, obs_metadata=self.obs) 

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

cat.write_catalog(catName) 

 

def testCatalogDistanceModulus(self): 

""" 

Does cosmologicalDistanceModulus get properly applied 

""" 

dbObj = myTestGals(database=self.dbName) 

cosmoCat = cosmologicalGalaxyCatalog(dbObj, obs_metadata=self.obs) 

controlCat = absoluteGalaxyCatalog(dbObj, obs_metadata=self.obs) 

cosmoIter = cosmoCat.iter_catalog(chunk_size=self.dbSize) 

controlIter = controlCat.iter_catalog(chunk_size=self.dbSize) 

 

cosmology = CosmologyObject() 

 

for (cosmoRow, controlRow) in zip(cosmoIter, controlIter): 

modulus = cosmology.distanceModulus(controlRow[25]) 

self.assertEqual(cosmoRow[0], controlRow[0]) 

self.assertEqual(cosmoRow[25], controlRow[25]) 

self.assertEqual(cosmoRow[26], modulus) 

for i in range(1, 25): 

self.assertAlmostEqual(cosmoRow[i], controlRow[i] + modulus, 6) 

 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()