UserContributedScripts: generate24HourTBW.py

File generate24HourTBW.py, 1.0 KB (added by jayce, 4 years ago)

Script to generate a 24-hour TBW run with observations every 15 minutes.

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Script to generate a TBW SDF file that observes every 15 minutes for 24 hours.
6"""
7
8import os
9import sys
10from datetime import datetime, timedelta
11
12from lsl.common import sdf
13
14
15def main(args):
16        # Setup
17        date = args[0]
18        date = date.replace('-', '/')
19       
20        # Start and stop times for the run
21        tStart = datetime.strptime(date, '%Y/%m/%d')
22        tEnd = tStart + timedelta(days=1)
23       
24        # Create the SDF...
25        observer = sdf.Observer("TBW Observer", 99)
26        session = sdf.Session("24-hour TBW Session", 1, comments="Generated by generate24HourTBW.py on %s" % datetime.utcnow())
27        project = sdf.Project(observer, "24-hour TBW Capture Project", 1, [session,])
28       
29        # ... and the individual captures
30        tTBW = tStart
31        tIncrement = timedelta(seconds=15*60)
32        while tTBW < tEnd:
33                obs = sdf.TBW('TBW @ %s' % tTBW.strftime("%H:%M:%S"), 'All-Sky', tTBW.strftime("UTC %Y/%m/%d %H:%M:%S"), 12000000)
34                project.sessions[0].observations.append(obs)
35               
36                tTBW += tIncrement
37               
38        # Done
39        print project.render()
40
41
42if __name__ == "__main__":
43        main(sys.argv[1:])
44