Ejemplo n.º 1
0
def alignsample(xpos, ypos, exposuretime=1, number_ob=15, number_di=15):
    """Perform a 'sample alignment'.

    Moves the sample to a safe position and takes first *number_di* dark images
    with *exposuretime* and then *number_ob* open beam images with the same
    *exposuretime*.  Thereafter moves the sample to *xpos*, *ypos*.
    """
    if not (0 < number_ob < 100):
        raise UsageError('Number of open beam images must be in [1..99]')
    if not (0 < number_di < 100):
        raise UsageError('Number of dark images must be in [1..99]')
    stx = session.getDevice('stx')
    sty = session.getDevice('sty')

    session.log.info('Acquire openbeam and dark images')
    sty.maw(1.0)
    stx.maw(1.0)

    for _i in range(number_di):
        darkimage(t=exposuretime)
    for _i in range(number_ob):
        openbeamimage(t=exposuretime)

    stx.maw(xpos)
    sty.maw(ypos)
    session.log.info('Sample is aligned')
Ejemplo n.º 2
0
 def CheckMagazinSlotUsed(self, slot):
     # checks if the given slot in the magazin is used (contains a monoframe)
     self.log.info('checking of there IS mono in magazine slot %r' % slot)
     if self._attached_magazineocc.status(0)[0] != status.OK:
         raise UsageError(
             self, 'Magazine occupancy switches are in warning state!')
     index = self.positions.index(slot)
     if (self._attached_magazineocc.read() >> index * 2) & 1:
         raise UsageError(self, 'Position %r is empty!' % slot)
Ejemplo n.º 3
0
 def CheckMagazinSlotEmpty(self, slot):
     # checks if the given slot in the magazin is empty
     self.log.info('checking of there IS NOT mono in magazine slot %r' %
                   slot)
     if self._attached_magazineocc.status(0)[0] != status.OK:
         raise UsageError(
             self, 'Magazine occupancy switches are in warning state!')
     index = self.positions.index(slot)
     if not ((self._attached_magazineocc.read() >> index * 2) & 1):
         raise UsageError(self, 'Position %r is already occupied!' % slot)
Ejemplo n.º 4
0
 def _setrefcounter(self, raise_error=True):
     self.log.debug('in setrefcounter')
     if not self.isAtReference():
         if raise_error:
             raise UsageError('cannot set reference counter, not at '
                              'reference point')
     self.steps = self.refpos
Ejemplo n.º 5
0
 def doStop(self):
     if self.stoppable:
         self._stop()
     else:
         raise UsageError(
             self, "Please use: 'move(%s, 'off')' to stop the "
             "moving device" % self)
Ejemplo n.º 6
0
 def wrapped(*args, **kwds):
     if not parallel_safe and session.checkParallel():
         raise UsageError('the %s command cannot be used with "execute now"'
                          % func.__name__)
     try:
         try:
             # try executing the original function with the given arguments
             return func(*args, **kwds)
         except TypeError:
             # find out if the call itself caused this error, which means
             # that wrong arguments were given to the command
             traceback = sys.exc_info()[2]
             # find last call frame
             while traceback.tb_next:
                 traceback = traceback.tb_next
             if traceback.tb_frame.f_code is wrapped.__code__:
                 session.log.error('Invalid arguments for %s()',
                                   func.__name__)
                 help(func)
             raise
         except UsageError:
             # for usage errors, print the error and the help for the
             # command
             help(func)
             raise
     except RERAISE_EXCEPTIONS:
         # don't handle these, they should lead to an unconditional abort
         raise
     except Exception:
         # all others we'll handle and continue, if wanted
         if hasattr(session.experiment, 'errorbehavior') and \
            session.experiment.errorbehavior == 'report':
             session.scriptEvent('exception', sys.exc_info())
         else:
             raise
Ejemplo n.º 7
0
    def change(self, old, whereto):
        ''' cool kurze Wechselroutine
        Der Knackpunkt ist in den Hilfsroutinen!'''
        if not (old in self.monos + ['None']):
            raise UsageError(
                self, '\'%s\' is illegal value for Mono, use one '
                'of ' % old + ', '.join(self.monos + ['None']))
        if not (whereto in self.monos + ['None']):
            raise UsageError(
                self, '\'%s\' is illegal value for Mono, use one '
                'of ' % whereto + ', '.join(self.monos + ['None']))
        self.PrepareChange()
        if self.monos.index(whereto) == self.monos.index(old):
            # Nothing to do, requested Mono is supposed to be on the table
            return
        # Ok, we have a good state, the only thing we do not know is which mono
        # is on the table......
        # for this we use the (cached) parameter mono_on_table

        if self.mono_on_table != old:
            raise UsageError(
                self, 'Mono %s is not supposed to be on the '
                'table, %s is!' % (old, self.mono_on_table))

        seq = []
        # 0) move magazine to mono position
        magpos_to_put = self.positions[self.monos.index(old)]
        seq.append(SeqMethod(self, 'CheckMagazinSlotEmpty', magpos_to_put))
        seq.append(SeqDev(self._attached_magazine, magpos_to_put))
        # 1) move away the old mono, if any
        if old != 'None':
            seq.extend(self._gen_table2lift())
            seq.extend(
                self._gen_lift2mag(self.positions[self.monos.index(old)]))
        # 2) fetch the new mono (if any) from the magazin
        if whereto != 'None':
            seq.extend(
                self._gen_mag2lift(self.positions[self.monos.index(whereto)]))
            seq.extend(self._gen_lift2table())
            seq.append(
                SeqDev(self._attached_magazine,
                       self.shields[self.monos.index(whereto)]))

        # seq.append(SeqDev(self._attached_enable, 0)) - will be done in FinishChange
        seq.append(SeqMethod(self, 'FinishChange'))
        self._start(seq)
        self.wait()
