Esempio n. 1
0
def runScattering(acqEntries, configSetting):
    
    for seqIndex in range(len(acqEntries)):
        acqEntry = acqEntries[seqIndex]
        sampleEntry = samples[acqEntry['sample']]
        
        # Click if runnable
        if isRunScattering(acqEntry['runId']):
            # Set sample
            quokka.setSample(sampleEntry['position'], sampleEntry['name'], sampleEntry['description'], sampleEntry['thickness'], isDriveSampleStage())
            # Clear transmission flag
            sics.set('transmissionflag', 0)
            sleep(0.1)
            # Set attenuation
            log('Finding safe attenuation value ...')
            startingAttenuation = driveSafeAttenuation(configSetting['manualAttenuationAlgorithm'], configSetting['startingAttenuation'])
            # Acquire data
            mode = configSetting['scatteringMode']
            preset = getScatteringPreset(acqEntry['runId'], acqEntry['preset'])
            updateScatteringRunState(acqEntry['runId'], True)
            log('Start scattering run on ' + sampleEntry['name'] + ' (mode: ' + mode.key + ', preset: ' + str(preset) + ') ... ')
            # Scan (force scan if this is a dark current scan)
            dataFile = scan(mode, dataType.HISTOGRAM_XY, preset, getForcedScanValue(sampleEntry['type']))
            # Update data file name
            updateScatteringRunState(acqEntry['runId'], False)
            updateScatteringDetails(acqEntry['runId'], dataFile[-14:-7], getLambdaValue(), getAttValue(), getL1Value(), getL2Value())
            # Print instrument state
            sleep(0.2)
            # Drive attenuation back safer value
            log('Drive attenuation back to safe value ...')
            if startingAttenuation is None:
                startingAttenuation = 300
            driveAtt(startingAttenuation)
            quokka.printQuokkaSettings()
Esempio n. 2
0
def driveFlipper(value):
    slog('Driving flipper to %s ...' % value)

    # make sure that value is int
    value = int(value)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            sics.set('/instrument/flipper/set_flip_on', value)

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            if getFlipper() != value:
                raise Exception('unable to set Flipper')

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog('Retry setting Flipper')
            time.sleep(1)

    slog('Flipper is set to %s' % getFlipper())
Esempio n. 3
0
def driveFlipper(value):
    # Clear interrupt flag
    sics.getSicsController().clearInterrupt()
    # Set timeout to 120 sec
    timeout = 120
    counter = 0
    # Set flipper
    sics.set('/instrument/flipper/set_flip_on', value)
    log('Driving flipper to ' + str(value) + "...")
    while True:
        flipperValue = sics.getValue('/instrument/flipper/flip_on').getIntData()
        # Test if value is set 
        if flipperValue == value:
            log('Flipper is set to ' + str(flipperValue))
            return
        else:
            # Check timeout
            if counter >= timeout:
                raise Exception('Failed to set flipper to ' + str(value))
            # Check interrupt
            if sics.getSicsController().isInterrupted() == 1:
                raise Exception('SICS has been interrupted')
            # Otherwise sleep for 1 sec
            counter += 1
            time.sleep(1)
Esempio n. 4
0
def driveGuide(guideConfig):
    # Set configuration
    if hasattr(guideConfig, 'key'):
        guideConfig = guideConfig.key
    sics.set('/commands/optics/guide/configuration', guideConfig)
    log('Moving guide to ' + guideConfig)
    sicsController = SicsCore.getSicsController()
    commandController = sicsController.findComponentController('/commands/optics/guide')
    # Setting of configuration and starting a command are committed to SICS via different communication channels
    # In order to make those in sync, we need to wait for the configuration to be settled.
    time.sleep(0.1)
    
    # Start command now
    cnt = 0
    while cnt < 20:
        try:
            commandController.syncExecute();
            break
        except SicsExecutionException, e:
            em = str(e.getMessage())
            if em.__contains__('Interrupted'):
                raise e
            log('retry moving guide to ' + str(guideConfig))
            time.sleep(1)
            while not sicsController.getServerStatus().equals(ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.3)
            cnt += 1
def multi_run():
#    sics.drive('att', 300)
#    sics.drive('nvs_lambda', 10)
#    sleep(0.1)
#    scan_att_katy(120, 30, 5, [1200 , 1200, 1800, 3600, 7200])
#    sics.drive('att', 330)
#    sics.drive('nvs_lambda', 10)
#    sleep(0.1)
#    sleep(0.1)
#    scan_att_katy(210, 30, 5, [1200 , 600, 1200, 1800, 3600])
#    sics.drive('att', 330)

