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

from builtins import zip 

import matplotlib 

matplotlib.use("Agg") 

import numpy as np 

import healpy as hp 

import unittest 

import lsst.sims.maf.metrics as metrics 

import lsst.utils.tests 

 

 

class TestSummaryMetrics(unittest.TestCase): 

 

def testTableFractionMetric(self): 

"""Test the table summary metric """ 

metricdata1 = np.arange(0, 1.5, .02) 

metricdata = np.array(list(zip(metricdata1)), dtype=[('testdata', 'float')]) 

for nbins in [10, 20, 5]: 

metric = metrics.TableFractionMetric('testdata', nbins=nbins) 

table = metric.run(metricdata) 

self.assertEqual(len(table), nbins+3) 

self.assertEqual(table['value'][0], np.size(np.where(metricdata1 == 0)[0])) 

self.assertEqual(table['value'][-1], np.size(np.where(metricdata1 > 1)[0])) 

self.assertEqual(table['value'][-2], np.size(np.where(metricdata1 == 1)[0])) 

self.assertEqual(table['value'].sum(), metricdata1.size) 

 

def testIdentityMetric(self): 

"""Test identity metric.""" 

dv = np.arange(0, 10, .5) 

dv = np.array(list(zip(dv)), dtype=[('testdata', 'float')]) 

testmetric = metrics.IdentityMetric('testdata') 

np.testing.assert_equal(testmetric.run(dv), dv['testdata']) 

 

def testfONv(self): 

""" 

Test the fONv metric. 

""" 

nside = 128 

metric = metrics.fONv(col='ack', nside=nside, Nvisit=825, Asky=18000.) 

npix = hp.nside2npix(nside) 

names = ['blah'] 

types = [float] 

data = np.zeros(npix, dtype=list(zip(names, types))) 

# Set all the pixels to have 826 counts 

data['blah'] = data['blah']+826 

slicePoint = {'sid': 0} 

result1 = metric.run(data, slicePoint) 

deginsph = 129600./np.pi 

np.testing.assert_almost_equal(result1*18000., deginsph) 

data['blah'][:data.size//2] = 0 

result2 = metric.run(data, slicePoint) 

np.testing.assert_almost_equal(result2*18000., deginsph/2.) 

 

def testfOArea(self): 

"""Test fOArea metric.""" 

nside = 128 

metric = metrics.fOArea(col='ack', nside=nside, Nvisit=825, Asky=18000.) 

npix = hp.nside2npix(nside) 

names = ['blah'] 

types = [float] 

data = np.zeros(npix, dtype=list(zip(names, types))) 

# Set all the pixels to have 826 counts 

data['blah'] = data['blah']+826 

slicePoint = {'sid': 0} 

result1 = metric.run(data, slicePoint) 

np.testing.assert_almost_equal(result1*825, 826) 

data['blah'][:data.size//2] = 0 

result2 = metric.run(data, slicePoint) 

 

def testNormalizeMetric(self): 

"""Test normalize metric.""" 

data = np.ones(10, dtype=list(zip(['testcol'], ['float']))) 

metric = metrics.NormalizeMetric(col='testcol', normVal=5.5) 

result = metric.run(data) 

np.testing.assert_equal(result, np.ones(10, float)/5.5) 

 

def testZeropointMetric(self): 

"""Test zeropoint metric.""" 

data = np.ones(10, dtype=list(zip(['testcol'], ['float']))) 

metric = metrics.ZeropointMetric(col='testcol', zp=5.5) 

result = metric.run(data) 

np.testing.assert_equal(result, np.ones(10, float)+5.5) 

 

def testTotalPowerMetric(self): 

nside = 128 

data = np.ones(12*nside**2, dtype=list(zip(['testcol'], ['float']))) 

metric = metrics.TotalPowerMetric(col='testcol') 

result = metric.run(data) 

np.testing.assert_equal(result, 0.0) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()