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

import numpy as np 

from astropy.time import Time, TimeDelta 

import unittest 

import lsst.utils.tests 

from lsst.sims.downtimeModel import DowntimeModel, DowntimeModelConfig 

from lsst.sims.downtimeModel import ScheduledDowntimeData, UnscheduledDowntimeData 

 

class TestDowntimeModel(unittest.TestCase): 

def setUp(self): 

# Set config to known values. 

config = DowntimeModelConfig() 

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

config.efd_delta_time = 0 

config.target_columns = ['test_time'] 

self.config = config 

 

def test_configure(self): 

# Configure with defaults. 

downtimeModel = DowntimeModel() 

conf = DowntimeModelConfig() 

self.assertEqual(downtimeModel._config, conf) 

# Test specifying the config. 

downtimeModel = DowntimeModel(self.config) 

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

# Test specifying an incorrect config. 

self.assertRaises(RuntimeError, DowntimeModel, 0.8) 

 

def test_status(self): 

downtimeModel = DowntimeModel() 

confDict = downtimeModel.config_info() 

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

'target_columns'] 

for k in expected_keys: 

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

 

def test_efd_requirements(self): 

downtimeModel = DowntimeModel(self.config) 

cols = downtimeModel.efd_requirements[0] 

deltaT = downtimeModel.efd_requirements[1] 

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

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

 

def test_targetmap_requirements(self): 

downtimeModel = DowntimeModel(self.config) 

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

 

def test_call(self): 

# Check the calculation from fwhm_500 to fwhm_eff/fwhm_geom. 

# Use simple effective wavelengths and airmass values. 

downtimeModel = DowntimeModel(self.config) 

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

sched = ScheduledDowntimeData(t) 

sched.read_data() 

unsched = UnscheduledDowntimeData(t) 

unsched.make_data() 

efdData = {'unscheduled_downtimes': unsched(), 

'scheduled_downtimes': sched()} 

# Set time to within first scheduled downtime. 

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

targetDict = {'test_time': t_now} 

dt_status = downtimeModel(efdData, targetDict) 

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

# Check keys 

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

self.assertTrue(k in dt_status) 

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

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

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

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

 

 

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

pass 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

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

lsst.utils.tests.init() 

unittest.main()