track_doppler.py 2.89 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
14
15
import subprocess

from telescope import telescope
from camrasdevices import Receiver, LocalOscillator

import time

16
freq_hi = 1420.405751 * u.MHz
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
17

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
18
def doppler_harm(sky_coordinate, time, tracking_frequency, location, variant):
19
20
    ra  = sky_coordinate.ra.to(u.rad).value
    dec = sky_coordinate.dec.to(u.rad).value
21
22
23
24
    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
25
    argstring = "{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}".format(
26
            ra=ra, dec=dec, time=t, dt_lat=dt_lat, dt_lon=dt_lon, dt_alt=dt_alt)
27

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

    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
35
36
37
38
39
40
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')

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

59
60
61
62
    if not lo:
        lo = LocalOscillator();
    if not dt:
        dt = telescope();
63
64
    if not exit_event:
        exit_event = threading.Event()
65
66
67
68
69
    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)
70

71
    while not exit_event.is_set():
72
        sky_coordinate = dt.radec
73
        freq_doppler = doppler_function(sky_coordinate, Time.now(), tracking_frequency, dt_loc)
74
        dfreq = 1*u.GHz + tracking_frequency - freq_doppler
75
        lo.frequency = dfreq
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
76
        exit_event.wait(timeout=timeout)
77
    lo.frequency = 1*u.GHz