#    sics.drive('att', 330)
#    sics.drive('nvs_lambda', 11)
#    sleep(0.1)
#    sleep(0.1)    
#    sleep(0.1)
#    scan_att_katy(180, 30, 6, [1200 , 600, 1200, 1800, 3600, 3600])
#    sics.drive('att', 330)
    
    sics.drive('att', 330)
    sleep(0.1)
    sleep(0.1)
    scan_att_katy(300, 30, 2, [600 , 14400])
    sics.drive('att', 330)
    
    sics.set('/instrument/detector/detector_y/speed', 53)
    driveDet(19250, 0)
    
    
    sics.drive('att', 330)
    sleep(0.1)  
    sleep(0.1)
    scan_att_katy(330, 30, 1, [14400])
    sics.drive('att', 330)
Esempio n. 6
0
def driveFlipper(value):
    # Clear interrupt flag
    sics.getSicsController().clearInterrupt()
    # Set timeout to 120 sec
    timeout = 120
    counter = 0
    # Set flipper
    sics.set('/instrument/flipper/set_flip_on', value)
    log('Driving flipper to ' + str(value) + "...")
    while True:
        flipperValue = sics.getValue('/instrument/flipper/flip_on').getIntData()
        # Test if value is set 
        if flipperValue == value:
            log('Flipper is set to ' + str(flipperValue))
            return
        else:
            # Check timeout
            if counter >= timeout:
                raise Exception('Failed to set flipper to ' + str(value))
            # Check interrupt
            if sics.getSicsController().isInterrupted() == 1:
                raise Exception('SICS has been interrupted')
            # Otherwise sleep for 1 sec
            counter += 1
            time.sleep(1)
Esempio n. 7
0
def driveFlipper(value):
    slog('Driving flipper to %s ...' % value)

    # make sure that value is int
    value = int(value)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            sics.set('/instrument/flipper/set_flip_on', value)

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            if getFlipper() != value:
                raise Exception('unable to set Flipper')

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog('Retry setting Flipper')
            time.sleep(1)

    slog('Flipper is set to %s' % getFlipper())
Esempio n. 8
0
def runTransmission(acqEntries, configSetting):
    
    for seqIndex in range(len(acqEntries)):
        acqEntry = acqEntries[seqIndex]
        sampleEntry = samples[acqEntry['sample']]
        
        # Click if runnable
        if isRunTransmission(acqEntry['runId']):
            # Set sample
            quokka.setSample(sampleEntry['position'], sampleEntry['name'], sampleEntry['description'], sampleEntry['thickness'], isDriveSampleStage())
            # Set transmission flag
            sics.set('transmissionflag', 1)
            sleep(0.1)
            # Set attenuation
            # Acquire data
            mode = configSetting['transmissionMode']
            preset = configSetting['transmissionPreset']
            updateTransmissionRunState(acqEntry['runId'], True)
            log('Start transmission run on ' + sampleEntry['name'] + ' ...')
            dataFile = scan(mode, dataType.HISTOGRAM_XY, preset, getForcedScanValue(sampleEntry['type']))
            # Update data file name
            updateTransmissionRunState(acqEntry['runId'], False)
            updateTransmissionDetails(acqEntry['runId'], dataFile[-14:-7], getLambdaValue(), getAttValue(), getL1Value(), getL2Value())
            # Print instrument state
            sleep(0.2)
            quokka.printQuokkaSettings()
Esempio n. 9
0
def driveGuide(guideConfig):
    # Set configuration
    sics.set('/commands/optics/guide/configuration', guideConfig.key)
    log('Moving guide to ' + guideConfig.key)
    sicsController = SicsCore.getSicsController()
    commandController = sicsController.findComponentController('/commands/optics/guide')
    # Setting of configuration and starting a command are committed to SICS via different communication channels
    # In order to make those in sync, we need to wait for the configuration to be settled.
    time.sleep(0.1)
    
    # Start command now
    cnt = 0
    while cnt < 20:
        try:
            commandController.syncExecute();
            break
        except SicsExecutionException, e:
            em = str(e.getMessage())
            if em.__contains__('Interrupted'):
                raise e
            log('retry moving guide to ' + str(guideConfig.key))
            time.sleep(1)
            while not sicsController.getServerStatus().equals(ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.3)
            cnt += 1
def setTemperature(setpoint, heaterRange, waitForTemperature, tempSettleTime): 
    slog('set tc1 heater range=' + str(heaterRange))
    sics.set('/sample/tc1/heater/heaterRange',heaterRange)
    if waitForTemperature==0:
        slog('set sample T=' +  str(setpoint) + ' & not wait for it')
        sics.run('tc1_driveable', setpoint)
    else:
        slog('set sample T=' +  str(setpoint) + ' & wait till it is reached')
        sics.drive('tc1_driveable', setpoint)
        sleep(tempSettleTime)
        slog('waiting '+ str(tempSettleTime) +'sec for temperature to settle')
Esempio n. 11
0
def driveGuide(guideConfig):
    # Set configuration
    sics.set('/commands/optics/guide/configuration', guideConfig.key)
    log('Moving guide to ' + guideConfig.key)
    sicsController = SicsCore.getSicsController()
    commandController = sicsController.findComponentController('/commands/optics/guide')
    # Setting of configuration and starting a command are committed to SICS via different communication channels
    # In order to make those in sync, we need to wait for the configuration to be settled.
    time.sleep(0.1)
    # Start command now
    commandController.syncExecute();
    log('Guide is moved to ' + getGuideConfig())
Esempio n. 12
0
def driveGuide(guideConfig):
    # Set configuration
    sics.set('/commands/optics/guide/configuration', guideConfig.key)
    log('Moving guide to ' + guideConfig.key)
    sicsController = SicsCore.getSicsController()
    commandController = sicsController.findComponentController(
        '/commands/optics/guide')
    # Setting of configuration and starting a command are committed to SICS via different communication channels
    # In order to make those in sync, we need to wait for the configuration to be settled.
    time.sleep(0.1)
    # Start command now
    commandController.syncExecute()
    log('Guide is moved to ' + getGuideConfig())
Esempio n. 13
0
def setupMeasurement(parameters, meas_mode):
    # parameters
    script    = strOrDefault(parameters['SetupScript'])
    att_algo  = str(parameters['AttenuationAlgorithm']).lower()
    att_angle = int(parameters['AttenuationAngle'])
    acq_mode  = ACQUISITION_MODE.ba  # all acquisitions are done via ba mode

    # ATTENUATION_ALGO = Enumeration('fixed', 'iterative')
    att_algos = dict()
    att_algos["fixed attenuation"]     = ATTENUATION_ALGO.fixed
    att_algos["iterative attenuation"] = ATTENUATION_ALGO.iterative

    # check parameters
    if att_algo not in att_algos:
        raise Exception('unknown attenuation algorithm: ' + att_algo)
    if att_angle not in ATT_VALUES:
        raise Exception('unexpected attenuation angle: %i' % att_angle)
    if meas_mode not in MEASUREMENT_MODE:
        raise Exception('unknown measurement mode: ' + meas_mode)
    if acq_mode not in ACQUISITION_MODE:
        raise Exception('unknown acquisition mode: ' + acq_mode)

    # state (global variable)
    state.att_algo  = att_algos[att_algo]
    state.att_angle = att_angle

    state.meas_mode = meas_mode
    state.acq_mode  = acq_mode

    if state.meas_mode == MEASUREMENT_MODE.transmission:
        # set transmission flag
        slog('Set instrument to transmission mode')
        sics.set('transmissionflag', 1)
    else:
        # unset transmission flag
        slog('Set instrument to scattering mode')
        sics.set('transmissionflag', 0)

    time.sleep(0.5)

    # before instrument can move to new configuration, move to safe attenuation angle
    driveToSafeAtt()

    # run configuration script
    slog('Driving configuration script...')
    exec script in globals()
Esempio n. 14
0
def driveGuide(value):
    if value not in GUIDE_CONFIG:
        slog('[WARNING] unknown guide configuration: ' + value)

    # set target configuration
    sics.set('/commands/optics/guide/configuration', value)

    if getGuideConfig() == value:
        slog('Guide was already moved to %s (no action is required)' % value)
        return

    slog('Moving guide to ' + value)

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController('/commands/optics/guide')

    # setting of configuration and starting a command are committed to SICS via different communication channels
    # in order to make those in sync, we need to wait for the configuration to settle
    time.sleep(0.5)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            timeout = datetime.now() + timedelta(minutes=5)
            controller.syncExecute()

            while (getGuideConfig() != value) and (datetime.now() < timeout):
                sleep(0.5)

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog(str(e), f_err=True)
            slog('Retry moving guide')
            time.sleep(1)

    slog('Guide is moved to ' + getGuideConfig())
Esempio n. 15
0
 def multi_set(self):
     if not self.wavelength is None:
         sics.set('/instrument/velocity_selector/wavelength', self.wavelength)
     if not self.wavelength_spread is None:
         log('set wavelength_spread to ' + str(self.wavelength_spread))
         sics.set('/instrument/velocity_selector/wavelength_spread', self.wavelength_spread)
     if not self.beamcenterx is None :
         log('set beam centre x to ' + str(self.beamcenterx))
         sics.set('beamcenterx', self.beamcenterx)
     if not self.beamcenterz is None :
         log('set beam centre z to ' + str(self.beamcenterz))
         sics.set('beamcenterz', self.beamcenterz)
