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
HPIB
Commits
68615186
Commit
68615186
authored
Apr 23, 2018
by
Tammo Jan Dijkema
Browse files
Use astropy quantities for camrasdevice setter and getter, use custom function for tracking
parent
f45c2cc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
camrasdevices.py
View file @
68615186
import
hpib
import
hpib
from
hpib
import
HpibDevice
from
hpib
import
HpibDevice
import
astropy.units
as
u
from
astropy.units
import
Quantity
import
threading
import
threading
class
CamrasHpibDevice
(
HpibDevice
):
class
CamrasHpibDevice
(
HpibDevice
):
...
@@ -17,15 +19,18 @@ class CamrasHpibDevice(HpibDevice):
...
@@ -17,15 +19,18 @@ class CamrasHpibDevice(HpibDevice):
@
property
@
property
def
frequency
(
self
):
def
frequency
(
self
):
"""Returns the frequency (in Hz) of the device. Throws a RuntimeError if no response"""
"""Returns the frequency of the device as an astropy Quantity.
Throws a RuntimeError if no response"""
freq_str
=
self
.
query
(
"freq?"
)
freq_str
=
self
.
query
(
"freq?"
)
if
len
(
freq_str
)
==
0
:
if
len
(
freq_str
)
==
0
:
raise
RuntimeError
(
"Camras device at address {} is not responding"
.
format
(
self
.
_hpib_address
))
raise
RuntimeError
(
"Camras device at address {} is not responding"
.
format
(
self
.
_hpib_address
))
return
int
(
float
(
self
.
query
(
"freq?"
)))
return
int
(
float
(
self
.
query
(
"freq?"
)))
*
u
.
Hz
@
frequency
.
setter
@
frequency
.
setter
def
frequency
(
self
,
freq
):
def
frequency
(
self
,
freq
):
"""Set the device to the specified frequency. Throws a RuntimeError if failed"""
"""Set the device to the specified frequency. Throws a RuntimeError if failed"""
if
isinstance
(
freq
,
Quantity
):
freq
=
freq
.
to
(
u
.
Hz
).
value
self
.
command
(
"freq {:d} Hz"
.
format
(
int
(
freq
)))
self
.
command
(
"freq {:d} Hz"
.
format
(
int
(
freq
)))
new_freq
=
self
.
frequency
new_freq
=
self
.
frequency
if
int
(
new_freq
)
!=
int
(
freq
):
if
int
(
new_freq
)
!=
int
(
freq
):
...
...
track_doppler.py
View file @
68615186
...
@@ -11,17 +11,40 @@ from camrasdevices import Receiver, LocalOscillator
...
@@ -11,17 +11,40 @@ from camrasdevices import Receiver, LocalOscillator
import
time
import
time
freq_hi
=
1420.405751
freq_hi
=
1420.405751
*
u
.
MHz
def
track_doppler
(
lo
=
None
,
dt
=
None
,
def
doppler_harm
(
sky_coordinate
,
time
,
tracking_frequency
):
tracking_frequency
=
freq_hi
,
doppler_executable
=
"/home/harm/bin/doppler_mb"
,
exit_event
=
None
):
"""Sets the Local Oscillator to a frequency to correct for Doppler shift"""
dt_lat
=
np
.
deg2rad
(
52.812019
)
dt_lat
=
np
.
deg2rad
(
52.812019
)
dt_lon
=
np
.
deg2rad
(
6.396169
)
dt_lon
=
np
.
deg2rad
(
6.396169
)
dt_alt
=
25.0
dt_alt
=
25.0
ra
=
sky_coordinate
.
ra
.
to
(
u
.
rad
).
value
dec
=
sky_coordinate
.
dec
.
to
(
u
.
rad
).
value
argstring
=
"{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}"
.
format
(
ra
=
ra
,
dec
=
dec
,
time
=
time
,
dt_lat
=
dt_lat
,
dt_lon
=
dt_lon
,
dt_alt
=
dt_alt
)
doppler_executable
=
"/home/harm/bin/doppler_mb"
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
def
track_doppler
(
lo
=
None
,
dt
=
None
,
tracking_frequency
=
freq_hi
,
doppler_function
=
doppler_harm
,
exit_event
=
None
):
"""Sets the Local Oscillator to a frequency to correct for Doppler shift
Args:
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
"""
if
not
lo
:
if
not
lo
:
lo
=
LocalOscillator
();
lo
=
LocalOscillator
();
if
not
dt
:
if
not
dt
:
...
@@ -30,14 +53,8 @@ def track_doppler(lo=None, dt=None,
...
@@ -30,14 +53,8 @@ def track_doppler(lo=None, dt=None,
exit_event
=
threading
.
Event
()
exit_event
=
threading
.
Event
()
while
not
exit_event
.
is_set
():
while
not
exit_event
.
is_set
():
ra
=
dt
.
radec
.
ra
.
to
(
u
.
rad
).
value
sky_coordinate
=
dt
.
radec
dec
=
dt
.
radec
.
dec
.
to
(
u
.
rad
).
value
freq_doppler
=
doppler_function
(
sky_coordinate
,
time
.
time
(),
tracking_frequency
)
t
=
time
.
time
()
dfreq
=
1
*
u
.
GHz
+
tracking_frequency
-
freq_doppler
argstring
=
"{ra} {dec} 2000 {time} {dt_lat} {dt_lon} {dt_alt}"
.
format
(
ra
=
ra
,
dec
=
dec
,
time
=
t
,
dt_lat
=
dt_lat
,
dt_lon
=
dt_lon
,
dt_alt
=
dt_alt
)
doppler_cmd
=
doppler_executable
+
" "
+
argstring
+
" "
+
str
(
tracking_frequency
)
freq_doppler
=
float
(
subprocess
.
Popen
(
doppler_cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
).
stdout
.
read
())
dfreq
=
1000.0
+
tracking_frequency
-
freq_doppler
lo
.
frequency
=
dfreq
*
1e6
lo
.
frequency
=
dfreq
*
1e6
exit_event
.
wait
(
timeout
=
0.5
)
exit_event
.
wait
(
timeout
=
0.5
)
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