-
Notifications
You must be signed in to change notification settings - Fork 2
/
formatSweepFile.py
54 lines (44 loc) · 1.34 KB
/
formatSweepFile.py
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
import numpy as np
import re
import csv
def dec_format(deg,m):
degnum=int(deg)
degnum=90-degnum
minnum=int(m)
if minnum!=0 and degnum>0:
degnum-=1
minnum=60-minnum
degstr=tp(str(degnum))+"d"+tp(str(minnum))+"m0.00s"
return(degstr)
def tp(s):
if len(s)==1:
s='0'+s
return s
def date_format(datestr):
m,d,y=datestr.split('-')
d=tp(d)
m=tp(m)
return('-'.join([y,m,d]))
def formatSweepFile(inputSweeps, startInt):
a = open(inputSweeps, 'r')
b = open('default_sweep.ini','w')
outputstr=''
index=startInt
with open(inputSweeps) as csvfile:
reader=csv.DictReader(csvfile)
for row in reader:
date=date_format(row['date'])+"T20:40:00.0"
startRA=tp(row['startRAh'])+'h'+tp(row['startRAm'])+'m'+'0.00s'
endRA=tp(row['endRAh'])+'h'+tp(row['endRAm'])+'m'+'0.00s'
startDec=dec_format(row['startDecd'],row['startDecm'])
endDec=dec_format(row['endDecd'],row['endDecm'])
name='Sweep'+row['name']
block_dict={'name':name,'startRA':startRA,'endRA':endRA,'startDec':startDec,'endDec':endDec,'date':date}
for k in block_dict:
outputstr+='\n'+str(index)+'\\'+k+'='+block_dict[k]
index+=1
headers='[General]\narrow_scale=1.5\nsweep_count=%d\nsweeps_version=2.0\nuse_decimal_degrees=false\nuse_semi_transparency=false\n\n[sweep]' %(index+1)
b.write(headers+outputstr)
a.close()
b.close()
formatSweepFile('sweep_data.csv', 0)