-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhops4_visplot_example.py.in
More file actions
116 lines (99 loc) · 4.83 KB
/
Copy pathhops4_visplot_example.py.in
File metadata and controls
116 lines (99 loc) · 4.83 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
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
#!@PY_EXE@
#
# demo for HOPS4 fringe data retrieval using python interface
# which shows how to access the corrected visibility data
# in a fringe file (summed along the time axis), and plot the amp/phase
# on a per-channel basis
#
import pyMHO_Containers
from hops_visualization import fourfit_plot
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
import argparse
def plot_data(file_data):
if file_data != None:
n_obj = file_data.get_nobjects()
obj_info = file_data.get_object_id_list()
print("object info is:", obj_info)
uuid = ""
for object_record in obj_info:
if "shortname" in object_record:
sname = object_record["shortname"]
#plot data is stored in 'tags' object
if sname == "vis":
print("located a vis object")
uuid = object_record["object_uuid"]
if uuid != "":
table_data = file_data.get_object(object_record["object_uuid"] )
if table_data != None:
class_name = table_data.get_classname()
print("retrieved table object: ", uuid, "of type: \n", class_name)
rank = table_data.get_rank()
print("table data object array has rank: ", rank)
table_meta = table_data.get_metadata()
print("table meta data: \n", table_meta)
table_data_arr = table_data.get_numpy_array()
print("table data array has dtype: ", table_data_arr.dtype)
print("table data array has shape: ", table_data_arr.shape)
print("table data array has strides: ", table_data_arr.strides)
for i in range(0,rank):
dim = table_data.get_dimension(i)
print("dimension: ", i, " has size: ", dim)
axis = table_data.get_axis(i)
print("coordinate axis: ", i, " = ", axis)
axis_meta = table_data.get_axis_metadata(i)
print("axis meta data: \n", axis_meta)
#loop over the channels (dim=1)
for ch in range(0, table_data.get_dimension(1) ):
channel_sky_freq = table_data.get_axis(1)[ch]
subview = table_data_arr[0, ch, 0, :]
#print("subview = ", subview)
plt.plot(table_data.get_axis(3), np.absolute(subview), marker='o', linestyle='-', label='amp')
plt.plot(table_data.get_axis(3), np.angle(subview, deg=True), marker='*', linestyle='--', label='phase')
plt.title("channel freq: " + str(channel_sky_freq) + " (MHz)")
plt.xlabel("sub-channel freq (MHz)")
legend = plt.legend(loc = 4, fontsize = 'small', fancybox = True)
plt.show()
def plot_fringe_file(scan_store, name):
scan_store.load_fringe(name)
file_data = scan_store.get_fringe_data(name)
plot_data(file_data)
def main():
parser = argparse.ArgumentParser(
prog='hops4_visplot_example.py', \
description='''Example utility demo on how extract reduced
cross-power data from hops4 fringe file and display it. For
this example, the fringe file must be generated by
fourfit4 called with the "-X 2" option. ''' \
)
parser.add_argument("filename", type=str, default="", help='the fringe file to be opened')
args = parser.parse_args()
ffile = os.path.abspath(args.filename)
#figure out the corresponding scan directory
scan_dir, basename = os.path.split(ffile);
print("Exploring the directory: ", scan_dir)
scan_store = pyMHO_Containers.MHO_PyScanStoreInterface()
scan_store.set_directory(scan_dir)
scan_store.initialize()
if scan_store.is_valid():
stations = scan_store.get_station_list()
baselines = scan_store.get_baseline_list()
fringes = scan_store.get_fringe_list()
print("The number of station files = ", len(stations))
print("The number of baseline files = ", len(baselines))
print("The number of fringe files = ", len(fringes))
for fr in fringes:
if fr == basename:
plot_fringe_file(scan_store, basename)
return 0
else:
print("The directory", scan_dir, "does not appear to be a valid HOPS4 scan directory")
return 1
if __name__ == '__main__':
main()
sys.exit(0)
#
# eof
#