Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALBurst 2.0.7.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros Modules Pages
date.py
Go to the documentation of this file.
1# Copyright (C) 2006,2007,2009,2015-2018 Kipp Cannon
2#
3# This program is free software; you can redistribute it and/or modify it
4# under the terms of the GNU General Public License as published by the
5# Free Software Foundation; either version 2 of the License, or (at your
6# option) any later version.
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11# Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17
18#
19# =============================================================================
20#
21# Preamble
22#
23# =============================================================================
24#
25
26
27"""
28This module provides a few time-related utilities that have been used in
29burst searches in the past.
30"""
31
32
33import math
34
35
36import lal
37
38
39__author__ = "Kipp Cannon <kipp.cannon@ligo.org>"
40from .git_version import date as __date__
41from .git_version import version as __version__
42
43
44#
45# =============================================================================
46#
47# Function Wrappers
48#
49# =============================================================================
50#
51
52
53def XLALTimeDelayFromEarthCenter(pos, ra, dec, gps):
54 return lal.ArrivalTimeDiff(pos, (0.0, 0.0, 0.0), ra, dec, gps)
55
56
57#
58# =============================================================================
59#
60# Time Generators
61#
62# =============================================================================
63#
64
65
66def utc_midnight(gps):
67 """
68 Truncate a LIGOTimeGPS to UTC midnight.
69 """
70 # convert to UTC (as list so we can edit it)
71 tm = list(lal.GPSToUTC(int(gps)))
72
73 # truncate to midnight
74 tm[3] = 0 # hours
75 tm[4] = 0 # minutes
76 tm[5] = 0 # seconds
77
78 # convert back to LIGOTimeGPS
79 return lal.LIGOTimeGPS(lal.UTCToGPS(tuple(tm)))
80
81
82def UTCMidnights(start, end):
83 """
84 Iterator for generating LIGOTimeGPS objects for UTC midnights.
85 """
86 # 86402 == more seconds than there are in 1 day, but less than
87 # there are in 2 days. Can 1 day have more than 1 leap second? If
88 # so, this constant should be increased.
89 midnight = utc_midnight(start)
90 if midnight < start:
91 midnight = utc_midnight(midnight + 86402)
92 while midnight < end:
93 yield midnight
94 midnight = utc_midnight(midnight + 86402)
95
96
97def gmst_0h(gps):
98 """
99 Truncate a LIGOTimeGPS to Greenwich mean sidereal 0 rad.
100 """
101 gmst = lal.GreenwichMeanSiderealTime(gps)
102 residual = gmst % (2.0 * math.pi)
103 if residual:
104 gmst -= residual
105 return lal.GreenwichMeanSiderealTimeToGPS(gmst)
106
107
108def GMST_0hs(start, end):
109 """
110 Iterator for generating LIGOTimeGPS objects for Greenwich Mean
111 Sidereal 0h.
112 """
113 midnight = gmst_0h(start)
114 if midnight < start:
115 midnight = gmst_0h(midnight + 86402)
116 while midnight < end:
117 yield midnight
118 midnight = gmst_0h(midnight + 86402)
def GMST_0hs(start, end)
Iterator for generating LIGOTimeGPS objects for Greenwich Mean Sidereal 0h.
Definition: date.py:112
def UTCMidnights(start, end)
Iterator for generating LIGOTimeGPS objects for UTC midnights.
Definition: date.py:85
def XLALTimeDelayFromEarthCenter(pos, ra, dec, gps)
Definition: date.py:53
def utc_midnight(gps)
Truncate a LIGOTimeGPS to UTC midnight.
Definition: date.py:69
def gmst_0h(gps)
Truncate a LIGOTimeGPS to Greenwich mean sidereal 0 rad.
Definition: date.py:100