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

import unittest 

import matplotlib 

matplotlib.use("Agg") 

 

import lsst.sims.maf.metrics as metrics 

import lsst.sims.maf.slicers as slicers 

import lsst.sims.maf.stackers as stackers 

import lsst.sims.maf.maps as maps 

import lsst.sims.maf.metricBundles as metricBundles 

import lsst.sims.maf.db as db 

import glob 

import os 

import tempfile 

import shutil 

import lsst.utils.tests 

from lsst.utils import getPackageDir 

from lsst.sims.utils.CodeUtilities import sims_clean_up 

 

 

class TestMetricBundle(unittest.TestCase): 

 

@classmethod 

def tearDownClass(cls): 

sims_clean_up() 

 

def setUp(self): 

self.outDir = tempfile.mkdtemp(prefix='TMB') 

 

def testOut(self): 

""" 

Check that the metric bundle can generate the expected output 

""" 

nside = 8 

slicer = slicers.HealpixSlicer(nside=nside) 

metric = metrics.MeanMetric(col='airmass') 

sql = 'filter="r"' 

stacker1 = stackers.RandomDitherFieldPerVisitStacker() 

stacker2 = stackers.GalacticStacker() 

map1 = maps.GalCoordsMap() 

map2 = maps.StellarDensityMap() 

 

metricB = metricBundles.MetricBundle(metric, slicer, sql, stackerList=[stacker1, stacker2]) 

database = os.path.join(getPackageDir('sims_data'), 'OpSimData', 'astro-lsst-01_2014.db') 

 

opsdb = db.OpsimDatabaseV4(database=database) 

resultsDb = db.ResultsDb(outDir=self.outDir) 

 

bgroup = metricBundles.MetricBundleGroup({0: metricB}, opsdb, outDir=self.outDir, resultsDb=resultsDb) 

bgroup.runAll() 

bgroup.plotAll() 

bgroup.writeAll() 

 

opsdb.close() 

 

outThumbs = glob.glob(os.path.join(self.outDir, 'thumb*')) 

outNpz = glob.glob(os.path.join(self.outDir, '*.npz')) 

outPdf = glob.glob(os.path.join(self.outDir, '*.pdf')) 

 

# By default, make 3 plots for healpix 

assert(len(outThumbs) == 3) 

assert(len(outPdf) == 3) 

assert(len(outNpz) == 1) 

 

def tearDown(self): 

65 ↛ exitline 65 didn't return from function 'tearDown', because the condition on line 65 was never false if os.path.isdir(self.outDir): 

shutil.rmtree(self.outDir) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()