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 print_function 

2from builtins import next 

3import unittest 

4import numpy 

5import lsst 

6import lsst.utils.tests 

7from lsst.sims.catalogs.db import CatalogDBObject 

8from lsst.sims.utils import ObservationMetaData 

9from lsst.sims.utils import haversine 

10 

11# The following is to get the object ids in the registry 

12import lsst.sims.catUtils.baseCatalogModels as bcm 

13 

14_testSpatialConstraints_is_connected = True 

15 

16try: 

17 _test_db = bcm.GalaxyObj() 

18except: 

19 _testSpatialConstraints_is_connected = False 

20 

21 

22def setup_module(module): 

23 lsst.utils.tests.init() 

24 

25 

26class testCatalogBounds(unittest.TestCase): 

27 #@unittest.skipIf(not _testSpatialConstraints_is_connected, 

28 # "We are not connnected to fatboy") 

29 @unittest.skip('will fail until we have restored SSO tables on fatboy') 

30 def testCircleBounds(self): 

31 """Test Sql Server circular search region. 

32 exepectedFailure used despite expectation of success 

33 because the test depends on a network connection. 

34 """ 

35 column_outputs = ['raJ2000', 'decJ2000'] 

36 for objname, objcls in CatalogDBObject.registry.items(): 

37 if (not objcls.doRunTest or 

38 (objcls.testObservationMetaData is None) or 

39 (objcls.testObservationMetaData.bounds is None) or 

40 (objcls.testObservationMetaData.bounds.boundType != 'circle')): 

41 

42 continue 

43 

44 print("Running tests for", objname) 

45 obs_metadata = objcls.testObservationMetaData 

46 dbobj = objcls(verbose=False) 

47 result = dbobj.query_columns(column_outputs, obs_metadata=obs_metadata) 

48 

49 # testObservationMetadata gives few enough results for one chunk 

50 try: 

51 result = next(result) 

52 except StopIteration: 

53 raise RuntimeError("No results for %s."%(objname)) 

54 

55 # confirm radius > distance from all points to center 

56 self.assertGreater(obs_metadata.bounds.radius + 1.e-4, 

57 max(haversine(numpy.radians(obs_metadata.pointingRA), 

58 numpy.radians(obs_metadata.pointingDec), 

59 result['raJ2000'], result['decJ2000']))) 

60 

61 #@unittest.skipIf(not _testSpatialConstraints_is_connected, 

62 # "We are not connected to fatboy") 

63 @unittest.skip('will fail until we have restored SSO tables on fatboy') 

64 def testBoxBounds(self): 

65 """Test Sql Server rectangular search region (ra/dec cuts). 

66 exepectedFailure used despite expectation of success 

67 because test depends on a network connection. 

68 """ 

69 column_outputs = ['raJ2000', 'decJ2000'] 

70 for objname, objcls in CatalogDBObject.registry.items(): 

71 if (not objcls.doRunTest or 

72 (objcls.testObservationMetaData is None) or 

73 (objcls.testObservationMetaData.bounds is None) or 

74 (objcls.testObservationMetaData.bounds.boundType != 'circle')): 

75 

76 continue 

77 

78 print("Running tests for", objname) 

79 circ_bounds = objcls.testObservationMetaData.bounds 

80 length = numpy.degrees(circ_bounds.radius) 

81 raCenter = numpy.degrees(circ_bounds.RA)+length 

82 decCenter = numpy.degrees(circ_bounds.DEC)+length 

83 obs_metadata = ObservationMetaData(boundType='box', 

84 pointingRA=raCenter, 

85 pointingDec=decCenter, 

86 boundLength=length, 

87 mjd=51000., bandpassName='i') 

88 dbobj = objcls(verbose=False) 

89 result = dbobj.query_columns(column_outputs, obs_metadata=obs_metadata) 

90 # testObservationMetadata gives few enough results for one chunk 

91 try: 

92 result = next(result) 

93 except StopIteration: 

94 raise RuntimeError("No results for %s."%(objname)) 

95 

96 self.assertLess(max(result['raJ2000']), numpy.radians(raCenter+length)) 

97 self.assertGreater(min(result['raJ2000']), numpy.radians(raCenter-length)) 

98 

99 self.assertLess(max(result['decJ2000']), numpy.radians(decCenter+length)) 

100 self.assertGreater(max(result['decJ2000']), numpy.radians(decCenter-length)) 

101 

102 

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

104 pass 

105 

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

107 lsst.utils.tests.init() 

108 unittest.main()