forked from bmarcote/seffers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfringeSelect.py
executable file
·118 lines (92 loc) · 4.39 KB
/
fringeSelect.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
#!/usr/bin/env python3
import argparse
import sys
import numpy as np
import math
import webbrowser
import requests
from os import path,remove
from tqdm import tqdm
from stations import Station
from util_functions import *
from sources import Flux,Source,load_rfc_cat, get_up_sources
def print_sources(sources):
print("{:>2} {:4} {:12} {:11} {:}".format('#', 'Cal?', 'Source name', 'Other name', 'Flux Unresolved (at {}-band)'.format(rfcBand)))
for i,source in enumerate(sources):
if i > 9:
break
print("{:2} {:4} {:12} {:11} {:3.2f} {:3.2f}".format(i, 'Y' if source.isCal else 'N', source.name, source.ivsname, source.flux[rfcBand].resolved, source.flux[rfcBand].unresolved))
#parse inputs
parser = argparse.ArgumentParser(description='Provide some options for sources to use as fringe finders.\nBased on RfC catalogue.')
parser.add_argument('timeStart', type=str, help="The start date/time of your experiment. Format ='DD/MM/YYYY HH:MM'")
parser.add_argument('duration', type=float, help="The duration of your experiment (in hours)")
parser.add_argument('-b', "--band", type=str, default='c', help="The band you are searching for, one of l, s, c, m, x, u, k, q.\nIf not specified will default to using C-band fluxes as priority.")
parser.add_argument('-e', "--min-el", type=int, default=20, help="The minimum elevation to consider a source being 'up'. Defaults to 20.")
parser.add_argument('-f', "--min-flux", type=float, default=1.0, help="The mimimum flux density of sources to consider. Defaults to 1.0 Jy")
parser.add_argument('stations',type=str, nargs='+', help="Space delimited list of stations")
args = parser.parse_args()
#need to get rfc catalogue if we don't have it
if not path.isfile("./rfc_2018c_cat.txt"):
print("RFC VLBI Source Position Catalogue not found, downloading.\nThis might take a moment...")
url = "http://astrogeo.org/vlbi/solutions/rfc_2018c/rfc_2018c_cat.txt"
r = requests.get(url, stream=True)
# Total size in bytes.
total_size = int(r.headers.get('content-length', 0));
block_size = 1024
wrote = 0
with open('rfc_2018c_cat.txt', 'wb') as f:
for data in tqdm(r.iter_content(block_size), total=math.ceil(total_size//block_size) , unit='KB', unit_scale=True):
wrote = wrote + len(data)
f.write(data)
if total_size != 0 and wrote != total_size:
print("ERROR, something went wrong with the download.")
remove("./rfc_2018c_cat.txt")
sys.exit(1)
print("Done")
#rfc only has fluxes for bands, s, c, u, and k so pick the closest band to requested.
if args.band in ['l', 's']:
rfcBand = 's'
elif args.band in ['c','m']:
rfcBand = 'c'
elif args.band == 'x':
rfcBand = 'x'
elif args.band == 'u':
rfcBand = 'u'
elif args.band in ['k','q']:
rfcBand = 'k'
else:
#not a known band?
print("Error band {} is unknown.".format(args.band))
sys.exit(2)
#load station information for all stations.
stationList = Station.stations_from_file('./station_location.txt')
stations = [stationList[station.upper()] for station in args.stations]
obsTimes = get_obs_times(get_time(args.timeStart), args.duration)
sourceCat = load_rfc_cat("./rfc_2018c_cat.txt", rfcBand, args.min_flux)
sources = get_up_sources(stations, sourceCat, obsTimes, minEl=args.min_el, minFluxBand=rfcBand)
#ask which source to plot
while True:
print()
print_sources(sources)
srcIndex = input("Please select the source to plot (0-9, q to quit): ")
if srcIndex == 'q':
break
try: srcIndex = int(srcIndex)
except ValueError:
print("Must be an int (or q)!")
continue
if srcIndex in (list(range(10)) if len(sources) > 10 else list(range(len(sources)))):
print("Astrogeo calibrator link, has source maps, radplots:")
print(sources[srcIndex].get_astrogeo_link())
#webbrowser.open(sourceCoordString, new=0, autoraise=True)
links=sources[srcIndex].find_nmes()
if len(links) > 0:
print("The following NMEs have included this source:")
for a,b in zip(links[::2], links[1::2]):
print ("{:55} {:55}".format(a, b))
else:
print("No NME has included this source")
#plot the elevations for the selected source
sources[srcIndex].plot_elevation(stations, obsTimes)
else:
print("Not in range")