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

1import numpy as np 

2from astropy.time import Time, TimeDelta 

3import unittest 

4import lsst.utils.tests 

5from lsst.sims.downtimeModel import DowntimeModel, DowntimeModelConfig 

6from lsst.sims.downtimeModel import ScheduledDowntimeData, UnscheduledDowntimeData 

7 

8class TestDowntimeModel(unittest.TestCase): 

9 def setUp(self): 

10 # Set config to known values. 

11 config = DowntimeModelConfig() 

12 config.efd_columns = ['scheduled_downtimes', 'unscheduled_downtimes'] 

13 config.efd_delta_time = 0 

14 config.target_columns = ['test_time'] 

15 self.config = config 

16 

17 def test_configure(self): 

18 # Configure with defaults. 

19 downtimeModel = DowntimeModel() 

20 conf = DowntimeModelConfig() 

21 self.assertEqual(downtimeModel._config, conf) 

22 # Test specifying the config. 

23 downtimeModel = DowntimeModel(self.config) 

24 self.assertEqual(downtimeModel._config, self.config) 

25 # Test specifying an incorrect config. 

26 self.assertRaises(RuntimeError, DowntimeModel, 0.8) 

27 

28 def test_status(self): 

29 downtimeModel = DowntimeModel() 

30 confDict = downtimeModel.config_info() 

31 expected_keys = ['DowntimeModel_version', 'DowntimeModel_sha', 'efd_columns', 'efd_delta_time', 

32 'target_columns'] 

33 for k in expected_keys: 

34 self.assertTrue(k in confDict.keys()) 

35 

36 def test_efd_requirements(self): 

37 downtimeModel = DowntimeModel(self.config) 

38 cols = downtimeModel.efd_requirements[0] 

39 deltaT = downtimeModel.efd_requirements[1] 

40 self.assertEqual(self.config.efd_columns, cols) 

41 self.assertEqual(self.config.efd_delta_time, deltaT) 

42 

43 def test_targetmap_requirements(self): 

44 downtimeModel = DowntimeModel(self.config) 

45 self.assertEqual(downtimeModel.target_requirements, self.config.target_columns) 

46 

47 def test_call(self): 

48 # Check the calculation from fwhm_500 to fwhm_eff/fwhm_geom. 

49 # Use simple effective wavelengths and airmass values. 

50 downtimeModel = DowntimeModel(self.config) 

51 t = Time('2022-10-01') 

52 sched = ScheduledDowntimeData(t) 

53 sched.read_data() 

54 unsched = UnscheduledDowntimeData(t) 

55 unsched.make_data() 

56 efdData = {'unscheduled_downtimes': unsched(), 

57 'scheduled_downtimes': sched()} 

58 # Set time to within first scheduled downtime. 

59 t_now = sched.downtime[0]['start'] + TimeDelta(0.5, format='jd') 

60 targetDict = {'test_time': t_now} 

61 dt_status = downtimeModel(efdData, targetDict) 

62 # Expect return dict of : {'status': status, 'end': end_down, 'next': next_sched['start']} 

63 # Check keys 

64 for k in ('status', 'end', 'next'): 

65 self.assertTrue(k in dt_status) 

66 # downtime status is "True" if system is down. 

67 self.assertEqual(True, dt_status['status']) 

68 self.assertEqual(dt_status['end'], sched.downtime[0]['end']) 

69 self.assertEqual(dt_status['next'], sched.downtime[1]['start']) 

70 

71 

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

73 pass 

74 

75def setup_module(module): 

76 lsst.utils.tests.init() 

77 

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

79 lsst.utils.tests.init() 

80 unittest.main()