track_doppler.py 2.7 KB
Newer Older
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
1
import astropy.units as u
2
3
from astropy.coordinates import SkyCoord, EarthLocation
from astropy.time import Time
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
4
import numpy as np
5
import argparse
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
6

7
8
import threading

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

from telescope import telescope
from camrasdevices import Receiver, LocalOscillator

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

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
16
def doppler_harm(sky_coordinate, time, tracking_frequency, location, variant):
17
18
    ra  = sky_coordinate.ra.to(u.rad).value
    dec = sky_coordinate.dec.to(u.rad).value
19
20
21
22
    t = time.unix
    dt_lat = location.lat.to(u.rad).value
    dt_lon = location.lon.to(u.rad).value
    dt_alt = location.height.to(u.m).value
23
    argstring = "{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}".format(
24
            ra=ra, dec=dec, time=t, dt_lat=dt_lat, dt_lon=dt_lon, dt_alt=dt_alt)
25

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
26
    doppler_executable = "/home/harm/bin/doppler_"+variant
27
28
29
30
31
32

    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

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
33
34
35
36
37
38
def doppler_harm_bl(sky_coordinate, time, tracking_frequency, location):
    return doppler_harm(sky_coordinate, time, tracking_frequency, location, 'bl')

def doppler_harm_mb(sky_coordinate, time, tracking_frequency, location):
    return doppler_harm(sky_coordinate, time, tracking_frequency, location, 'mb')

39
def track_doppler(dt, lo,
40
                  tracking_frequency=freq_hi,
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
41
                  doppler_function=doppler_harm_bl,
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
42
43
                  exit_event=None,
                  timeout=0.5):
44
45
    """Sets the Local Oscillator to a frequency to correct for Doppler shift. When exit event is
    set, return the LO frequency to 1GHz.
46
47
    
    Args:
48
        dt (Telescope): a Telescope instance to read the current pointing from.
49
        lo (LocalOscillator): the local oscillator of which the frequency will be set.
50
51
        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
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
52
        timeout (float): timeout between updates of the Local Oscillator
53
54
    """

55
56
    if not exit_event:
        exit_event = threading.Event()
57
58
59
60
61
    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)
62

63
    while not exit_event.is_set():
64
        sky_coordinate = dt.radec
65
66
67
68
        if sky_coordinate:
            freq_doppler = doppler_function(sky_coordinate, Time.now(), tracking_frequency, dt_loc)
            dfreq = 1*u.GHz + tracking_frequency - freq_doppler
            lo.frequency = dfreq
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
69
        exit_event.wait(timeout=timeout)
70
    lo.frequency = 1*u.GHz