def _startRaw(self, target): """Target is the raw value, i.e. a list of positions.""" moveables = self._attached_moveables if not isinstance(target, (tuple, list)) or \ len(target) < len(moveables): raise InvalidValueError( self, 'doStart needs a tuple of %d ' 'positions for this device!' % len(moveables)) # only check and move the moveables, which are first in self.devices for d, t in zip(moveables, target): if not d.isAllowed(t): raise InvalidValueError( self, 'target value %r not accepted ' 'by device %s' % (t, d.name)) # Move first in all needed blades into the beam to reduce the # activation of sample and/or save the detector and them move out the # not needed ones for d, t in zip(moveables, target): self.log.debug('moving %r to %r', d, t) if t == 'in': d.start(t) for d, t in zip(moveables, target): self.log.debug('moving %r to %r', d, t) if t == 'out': d.start(t) if self.blockingmove: multiWait(moveables)
def _read(self): if not self.cid: raise InvalidValueError(self, 'Connection lost to CARESS') if hasattr(self._caressObject, 'read_module'): # result = self._caressObject.read_module(0x80000000, self.cid) result, state, val = self._caressObject.read_module(0, self.cid) if result != CARESS.OK: raise CommunicationError( self, 'Could not read the CARESS module: %d' % self.cid) if hasattr(val, 'f'): return (state, val.f) return ( state, val.l, ) else: _ = () self.log.debug('read module: %d', self.cid) l, result = self._caressObject.read_module_orb(0, self.cid, _) self.log.debug('read_module: %d, %r', l, result) if l != 0: raise CommunicationError( self, 'Could not read the CARESS module: %d' % self.cid) if result[0].value() != self.cid: raise CommunicationError( self, 'Answer from wrong module!: %d %r' % (self.cid, result[0])) state = result[1].value() if state == OFF_LINE: raise NicosError(self, 'Module is off line!') if result[2].value() < 1: raise InvalidValueError(self, 'No position in data') return state, result[4].value()
def _check_shutter(self): if (self.ctrl_photoshutter and self._attached_photoshutter.read() == CLOSED): raise InvalidValueError(self, 'photo shutter not open after ' 'exposure, check safety system') if (self.ctrl_gammashutter and self._attached_gammashutter.read() == CLOSED): raise InvalidValueError(self, 'gamma shutter not open after ' 'exposure, check safety system')
def _write_command(self, command): ret = self._dev.communicate(command) if not ret.startswith('ACK'): if ret.startswith('ERR'): raise InvalidValueError(self, 'Command: %s is invalid ' % command) raise InvalidValueError( self, 'Command: %s has invalid ' 'parameters' % command)
def doStart(self, target): if self._subprocess is not None: raise InvalidValueError('Process is still running') fullargs = list(self.args) fullargs.insert(0, self.subprocess) self._subprocess = createSubprocess(fullargs)
def _extractPos(self, hkle): ki = self._attached_mono.read(0) kf = self._attached_ana.read(0) if self.inelastic: if self.emode == 'FKI': kf = ki - hkle[3] else: ki = kf + hkle[3] ki = to_k(ki, self._attached_mono.unit) kf = to_k(kf, self._attached_ana.unit) qepos = tasQEPosition(ki, kf, hkle[0], hkle[1], hkle[2], 0) ub = session.experiment.sample.getUB() try: angpos = calcTasQAngles(ub, np.array(self.plane_normal), self.scattering_sense, 0, qepos) except RuntimeError as xx: raise InvalidValueError(xx) from None poslist = [('a3', angpos.a3), ('a4', angpos.sample_two_theta)] if self.inelastic: poslist.append(('mono', from_k(ki, self._attached_mono.unit))) poslist.append(('ana', from_k(kf, self._attached_ana.unit))) if self.out_of_plane: poslist.append(('sgu', angpos.sgu)) poslist.append(('sgl', angpos.sgl)) return poslist
def modify_reflection(self, idx, Qpos=None, angles=None, aux=None): oldref = self.get_reflection(idx) if not Qpos: Qpos = oldref[0] if len(Qpos) != len(oldref[0]): raise InvalidValueError('Expected %d values for Q, got %d' % (len(oldref[0]), len(Qpos))) if not angles: angles = oldref[1] if len(angles) != len(oldref[1]): raise InvalidValueError('Expected %d angles, got %d' % (len(oldref[1]), len(angles))) if not aux: aux = oldref[2] if len(aux) != len(oldref[2]): raise InvalidValueError('Expected %d auxiliaries, got %d' % (len(oldref[2]), len(aux))) reflist = list(self.reflection_list) reflist[idx] = (Qpos, angles, aux) self.reflection_list = reflist
def append(self, Qpos=None, angles=None, aux=None): if not Qpos and not angles: raise InvalidValueError('One of reciprocal coordinates ' 'or angles must be given') if not Qpos: Qpos = (0,)*self._hkl_len if len(Qpos) != self._hkl_len: raise InvalidValueError('Reciprocal coordinates mismatch, ' 'need %d, got %d' % (self._hkl_len, len(Qpos))) if not angles: angles = (0,)*self._angle_len if len(angles) != self._angle_len: raise InvalidValueError('Angle settings mismatch, ' 'need %d, got %d' % (self._angle_len, len(angles))) if not aux: aux = () reflist = list(self.reflection_list) reflist.append((Qpos, angles, aux)) self.reflection_list = reflist
def setEnergy(self, radiation=None, **value): """Either load the predefined settings that are suitable for usage with silver, chromium, copper or molybdenum radiation or set the x-ray and threshold energy to any other appropriate values. :param str radiation: 'Ag', 'Cr', 'Cu' or 'Mo' (case insensitive) :param dict[str, float] value: {'xray': x, 'threshold': y} """ if not (radiation or value) or radiation and value: raise InvalidValueError('call either dev.SetEnergy("<radiation>") ' 'or dev.SetEnergy(xray=x, threshold=y)') if radiation: self._dev.LoadEnergySettings(radiation) else: self.energy = value
def _readblock(self): if hasattr(self._caressObject, 'readblock_module') and \ hasattr(self._caressObject, 'readblock_params'): _type = CARESS.TypeLong _start = 0 _end = 0 try: result, _start, _end, _type = \ self._caress_guard(self._caressObject.readblock_params, READBLOCK_NORMAL, self.cid, _start, _end, _type) if result != CARESS.OK: raise CommunicationError( self, 'Could not read the CARESS ' 'module') result, _status, data = \ self._caress_guard(self._caressObject.readblock_module, READBLOCK_NORMAL, self.cid, _start, _end) if result != CARESS.OK: raise CommunicationError( self, 'Could not read the CARESS ' 'module') # self.log.warning('%r', data) return [self._width, self._height, 1] + data.al except CORBA.COMM_FAILURE as ex: raise CommunicationError( self, 'Could not read the CARESS ' 'module : %s' % (ex, )) else: _ = () result = self._caress_guard(self._caressObject.read_module_orb, 0, self.cid, _) self.log.debug('read_module: %r', result) if result[0] != 0: raise CommunicationError(self, 'Could not read the CARESS module') if result[1][0].value() != self.cid: raise NicosError( self, 'Answer from wrong module!: %d %r' % (self.cid, result[1][0])) if result[1][1].value() == OFF_LINE: raise NicosError(self, 'Module is off line!') if result[1][2].value() < 1: raise InvalidValueError(self, 'No position in data') return result[1][1].value(), result[1][4].value()
def get_reflection(self, idx): if idx < 0 or idx > len(self.reflection_list): raise InvalidValueError('NO reflection with ' 'index %d found' % idx) return self.reflection_list[idx]
def doWriteReflist(self, name): if name not in self._adevs: raise InvalidValueError('% is no known reflection list' % name) if not isinstance(self._adevs[name], ReflexList): raise InvalidValueError('%s is not a reflection list' % name)
def doFinish(self): Detector.doFinish(self) if self.ctrl_shutter and self._attached_shutter.read() == CLOSED: raise InvalidValueError(self, 'shutter not open after exposure, ' 'check safety system')