Package dics :: Module dcs
[hide private]
[frames] | no frames]

Source Code for Module dics.dcs

  1  from Ultracam import * 
  2  import logging 
  3   
4 -class dcs:
5 """ 6 Class which provides an interface to the DAZLE detector control system. 7 """
8 - def __init__(self, camera_url, filesave_url, name='dcs'):
9 """ 10 Arguments: 11 12 cameraURL: URL of the camera task on the dectector control computer 13 e.g. 'optics26:7063' 14 filesaveURL: URL of the filesave task on the detector control computer 15 e.g. 'optics26:5417' 16 name: Indentifier used for logging purposes. 17 """ 18 self.name = name 19 self.logger = logging.getLogger(name) 20 21 # Create an Ultracam object and initialise it. 22 self.logger.info('Connecting to DCS...') 23 self.uc = Ultracam(camera_url, filesave_url) 24 if self.uc.initialise(): 25 self.logger.info('DCS initialised.') 26 else: 27 self.logger.critical('Failed to initialise DCS!') 28 29 # Do we need to RCO and RST too? Test scripts don't. 30 self.RCO() 31 self.RST() 32 33 # Check that everything is OK. 34 cstate, cstatus, fstate, fstatus = self.uc.getStatus() 35 if cstatus == 'OK' and fstatus == 'OK': 36 self.logger.debug('DCS status: %s %s %s %s' % \ 37 (cstate, cstatus, fstate, fstatus)) 38 else: 39 self.logger.warning('DCS status: %s %s %s %s' % \ 40 (cstate, cstatus, fstate, fstatus))
41
42 - def getStatus(self):
43 """ 44 Queries the state and status of the camera and filesave processes, 45 and returns a tuple of (cstate, cstatus, fstate, fstatus). 46 """ 47 return self.uc.getStatus()
48
49 - def powerOn(self):
50 """ 51 Powers on the detector. 52 """ 53 self.logger.debug('powerOn() called.') 54 # Load the relevant app. 55 pon = self.uc.getApplication('dazle_pon_app.xml') 56 # Execute it. 57 state, status = self.uc.execute(pon) 58 # Verify it worked. 59 self.uc.wait_for_idle() 60 if state == 'IDLE' and status == 'OK': 61 self.logger.debug('Detector powered on.') 62 else: 63 self.logger.critical('Power on failed, state: %s, status: %s' % \ 64 (state, status))
65
66 - def powerOff(self):
67 """ 68 Powers off the detector. 69 """ 70 self.logger.debug('powerOff() called.') 71 # Load the relevant app. 72 pof = self.uc.getApplication('dazle_pof_app.xml') 73 # Execute it. 74 state, status = self.uc.execute(pof) 75 # Verify it worked. 76 self.uc.wait_for_idle() 77 if state == 'IDLE' and status == 'OK': 78 self.logger.debug('Detector powered off.') 79 else: 80 self.logger.critical('Power off failed, state: %s, status: %s' % \ 81 (state, status))
82
83 - def RCO(self):
84 """ 85 Executes the 'RCO' command, whatever that does... 86 """ 87 state, status = self.uc.RCO() 88 if status == 'OK': 89 self.logger.debug('RCO successful.') 90 else: 91 self.logger.critical('RCO failed, state: %s, status: %s' % \ 92 (state, status))
93 - def RST(self):
94 """ 95 Executes the 'RST' command, whatever that does... 96 """ 97 state, status = self.uc.RST() 98 if status == 'OK': 99 self.logger.debug('RST successful.') 100 else: 101 self.logger.critical('RST failed, state: %s, status: %s' % \ 102 (state, status))
103
104 - def dummy(self, DWELL=1, NUM_EXPS=1):
105 """ 106 Executes the dummy SRR application written by the ATC to generate 107 a frame of fake data. 108 """ 109 self.logger.debug('dummy(DWELL=%i, NUM_EXPS=%i) called.' \ 110 % (DWELL, NUM_EXPS)) 111 self.__doExposure('dazle_dummy_app.xml', DWELL, NUM_EXPS)
112
113 - def SRR(self, DWELL=1, NUM_EXPS=1):
114 """ 115 Executes the SRR application to take a single raw read frame (or 116 take multiple single raw reads and average them, if NUM_EXPS!=1). 117 """ 118 self.logger.debug('SRR(DWELL=%i, NUM_EXPS%i) called.' \ 119 % (DWELL, NUM_EXPS)) 120 self.__doExposure('dazle_srr_app.xml', DWELL, NUM_EXPS)
121
122 - def CDS(self, DWELL=1, NUM_EXPS=1):
123 """ 124 Executes the CDS application to take a correllated double sampling 125 exposure (or take multiple CDS exposures and average them, if 126 NUM_EXPS!=1). 127 """ 128 self.logger.debug('CDS(DWELL=%i, NUM_EXPS=%i) called.' \ 129 % (DWELL, NUM_EXPS)) 130 self.__doExposure('dazle_cds_app.xml', DWELL, NUM_EXPS)
131
132 - def NDR(self, DWELL, NUM_READ, NUM_EXPS):
133 """ 134 Executes the 'sample up the ramp' non-destructive read application 135 (or do this multiple times and average the result is NUM_EXPS!=1). 136 """ 137 self.logger.debug('NDR(DWELL=%i, NUM_READ=%i, NUM_EXPS=%i) called.' \ 138 % (DWELL, NUM_READ, NUM_EXPS)) 139 self.__doExposure('dazle_ndr_app.xml', DWELL, NUM_EXPS, NUM_READ)
140
141 - def __doExposure(self, appname, DWELL, NUM_EXPS, NUM_READ=None):
142 app = self.uc.getApplication(appname) 143 if not app.setparam('DWELL', DWELL): 144 self.logger.warning("Couldn't set DWELL!") 145 if not app.setparam('NUM_EXPS', NUM_EXPS): 146 self.logger.warning("Couldn't set NUM_EXPS!") 147 if NUM_READ and not app.setparam('NUM_READ', NUM_READ): 148 self.logger.warning("Couldn't set NUM_READ!") 149 self.uc.wait_for_idle() 150 cstate, cstatus = self.uc.execute(app) 151 fstate, fstatus, filename = self.uc.getFStatus() 152 if cstatus == 'OK' and fstatus == 'OK': 153 self.logger.debug(\ 154 'cstate: %s, cstatus: %s, fstate: %s, fstatus: %s.' % \ 155 (cstate, cstatus, fstate, fstatus)) 156 self.logger.info('Wrote data to %s.*.' % filename) 157 else: 158 self.logger.critical(\ 159 'Problem taking exposure, ' + \ 160 'cstate: %s, cstatus: %s, fstate: %s, fstatus: %s, file: %s.' \ 161 % (cstate, cstatus, fstate, fstatus, file))
162