Browse Source

Started rewrite of sources.py, beginning of fringeSelect which can help you find a fringe finder

pull/2/head
Jay Blanchard 3 years ago
parent
commit
e64edff7d7
  1. 39
      fringeSelect.py
  2. 171
      sources.py
  3. 156
      sources_old.py

39
fringeSelect.py

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import argparse
import numpy as np
from stations import Station
from util_functions import *
#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 ='YYYY-MM-DD HH:MM:SS.S'")
parser.add_argument('duration', type=float, help="The duration of your experiment (in hours)")
parser.add_argument('-b', "--band", type=str, default="none", help="The band you are searching for, one of l, s, c, m, x, u, k, q")
parser.add_argument('stations',type=str, nargs='+', help="Space delimited list of stations")
args = parser.parse_args()
#load station information for all stations.
all_stations = Station.stations_from_file('./station_location.txt')
sourceCat = np.loadtxt('./rfc_2018c_cat.txt', comments='#', dtype={'names': ('cal', 'name', 'ivsname', 'raH', 'raM', 'raS', 'degH', 'degM',
'degS', 'noObs', 'fluxSR', 'fluxSU', 'fluxCR', 'fluxCU',
'fluxXR', 'fluxXU', 'fluxUR', 'fluxUU', 'fluxKR', 'fluxKU'),
'formats': ('bool', '|S15', '|S15', 'int', 'int', 'float', 'int', 'int',
'float', 'int', 'float', 'float', 'float', 'float', 'float',
'float', 'float', 'float', 'float', 'float')},
usecols=(0,1,2,3,4,5,6,7,8,12,13,14,15,16,17,18,19,20,21,22),
converters={0: lambda cal: True if cal=='Y' else False,
13: lambda f: 0.0 if '<' in str(f) else f,
14: lambda f: 0.0 if '<' in str(f) else f,
15: lambda f: 0.0 if '<' in str(f) else f,
16: lambda f: 0.0 if '<' in str(f) else f,
17: lambda f: 0.0 if '<' in str(f) else f,
18: lambda f: 0.0 if '<' in str(f) else f,
19: lambda f: 0.0 if '<' in str(f) else f,
20: lambda f: 0.0 if '<' in str(f) else f,
21: lambda f: 0.0 if '<' in str(f) else f,
22: lambda f: 0.0 if '<' in str(f) else f})

171
sources.py

