Commit 68615186 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Use astropy quantities for camrasdevice setter and getter, use custom function for tracking

parent f45c2cc7
import hpib
from hpib import HpibDevice
import astropy.units as u
from astropy.units import Quantity
import threading
class CamrasHpibDevice(HpibDevice):
......@@ -17,15 +19,18 @@ class CamrasHpibDevice(HpibDevice):
@property
def frequency(self):
"""Returns the frequency (in Hz) of the device. Throws a RuntimeError if no response"""
"""Returns the frequency of the device as an astropy Quantity.
Throws a RuntimeError if no response"""
freq_str = self.query("freq?")
if len(freq_str)==0:
raise RuntimeError("Camras device at address {} is not responding".format(self._hpib_address))
return int(float(self.query("freq?")))
return int(float(self.query("freq?"))) * u.Hz
@frequency.setter
def frequency(self, freq):
"""Set the device to the specified frequency. Throws a RuntimeError if failed"""
if isinstance(freq, Quantity):
freq = freq.to(u.Hz).value
self.command("freq {:d} Hz".format(int(freq)))
new_freq = self.frequency
if int(new_freq) != int(freq):
......
......@@ -11,17 +11,40 @@ from camrasdevices import Receiver, LocalOscillator
import time
freq_hi = 1420.405751
freq_hi = 1420.405751 * u.MHz
def track_doppler(lo=None, dt=None,
tracking_frequency=freq_hi,
doppler_executable="/home/harm/bin/doppler_mb",
exit_event=None):
"""Sets the Local Oscillator to a frequency to correct for Doppler shift"""
def doppler_harm(sky_coordinate, time, tracking_frequency):
dt_lat = np.deg2rad(52.812019)
dt_lon = np.deg2rad(6.396169)
dt_alt = 25.0
ra = sky_coordinate.ra.to(u.rad).value
dec = sky_coordinate.dec.to(u.rad).value
argstring = "{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}".format(
ra=ra, dec=dec, time=time, dt_lat=dt_lat, dt_lon=dt_lon, dt_alt=dt_alt)
doppler_executable = "/home/harm/bin/doppler_mb"
doppler_cmd = doppler_executable + " " + argstring + " " + str(tracking_frequency.to(u.MHz).value)
freq_doppler = float(subprocess.Popen(doppler_cmd, stdout=subprocess.PIPE, shell=True).stdout.read())
return freq_doppler * u.MHz
def track_doppler(lo=None, dt=None,
tracking_frequency=freq_hi,
doppler_function=doppler_harm,
exit_event=None):
"""Sets the Local Oscillator to a frequency to correct for Doppler shift
Args:
lo (LocalOscillator): the local oscillator of which the frequency will be set.
Defaults to None, in this case one will be created
dt (Telescope): a Telescope instance to read the current pointing from.
Defaults to None, in this case one will be created
doppler_function (function): a function that computes the doppler frequency.
This function gets a SkyCoord and a time (float), and should return a frequency Quantity
"""
if not lo:
lo = LocalOscillator();
if not dt:
......@@ -30,14 +53,8 @@ def track_doppler(lo=None, dt=None,
exit_event = threading.Event()
while not exit_event.is_set():
ra = dt.radec.ra.to(u.rad).value
dec = dt.radec.dec.to(u.rad).value
t = time.time()
argstring = "{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}".format(
ra=ra, dec=dec, time=t, dt_lat=dt_lat, dt_lon=dt_lon, dt_alt=dt_alt)
doppler_cmd = doppler_executable + " " + argstring + " " + str(tracking_frequency)
freq_doppler = float(subprocess.Popen(doppler_cmd, stdout=subprocess.PIPE, shell=True).stdout.read())
dfreq = 1000.0 + tracking_frequency - freq_doppler
sky_coordinate = dt.radec
freq_doppler = doppler_function(sky_coordinate, time.time(), tracking_frequency)
dfreq = 1*u.GHz + tracking_frequency - freq_doppler
lo.frequency = dfreq * 1e6
exit_event.wait(timeout=0.5)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment