def SetDetectorEnergy(radiation=None, **value): """For all default detectors set with `SetDetectors()` either load the predefined settings for that are suitable for usage with silver, chromium, copper, iron or molybdenum radiation or set the x-ray and threshold energy to any other appropriate values. The following keyword arguments are accepted: * *xray* -- x-ray energy in kilo electron volt * *threshold* -- threshold energy in kilo electron volt * *wait* -- whether the command should wait until all detectors completed the parameter update (defaults to 'True') Examples: >>> # load predefined settings for copper radiation >>> SetDetectorEnergy('Cu') >>> >>> # set energy values explicitly >>> SetDetectorEnergy(xray= 9.243, threshold= 8.0) >>> >>> # load predefined settings for silver radiation and return immediately >>> SetDetectorEnergy('Ag', wait=False) """ wait = value.pop('wait', True) configured = [] for det in session.experiment.detectors: for ch in det._channels: if hasattr(ch, 'setEnergy'): configured.append(det) ch.setEnergy(radiation, **value) break # maximum one channel per detector can set energy if wait: device.wait(*configured)
def set_cascade(): """Set Cascade Frequency Generator Freqs and Trigger.""" echotime = session.getDevice('echotime') psd_chop_freq = session.getDevice('psd_chop_freq') psd_timebin_freq = session.getDevice('psd_timebin_freq') fg_burst = session.getDevice('fg_burst') tau = echotime.target f1 = echotime.currenttable[tau]['cbox_0a_fg_freq'] f2 = echotime.currenttable[tau]['cbox_0b_fg_freq'] move(psd_chop_freq, 2 * (f2 - f1)) move(psd_timebin_freq, 32 * (f2 - f1)) move(fg_burst, 'arm') move(fg_burst, 'trigger') wait()
def zero(): """Shut down all (static) power supplies.""" ps = [ 'hrf_0a', 'hrf_0b', 'hrf_1a', 'hrf_1b', 'hsf_0a', 'hsf_0b', 'hsf_1', 'sf_0a', 'sf_0b', 'sf_1', 'gf1', 'gf2', 'gf4', 'gf5', 'gf6', 'gf7', 'gf8', 'gf9', 'gf10', 'nse0', 'nse1' ] for powersupply in ps: powersupply = session.getDevice(powersupply) move(powersupply, 0.001) wait() # Stop regulation and turn fg_amp off stop('cbox_0a_reg_amp', 'cbox_0b_reg_amp', 'cbox_1_reg_amp') maw('cbox_0a_fg_amp', 0.001, 'cbox_0b_fg_amp', 0.001, 'cbox_1_fg_amp', 0.001)
def test_stop_privileged(self, session, log): # Change the user level to lower access rights to check that the stop # on higher level requesting devices will be ignored AddSetup('device') motor = session.getDevice('motor') pdev = session.getDevice('privdev') speed = pdev.speed pdev.speed = motor.speed = 0.1 move(pdev, 10, motor, 10) with session.withUserLevel(GUEST): assert pdev.status(0)[0] == devstatus.BUSY assert motor.status(0)[0] == devstatus.BUSY assert raises(AccessError, pdev.stop) stop(pdev, motor) wait(motor) assert motor.status(0)[0] == devstatus.OK assert pdev.status(0)[0] == devstatus.BUSY stop(pdev) wait(pdev) assert pdev.status(0)[0] == devstatus.OK pdev.speed = motor.speed = speed
def test_wait(self, session, log): """Check wait() command.""" motor = session.getDevice('motor') tdev = session.getDevice('tdev') tdev._status_exception = NicosError('expected failed status') move(motor, 10) wait(motor, 0.1) # session.log.error('expl. devices: %r', session.explicit_devices) wait() with log.assert_errors(r'expected failed status'): wait(tdev) tdev._status_exception = None
def setecho(time): """Wrap setting of an echotime.""" echotime = session.getDevice('echotime') move(echotime, time) # set_cascade() wait(echotime)