track_doppler.py 2.83 KB
Newer Older
1
2
from typing import Any, Union

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
3
import astropy.units as u
4
from astropy.coordinates import EarthLocation
5
from astropy.time import Time
6
import threading
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
7
8
import subprocess

9
from vlsr import doppler_frequency
10
from camrasdevices import LocalOscillator
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
11

12
freq_hi = 1420.405751 * u.MHz
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
13

14

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

25
    doppler_executable = "/home/harm/bin/doppler_" + variant
26

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())
33
34
35

    return freq_doppler * u.MHz

36

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

40

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
41
42
43
def doppler_harm_mb(sky_coordinate, time, tracking_frequency, location):
    return doppler_harm(sky_coordinate, time, tracking_frequency, location, 'mb')

44

45
def track_doppler(dt, lo,
46
                  tracking_frequency=freq_hi,
47
                  doppler_function=doppler_frequency,
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
48
                  exit_event=None,
49
                  timeout=0.3):
50
51
    """Sets the Local Oscillator to a frequency to correct for Doppler shift. When exit event is
    set, return the LO frequency to 1GHz.
52

53
    Args:
54
        dt (Telescope): a Telescope instance to read the current pointing from.
55
        lo (LocalOscillator): the local oscillator of which the frequency will be set.
56
57
        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
58
        timeout (float): timeout between updates of the Local Oscillator
59
60
    """

61
62
    if not exit_event:
        exit_event = threading.Event()
63
64
65
66
    dt_lat = 52.812019 * u.deg
    dt_lon = 6.396169 * u.deg
    dt_alt = 25.0 * u.m

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

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