-
Notifications
You must be signed in to change notification settings - Fork 6
/
checkvis.py
130 lines (109 loc) · 3.84 KB
/
checkvis.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
2015 March 24
Shane Bussmann
Compare simulated visibilities from my implementation of miriad's uvmodel
routine and to miriad's implementation. Also plot the difference. Do this for
the real and imaginary components as well as the weights. And possibly the u,
v, and w values as well.
"""
import uvutil
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from pylab import savefig
from subprocess import call
import uvmodel
import os
def iterPlot(simvis, nfigures, color, label):
"""
Plot simulated visibilities, weights, and uvw values vs. entry number.
"""
for i in range(nfigures):
plt.figure(i)
plt.plot(simvis[i, :], ',', color=color, label=label)
def rollUp(visfile):
u, v, w = uvutil.uvload(visfile)
data, weight = uvutil.visload(visfile)
real = np.real(data)
imag = np.imag(data)
nvis = u.size
rolled = np.zeros((6, nvis))
rolled[0, :] = u.flatten()
rolled[1, :] = v.flatten()
rolled[2, :] = w.flatten()
rolled[3, :] = real.flatten()
rolled[4, :] = imag.flatten()
rolled[5, :] = weight.flatten()
return rolled
def savePlots(names, nfigures, colors):
for i in range(nfigures):
name = names[i]
plt.figure(i)
plt.ylabel(name)
plt.xlabel('Observation Number')
plt.legend()
leg = plt.legend(loc = 'best')
for i, text in enumerate(leg.get_texts()):
color = colors[i]
plt.setp(text, color = color)
plt.tight_layout()
savefig('viscompare_' + name + '.pdf')
print("Finished saving " + name + " figure!")
def iterFig(uvmcmcfitFile, miriadFile):
uvmcmcfit = rollUp(uvmcmcfitFile)
miriad = rollUp(miriadFile)
#miriad[5, :] = miriad[5, :] * 2
difference = uvmcmcfit - miriad
nfigures = uvmcmcfit[:, 0].size
plt.ioff()
iterPlot(uvmcmcfit, nfigures, 'red', 'uvmcmcfit')
print("Finished plotting uvmcmcfit data!")
iterPlot(miriad, nfigures, 'blue', 'miriad')
print("Finished plotting miriad data!")
iterPlot(difference, nfigures, 'black', 'difference')
print("Finished plotting uvmcmcfit - miriad data!")
names = ['u', 'v', 'w', 'real', 'imaginary', 'weights']
colors = ['red', 'blue', 'black']
savePlots(names, nfigures, colors)
def miriadVis(model, data, simfile):
"""
Use miriad to make a simulated visibility dataset given a model and data.
"""
# first turn the model image into miriad format
try:
oldbase_model = os.path.splitext(model)[0]
modelmiriad = oldbase_model + '.miriad'
cmd = 'rm -rf ' + modelmiriad
call(cmd, shell=True)
except:
print("Uh oh, couldn't remove the existing file.")
try:
cmd = 'fits op=xyin in=' + model + ' out=' + modelmiriad
call(cmd, shell=True)
except:
print("Uh oh, couldn't make the miriad model image.")
# next, turn the observed visibilities into miriad format
oldbase_data = os.path.splitext(data)[0]
datamiriad = oldbase_data + '.miriad'
cmd = 'rm -rf ' + datamiriad
call(cmd, shell=True)
cmd = 'fits op=uvin in=' + data + ' out=' + datamiriad
call(cmd, shell=True)
# next, make the simulated visibilities
cmd = 'rm -rf ' + simfile
call(cmd, shell=True)
cmd = 'uvmodel options=replace model=' + modelmiriad + ' vis=' + \
datamiriad + ' out=' + simfile
call(cmd, shell=True)
# and convert the simulated visibilities to uvfits format
oldbase_sim = os.path.splitext(simfile)[0]
simfilefits = oldbase_sim + '.uvfits'
cmd = 'rm -rf ' + simfilefits
call(cmd, shell=True)
cmd = 'fits op=uvout in=' + simfile + ' out=' + simfilefits
call(cmd, shell=True)
def uvmcmcfitVis(model, data, simfile):
#cmd = 'rm -rf ' + simfile
#call(cmd, shell=True)
uvmodel.replace(model, data, simfile, miriad=True)