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 track_doppler
import unittest
from mock import call, patch
from astropy.coordinates import SkyCoord from astropy.coordinates import SkyCoord
import astropy.units as u 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(): class DummyTelescope():
def __init__(self): def __init__(self):
fake_pointing = SkyCoord(ra=0.*u.deg, dec=31.*u.deg)
self.radec = fake_pointing
pass pass
def getJ2000(self): def getJ2000(self):
for i in range(3): for i in range(3):
fake_pointing = SkyCoord(ra=0.*u.deg, dec=31.*u.deg) yield {'radec': self.radec}
yield {'radec': fake_pointing,}
class DummyLocalOscillator(): class DummyLocalOscillator(object):
def __init__(self): def __init__(self):
self._frequency = 0 self._frequency = 0
pass pass
...@@ -27,4 +42,7 @@ class DummyLocalOscillator(): ...@@ -27,4 +42,7 @@ class DummyLocalOscillator():
self._frequency = freq self._frequency = freq
print("Dummy LO set to {}".format(self._frequency)) 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 ...@@ -2,6 +2,8 @@ import astropy.units as u
import numpy as np import numpy as np
import argparse import argparse
import threading
import subprocess import subprocess
from telescope import telescope from telescope import telescope
...@@ -13,7 +15,8 @@ freq_hi = 1420.405751 ...@@ -13,7 +15,8 @@ freq_hi = 1420.405751
def track_doppler(lo=None, dt=None, def track_doppler(lo=None, dt=None,
tracking_frequency=freq_hi, 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""" """Sets the Local Oscillator to a frequency to correct for Doppler shift"""
dt_lat = np.deg2rad(52.812019) dt_lat = np.deg2rad(52.812019)
dt_lon = np.deg2rad(6.396169) dt_lon = np.deg2rad(6.396169)
...@@ -23,10 +26,12 @@ def track_doppler(lo=None, dt=None, ...@@ -23,10 +26,12 @@ def track_doppler(lo=None, dt=None,
lo = LocalOscillator(); lo = LocalOscillator();
if not dt: if not dt:
dt = telescope(); dt = telescope();
if not exit_event:
exit_event = threading.Event()
for pointing in dt.getJ2000(): while not exit_event.is_set():
ra = pointing['radec'].ra.to(u.rad).value ra = dt.radec.ra.to(u.rad).value
dec = pointing['radec'].dec.to(u.rad).value dec = dt.radec.dec.to(u.rad).value
t = time.time() t = time.time()
argstring = "{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}".format( 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) 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, ...@@ -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()) freq_doppler = float(subprocess.Popen(doppler_cmd, stdout=subprocess.PIPE, shell=True).stdout.read())
dfreq = 1000.0 + tracking_frequency - freq_doppler dfreq = 1000.0 + tracking_frequency - freq_doppler
lo.frequency = dfreq * 1e6 lo.frequency = dfreq * 1e6
exit_event.wait(timeout=0.5)
Supports Markdown
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