Ejemplo n.º 8
0
def _count(*detlist, **preset):
    temporary = preset.pop('temporary', False)
    live = preset.get('live', False)
    # sanitize detector list; support count(1) and count('info')
    detectors = []
    for det in detlist:
        if isinstance(det, number_types):
            preset['t'] = det
            continue
        elif isinstance(det, string_types):
            preset['info'] = det  # XXX
            continue
        if not isinstance(det, Measurable):
            raise UsageError('device %s is not a measurable device' % det)
        detectors.append(det)
    # check if manual scan is active
    scan = getattr(session, '_manualscan', None)
    if scan is not None:
        if detectors:
            raise UsageError('cannot specify different detector list '
                             'in manual scan')
        return scan.step(**preset)
    # counting without detectors is not useful, but does not error out
    if not detectors:
        detectors = session.experiment.detectors
        if not detectors:
            session.log.warning('counting without detector, use SetDetectors()'
                                ' to select which detector(s) you want to use')
    # check preset names for validity
    names = set(preset)
    for det in detectors:
        names.difference_update(det.presetInfo())
    if names:
        session.log.warning(
            'these preset keys were not recognized by any of '
            'the detectors: %s -- detectors are %s', ', '.join(names),
            ', '.join(map(str, detectors)))
    # check detector types
    has_sub = sum(isinstance(det, SubscanMeasurable) for det in detectors)
    if has_sub > 0:
        # XXX(dataapi): support both types
        if not len(detectors) == has_sub == 1:
            raise NicosError('cannot acquire on normal and subscan detectors')

    return inner_count(detectors, preset, temporary, live)
Ejemplo n.º 9
0
 def _setrefcounter(self):
     self.log.debug('in setrefcounter')
     if self.refpos is not None:
         self.setPosition(self.refpos)
         self._setROParam('target', self.refpos)
         self.log.debug('%r %r', self.refpos, self.target)
         session.delay(0.1)
     if not self.isAtReference():
         raise UsageError('cannot set reference counter, not at reference '
                          'point')
Ejemplo n.º 10
0
 def __init__(self, devices, startend, numpoints, firstmoves=None,
              multistep=None, detlist=None, envlist=None, preset=None,
              scaninfo=None, subscan=False, xindex=None):
     self._etime = ElapsedTime('SweepScan')
     # for sweeps the dry run usually shows only one step; in the case of
     # multisteps we take the first N
     self._simpoints = 1
     self._numpoints = numpoints
     if multistep:
         self._simpoints = len(multistep[0][1])
         self._numpoints = numpoints * self._simpoints
     self._sweepdevices = devices
     if numpoints < 0:
         points = Repeater([])
     else:
         points = [[]] * numpoints
     # start for sweep devices are "firstmoves"
     firstmoves = firstmoves or []
     self._sweeptargets = []
     for dev, (start, end) in zip(devices, startend):
         if start is not None:
             firstmoves.append((dev, start))
         self._sweeptargets.append(end)
     # sweep scans support a special "delay" and "minstep" presets
     self._delay = preset.pop('delay', 0)
     self._minstep = preset.pop('minstep', 0)
     if not isinstance(self._minstep, list):
         self._minstep = [self._minstep] * len(devices)
     elif len(self._minstep) != len(devices):
         raise UsageError('Invalid number of minstep values. For each '
                          'device a minstep value must be given!')
     Scan.__init__(self, [], points, [], firstmoves, multistep,
                   detlist, envlist, preset, scaninfo, subscan, xindex)
     # XXX(dataapi): devices should be in devlist, not envlist
     if not devices:
         self._envlist.insert(0, self._etime)
     else:
         for dev in devices[::-1]:
             if dev in self._envlist:
                 self._envlist.remove(dev)
             self._envlist.insert(0, dev)
Ejemplo n.º 11
0
 def __delitem__(self, name):
     if name in self.__forbidden:
         raise UsageError('%s cannot be deleted; it is a builtin, '
                          'a command or a device' % name)
     dict.__delitem__(self, name)
Ejemplo n.º 12
0
 def __setitem__(self, name, value):
     if name in self.__forbidden:
         raise UsageError('%s cannot be assigned; it is a builtin, '
                          'a command or a device' % name)
     dict.__setitem__(self, name, value)