@ -1,156 +1,33 @@
#from collections import defaultdict
#import urllib
#from html.parser import HTMLParser
#import astropy.coordinates as coord
#import astropy.units as u
class Source:
"""Contains the information of a radio source available in VLBI catalogs for
calibrators
"""
self.name = None
self.oldname = None
self.coordinates = None
self.images = []
self.radplots = []
#self.nmes = None # To be implemented
def __init__(self, name, oldname, coordinates):
"""Initialize a new source with a specific name (J2000) and its coordinates.
Input
-----
- name : str
Name of the source as povided in the J2000 catalog (e.g. J2045+5049)
- oldname : str
Name of the source as povided in the B1950 catalog (e.g. 2044+504)
- coordinates : astropy.coordinates
Coordinates of the source as provided by the astropy.coordinates package.
"""
self.name = name.upper()
self.oldname = oldname.upper()
self.coordinates = coordinates
# Search if it is available in catalogs
self.images = defaultdict(list)
self.radplots = defaultdict(list)
image_vsop = get_source_in_vsop5GHz('image')
if image_vsop is not None:
self.images['C'] = [image_vsop]
radplot_vsop = get_source_in_vsop5GHz('radplot')
if radplot_vsop is not None:
self.radplots['C'] = [radplot_vsop]
rfc_images, rfc_radplots = get_source_in_rfc()
for aband in rfc_images:
self.images[aband].append(rfc_images[aband])
for aband in rfc_radplots:
self.radplots[aband].append(rfc_radplots[aband])
def get_source_in_vsop5GHz(self, type_plot):
"""Get the images of the source available in the VSOP 5-GHz catalog:
http://www.jive.nl/svlbi/vlbapls/index.htm
There are two types of images available: the actual image of the source or the
correlated flux density versus the projected baseline length plot (radplot).
class Flux:
def __init__(self, resolvedFlux, unresolvedFlux):
"""Initialises a flux (contains unresolved and resolved flux)
Inputs
------
- type_plot : str
Can take only two possible values:
image - will take the image of the source at 5 GHz.
radplot - will take the plot of the correlated flux density versus the projected baseline length.
Outputs
-------
- url_to_image : str
Returns the url where the requested image is located (usually is a gif file).
- resolvedFlux: the resolved flux of the source
- unresolvedFlux: the unresolved flux of the source
"""
possible_url = 'http://www.jive.nl/svlbi/vlbapls/{}.htm'.format(self.name)
if website_exists(possible_url):
if type_plot == 'image':
return 'http://www.jive.nl/svlbi/vlbapls/img/{}MAP.color.gif'.format(self.oldname)
elif type_plot == 'radplot':
return 'http://www.jive.nl/svlbi/vlbapls/img/{}MAP.radplot.gif'.format(self.oldname)
else:
raise ValueError('Only "image" or "radplot" are valid types for type_plot.')
else:
return None
self.resolved = resolvedFlux
self.unresolved = unresolvedFlux
assert isinstance(unresolvedFlux, float)
assert isinstance(resolvedFlux, float)
class Source:
def get_source_in_rfc(self):
"""Get the images of the source available in the RFC catalog:
http://astrogeo.org/vlbi/solutions/rfc_2017a
There are two types of images available: the actual image of the source or the
correlated flux density versus the projected baseline length plot (radplot).
def __init__(self, name, ivsname, coord, noObs, fluxes):
"""Initializes a source.
Inputs
------
- band : str
Frequency band at which the plots are requested. Possible values are:
S, C, X, U, K, Q (in capital letters)
Outputs
-------
- url_to_image : dict
Returns the url where the requested images of the source are located (usually as ps files).
It is a dictionary with the different bands as keys (S, C, X, U, K, Q).
- url_to_radplot : dict
Same as previous one but for plots of the correlated flux density vs projected baseline
length is located (usually is a ps file).
In both outputs, it will return an empty dict if there are not files for this particular source.
- name: the J2000 name
- ivsname: the ivsname
- coord: astropy coord
- noObs: the number of times this source has been observed in the IVS cat (useful filter maybe)
- fluxes: dict of fluxes with band as key names.
"""
return get_rfclink_to_file(self.source)
def website_exists(url):
"""Returns True or False if the provided URL exists or not.
- url : str
An url to check if it exists or not.
"""
try:
theurl = urllib.request.urlopen(url).code
return True
except HTTPError:
return False
class LinkParser(HTMLParser):
def reset(self):
HTMLParser.reset(self)
self.links = iter([])
def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
self.links = chain(self.links, [value])
def get_links(f, parser):
encoding = f.headers.get_content_charset() or 'UTF-8'
for line in f:
parser.feed(line.decode(encoding))
yield from parser.links
def get_rfclink_to_file(source):
url = 'http://astrogeo.org/images/{}/'.format(source)
parser = LinkParser()
f = urllib.requests.urlopen(url)
links = get_links(f, parser)
url_image, url_radplot = {}, {}
for alink in links:
if 'pet_map.ps' in alink:
# Get the band (the url name is SOURCE_BAND_EPOCH_...ps)
band = alink[alink.index('_')+1]
if band not in url_image:
url_image[band] = alink
elif 'pet_rad.ps' in alink:
band = alink[alink.index('_')+1]
if band not in url_radplot:
url_radplot[band] = alink
return url_image, url_radplot
self.source = name
self.ivsname = ivsname
self.coord = coord
self._noObs = noObs
self.fluxes = fluxes

156
sources_old.py

