-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_delays.py
More file actions
executable file
·91 lines (71 loc) · 2.64 KB
/
fix_delays.py
File metadata and controls
executable file
·91 lines (71 loc) · 2.64 KB
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
#!/usr/bin/env python
# Copyright (C) 2017 by Sarah Buchner
# Licensed under the Academic Free License version 3.0
# This program comes with ABSOLUTELY NO WARRANTY.
# You are free to modify and redistribute this code as long
# as you do not remove the above attribution and reasonably
# inform recipients that you have modified the original work.
import numpy as np
import os
import sys
import glob
import argparse
import subprocess
import csv
# initialize parameters
parser = argparse.ArgumentParser(description='psradd .ar sub-ints to creates .tot file for observation')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='verbose mode')
parser.add_argument('-o', '--output', dest='output', metavar='output_dir', default='.', help='output directory')
parser.add_argument('-t', '--tim', dest='tim')
parser.add_argument('-d', '--delay', dest='delay')
parser.add_argument('-c', '--cable',dest='cable',action='store_true',help='correct for cable length')
parser.add_argument('-a','--add',dest='add',metavar='add',type=float,help='additional delay')
args = parser.parse_args()
if args.cable:
print "include cable"
if args.add:
print "additional delay %.2f" %(args.add)
def readDelaysFile(file):
result = {}
with open(file, 'r') as f:
line = csv.DictReader(f, delimiter=';')
for d in line:
result.setdefault(d['name'], []).append((float(d['delay']), float(d['HDel']), float(d['VDel']), int(d['NAnts'])))
return result
result=readDelaysFile(args.delay)
add=np.double(args.add)
toa=open(args.tim,'r')
toa.readline()
new=open(args.output,'w')
new.write('FORMAT 1\n')
for line in toa:
a=line.split(' ')[:3]
b=line.split(' ')[3:]
fl=" ".join(b).replace('\n','')
file=a[0]
freq=a[1]
ext=file.split('.')[-1]
name=file.replace('.'+ext,'')
mjd=np.double(a[2])
try:
max_delay=np.double(result[name][0][0])
extra_delay=max_delay*1.01
cable=np.double(result[name][0][1])/(3E8*0.7)*1E6
print "max_delay %.2f %.2f" %(max_delay,cable)
nant=int(result[name][0][3])
delaytot = extra_delay
if (args.cable):
print "include cable %.2f" %(cable)
delaytot = delaytot-cable
print delaytot
if (args.add > 0.0):
print "delaytot"
delaytot = delaytot-add
print delaytot
delaytot_mjd=np.double(delaytot*1E-6/(24*3600))
print "delay = %.2f usec %.12f %.12f days" %(delaytot,mjd-delaytot_mjd,mjd)
new.write("%s %s %.20lgi %s -nant %d \n" %(file,freq,mjd-delaytot_mjd,fl,nant))
except:
print "error on file" %(file)
continue
new.close()