Commit a2acaddf authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Use ZMQ instead of UDP

parent 9da9ac32
......@@ -11,7 +11,7 @@ Tammo Jan Dijkema, 29 June 2020
import time
import matplotlib.pyplot as plt
import pandas as pd
import socket
import zmq
import struct
import numpy as np
from telescope import telescope
......@@ -20,6 +20,15 @@ from astropy.time import Time
import astropy.units as u
from matplotlib import cm
import logging
logger = logging.getLogger()
logger.setLevel(level=logging.INFO)
context = zmq.Context()
receiver = context.socket(zmq.PULL)
receiver.connect("tcp://127.0.0.1:5557")
colormap = cm.Greys
dt = telescope(consoleHost='console')
......@@ -28,37 +37,35 @@ cas_a = SkyCoord.from_name("Cassiopeia A")
dwl = EarthLocation(lon=Angle("6:23:46.21 degrees"),
lat=Angle("52:48:43.27 degrees"))
UDP_IP = "127.0.0.1"
UDP_PORT = 7805
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
# create an empty dataframe that will store streaming data
df = pd.DataFrame(np.zeros((0, 2)), columns=["Separation", "Signal"])
SEPARATION_AZ = True
# create plot
plt.ion()
fig, ax = plt.subplots()
ax.set_xlim((-10, 10))
if SEPARATION_AZ:
ax.set_xlim((-6, 6))
else:
ax.set_xlim((0, 6))
#ax.set_ylim((0, None))
ax.set_xlabel("Afstand tot zon (graden)")
ax.set_ylabel("Signaalsterkte (ongekalibreerd)")
fig.canvas.set_window_title('Live waarneming Dwingeloo radiotelescoop op 1330 MHz')
ax.set_title('Live waarneming Dwingeloo radiotelescoop op 1330 MHz')
SEPARATION_AZ = True
while True:
data, addr = sock.recvfrom(1024)
if len(data) != 4:
continue
signal = struct.unpack('f', data)[0]
buff = receiver.recv()
signal = np.frombuffer(buff, dtype="float32")[-1]
#print(signal, flush=True)
# append new row to dataframe
pos = dt.radec
az = dt.az
el = dt.el
if pos is None or az is None:
continue
......@@ -68,8 +75,8 @@ while True:
dwl_altaz = AltAz(location=dwl, obstime=Time.now())
az_sun = get_sun(Time.now()).transform_to(dwl_altaz).az
az_cas = cas_a.transform_to(dwl_altaz).az
separation_sun = (az - az_sun).wrap_at(180*u.deg).degree
separation_cas = (az - az_cas).wrap_at(180*u.deg).degree
separation_sun = (az - az_sun).wrap_at(180*u.deg).degree * np.cos(el)
separation_cas = (az - az_cas).wrap_at(180*u.deg).degree * np.cos(el)
if abs(separation_sun) < abs(separation_cas):
separation = separation_sun
else:
......@@ -87,7 +94,9 @@ while True:
# plot all data
#ax.plot(df["Separation"], df["Signal"], 'k.')
ax.scatter(df["Separation"], df["Signal"], s=3, c=colormap(np.arange(len(df))**2))
ax.scatter(df["Separation"], df["Signal"], s=3, color='black')
ax.scatter(df["Separation"][-2:], df["Signal"][-2:], s=3, color='red')
ax.set_ylim((3000, 1.3 * max(df["Signal"])))
# show the plot
plt.show()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment