Commit 827ed46e authored by marc's avatar marc
Browse files

created startMeasurement method in measurements

parent 5bfff69b
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.6</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
</pydev_project>
......@@ -2,8 +2,8 @@ from __future__ import print_function
import logging
from configparser import ConfigParser
import os.path
import subprocess
import time
from idlelib.dynOptionMenuWidget import _dyn_option_menu
config = ConfigParser()
config.readfp(open(os.path.join(os.path.dirname(__file__), 'measurements.ini')))
......@@ -11,31 +11,29 @@ config.readfp(open(os.path.join(os.path.dirname(__file__), 'measurements.ini')))
logging.basicConfig(level=logging.DEBUG)
class measurements():
def __init__(self,tool=None, integrationTime=None, outputFile=None, radec=None, metaData=None):
def __init__(self):
'''
Initializes a measurement instance.
'''
self._tool = tool
self._tool = None
self._tools = []
self._integrationTime = integrationTime
self._outputFile = outputFile
self._radec = radec
self._integrationTime = 2
self._outputFile = None
self._radec = None
self._startTime = time.strftime("%Y%m%d-%h%m%s")
self._staticMetaData = {"Observer":"CAMRAS","Date" : self._startTime, "RaDEC" : self._radec}
self._dynamicMetaData = {}
'''
Read tools from ini file
Read keys measurement tools from ini file. Value contains the absolute path to the tools.
'''
self._tools.append(config.get('Tools','DumpWide'))
self._tools.append(config.get('Tools','Int32Bin'))
self._tools.append(config.get('Tools','PulsarRecord'))
self._tools.append(config.get('Tools','RawRecord'))
for key in config['Tools']:
self._tools.append(key)
def getTools(self):
'''
read the list of tools to output measurememnts
read the list of tools to output measurements
'''
logging.info('List of measument tools: {}'.format(self._tools))
logging.info('List of measurements tools: {}'.format(self._tools))
return(self._tools)
def getIntegrationTime(self):
......@@ -56,27 +54,47 @@ class measurements():
logging.info('Meta data is: {}'.format(metaData))
return(metaData)
def setTool(self, measProg):
def setMetaData(self,metaData):
self._staticMetaData = metaData
self._dynamicMetaData = None
def startMeasurement(self, tool, integrationTime, outputFile, metaData):
'''
Define the required tool to perform the measurement
'''
self._tool = measProg
logging.info('Used measument tool set to: {}'.format(self._tool))
def setIntegrationTime(self, integrationTime):
self._tool = config["Tools"][tool]
self._integrationTime = integrationTime
logging.info('Integration time set to: {}'.format(self._integrationTime))
def setMetaData(self,metaData):
self._outputFile = outputFile
self._staticMetaData = metaData
self._dynamicMetaData = None
logging.info('Used measument tool set to: {}'.format(self._tool))
logging.info('Integration time set to: {}'.format(self._integrationTime))
logging.info('Output file is: {}'.format(self._outputFile))
'''
Compile CLI and execute command
'''
measCLI = self._tool +" "+ str(self._integrationTime)
logging.info('Excute CLI: {}'.format(measCLI))
'''
Note: in the stub dumpwide I added /bin/bash, otherwise you get an Exec format error.
'''
self.measurement = subprocess.Popen(self._tool, stdout=subprocess.PIPE)
self.measurement.wait()
measResults = self.measurement.stdout
""" Write results into file"""
for line in measResults:
self._outputFile.write(str(line))
if __name__ == '__main__':
myMeas = measurements()
myMeas.getMetaData()
measnum = 123
measFile = open('/tmp/DT-' + '{:03d}'.format(measnum) + "-" + time.strftime("%Y%m%d") + ".dat",'w')
logging.info("Output to file: {}".format(measFile))
for tool in myMeas.getTools():
myMeas.setTool(tool)
myMeas.setIntegrationTime(2)
myMeas.getIntegrationTime()
\ No newline at end of file
myMeas.startMeasurement('dumpwide', 120, measFile, metaData=None)
measFile.close()
\ No newline at end of file
[Tools]
DumpWide: dumpwide
Int32Bin: int32bin
PulsarRecord: pulsarrecord
RawRecord: rawrecord
\ No newline at end of file
dumpwide: /home/marc/bin/dumpwide
int32bin: /usr/bin/int32bin
pulsarrecord: /usr/bin/pulsarrecord
rawrecord: /usr/bin/rawrecord
Supports Markdown
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