Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
zonnedemo
Commits
b390612b
Commit
b390612b
authored
Jul 02, 2020
by
Tammo Jan Dijkema
Browse files
Use threading for signal
parent
e3e4206e
Changes
1
Hide whitespace changes
Inline
Side-by-side
zonnewaarneming.py
View file @
b390612b
...
...
@@ -19,27 +19,36 @@ from astropy.coordinates import get_sun, SkyCoord, AltAz, EarthLocation, Angle
from
astropy.time
import
Time
import
astropy.units
as
u
from
matplotlib
import
cm
from
threading
import
Thread
import
logging
plt
.
ion
()
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"
)
signal
=
0.
prev_signal
=
0.
colormap
=
cm
.
Greys
def
signal_thread
():
global
signal
context
=
zmq
.
Context
()
receiver
=
context
.
socket
(
zmq
.
PULL
)
receiver
.
connect
(
"tcp://127.0.0.1:5557"
)
while
True
:
buff
=
receiver
.
recv
()
signal
=
np
.
frombuffer
(
buff
,
dtype
=
"float32"
)[
-
1
]
dt
=
telescope
(
consoleHost
=
'console'
)
s
=
Thread
(
target
=
signal_thread
)
s
.
daemon
=
True
s
.
start
()
dt
=
telescope
(
consoleHost
=
'localhost'
)
cas_a
=
SkyCoord
.
from_name
(
"Cassiopeia A"
)
dwl
=
EarthLocation
(
lon
=
Angle
(
"6:23:46.21 degrees"
),
lat
=
Angle
(
"52:48:43.27 degrees"
))
# create an empty dataframe that will store streaming data
df
=
pd
.
DataFrame
(
np
.
zeros
((
0
,
2
)),
columns
=
[
"Separation"
,
"Signal"
])
SEPARATION_AZ
=
True
# create plot
...
...
@@ -50,27 +59,35 @@ if SEPARATION_AZ:
else
:
ax
.
set_xlim
((
0
,
6
))
ax
.
axvline
(
x
=
0
,
linestyle
=
'--'
,
color
=
'grey'
,
linewidth
=
.
5
)
#ax.set_ylim((0, None))
ax
.
set_xlabel
(
"Afstand tot
zon
(graden)"
)
ax
.
set_xlabel
(
"Afstand tot
middelpunt
(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'
)
prev_points
=
None
separation
=
None
maxsignal
=
0.
while
True
:
buff
=
receiver
.
recv
()
signal
=
np
.
frombuffer
(
buff
,
dtype
=
"float32"
)[
-
1
]
#print(signal, flush=True)
time
.
sleep
(
0.2
)
if
signal
==
prev_signal
:
continue
prev_signal
=
signal
# append new row to dataframe
pos
=
dt
.
radec
az
=
dt
.
az
el
=
dt
.
el
if
pos
is
None
or
az
is
None
:
print
(
"No azimuth received!"
)
continue
az
=
Angle
(
az
+
180
*
u
.
deg
)
color
=
'black'
if
SEPARATION_AZ
:
dwl_altaz
=
AltAz
(
location
=
dwl
,
obstime
=
Time
.
now
())
az_sun
=
get_sun
(
Time
.
now
()).
transform_to
(
dwl_altaz
).
az
...
...
@@ -81,26 +98,29 @@ while True:
separation
=
separation_sun
else
:
separation
=
separation_cas
color
=
'blue'
else
:
separation_sun
=
get_sun
(
Time
.
now
()).
separation
(
pos
).
deg
separation_cas
=
cas_a
.
separation
(
pos
).
deg
separation
=
min
(
separation_sun
,
separation_cas
)
if
abs
(
separation
)
>
10
and
len
(
df
)
>
10
:
print
(
signal
,
flush
=
True
)
if
signal
>
maxsignal
:
maxsignal
=
signal
if
abs
(
separation
)
>
10
:
plt
.
pause
(
2
)
print
(
f
"Out of range, separation is
{
separation
:
.
1
f
}
"
)
continue
df
.
loc
[
len
(
df
)]
=
[
separation
,
signal
]
# plot all data
#ax.plot(df["Separation"], df["Signal"], 'k.'
)
ax
.
scatter
(
df
[
"S
eparation
"
],
df
[
"S
ignal
"
],
s
=
3
,
color
=
'black'
)
ax
.
scatter
(
df
[
"S
eparation
"
][
-
2
:],
df
[
"Signal"
][
-
2
:
],
s
=
3
,
color
=
'red'
)
ax
.
set_ylim
((
3000
,
1.3
*
max
(
df
[
"S
ignal
"
])
))
if
prev_points
is
not
None
:
prev_points
.
remove
(
)
ax
.
scatter
(
[
s
eparation
],
[
s
ignal
],
s
=
3
,
color
=
color
)
prev_points
=
ax
.
scatter
(
[
s
eparation
],
[
signal
],
s
=
3
0
,
color
=
'red'
)
ax
.
set_ylim
((
3000
,
1.3
*
max
s
ignal
))
# show the plot
plt
.
show
()
plt
.
pause
(
0.0001
)
# <-- sets the current plot until refreshed
# be nice to the cpu :)
time
.
sleep
(.
1
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment