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

from __future__ import division 

from datetime import datetime, timedelta 

import math 

 

import palpy 

 

__all__ = ["DateProfile"] 

 

class DateProfile(object): 

""" 

This class handles calculating the Modified Julian Date and the Local Sidereal Time for 

the internal timestamp and location coordinates. 

""" 

 

SECONDS_IN_HOUR = 60.0 * 60.0 

 

def __init__(self, timestamp, location): 

"""Initialize the class. 

 

Parameters 

---------- 

timestamp : float 

The UTC timestamp for a given date/time. 

location : lsst.ts.dateloc.ObservatoryLocation 

The location site information instance. 

""" 

self.location = location 

self.update(timestamp) 

 

def __call__(self, timestamp): 

"""Modified Julian Date and Local Sidereal Time from instance. 

 

Parameters 

---------- 

timestamp : float 

The UTC timestamp to get the MJD and LST for. 

 

Returns 

------- 

(float, float) 

A tuple of the Modified Julian Date and Local Sidereal Time (radians). 

""" 

self.update(timestamp) 

return (self.mjd, self.lst_rad) 

 

def __get_timestamp(self, dt): 

"""float: Return a timestamp from the datetime instance. 

""" 

return (dt - datetime(1970, 1, 1)).total_seconds() 

 

@property 

def lst_rad(self): 

"""float: Return the Local Sidereal Time (radians) for the internal timestamp. 

""" 

value = palpy.gmst(self.mjd) + self.location.longitude_rad 

if value < 0.: 

value += 2.0 * math.pi 

return value 

 

@property 

def mjd(self): 

"""float: Return the Modified Julian Date for the internal timestamp. 

""" 

mjd = palpy.caldj(self.current_dt.year, self.current_dt.month, self.current_dt.day) 

mjd += (self.current_dt.hour / 24.0) + (self.current_dt.minute / 1440.) + \ 

(self.current_dt.second / 86400.) 

return mjd 

 

def midnight_timestamp(self): 

"""float: Return the UTC timestamp of midnight for the current date. 

""" 

midnight_dt = datetime(self.current_dt.year, self.current_dt.month, self.current_dt.day) 

return self.__get_timestamp(midnight_dt) 

 

def next_midnight_timestamp(self): 

"""float: Return the UTC timestamp of midnight for the next day after current date. 

""" 

midnight_dt = datetime(self.current_dt.year, self.current_dt.month, self.current_dt.day) 

midnight_dt += timedelta(**{"days": 1}) 

return self.__get_timestamp(midnight_dt) 

 

def previous_midnight_timestamp(self): 

"""float: Return the UTC timestamp of midnight for the next day before current date. 

""" 

midnight_dt = datetime(self.current_dt.year, self.current_dt.month, self.current_dt.day) 

midnight_dt -= timedelta(**{"days": 1}) 

return self.__get_timestamp(midnight_dt) 

 

def update(self, timestamp): 

"""Change the internal timestamp to requested one. 

 

Parameters 

---------- 

timestamp : float 

The UTC timestamp to update the internal timestamp to. 

""" 

self.timestamp = timestamp 

self.current_dt = datetime.utcfromtimestamp(self.timestamp)