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 _applyParams(self, number, parameters): Sample._applyParams(self, number, parameters) self._applyKwsParams(parameters) self.log.info('moving to position of sample %s (%s)...', number, parameters['name'] or 'unnamed') waitdevs = [] if self.aperture != (0, 0, 0, 0): ap = session.getDevice(self.apname) ap.opmode = 'offcentered' # to be sure ap.move(self.aperture) waitdevs.append(ap) for devname, devpos in iteritems(self.position): dev = session.getDevice(devname) dev.move(devpos) waitdevs.append(dev) multiWait(waitdevs)
def _move2start(self): self.log.info('Move %s for monochromator change', ', '.join(sorted(self.changing_positions))) for dev, pos in self._changing_values.items(): dev.start(pos) # multiWait(self._changing_values) multiWait(self._changing_values.keys()) for dev, pos in self._changing_values.items(): if abs(dev.read(0) - pos) > dev.precision: raise PositionError( self, "'%s' did not reach target position " "'%s'" % (dev, pos)) for dev in self._changing_values: dev.fix('Monochromator change in progress')
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)) for d, t in zip(moveables, target): self.log.debug('moving %r to %r', d, t) d.start(t) if self.blockingmove: multiWait(moveables)
def _finalize(self): """Will be called after a successful monochromator change.""" # test this! # self.log.debug('Enabling Powerstages for %s', # ', '.join(sorted(self.changing_positions))) # for dev in self._changing_values: # dev.power = 'on' self.log.info('releasing mono devices') # self._attached_monochromator.release() for dev in self._changing_values: dev.release() self.log.info('move mono devices to the nominal positions') for dev, pos in self._init_values.items(): dev.start(pos) multiWait(self._init_values.keys()) for dev, pos in self._init_values.items(): if abs(dev.read(0) - pos) > dev.precision: raise PositionError( self, "'%s' did not reach target position " "'%s'" % (dev, pos))
def doReset(self): multiReset(self._axes) multiWait(self._axes)
def _wait_hook(devs): """Default wait hook""" values = multiWait(devs) for dev in devs: dev.log.info('at %20s %s', dev.format(values[dev]), dev.unit)
def kwscount(**arguments): """Move sample and devices into place followed by a count. This takes KWS-specific circumstances such as sample time factor into account. Example: >>> kwscount(sample=1, selector='12A', resolution='2m', sample_pos='1.3m', time=3600) Keywords for standard instrument components are: * sample (sample number or name if unique, defaults to no sample change) * selector (must be present) * resolution (must be present) * sample_pos (must be present) * detector (must be present) * beamstop (defaults to out) * polarizer (defaults to out) * chopper (defaults to off) Any other keywords are interpreted as devices names and the target values. """ def sort_key(kv): try: # main components move first, in selected order return (0, DEFAULT.index(kv[0])) except ValueError: # all other devices move last, sorted by devname return (1, kv[0]) # check that all required components are present, and put defaults for # optional components if 'selector' not in arguments: raise UsageError('kwscount must have a value for the selector') if 'detector' not in arguments: raise UsageError('kwscount must have a value for the detector') if 'sample_pos' not in arguments: raise UsageError('kwscount must have a value for the sample_pos') if 'detector' not in arguments: raise UsageError('kwscount must have a value for the detector') if 'beamstop' not in arguments: arguments['beamstop'] = 'out' if 'polarizer' not in arguments: arguments['polarizer'] = 'out' if 'chopper' not in arguments: arguments['chopper'] = 'off' # leave space between kwscounts session.log.info('') # measurement time meastime = arguments.pop('time', 0) # select sample sample = arguments.pop('sample', None) # move devices waiters = [] # the order is important! devs = listitems(arguments) devs.sort(key=sort_key) # add moved devices to sampleenv _fixupSampleenv(devs) # start devices for devname, value in devs: if devname == 'chopper': # currently a no-op continue dev = session.getDevice(devname, Moveable) dev.start(value) if devname == 'selector': dev2 = session.getDevice('sel_speed') session.log.info('%-12s --> %s (%s)', devname, dev.format(value), dev2.format(dev2.target, unit=True)) else: session.log.info('%-12s --> %s', devname, dev.format(value, unit=True)) waiters.append(dev) # select and wait for sample here if sample is not None: session.experiment.sample.select(sample) # now wait for everyone else multiWait(waiters) # count session.log.info('Now counting for %d seconds...', meastime) count(t=meastime)