track_doppler.py 2.16 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, location):
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    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:
36
37
38
39
40
41
        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
42
43
    """

44
45
46
47
    if not lo:
        lo = LocalOscillator();
    if not dt:
        dt = telescope();
48
49
    if not exit_event:
        exit_event = threading.Event()
50
51
52
53
54
    dt_lat = 52.812019 * u.deg
    dt_lon = 6.396169 * u.deg
    dt_alt = 25.0 * u.m

    dt_loc = EarthLocation.from_geodetic(lat = dt_lat, lon = dt_lon, height = dt_alt)
55

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