Commit 34b510d8 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Add progress indicator

parent 711a56a3
...@@ -4,12 +4,13 @@ import logging ...@@ -4,12 +4,13 @@ import logging
from telescope import telescope from telescope import telescope
from PyQt5 import QtGui from PyQt5 import QtGui
from PyQt5.QtCore import QThread, QRunnable, QObject, pyqtSignal, pyqtSlot, QThreadPool from PyQt5.QtCore import QRunnable, QObject, pyqtSignal, pyqtSlot, QThreadPool
from PyQt5.QtWidgets import (QFileDialog, QApplication, QMainWindow, QTableWidgetItem) from PyQt5.QtWidgets import (QFileDialog, QApplication, QMainWindow, QTableWidgetItem)
from ui.dtobswindow import Ui_mainWindow from ui.dtobswindow import Ui_mainWindow
import subprocess import subprocess
import traceback import traceback
import time import time
import numpy as np
from astropy import units as u from astropy import units as u
from astropy.coordinates import SkyCoord from astropy.coordinates import SkyCoord
...@@ -37,7 +38,7 @@ class WorkerSignals(QObject): ...@@ -37,7 +38,7 @@ class WorkerSignals(QObject):
allfinished = pyqtSignal() allfinished = pyqtSignal()
# error = pyqtSignal(tuple) # error = pyqtSignal(tuple)
# result = pyqtSignal(object) # result = pyqtSignal(object)
# progress = pyqtSignal(int) progress = pyqtSignal(int, int, str) # meas_num, percent_complete, remaining
class Worker(QRunnable): class Worker(QRunnable):
""" Execute a function asynchronously, connect to signals """ """ Execute a function asynchronously, connect to signals """
...@@ -51,6 +52,7 @@ class Worker(QRunnable): ...@@ -51,6 +52,7 @@ class Worker(QRunnable):
self.signals = WorkerSignals() self.signals = WorkerSignals()
self.kwargs['oneSetpointCompleteSignal'] = self.signals.finished self.kwargs['oneSetpointCompleteSignal'] = self.signals.finished
self.kwargs['progressSignal'] = self.signals.progress
@pyqtSlot() @pyqtSlot()
def run(self): def run(self):
...@@ -87,7 +89,6 @@ class DTObservationProgram(Ui_mainWindow): ...@@ -87,7 +89,6 @@ class DTObservationProgram(Ui_mainWindow):
(raStr, decStr) = self.radec.to_string('hmsdms').split() (raStr, decStr) = self.radec.to_string('hmsdms').split()
self.tableWidgetPointings.insertRow(rowPosition) self.tableWidgetPointings.insertRow(rowPosition)
#measurement = '{:3d}\t {:3.5f}\t {:3.5f}'.format(int(meas),float(RA), float(Dec))
self.tableWidgetPointings.setItem(rowPosition, 0, QTableWidgetItem(raStr)) self.tableWidgetPointings.setItem(rowPosition, 0, QTableWidgetItem(raStr))
self.tableWidgetPointings.setItem(rowPosition, 1, QTableWidgetItem(decStr)) self.tableWidgetPointings.setItem(rowPosition, 1, QTableWidgetItem(decStr))
self.tableWidgetPointings.setItem(rowPosition, 2, QTableWidgetItem("")) self.tableWidgetPointings.setItem(rowPosition, 2, QTableWidgetItem(""))
...@@ -102,7 +103,6 @@ class DTObservationProgram(Ui_mainWindow): ...@@ -102,7 +103,6 @@ class DTObservationProgram(Ui_mainWindow):
def measCompleted(self, meas_num, status): def measCompleted(self, meas_num, status):
""" Make the meas_num-th row of the table green """ """ Make the meas_num-th row of the table green """
print("One setpoint complete, namely", meas_num, status)
colors = {'Completed': QtGui.QColor('green'), colors = {'Completed': QtGui.QColor('green'),
'Slewing' : QtGui.QColor('yellow'), 'Slewing' : QtGui.QColor('yellow'),
'Measuring': QtGui.QColor('cyan')} 'Measuring': QtGui.QColor('cyan')}
...@@ -111,23 +111,50 @@ class DTObservationProgram(Ui_mainWindow): ...@@ -111,23 +111,50 @@ class DTObservationProgram(Ui_mainWindow):
self.tableWidgetPointings.item(meas_num,column).setBackground(colors[status]) self.tableWidgetPointings.item(meas_num,column).setBackground(colors[status])
self.tableWidgetPointings.resizeColumnsToContents() self.tableWidgetPointings.resizeColumnsToContents()
def goToSetpoints(self, setpoints, oneSetpointCompleteSignal=None): def goToSetpoints(self, setpoints, oneSetpointCompleteSignal=None, progressSignal=None):
""" Send a list of setpoints to the telescope """ """ Send a list of setpoints to the telescope """
for setpoint_nr, setpoint in enumerate(setpoints): for setpoint_nr, setpoint in enumerate(setpoints):
self.myDT.setRaDec(setpoint) self.myDT.setRaDec(setpoint)
oneSetpointCompleteSignal.emit(setpoint_nr, 'Slewing') oneSetpointCompleteSignal.emit(setpoint_nr, 'Slewing')
time.sleep(2) time.sleep(3)
self.myDT.waitUntilThere() 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') oneSetpointCompleteSignal.emit(setpoint_nr, 'Measuring')
time.sleep(2) # Todo: call function here self.doMeasurement(setpoint_nr, progressSignal=progressSignal)
self.startMeasure()
oneSetpointCompleteSignal.emit(setpoint_nr, 'Completed') oneSetpointCompleteSignal.emit(setpoint_nr, 'Completed')
def startMeasure(self): 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.setItem(meas_num, 2, QTableWidgetItem(remaining_str))
def doMeasurement(self, measnum, progressSignal=None):
""" Dumping data into file including meta-data""" """ Dumping data into file including meta-data"""
print("start dump-wide") print("start dump-wide")
data = subprocess.Popen(["cat","/home_local/camrasdemo/test-001.txt"], stdout=subprocess.PIPE).stdout integrationTime = self.spinBoxIntTime.value()
#self.measprog = subprocess.Popen(["cat","/home_local/camrasdemo/test-001.txt"], stdout=subprocess.PIPE)
self.measprog = subprocess.Popen(["sleep", 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()
data = self.measprog.stdout
def startMeasurement(self): def startMeasurement(self):
print("Measurement started") print("Measurement started")
...@@ -137,8 +164,6 @@ class DTObservationProgram(Ui_mainWindow): ...@@ -137,8 +164,6 @@ class DTObservationProgram(Ui_mainWindow):
dec = self.tableWidgetPointings.item(meas, 1).text() dec = self.tableWidgetPointings.item(meas, 1).text()
self.tableWidgetPointings.setItem(meas, 2, QTableWidgetItem("Scheduled")) self.tableWidgetPointings.setItem(meas, 2, QTableWidgetItem("Scheduled"))
for column in range(3):
self.tableWidgetPointings.item(meas,column).setBackground(QtGui.QColor('gray'))
self.tableWidgetPointings.resizeColumnsToContents() self.tableWidgetPointings.resizeColumnsToContents()
setpoint = SkyCoord(ra, dec, frame='icrs') setpoint = SkyCoord(ra, dec, frame='icrs')
setpoints.append(setpoint) setpoints.append(setpoint)
...@@ -146,6 +171,7 @@ class DTObservationProgram(Ui_mainWindow): ...@@ -146,6 +171,7 @@ class DTObservationProgram(Ui_mainWindow):
worker = Worker(self.goToSetpoints, setpoints) worker = Worker(self.goToSetpoints, setpoints)
worker.signals.finished.connect(self.measCompleted) worker.signals.finished.connect(self.measCompleted)
worker.signals.allfinished.connect(self.allCompleted) worker.signals.allfinished.connect(self.allCompleted)
worker.signals.progress.connect(self.updateProgress)
self.threadpool.start(worker) self.threadpool.start(worker)
def stopMeasurement(self): def stopMeasurement(self):
...@@ -160,3 +186,4 @@ if __name__ == '__main__': ...@@ -160,3 +186,4 @@ if __name__ == '__main__':
mainWindow.show() mainWindow.show()
sys.exit(app.exec_()) sys.exit(app.exec_())
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