Esempio n. 16
0
def initiate(info):
    # parameters
    title = info.experimentTitle
    pnumber = str(info.proposalNumber)
    users = str(info.users)
    sample_stage = str(info.sampleStage)

    # update sics
    sics.set('title', title)
    sics.execute('hset /experiment/experiment_identifier ' + pnumber)

    sics.set('user', users)
    #sics.execute('hset /user/email ' + email) # !!!
    #sics.execute('hset /user/phone ' + phone)

    # clear environment drive scripts
    state.env_drive = dict()

    setSampleStage(sample_stage)
Esempio n. 17
0
 def multi_set(self):
     if not self.wavelength is None:
         log("set wavelength_spread to " + str(self.wavelength_spread))
         sics.set("/instrument/velocity_selector/wavelength", self.wavelength)
     if not self.wavelength_spread is None:
         log("set wavelength_spread to " + str(self.wavelength_spread))
         sics.set("/instrument/velocity_selector/wavelength_spread", self.wavelength_spread)
     if not self.beamcenterx is None:
         log("set beam centre x to " + str(self.beamcenterx))
         sics.set("beamcenterx", self.beamcenterx)
     if not self.beamcenterz is None:
         log("set beam centre z to " + str(self.beamcenterz))
         sics.set("beamcenterz", self.beamcenterz)
Esempio n. 18
0
 def multi_set(self):
     if not self.wavelength is None:
         log('set wavelength_spread to ' + str(self.wavelength_spread))
         sics.set('/instrument/velocity_selector/wavelength', self.wavelength)
     if not self.wavelength_spread is None:
         log('set wavelength_spread to ' + str(self.wavelength_spread))
         sics.set('/instrument/velocity_selector/wavelength_spread', self.wavelength_spread)
     if not self.beamcenterx is None :
         log('set beam centre x to ' + str(self.beamcenterx))
         sics.set('beamcenterx', self.beamcenterx)
     if not self.beamcenterz is None :
         log('set beam centre z to ' + str(self.beamcenterz))
         sics.set('beamcenterz', self.beamcenterz)
Esempio n. 19
0
def initiate(info):
    # parameters
    title        = strOrDefault(info.experimentTitle, "Unknown")
    pnumber      = strOrDefault(info.proposalNumber, "0")
    users        = strOrDefault(info.users, "Unknown")
    emails       = strOrDefault(info.emails, "Unknown")
    phones       = strOrDefault(info.phones, "Unknown")
    sample_stage = str(info.sampleStage)

    # update sics
    sics.set('title', title)
    sics.execute('hset /experiment/experiment_identifier ' + pnumber)

    sics.set('user', users)
    sics.execute('hset /user/email "%s"' % emails)
    sics.execute('hset /user/phone "%s"' % phones)

    # clear environment drive scripts
    state.env_drive = dict()

    setSampleStage(sample_stage)
Esempio n. 20
0
def setSample(position, name="UNKNOWN", description="UNKNOWN", thickness=0, driveSampleStage=True):
    if driveSampleStage:
        driveSample(position)
    # Set sample name and description
    sics.set("samplename", name)
    sics.set("sampledescription", description)
    sics.set("samplethickness", thickness)
Esempio n. 21
0
def setSample(position, name='UNKNOWN', description='UNKNOWN', thickness=0, driveSampleStage=True):
    if driveSampleStage:
        driveSample(position)
    # Set sample name and description
    sics.set('samplename', name)
    sics.set('sampledescription', description)
    sics.set('samplethickness', thickness)
Esempio n. 22
0
def setSample(position, name='UNKNOWN', description='UNKNOWN', thickness=0, driveSampleStage=True):
    if driveSampleStage:
        driveSample(position)
    # Set sample name and description
    sics.set('samplename', name)
    sics.set('sampledescription', description)
    sics.set('samplethickness', thickness)
Esempio n. 23
0
def driveGuide(value):
    if value not in GUIDE_CONFIG:
        slog('[WARNING] unknown guide configuration: ' + value)

    # set target configuration
    sics.set('/commands/optics/guide/configuration', value)

    slog('Moving guide to ' + value)

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController(
        '/commands/optics/guide')

    # setting of configuration and starting a command are committed to SICS via different communication channels
    # in order to make those in sync, we need to wait for the configuration to settle
    time.sleep(0.5)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            controller.syncExecute()
            sics.handleInterrupt()
            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog('Retry moving guide')
            time.sleep(1)

    slog('Guide is moved to ' + getGuideConfig())
