-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
652 lines (485 loc) · 24.1 KB
/
util.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#useful functions
import os
from pyuvdata import UVData
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.colors as colors
import matplotlib.gridspec as gridspec
import numpy.ma as ma
#plots all auto waterfall+line plots for the loaded file
def allauto_waterfall_lineplot (uv, file_number ,colorbar_min, colorbar_max, save=False, boundaries = False):
for ant in uv.antenna_numbers:
freq = uv.freq_array[0]*1e-6
fig = plt.figure(figsize=(20,20))
#can use gridspec instead of saying add_subplot(1,2,1) etc
gs = gridspec.GridSpec(2, 1, height_ratios=[2,1])
#creates waterfall subplot
waterfall= plt.subplot(gs[0])
#create time axis
jd_ax=plt.gca()
#there are a lot of redundancies in time_array, so to make sure that we have a list
#of unique times to work with, we start off by making a new array... not doing this will
#make things get messy. gave me a blank plot at first with a bunch of lines on the side
#before i did this.
times= np.unique(uv.time_array)
#create the plot. uv.get_data will get data from specified antennas
#colors.LogNorm() puts colors on log scale
im = plt.imshow(np.abs(uv.get_data((ant,ant, uv.polarization_array[0]))),norm=colors.LogNorm(),
vmin=colorbar_min, vmax=colorbar_max, aspect='auto')
waterfall.set_title(str(file_number)+'Waterfall+Lineplot, Antenna '+str(ant))
# get an array of frequencies in MHz
freqs = uv.freq_array[0, :] / 1000000
xticks = np.arange(0, len(freqs), 120)
plt.xticks(xticks, labels =np.around(freqs[xticks],2))
jd_ax.set_ylabel('JD Time (days)')
#makes equally spaced ticks in increments of 100. since we are assuming time is pretty
#continuous, this will cover all times pretty well if we go from 0 to the length
jd_yticks = np.arange(0,len(times),100)
#set_yticks takes a List of y-axis tick locations. its purpose is to set tick locations
jd_ax.set_yticks(jd_yticks)
#this function actually determines what the tickmarks will say.
jd_ax.set_yticklabels(np.around(times[jd_yticks],2))
#create second axis
lst_ax = jd_ax.twinx()
lst_ax.set_ylabel('LST Time (hour of the day)')
#lst_array is in radians, and we want it in *hours*.. rad*180/pi = degrees
#one hour= 15 degrees
lst_hours = (uv.lst_array*(180/np.pi))/(15)
#creates array of unique lsts
lsts= lst_hours.reshape(uv.Ntimes,uv.Nbls)
lsts = lsts[:,0]
#set the ticks of the lst axis to match the lst_array in hours
lst_yticks = np.arange(0,len(lsts),100)
lst_ax.set_yticks(lst_yticks)
lst_ax.set_yticklabels(np.around(lsts[lst_yticks],2))
#gives the lst_axis information about the jd_axis. stuff like the y-dimension of the data.
#gets the axes to line up properly. will make it so that the tick-marks lining up, and the
#zeroth entry of times[jd_yticks] lining up with the zeroth entry of lsts[lst_yticks]
lst_ax.set_ylim(jd_ax.get_ylim())
#makes it so that the second axis does not alter the structure of the figure
jd_ax.autoscale(False)
lst_ax.autoscale(False)
#creates line subplot and positions it according to gs[1]
line= plt.subplot(gs[1])
#drawing faint grey lines at boundaries
if boundaries == True:
channel_boundaries = [192,384,576,768,960,1152,1344]
freq_boundaries = []
for channel in channel_boundaries:
freq_boundary = freq[channel]
freq_boundaries.append(freq_boundary)
plt.axvline(freq_boundaries[0],0,1, color = '0.8')
plt.axvline(freq_boundaries[1],0,1, color = '0.8')
plt.axvline(freq_boundaries[2],0,1, color = '0.8')
plt.axvline(freq_boundaries[3],0,1, color = '0.8')
plt.axvline(freq_boundaries[4],0,1, color = '0.8')
plt.axvline(freq_boundaries[5],0,1, color = '0.8')
plt.axvline(freq_boundaries[6],0,1, color = '0.8')
averaged_data= np.abs(np.average(uv.get_data((ant,ant, uv.polarization_array[0])),0))
plt.plot(freq,averaged_data)
line.set_yscale('log')
line.set_xlabel('Frequency (MHz)')
line.set_ylabel('Power')
#sets the range of the graph to be the same range as waterfall plot
line.set_xlim(freq[0],freq[-1])
#makes waterfall x ticks invisible
plt.setp(waterfall.get_xticklabels(), visible=False)
#brings plots together
plt.subplots_adjust(hspace=.0)
#pad moves colorbar farther from plot
cbar = plt.colorbar(im, pad= 0.15, orientation = 'horizontal')
cbar.set_label('Power -->')
if save == False:
print('Fig not saved to file')
elif save == True:
plt.savefig('/lustre/aoc/projects/hera/amyers/gitrepos/monsterDetection/waterfalls/'+
str(file_number)+'_WF_LP_ant'+str(ant))
print('Fig saved to file')
plt.show()
plt.close()
return;
#plots a single waterfall+line plot for the given antenna and colorbar lims
def auto_waterfall_lineplot (uv, file_number, ant,colorbar_min, colorbar_max, save=False, boundaries = False):
freq = uv.freq_array[0]*1e-6
fig = plt.figure(figsize=(20,20))
#can use gridspec instead of saying add_subplot(1,2,1) etc
gs = gridspec.GridSpec(2, 1, height_ratios=[2,1])
#creates waterfall subplot
waterfall= plt.subplot(gs[0])
#create time axis
jd_ax=plt.gca()
#there are a lot of redundancies in time_array, so to make sure that we have a list
#of unique times to work with, we start off by making a new array... not doing this will
#make things get messy. gave me a blank plot at first with a bunch of lines on the side
#before i did this.
times= np.unique(uv.time_array)
#create the plot. uv.get_data will get data from specified antennas
#colors.LogNorm() puts colors on log scale
im = plt.imshow(np.abs(uv.get_data((ant,ant, uv.polarization_array[0]))),norm=colors.LogNorm(),
vmin=colorbar_min, vmax=colorbar_max, aspect='auto')
waterfall.set_title(str(file_number)+' Waterfall+Lineplot, Antenna '+str(ant))
# get an array of frequencies in MHz
freqs = uv.freq_array[0, :] / 1000000
xticks = np.arange(0, len(freqs), 120)
plt.xticks(xticks, labels =np.around(freqs[xticks],2))
jd_ax.set_ylabel('JD Time (days)')
#makes equally spaced ticks in increments of 100. since we are assuming time is pretty
#continuous, this will cover all times pretty well if we go from 0 to the length
jd_yticks = np.arange(0,len(times),100)
#set_yticks takes a List of y-axis tick locations. its purpose is to set tick locations
jd_ax.set_yticks(jd_yticks)
#this function actually determines what the tickmarks will say.
jd_ax.set_yticklabels(np.around(times[jd_yticks],2))
#create second axis
lst_ax = jd_ax.twinx()
lst_ax.set_ylabel('LST Time (hour of the day)')
#lst_array is in radians, and we want it in *hours*.. rad*180/pi = degrees
#one hour= 15 degrees
lst_hours = (uv.lst_array*(180/np.pi))/(15)
#creates array of unique lsts
lsts= lst_hours.reshape(uv.Ntimes,uv.Nbls)
lsts = lsts[:,0]
#set the ticks of the lst axis to match the lst_array in hours
lst_yticks = np.arange(0,len(lsts),100)
lst_ax.set_yticks(lst_yticks)
lst_ax.set_yticklabels(np.around(lsts[lst_yticks],2))
#gives the lst_axis information about the jd_axis. stuff like the y-dimension of the data.
#gets the axes to line up properly. will make it so that the tick-marks lining up, and the
#zeroth entry of times[jd_yticks] lining up with the zeroth entry of lsts[lst_yticks]
lst_ax.set_ylim(jd_ax.get_ylim())
#makes it so that the second axis does not alter the structure of the figure
jd_ax.autoscale(False)
lst_ax.autoscale(False)
#creates line subplot and positions it according to gs[1]
line= plt.subplot(gs[1])
#drawing faint grey lines at boundaries
if boundaries == True:
channel_boundaries = [192,384,576,768,960,1152,1344]
freq_boundaries = []
for channel in channel_boundaries:
freq_boundary = freq[channel]
freq_boundaries.append(freq_boundary)
plt.axvline(freq_boundaries[0],0,1, color = '0.8')
plt.axvline(freq_boundaries[1],0,1, color = '0.8')
plt.axvline(freq_boundaries[2],0,1, color = '0.8')
plt.axvline(freq_boundaries[3],0,1, color = '0.8')
plt.axvline(freq_boundaries[4],0,1, color = '0.8')
plt.axvline(freq_boundaries[5],0,1, color = '0.8')
plt.axvline(freq_boundaries[6],0,1, color = '0.8')
averaged_data= np.abs(np.average(uv.get_data((ant,ant, uv.polarization_array[0])),0))
plt.plot(freq,averaged_data)
line.set_yscale('log')
line.set_xlabel('Frequency (MHz)')
line.set_ylabel('Power')
#sets the range of the graph to be the same range as waterfall plot
line.set_xlim(freq[0],freq[-1])
#makes waterfall x ticks invisible
plt.setp(waterfall.get_xticklabels(), visible=False)
#brings plots together
plt.subplots_adjust(hspace=.0)
#pad moves colorbar farther from plot
cbar = plt.colorbar(im, pad= 0.15, orientation = 'horizontal')
cbar.set_label('Power -->')
if save== False:
print('Fig not saved to file')
elif save == True:
plt.savefig('/lustre/aoc/projects/hera/amyers/gitrepos/monsterDetection/waterfalls/'+
str(file_number)+'_WF_LP_ant'+str(ant))
print('Fig saved to file')
plt.show()
plt.close()
#makes a lineplot every hour for the given antenna and loaded file
def every_hour_lineplot(uv, file_number, ant):
freq = uv.freq_array[0]*1e-6
times = np.unique(uv.time_array)
fig = plt.figure(figsize=(20,20))
def find_nearest(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return array[idx]
#creating hour_array, which has times from time_array that are spaced ~ 1 hour apart
hour_arrange = np.arange(times[0],times[-1],(1/24))
hour_array=[]
for hour_value in hour_arrange:
time = find_nearest(times,hour_value)
hour_array.append(time)
#setting up the structure of the subplots plots
nhours = len(hour_array)
cols = 3
rows = nhours//cols +1
i = 1
#creating the plots
for time in hour_array:
plt.subplot(rows,cols,i)
times_index = np.where(times == time)
#np.where outputs a tuple. [0] pulls out a single number array, int makes it a number
#which is not in an array
times_index = int(times_index[0])
dat = np.abs(uv.get_data((ant,ant,'xx'))[times_index])
plt.plot(freq,dat)
plt.title(str(file_number)+'Ant '+str(ant)+', time = '+str(time))
plt.yscale('log')
plt.ylim((1e6,1e8))
#add 1 to i
i +=1
#mask the inputted array
def mask(uv,input_array):
#this blocks out the entire ratio band.
radio = np.array(np.arange(300,501,1))
hand_picked = np.array([128,
640,
739,740,741,742,743,744,745,746,
810,811,844,845,
1117,1152,1166,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,
1183,1184,1185,1186,1187,1188,1189,1190,1191,1192,1193,1194,
1195,1196,1197,1198,1199,
1218,1219,1220,1231,1232,
1444,1445,1493,1494,
1510])
idx=np.concatenate((radio,hand_picked))
#creates masking array
spike_mask = np.zeros_like(input_array)
#tells the array which values to set to 1 (which values to mask out)
spike_mask[:,idx]= 1
#makes masked array without undesired values
masked_data = ma.masked_array(input_array, spike_mask)
return masked_data;
#plots a waterfall+line plot for the specified ant. uses the same mask as above.
def masked_auto_waterfall_lineplot (uv,file_number, ant,colorbar_min, colorbar_max, save = False):
#creating the mask
data_array = np.abs(uv.get_data((ant, ant, uv.polarization_array[0])))
#this blocks out the entire ratio band.
radio = np.array(np.arange(300,501,1))
hand_picked = np.array([128,
640,
739,740,741,742,743,744,745,746,
810,811,844,845,
1117,1152,1166,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,
1183,1184,1185,1186,1187,1188,1189,1190,1191,1192,1193,1194,
1195,1196,1197,1198,1199,
1218,1219,1220,1231,1232,
1444,1445,1493,1494,
1510])
idx=np.concatenate((radio,hand_picked))
#creates masking array
spike_mask = np.zeros_like(data_array)
#tells the array which values to set to 1 (which values to mask out)
spike_mask[:,idx]= 1
#makes masked array without undesired values
masked_data = ma.masked_array(data_array, spike_mask)
#plotting the graphs
freq = uv.freq_array[0]*1e-6
fig = plt.figure(figsize=(20,20))
#can use gridspec instead of saying add_subplot(1,2,1) etc
gs = gridspec.GridSpec(2, 1, height_ratios=[2,1])
#creates waterfall subplot
waterfall= plt.subplot(gs[0])
#create time axis
jd_ax=plt.gca()
#there are a lot of redundancies in time_array, so to make sure that we have a list
#of unique times to work with, we start off by making a new array... not doing this will
#make things get messy. gave me a blank plot at first with a bunch of lines on the side
#before i did this.
times= np.unique(uv.time_array)
#create the plot. uv.get_data will get data from specified antennas
#colors.LogNorm() puts colors on log scale
im = plt.imshow(masked_data,norm=colors.LogNorm(),
vmin=colorbar_min, vmax=colorbar_max, aspect='auto')
waterfall.set_title(str(file_number)+' Masked Waterfall+Lineplot, Antenna '+str(ant))
# get an array of frequencies in MHz
freqs = uv.freq_array[0, :] / 1000000
xticks = np.arange(0, len(freqs), 120)
plt.xticks(xticks, labels =np.around(freqs[xticks],2))
jd_ax.set_ylabel('JD Time (days)')
#makes equally spaced ticks in increments of 100. since we are assuming time is pretty
#continuous, this will cover all times pretty well if we go from 0 to the length
jd_yticks = np.arange(0,len(times),100)
#set_yticks takes a List of y-axis tick locations. its purpose is to set tick locations
jd_ax.set_yticks(jd_yticks)
#this function actually determines what the tickmarks will say.
jd_ax.set_yticklabels(np.around(times[jd_yticks],2))
#create second axis
lst_ax = jd_ax.twinx()
lst_ax.set_ylabel('LST Time (hour of the day)')
#lst_array is in radians, and we want it in *hours*.. rad*180/pi = degrees
#one hour= 15 degrees
lst_hours = (uv.lst_array*(180/np.pi))/(15)
#creates array of unique lsts
lsts= lst_hours.reshape(uv.Ntimes,uv.Nbls)
lsts = lsts[:,0]
#set the ticks of the lst axis to match the lst_array in hours
lst_yticks = np.arange(0,len(lsts),100)
lst_ax.set_yticks(lst_yticks)
lst_ax.set_yticklabels(np.around(lsts[lst_yticks],2))
#gives the lst_axis information about the jd_axis. stuff like the y-dimension of the data.
#gets the axes to line up properly. will make it so that the tick-marks lining up, and the
#zeroth entry of times[jd_yticks] lining up with the zeroth entry of lsts[lst_yticks]
lst_ax.set_ylim(jd_ax.get_ylim())
#makes it so that the second axis does not alter the structure of the figure
jd_ax.autoscale(False)
lst_ax.autoscale(False)
#creates line subplot and positions it according to gs[1]
line= plt.subplot(gs[1])
#gets power averaged over time
masked_mean_data= ma.mean(masked_data,0)
#used when i was trying to identify frequencies
#creates 1d array of frequency indeces
#freq_index= np.arange(0,uv.Nfreqs,1)
# plt.plot(freq_index,powers_avg)
# line.set_yscale('log')
plt.plot(freq,masked_mean_data)
line.set_yscale('log')
line.set_xlabel('Frequency (MHz)')
line.set_ylabel('Power')
#sets the range of the graph to be the same range as waterfall plot
line.set_xlim(freq[0],freq[-1])
#makes waterfall x ticks invisible
plt.setp(waterfall.get_xticklabels(), visible=False)
#brings plots together
plt.subplots_adjust(hspace=.0)
#pad moves colorbar farther from plot
cbar = plt.colorbar(im, pad= 0.15, orientation = 'horizontal')
cbar.set_label('Power -->')
if save == False:
print('Fig not saved to file')
elif save == True:
plt.savefig('/lustre/aoc/projects/hera/amyers/gitrepos/monsterDetection/waterfalls/'+
str(file_number)+'_masked_WF_LP_ant'+str(ant))
print('Fig saved to file')
plt.show()
plt.close()
#returns the array for the expected bandpass
def expected_power_bandpass(uv):
good_curves = [uv.get_data((0,0, uv.polarization_array[0])),
uv.get_data((1,1, uv.polarization_array[0])),
uv.get_data((13,13, uv.polarization_array[0])),
uv.get_data((14,14, uv.polarization_array[0])),
uv.get_data((23,23, uv.polarization_array[0])),
uv.get_data((25,25, uv.polarization_array[0])),
uv.get_data((39,39, uv.polarization_array[0])),
]
good_curves = np.asarray(good_curves)
average_curve= np.abs(np.average(good_curves,0))
expect_band = mask(uv,average_curve)
return expect_band[0]
#plots a waterfall for a single auto
def singleauto_waterfall (uv, file_number, ant, colorbar_min, colorbar_max, save = False):
fig = plt.figure(figsize=(15,12))
#create time axis
jd_ax=plt.gca()
#there are a lot of redundancies in time_array, so to make sure that we have a list
#of unique times to work with, we start off by making a new array... not doing this will
#make things get messy. gave me a blank plot at first with a bunch of lines on the side
#before i did this.
times= np.unique(uv.time_array)
#create the plot. uv.get_data will get data from specified antennas
#colors.LogNorm() puts colors on log scale
im = plt.imshow(np.abs(uv.get_data((ant,ant, uv.polarization_array[0]))),norm=colors.LogNorm(),
vmin=colorbar_min, vmax=colorbar_max, aspect='auto')
plt.title(str(file_number)+'Auto_'+str(ant)+' Waterfall Plot')
plt.xlabel('Frequency (MHz)')
# get an array of frequencies in MHz
freqs = uv.freq_array[0, :] / 1000000
xticks = np.arange(0, len(freqs), 120)
plt.xticks(xticks, labels =np.around(freqs[xticks],2))
jd_ax.set_ylabel('JD Time (days)')
#makes equally spaced ticks in increments of 100. since we are assuming time is pretty
#continuous, this will cover all times pretty well if we go from 0 to the length
jd_yticks = np.arange(0,len(times),100)
#set_yticks takes a List of y-axis tick locations. its purpose is to set tick locations
jd_ax.set_yticks(jd_yticks)
#this function actually determines what the tickmarks will say.
jd_ax.set_yticklabels(np.around(times[jd_yticks],2))
#pad moves colorbar farther from plot
cbar = plt.colorbar(im, pad= 0.2)
cbar.set_label('Power')
#create second axis
lst_ax = jd_ax.twinx()
lst_ax.set_ylabel('LST Time (hour of the day)')
#lst_array is in radians, and we want it in *hours*.. rad*180/pi = degrees
#one hour= 15 degrees
lst_hours = (uv.lst_array*(180/np.pi))/(15)
#creates array of unique lsts
lsts= lst_hours.reshape(uv.Ntimes,uv.Nbls)
lsts = lsts[:,0]
#set the ticks of the lst axis to match the lst_array in hours
lst_yticks = np.arange(0,len(lsts),100)
lst_ax.set_yticks(lst_yticks)
lst_ax.set_yticklabels(np.around(lsts[lst_yticks],2))
#gives the lst_axis information about the jd_axis. stuff like the y-dimension of the data.
#gets the axes to line up properly. will make it so that the tick-marks lining up, and the
#zeroth entry of times[jd_yticks] lining up with the zeroth entry of lsts[lst_yticks]
lst_ax.set_ylim(jd_ax.get_ylim())
#makes it so that the second axis does not alter the structure of the figure
jd_ax.autoscale(False)
lst_ax.autoscale(False)
if save == False:
print('Fig not saved to file')
elif save == True:
plt.savefig('/lustre/aoc/projects/hera/amyers/gitrepos/monsterDetection/waterfalls/'+
str(file_number)+'WF_ant'+str(ant))
print('Fig saved to file')
plt.show()
plt.close()
return;
#plots a waterfall for every antenna in the file
def allauto_waterfall (uv, file_number, colorbar_min, colorbar_max, save = False):
for ant in uv.antenna_numbers:
fig = plt.figure(figsize=(15,12))
#create time axis
jd_ax=plt.gca()
#there are a lot of redundancies in time_array, so to make sure that we have a list
#of unique times to work with, we start off by making a new array... not doing this will
#make things get messy. gave me a blank plot at first with a bunch of lines on the side
#before i did this.
times= np.unique(uv.time_array)
#create the plot. uv.get_data will get data from specified antennas
#colors.LogNorm() puts colors on log scale
im = plt.imshow(np.abs(uv.get_data((ant,ant, uv.polarization_array[0]))),norm=colors.LogNorm(),
vmin=colorbar_min, vmax=colorbar_max, aspect='auto')
plt.title(str(file_number)+'Auto_'+str(ant)+' Waterfall Plot')
plt.xlabel('Frequency (MHz)')
# get an array of frequencies in MHz
freqs = uv.freq_array[0, :] / 1000000
xticks = np.arange(0, len(freqs), 120)
plt.xticks(xticks, labels =np.around(freqs[xticks],2))
jd_ax.set_ylabel('JD Time (days)')
#makes equally spaced ticks in increments of 100. since we are assuming time is pretty
#continuous, this will cover all times pretty well if we go from 0 to the length
jd_yticks = np.arange(0,len(times),100)
#set_yticks takes a List of y-axis tick locations. its purpose is to set tick locations
jd_ax.set_yticks(jd_yticks)
#this function actually determines what the tickmarks will say.
jd_ax.set_yticklabels(np.around(times[jd_yticks],2))
#pad moves colorbar farther from plot
cbar = plt.colorbar(im, pad= 0.2)
cbar.set_label('Power')
#create second axis
lst_ax = jd_ax.twinx()
lst_ax.set_ylabel('LST Time (hour of the day)')
#lst_array is in radians, and we want it in *hours*.. rad*180/pi = degrees
#one hour= 15 degrees
lst_hours = (uv.lst_array*(180/np.pi))/(15)
#creates array of unique lsts
lsts= lst_hours.reshape(uv.Ntimes,uv.Nbls)
lsts = lsts[:,0]
#set the ticks of the lst axis to match the lst_array in hours
lst_yticks = np.arange(0,len(lsts),100)
lst_ax.set_yticks(lst_yticks)
lst_ax.set_yticklabels(np.around(lsts[lst_yticks],2))
#gives the lst_axis information about the jd_axis. stuff like the y-dimension of the data.
#gets the axes to line up properly. will make it so that the tick-marks lining up, and the
#zeroth entry of times[jd_yticks] lining up with the zeroth entry of lsts[lst_yticks]
lst_ax.set_ylim(jd_ax.get_ylim())
#makes it so that the second axis does not alter the structure of the figure
jd_ax.autoscale(False)
lst_ax.autoscale(False)
if save == False:
print('Fig not saved to file')
elif save == True:
plt.savefig('/lustre/aoc/projects/hera/amyers/gitrepos/monsterDetection/waterfalls/'+str(file_number)+
'_WF_ant'+str(ant))
print('Fig saved to file')
plt.show()
plt.close()
return;