track_doppler.py 2.17 KB
Newer Older
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
1
2
import astropy.units as u
import numpy as np
3
import argparse
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
4

5
6
import threading

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
7
8
9
10
11
12
13
import subprocess

from telescope import telescope
from camrasdevices import Receiver, LocalOscillator

import time

14
freq_hi = 1420.405751 * u.MHz
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
15

16
def doppler_harm(sky_coordinate, time, tracking_frequency):
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
17
18
19
20
    dt_lat = np.deg2rad(52.812019)
    dt_lon = np.deg2rad(6.396169)
    dt_alt = 25.0

21
22
23
24
25
26
27
28
29
30
31
32
    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

33
34
35
36
def doppler_vlsr(sky_coordinate, time, tracking_frequency):
    # TODO: finish this function (wrap doppler_frequency from vlsr
    return 42

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
    """

52
53
54
55
    if not lo:
        lo = LocalOscillator();
    if not dt:
        dt = telescope();
56
57
    if not exit_event:
        exit_event = threading.Event()
58

59
    while not exit_event.is_set():
60
61
62
        sky_coordinate = dt.radec
        freq_doppler = doppler_function(sky_coordinate, time.time(), tracking_frequency)
        dfreq = 1*u.GHz + tracking_frequency - freq_doppler
63
        lo.frequency = dfreq
64
        exit_event.wait(timeout=0.5)