Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, ra, dec, f_c=.012, name='', **kwargs):
"""ra: source's right ascension (epoch=2000)
dec: source's declination (epoch=2000)
f_c: the plasma frequency (a measure of the electron density)
in the direction of the source, which can cause the
source to appear displaced from its quiescent position
as a function of frequency."""
RadioBody.__init__(self, name=name)
ephem.FixedBody.__init__(self)
self._ra, self._dec, self.f_c = ra, dec, f_c
def compute(self, observer, refract=False):
def compute(self, observer, refract=False):
if self.in_cache(observer, refract): return
ephem.FixedBody.compute(self, observer)
self.map = self.gen_uvw_map(observer, refract=refract)
self.cache(observer, refract)
d_d = (d_Z*(-sin_Z*sin_lat + cos_Z*cos_lat*cos_A) \
- d_A*sin_Z*cos_lat*sin_A) / cos_d
# Convert zenith angle displacement into hour-angle component
d_H = (d_d*sin_H*sin_d - d_A*cos_A*sin_Z - d_Z*sin_A*cos_Z) \
/ (cos_H*cos_d)
return H + d_H, d + d_d
# ____ _ _ _____ _ _ ____ _
# | _ \ __ _ __| (_) ___ | ___(_)_ _____ __| | __ ) ___ __| |_ _
# | |_) / _` |/ _` | |/ _ \| |_ | \ \/ / _ \/ _` | _ \ / _ \ / _` | | | |
# | _ < (_| | (_| | | (_) | _| | |> < __/ (_| | |_) | (_) | (_| | |_| |
# |_| \_\__,_|\__,_|_|\___/|_| |_/_/\_\___|\__,_|____/ \___/ \__,_|\__, |
# |___/
class RadioFixedBody(ephem.FixedBody, RadioBody):
"""A class combining ephem's FixedBody with a RadioBody."""
def __init__(self, ra, dec, f_c=.012, name='', **kwargs):
"""ra: source's right ascension (epoch=2000)
dec: source's declination (epoch=2000)
f_c: the plasma frequency (a measure of the electron density)
in the direction of the source, which can cause the
source to appear displaced from its quiescent position
as a function of frequency."""
RadioBody.__init__(self, name=name)
ephem.FixedBody.__init__(self)
self._ra, self._dec, self.f_c = ra, dec, f_c
def compute(self, observer, refract=False):
if self.in_cache(observer, refract): return
ephem.FixedBody.compute(self, observer)
self.map = self.gen_uvw_map(observer, refract=refract)
self.cache(observer, refract)
def juldate2ephem(num):
"""Convert Julian date to an ephem date, which is measured from noon,
Jan. 1, 1900."""
return ephem.date(num - 2415020)
def set_ephemtime(self, t=None):
"""Set the current time to a time derived from the ephem package."""
if t is None: t = ephem.now()
self.date = t
self.epoch = t
self.cache += 1
def src_eq_vec(self, body):
__radd__ = __add__
def __neg__(self):
return -self.pos
def __sub__(self, a):
return self.pos - a.pos
def __rsub__(self, a):
return a.pos - self.pos
# _ _ _ _
# / \ _ __ _ __ __ _ _ _| | ___ ___ __ _| |_(_) ___ _ __
# / _ \ | '__| '__/ _` | | | | | / _ \ / __/ _` | __| |/ _ \| '_ \
# / ___ \| | | | | (_| | |_| | |__| (_) | (_| (_| | |_| | (_) | | | |
# /_/ \_\_| |_| \__,_|\__, |_____\___/ \___\__,_|\__|_|\___/|_| |_|
# |___/
class ArrayLocation(ephem.Observer):
"""Collected information about where and when an array is."""
def __init__(self, location=None, uv=None):
"""location: location of the array in (lat, long, [elev])
uv: Miriad UV file"""
ephem.Observer.__init__(self)
self.cache = 0
if not uv is None: self.from_uv(uv)
else:
if location is None:
raise ValueError('Must provide either uv or location.')
self.update_location(location)
def update_location(self, location):
"""Initialize the antenna array for the provided location. Locations
may be (lat, long) or (lat, long, elev)."""
if len(location) == 2: self.lat, self.long = location
else: self.lat, self.long, self.elev = location
def __init__(self, location=None, uv=None):
"""location: location of the array in (lat, long, [elev])
uv: Miriad UV file"""
ephem.Observer.__init__(self)
self.cache = 0
if not uv is None: self.from_uv(uv)
else:
if location is None:
raise ValueError('Must provide either uv or location.')
self.update_location(location)
def update_location(self, location):
def set_jultime(self, t=None):
"""Set the current time to a Julian date."""
if t is None: t = ephem.julian_date()
self.set_ephemtime(juldate2ephem(t))
def set_ephemtime(self, t=None):
def response(self, azalt, pol='x'):
"""Return the total antenna response to a source at azalt=(az, alt),
including beam response, per-frequency gain, and a phase offset."""
zang = ephem.separation(self.pointing, azalt)
beam_resp = self.beam.response(zang, azalt[0], pol=pol)
return beam_resp * self.gain