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
marc
dtObsGUI
Commits
a18e8d03
Commit
a18e8d03
authored
Oct 09, 2017
by
marc
Browse files
added meta data Observer and Description
parent
c0697dba
Changes
1
Hide whitespace changes
Inline
Side-by-side
DTObs.py
0 → 100644
View file @
a18e8d03
#!/usr/bin/env python3
import
sys
import
csv
import
logging
import
subprocess
import
traceback
import
time
import
numpy
as
np
from
PyQt5
import
QtGui
from
PyQt5.QtCore
import
QRunnable
,
QObject
,
pyqtSignal
,
pyqtSlot
,
QThreadPool
from
PyQt5.QtWidgets
import
(
QFileDialog
,
QApplication
,
QMainWindow
,
QTableWidgetItem
)
from
ui.dtobswindow
import
Ui_mainWindow
from
telescope
import
telescope
from
astropy
import
units
as
u
from
astropy.coordinates
import
SkyCoord
class
WorkerSignals
(
QObject
):
"""
Defines the signals available from a running worker thread.
Supported signals are:
finished
`int` of the setpoint number
error
`tuple` (exctype, value, traceback.format_exc() )
result
`object` data returned from processing, anything
progress
`int` inicating % progress
"""
finished
=
pyqtSignal
(
int
,
str
)
allfinished
=
pyqtSignal
()
# error = pyqtSignal(tuple)
# result = pyqtSignal(object)
progress
=
pyqtSignal
(
int
,
int
,
str
)
# meas_num, percent_complete, remaining
class
Worker
(
QRunnable
):
""" Execute a function asynchronously, connect to signals """
def
__init__
(
self
,
function_to_run
,
*
args
,
**
kwargs
):
super
(
Worker
,
self
).
__init__
()
# Store arguments
self
.
function_to_run
=
function_to_run
self
.
args
=
args
self
.
kwargs
=
kwargs
self
.
signals
=
WorkerSignals
()
self
.
kwargs
[
'oneSetpointCompleteSignal'
]
=
self
.
signals
.
finished
self
.
kwargs
[
'progressSignal'
]
=
self
.
signals
.
progress
@
pyqtSlot
()
def
run
(
self
):
""" Initialize the runner function with passed args, kwargs """
self
.
function_to_run
(
*
self
.
args
,
**
self
.
kwargs
)
self
.
signals
.
allfinished
.
emit
()
class
DTObservationProgram
(
Ui_mainWindow
):
def
__init__
(
self
,
mainWindow
):
self
.
radec
=
None
Ui_mainWindow
.
__init__
(
self
)
self
.
setupUi
(
mainWindow
)
self
.
actionOpen
.
triggered
.
connect
(
self
.
openFileNameDialog
)
self
.
actionClose
.
triggered
.
connect
(
self
.
closeMeasurement
)
self
.
actionQuit
.
triggered
.
connect
(
self
.
quitDTObs
)
self
.
pushButtonStartMeasurement
.
clicked
.
connect
(
self
.
startMeasurement
)
self
.
pushButtonStopMeasurement
.
clicked
.
connect
(
self
.
stopMeasurement
)
#self.myDT = telescope(setmode='J2000', consoleHost='consoledemo.dmz.camras.nl')
self
.
threadpool
=
QThreadPool
()
def
openFileNameDialog
(
self
):
'''
Clear tableWidget and read pointings from file
'''
fileName
,
_
=
QFileDialog
.
getOpenFileName
(
None
,
'Open File'
,
'/home/marc/git/CAMRASTools/DTObs'
)
if
fileName
:
reader
=
csv
.
reader
(
open
(
fileName
),
delimiter
=
'
\t
'
)
rowPosition
=
self
.
tableWidgetPointings
.
rowCount
()
for
meas
,
ra
,
dec
in
reader
:
self
.
radec
=
SkyCoord
(
float
(
ra
)
*
u
.
degree
,
float
(
dec
)
*
u
.
degree
,
frame
=
'icrs'
)
(
raStr
,
decStr
)
=
self
.
radec
.
to_string
(
'hmsdms'
).
split
()
self
.
tableWidgetPointings
.
insertRow
(
rowPosition
)
self
.
tableWidgetPointings
.
setItem
(
rowPosition
,
0
,
QTableWidgetItem
(
raStr
))
self
.
tableWidgetPointings
.
setItem
(
rowPosition
,
1
,
QTableWidgetItem
(
decStr
))
self
.
tableWidgetPointings
.
setItem
(
rowPosition
,
2
,
QTableWidgetItem
(
""
))
rowPosition
+=
1
self
.
tableWidgetPointings
.
resizeColumnsToContents
()
def
closeMeasurement
(
self
):
for
rowPosition
in
range
(
self
.
tableWidgetPointings
.
rowCount
(),
-
1
,
-
1
):
self
.
tableWidgetPointings
.
removeRow
(
rowPosition
)
def
quitDTObs
(
self
):
sys
.
exit
(
app
.
exec_
())
def
allCompleted
(
self
):
""" Callback function when all pointings completed """
print
(
"All pointings completed"
)
def
measCompleted
(
self
,
meas_num
,
status
):
""" Make the meas_num-th row of the table green """
colors
=
{
'Completed'
:
QtGui
.
QColor
(
'green'
),
'Slewing'
:
QtGui
.
QColor
(
'yellow'
),
'Measuring'
:
QtGui
.
QColor
(
'cyan'
)}
self
.
tableWidgetPointings
.
item
(
meas_num
,
2
).
setText
(
status
)
for
column
in
range
(
3
):
self
.
tableWidgetPointings
.
item
(
meas_num
,
column
).
setBackground
(
colors
[
status
])
self
.
tableWidgetPointings
.
resizeColumnsToContents
()
def
goToSetpoints
(
self
,
setpoints
,
oneSetpointCompleteSignal
=
None
,
progressSignal
=
None
):
""" Send a list of setpoints to the telescope """
for
setpoint_nr
,
setpoint
in
enumerate
(
setpoints
):
self
.
myDT
.
setRaDec
(
setpoint
)
oneSetpointCompleteSignal
.
emit
(
setpoint_nr
,
'Slewing'
)
time
.
sleep
(
3
)
dist
=
np
.
sqrt
(
self
.
myDT
.
dist_el
**
2
+
self
.
myDT
.
dist_az
**
2
)
firstDist
=
dist
while
not
dist
<
0.01
*
u
.
deg
:
percentSlew
=
max
(
100
-
dist
/
firstDist
*
100
,
0
)
progressSignal
.
emit
(
setpoint_nr
,
percentSlew
,
"{:.3f}°"
.
format
(
dist
.
value
))
#print("{:.3f}".format(dist))
#print("{:2.0f}".format(percentSlew.value))
self
.
myDT
.
getDistance
(
waitForUpdate
=
True
)
dist
=
np
.
sqrt
(
self
.
myDT
.
dist_el
**
2
+
self
.
myDT
.
dist_az
**
2
)
oneSetpointCompleteSignal
.
emit
(
setpoint_nr
,
'Measuring'
)
self
.
doMeasurement
(
setpoint_nr
,
progressSignal
=
progressSignal
)
oneSetpointCompleteSignal
.
emit
(
setpoint_nr
,
'Completed'
)
def
updateProgress
(
self
,
meas_num
,
progress_percent
,
remaining_str
):
"""
Update the table with some progress indicator
meas_num: the row which needs to be updated
progress_percent: integer giving the percentage complete
remaining_str: string indicating how much remaining, e.g. "1:30" or "3°"
"""
#self.tableWidgetPointings.item(meas_num, 2).setText(remaining_str)
self
.
tableWidgetPointings
.
item
(
meas_num
,
2
).
setText
(
str
(
progress_percent
)
+
"%"
)
def
doMeasurement
(
self
,
measnum
,
progressSignal
=
None
):
"""
Dumping data into file including meta-data
measProgramm: cli command read from comboBoxProgramma
integrationTime: string read from spinBoxIntTime
measprog: result of measurement of which
data: is the stdout result which need to be stored line by line
measFile: result file stroing the stdout results including meta data
"""
measFile
=
open
(
"Obs/DT-"
+
str
(
measnum
)
+
"-"
+
time
.
strftime
(
"%Y%m%d"
)
+
".dat"
,
'w'
)
print
(
"Output to file:"
,
measFile
)
integrationTime
=
self
.
spinBoxIntTime
.
value
()
measProgramme
=
self
.
comboBoxProgramma
.
currentText
()
""" Write meta data into measFile"""
measFile
.
write
(
"#Time: "
+
time
.
strftime
(
"%h%m%s"
)
+
"
\n
"
)
measFile
.
write
(
"#Observer: CAMRAS
\n
"
)
measFile
.
write
(
"#RA: xyz
\n
"
)
measFile
.
write
(
"#Dec: xyz
\n
"
)
measFile
.
write
(
"#Integration time: "
+
str
(
integrationTime
)
+
"
\n
"
)
measFile
.
write
(
"#Programme: "
+
measProgramme
+
"
\n
"
)
self
.
measprog
=
subprocess
.
Popen
([
"cat"
,
"test.dat"
,
str
(
integrationTime
)],
stdout
=
subprocess
.
PIPE
)
for
sec
in
range
(
integrationTime
):
remainstring
=
str
(
int
((
integrationTime
-
sec
)
/
60
))
+
":"
remainstring
+=
"{:02}"
.
format
((
integrationTime
-
sec
)
%
60
)
progressSignal
.
emit
(
measnum
,
int
(
float
(
sec
)
/
integrationTime
*
100
),
remainstring
)
time
.
sleep
(
1
)
self
.
measprog
.
wait
()
measResults
=
self
.
measprog
.
stdout
""" Write results into file"""
for
line
in
measResults
:
measFile
.
write
(
str
(
line
))
measFile
.
close
()
def
startMeasurement
(
self
):
print
(
"Measurement started"
)
setpoints
=
[]
for
meas
in
range
(
0
,
self
.
tableWidgetPointings
.
rowCount
()):
ra
=
self
.
tableWidgetPointings
.
item
(
meas
,
0
).
text
()
dec
=
self
.
tableWidgetPointings
.
item
(
meas
,
1
).
text
()
self
.
tableWidgetPointings
.
item
(
meas
,
2
).
setText
(
"Scheduled"
)
self
.
tableWidgetPointings
.
resizeColumnsToContents
()
setpoint
=
SkyCoord
(
ra
,
dec
,
frame
=
'icrs'
)
setpoints
.
append
(
setpoint
)
worker
=
Worker
(
self
.
goToSetpoints
,
setpoints
)
worker
.
signals
.
finished
.
connect
(
self
.
measCompleted
)
worker
.
signals
.
allfinished
.
connect
(
self
.
allCompleted
)
worker
.
signals
.
progress
.
connect
(
self
.
updateProgress
)
self
.
threadpool
.
start
(
worker
)
def
stopMeasurement
(
self
):
print
(
"Measurement stopped"
)
if
__name__
==
'__main__'
:
app
=
QApplication
(
sys
.
argv
)
mainWindow
=
QMainWindow
()
prog
=
DTObservationProgram
(
mainWindow
)
mainWindow
.
show
()
sys
.
exit
(
app
.
exec_
())
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