@ -0,0 +1,156 @@
#from collections import defaultdict
#import urllib
#from html.parser import HTMLParser
#import astropy.coordinates as coord
#import astropy.units as u
class Source:
"""Contains the information of a radio source available in VLBI catalogs for
calibrators
"""
self.name = None
self.oldname = None
self.coordinates = None
self.images = []
self.radplots = []
#self.nmes = None # To be implemented
def __init__(self, name, oldname, coordinates):
"""Initialize a new source with a specific name (J2000) and its coordinates.
Input
-----
- name : str
Name of the source as povided in the J2000 catalog (e.g. J2045+5049)
- oldname : str
Name of the source as povided in the B1950 catalog (e.g. 2044+504)
- coordinates : astropy.coordinates
Coordinates of the source as provided by the astropy.coordinates package.
"""
self.name = name.upper()
self.oldname = oldname.upper()
self.coordinates = coordinates
# Search if it is available in catalogs
self.images = defaultdict(list)
self.radplots = defaultdict(list)
image_vsop = get_source_in_vsop5GHz('image')
if image_vsop is not None:
self.images['C'] = [image_vsop]
radplot_vsop = get_source_in_vsop5GHz('radplot')
if radplot_vsop is not None:
self.radplots['C'] = [radplot_vsop]
rfc_images, rfc_radplots = get_source_in_rfc()
for aband in rfc_images:
self.images[aband].append(rfc_images[aband])
for aband in rfc_radplots:
self.radplots[aband].append(rfc_radplots[aband])
def get_source_in_vsop5GHz(self, type_plot):
"""Get the images of the source available in the VSOP 5-GHz catalog:
http://www.jive.nl/svlbi/vlbapls/index.htm
There are two types of images available: the actual image of the source or the
correlated flux density versus the projected baseline length plot (radplot).
Inputs
------
- type_plot : str
Can take only two possible values:
image - will take the image of the source at 5 GHz.
radplot - will take the plot of the correlated flux density versus the projected baseline length.
Outputs
-------
- url_to_image : str
Returns the url where the requested image is located (usually is a gif file).
"""
possible_url = 'http://www.jive.nl/svlbi/vlbapls/{}.htm'.format(self.name)
if website_exists(possible_url):
if type_plot == 'image':
return 'http://www.jive.nl/svlbi/vlbapls/img/{}MAP.color.gif'.format(self.oldname)
elif type_plot == 'radplot':
return 'http://www.jive.nl/svlbi/vlbapls/img/{}MAP.radplot.gif'.format(self.oldname)
else:
raise ValueError('Only "image" or "radplot" are valid types for type_plot.')
else:
return None
def get_source_in_rfc(self):
"""Get the images of the source available in the RFC catalog:
http://astrogeo.org/vlbi/solutions/rfc_2017a
There are two types of images available: the actual image of the source or the
correlated flux density versus the projected baseline length plot (radplot).
Inputs
------
- band : str
Frequency band at which the plots are requested. Possible values are:
S, C, X, U, K, Q (in capital letters)
Outputs
-------
- url_to_image : dict
Returns the url where the requested images of the source are located (usually as ps files).
It is a dictionary with the different bands as keys (S, C, X, U, K, Q).
- url_to_radplot : dict
Same as previous one but for plots of the correlated flux density vs projected baseline
length is located (usually is a ps file).
In both outputs, it will return an empty dict if there are not files for this particular source.
"""
return get_rfclink_to_file(self.source)
def website_exists(url):
"""Returns True or False if the provided URL exists or not.
- url : str
An url to check if it exists or not.
"""
try:
theurl = urllib.request.urlopen(url).code
return True
except HTTPError:
return False
class LinkParser(HTMLParser):
def reset(self):
HTMLParser.reset(self)
self.links = iter([])
def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
self.links = chain(self.links, [value])
def get_links(f, parser):
encoding = f.headers.get_content_charset() or 'UTF-8'
for line in f:
parser.feed(line.decode(encoding))
yield from parser.links
def get_rfclink_to_file(source):
url = 'http://astrogeo.org/images/{}/'.format(source)
parser = LinkParser()
f = urllib.requests.urlopen(url)
links = get_links(f, parser)
url_image, url_radplot = {}, {}
for alink in links:
if 'pet_map.ps' in alink:
# Get the band (the url name is SOURCE_BAND_EPOCH_...ps)
band = alink[alink.index('_')+1]
if band not in url_image:
url_image[band] = alink
elif 'pet_rad.ps' in alink:
band = alink[alink.index('_')+1]
if band not in url_radplot:
url_radplot[band] = alink
return url_image, url_radplot
Loading…
Cancel
Save