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

Use event to interrupt sleeping

parent 89662c2d
#!/usr/bin/env python3
import track_doppler
import unittest
from mock import call, patch
from astropy.coordinates import SkyCoord
import astropy.units as u
class DopplerTrackingTest(unittest.TestCase):
def setUp(self):
telescope_patch = patch('telescope.telescope')
self.telescope_mock = telescope_mock.start()
self.addCleanUp(telescope_patcher.stop)
local_oscillator_patch = patch('camrasdevices.LocalOscillator')
self.local_oscillator_mock = local_oscillator_patch.start()
self.addCleanUp(local_oscillator_patcher.stop)
def test_something(self):
pass
class DummyTelescope():
def __init__(self):
fake_pointing = SkyCoord(ra=0.*u.deg, dec=31.*u.deg)
self.radec = fake_pointing
pass
def getJ2000(self):
for i in range(3):
fake_pointing = SkyCoord(ra=0.*u.deg, dec=31.*u.deg)
yield {'radec': fake_pointing,}
yield {'radec': self.radec}
class DummyLocalOscillator():
class DummyLocalOscillator(object):
def __init__(self):
self._frequency = 0
pass
......@@ -27,4 +42,7 @@ class DummyLocalOscillator():
self._frequency = freq
print("Dummy LO set to {}".format(self._frequency))
track_hi.track_frequency(lo=DummyLocalOscillator(), dt=DummyTelescope())
track_doppler.track_doppler(lo=DummyLocalOscillator(), dt=DummyTelescope())
if __name__ == '__main__':
unittest.main()
......@@ -2,6 +2,8 @@ import astropy.units as u
import numpy as np
import argparse
import threading
import subprocess
from telescope import telescope
......@@ -13,7 +15,8 @@ freq_hi = 1420.405751
def track_doppler(lo=None, dt=None,
tracking_frequency=freq_hi,
doppler_executable="/home/harm/bin/doppler_mb"):
doppler_executable="/home/harm/bin/doppler_mb",
exit_event=None):
"""Sets the Local Oscillator to a frequency to correct for Doppler shift"""
dt_lat = np.deg2rad(52.812019)
dt_lon = np.deg2rad(6.396169)
......@@ -23,10 +26,12 @@ def track_doppler(lo=None, dt=None,
lo = LocalOscillator();
if not dt:
dt = telescope();
if not exit_event:
exit_event = threading.Event()
for pointing in dt.getJ2000():
ra = pointing['radec'].ra.to(u.rad).value
dec = pointing['radec'].dec.to(u.rad).value
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)
......@@ -35,3 +40,4 @@ def track_doppler(lo=None, dt=None,
freq_doppler = float(subprocess.Popen(doppler_cmd, stdout=subprocess.PIPE, shell=True).stdout.read())
dfreq = 1000.0 + 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