Esempio n. 24
0
def setupSample(parameters):
    # parameters
    name = parameters['Name']
    description = parameters['Description']
    thickness = float(parameters['Thickness'])
    position = float(parameters['Position'])

    # state
    state.sample_name = name
    state.sample_position = position

    # set sample name and description
    sics.set('samplename', name)
    sics.set('sampledescription', description)
    sics.set('samplethickness', thickness)

    # drive to sample position
    if state.sample_stage != SAMPLE_STAGE.fixed:
        driveToSamplePosition(position)
Esempio n. 25
0
def setupSample(parameters):
    # parameters
    name        = strOrDefault(parameters['Name'], "Unknown")
    description = strOrDefault(parameters['Description'], "N.A.")
    thickness   = float(parameters['Thickness'])
    position    = float(parameters['Position'])

    # state
    state.sample_name = name
    state.sample_position = position

    # set sample name and description
    sics.set('samplename', name)
    sics.set('sampledescription', description)
    sics.set('samplethickness', thickness)

    # drive to sample position
    if state.sample_stage != SAMPLE_STAGE.fixed:
        driveToSamplePosition(position)
# configuration unpol 1
log('drive to configuration unpol 1')
driveGuide(guideConfig.g1)
#don't change below scan command
scan_wavelength(wavelengthList, attList, mode, preset)

# configuration -+
#polariser in
log('drive to configuration -+')
driveGuide(guideConfig.p1)
scan_wavelength(wavelengthList, attList, mode, preset)
#
# configuration --
#polariser in
log('drive to configuration --')
sics.set('/sample/isops/relay', 1)
sleep(1)
sics.set('/sample/isops/relay', 0)
scan_wavelength(wavelengthList, attList, mode, preset)
#
# configuration +-
# Drive flipper
log('drive to configuration +-')
driveFlipper(1)
#sics.set('/instrument/flipper/set_frequency', 407)
sleep(60)
scan_wavelength(wavelengthList, attList, mode, preset)

#
# configuration ++
# Drive flipper
Esempio n. 27
0
def setupMeasurement(parameters, meas_mode):
    def lookup(parameters, name):
        if name in parameters:
            value = parameters[name]
            if value is not None:
                return int(value)
            else:
                return None  # e.g. for ba mode parameters can be set to None

        return None

    # parameters
    script = parameters['SetupScript']

    att_algo = str(parameters['AttenuationAlgorithm']).lower()
    att_angle = int(parameters['AttenuationAngle'])

    acq_mode = ACQUISITION_MODE.ba
    min_time = lookup(parameters, 'MinTime')
    max_time = lookup(parameters, 'MaxTime')
    counts = lookup(parameters, 'Counts')
    bm_counts = lookup(parameters, 'BmCounts')

    # ATTENUATION_ALGO = Enumeration('fixed', 'iterative', 'smart')
    att_algos = dict()
    att_algos["fixed attenuation"] = ATTENUATION_ALGO.fixed
    att_algos["iterative attenuation"] = ATTENUATION_ALGO.iterative
    att_algos["smart attenuation"] = ATTENUATION_ALGO.smart

    # check parameters
    if att_algo not in att_algos:
        raise Exception('unknown attenuation algorithm: ' + att_algo)
    if att_angle not in ATT_VALUES:
        raise Exception('unexpected attenuation angle: %i' % att_angle)
    if meas_mode not in MEASUREMENT_MODE:
        raise Exception('unknown measurement mode: ' + meas_mode)
    if acq_mode not in ACQUISITION_MODE:
        raise Exception('unknown acquisition mode: ' + acq_mode)

    # state (global variable)
    state.att_algo = att_algos[att_algo]
    state.att_angle = att_angle

    state.meas_mode = meas_mode
    state.acq_mode = acq_mode
    state.min_time = min_time
    state.max_time = max_time
    state.counts = counts
    state.bm_counts = bm_counts

    if state.meas_mode == MEASUREMENT_MODE.transmission:
        # set transmission flag
        slog('Set instrument to transmission mode')
        sics.set('transmissionflag', 1)
    else:
        # unset transmission flag
        slog('Set instrument to scattering mode')
        sics.set('transmissionflag', 0)

    time.sleep(0.5)

    # before instrument can move to new configuration, move to safe attenuation angle
    driveToSafeAtt()

    # run configuration script
    exec script in globals()
def setFlip(flag):
    sics.set('/sample/isops/relay', 1)
    sleep(60)
    sics.set('/sample/isops/relay', 0)
    sleep(60)