Ejemplo n.º 1
0
def createPVScannable( name, pv, addToNameSpace=True, hasUnits=True, getAsString=False):
    """
    utility function to create a scannable from a PV
    arguments:
    name - of scannable
    pv - pv 
    addToNameSpace = if True the scannable is accessible from the commandline after the call
    hasUnits - default True. The value is a number  and support is given for setUserUnits
    getAsString - default False. Useful if the PV is an enum as it returns the string representation. 
                 If true also set hasUnits to False 
    
    e.g.
    createPVScannable("acoll_average_size", "BL13J-OP-ACOLL-01:AVERAGESIZE", True)
    """
    sc = EpicsScannable()
    sc.setName(name)
    sc.setPvName(pv)
    sc.setUseNameAsInputName(True)
    sc.setHasUnits(hasUnits)
    sc.setGetAsString(getAsString)
    sc.afterPropertiesSet()
    sc.configure()
    if addToNameSpace:
        commandServer = InterfaceProvider.getJythonNamespace()    
        commandServer.placeInJythonNamespace(name,sc)
    return sc
Ejemplo n.º 2
0
def createPVScannable(name,
                      pv,
                      addToNameSpace=True,
                      hasUnits=True,
                      getAsString=False):
    """
    utility function to create a scannable from a PV
    arguments:
    name - of scannable
    pv - pv 
    addToNameSpace = if True the scannable is accessible from the commandline after the call
    hasUnits - default True. The value is a number  and support is given for setUserUnits
    getAsString - default False. Useful if the PV is an enum as it returns the string representation. 
                 If true also set hasUnits to False 
    
    e.g.
    createPVScannable("acoll_average_size", "BL13J-OP-ACOLL-01:AVERAGESIZE", True)
    """
    sc = EpicsScannable()
    sc.setName(name)
    sc.setPvName(pv)
    sc.setUseNameAsInputName(True)
    sc.setHasUnits(hasUnits)
    sc.setGetAsString(getAsString)
    sc.afterPropertiesSet()
    sc.configure()
    if addToNameSpace:
        commandServer = InterfaceProvider.getJythonNamespace()
        commandServer.placeInJythonNamespace(name, sc)
    return sc
Ejemplo n.º 3
0
def ls_pv_scannables(PV=""):
    """
    Function to list Scannables associated with EPICs PVs, the PV and the associated DESC field
    Usage:
        >ls_pv_scannables()
    
    or
    
        >ls_pv_scannables(<PV>)
    """
    from gda.device.scannable import ScannableMotor
    from gda.device.motor import EpicsMotor
    scannableConnectedToPV = None
    a = InterfaceProvider.getJythonNamespace().getNamesForAllObjectsOfType(
        Findable)
    l = filter(
        lambda x: isinstance(x, EpicsScannable) or
        (isinstance(x, ScannableMotor) and isinstance(x.motor, EpicsMotor)),
        a.values().toArray())
    for x in l:
        description = "unknown"
        pvName = "unknown"
        if isinstance(x, EpicsScannable):
            pvName = x.pvName
        if isinstance(x, ScannableMotor) and isinstance(x.motor, EpicsMotor):
            pvName = x.motor.pvName

        if PV != "":
            if PV.upper() == pvName.upper():
                scannableConnectedToPV = x
                break
        else:
            if x.configured:
                try:
                    description = caget(pvName + ".DESC")
                except:
                    description = "Unable to read description"
                    pass
            else:
                description = "Not configured!"
            print x.name, pvName, description

    if PV != "":
        if scannableConnectedToPV is None:
            print "No scannable found for PV " + PV
        print "Scannable " + x.name + " is connected to ", PV
Ejemplo n.º 4
0
def createScannableFromPV( name, pv, addToNameSpace=True, getAsString=True, hasUnits=False):
    """
    Description:
        utility function to create a scannable from a given PV
    Arguments:
        name - user-specified name of a scannable to be created, e.g. pixium10_DataType
        pv - EPICS identifier of pv to be used by the scannable, e.g. BL12I-EA-DET-10:CAM:DataType
        addToNameSpace = if True, the scannable is accessible from the commandline after the call
        getAsString - If True, output value is a string (useful for enum pv, in which case set getAsString=True, and set hasUnits=False)
        hasUnits - If False, output value is not converted to units - useful for enum pv with getAsString=True
    
    For example,
        createScannableFromPV("pixium10_DataType", "BL12I-EA-DET-10:CAM:DataType", True, True, False)
    creates a scannable for pv with the following enums:
    caget -d 31 BL12I-EA-DET-10:CAM:DataType
        BL12I-EA-DET-10:CAM:DataType
        Native data type: DBF_ENUM
        Request type:     DBR_CTRL_ENUM
        Element count:    1
        Value:            UInt32
        Status:           NO_ALARM
        Severity:         NO_ALARM
        Enums:            ( 8)
                          [ 0] Int8
                          [ 1] UInt8
                          [ 2] Int16
                          [ 3] UInt16
                          [ 4] Int32
                          [ 5] UInt32
                          [ 6] Float32
                          [ 7] Float64
    """
    sc = EpicsScannable()
    sc.setName(name)
    sc.setPvName(pv)
    sc.setUseNameAsInputName(True)
    sc.setGetAsString(getAsString)
    sc.setHasUnits(hasUnits)
    sc.afterPropertiesSet()
    sc.configure()
    if addToNameSpace:
        commandServer = InterfaceProvider.getJythonNamespace()
        commandServer.placeInJythonNamespace(name,sc)
    return sc
Ejemplo n.º 5
0
def ls_pv_scannables( PV=""):
    """
    Function to list Scannables associated with EPICs PVs, the PV and the associated DESC field
    Usage:
        >ls_pv_scannables()
    
    or
    
        >ls_pv_scannables(<PV>)
    """
    from gda.device.scannable import ScannableMotor
    from gda.device.motor import EpicsMotor
    scannableConnectedToPV=None
    a=InterfaceProvider.getJythonNamespace().getAllFromJythonNamespace()
    l=filter(lambda x: isinstance(x, EpicsScannable) or (isinstance(x, ScannableMotor) and isinstance(x.motor, EpicsMotor)), a.values().toArray())
    for x in l:
        description="unknown"
        pvName ="unknown"
        if isinstance(x, EpicsScannable):
            pvName=x.pvName
        if isinstance(x, ScannableMotor) and isinstance(x.motor, EpicsMotor):
            pvName=x.motor.pvName
            
        if PV != "":
            if PV.upper() == pvName.upper():
                scannableConnectedToPV=x
                break
        else:
            if x.configured:
                try:
                    description = caget(pvName + ".DESC")
                except:
                    description = "Unable to read description"
                    pass
            else:
                description = "Not configured!"
            print x.name, pvName, description

    if PV != "":
        if scannableConnectedToPV is None:
            print "No scannable found for PV " + PV
        print "Scannable " + x.name  + " is connected to ", PV
Ejemplo n.º 6
0
def tomoScan(
    description,
    inBeamPosition,
    outOfBeamPosition,
    exposureTime=1.0,
    start=0.0,
    stop=180.0,
    step=0.1,
    darkFieldInterval=0,
    flatFieldInterval=0,
    imagesPerDark=10,
    imagesPerFlat=10,
    optimizeBeamInterval=0,
    pattern="default",
    tomoRotationAxis=0,
    addNXEntry=True,
    autoAnalyse=True,
    additionalScannables=[],
):
    """
    Function to collect a tomography step scan
    Arguments:
    description - description of the scan or the sample that is being scanned. This is generally user-specific information that may be used to map to this scan later and is available in the NeXus file)
    inBeamPosition - position of X drive to move sample into the beam to take a projection
    outOfBeamPosition - position of X drive to move sample out of the beam to take a flat field image
    exposureTime - exposure time in seconds (default=1.0)
    start - first rotation angle (default=0.0)
    stop  - last rotation angle (default=180.0)
    step - rotation step size (default=0.1)
    darkFieldInterval - number of projections between each dark-field sub-sequence. 
        NOTE: at least 1 dark is ALWAYS taken both at the start and end of the scan provided imagesPerDark>0 
        (default=0: use this value if you DON'T want to take any darks between projections)
    flatFieldInterval - number of projections between each flat-field sub-sequence. 
        NOTE: at least 1 flat is ALWAYS taken both at the start and end the scan provided imagesPerFlat>0 
        (default=0: use this value if you DON'T want to take any flats between projections)
    imagesPerDark - number of images to be taken for each dark-field sub-sequence (default=10)
    imagesPerFlat - number of images to be taken for each flat-field sub-sequence (default=10)
    
    General scan sequence is: D, F, P,..., P, F, D
    where D stands for dark field, F - for flat field, and P - for projection.
    """
    dataFormat = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
    try:
        darkFieldInterval = int(darkFieldInterval)
        flatFieldInterval = int(flatFieldInterval)
        optimizeBeamInterval = int(optimizeBeamInterval)

        jns = beamline_parameters.JythonNameSpaceMapping(InterfaceProvider.getJythonNamespace())
        tomography_theta = jns.tomography_theta
        if tomography_theta is None:
            raise "tomography_theta is not defined in Jython namespace"
        tomography_shutter = jns.tomography_shutter
        if tomography_shutter is None:
            raise "tomography_shutter is not defined in Jython namespace"
        tomography_translation = jns.tomography_translation
        if tomography_translation is None:
            raise "tomography_translation is not defined in Jython namespace"

        tomography_detector = jns.tomography_detector
        if tomography_detector is None:
            raise "tomography_detector is not defined in Jython namespace"

        tomography_optimizer = jns.tomography_optimizer
        if tomography_optimizer is None:
            raise "tomography_optimizer is not defined in Jython namespace"

        tomography_time = jns.tomography_time
        if tomography_time is None:
            raise "tomography_time is not defined in Jython namespace"

        tomography_beammonitor = jns.tomography_beammonitor
        if tomography_beammonitor is None:
            raise "tomography_beammonitor is not defined in Jython namespace"

        tomography_camera_stage = jns.tomography_camera_stage
        if tomography_camera_stage is None:
            raise "tomography_camera_stage is not defined in Jython namespace"

        tomography_sample_stage = jns.tomography_sample_stage
        if tomography_sample_stage is None:
            raise "tomography_sample_stage is not defined in Jython namespace"

        tomo_additional_scannables = jns.tomography_additional_scannables
        if tomo_additional_scannables is None:
            raise "tomo_additional_scannables is not defined in Jython namespace"

        index = SimpleScannable()
        index.setCurrentPosition(0.0)
        index.setInputNames(["imageNumber"])
        index.setName("imageNumber")
        index.configure()

        image_key = SimpleScannable()
        image_key.setCurrentPosition(0.0)
        image_key.setInputNames(["image_key"])
        image_key.setName("image_key")
        image_key.configure()

        tomoScanDevice = make_tomoScanDevice(
            tomography_theta, tomography_shutter, tomography_translation, tomography_optimizer, image_key, index
        )

        #        return tomoScanDevice
        # generate list of positions
        numberSteps = ScannableUtils.getNumberSteps(tomography_theta, start, stop, step)
        theta_points = []
        theta_points.append(start)
        previousPoint = start
        for i in range(numberSteps):
            nextPoint = ScannableUtils.calculateNextPoint(previousPoint, step)
            theta_points.append(nextPoint)
            previousPoint = nextPoint

        # generateScanPoints
        optimizeBeamNo = 0
        optimizeBeamYes = 1
        shutterOpen = 1
        shutterClosed = 0
        shutterNoChange = 2
        scan_points = []
        theta_pos = theta_points[0]
        index = 0
        # Added shutterNoChange state for the shutter. The scan points are added using the (pseudo) ternary operator,
        # if index is 0 then the shutterPosition is added to the scan point, else shutterNoChange is added to scan points.
        for i in range(imagesPerDark):
            scan_points.append(
                (
                    theta_pos,
                    [shutterClosed, shutterNoChange][i != 0],
                    inBeamPosition,
                    optimizeBeamNo,
                    image_key_dark,
                    index,
                )
            )  # dark
            index = index + 1

        for i in range(imagesPerFlat):
            scan_points.append(
                (
                    theta_pos,
                    [shutterOpen, shutterNoChange][i != 0],
                    outOfBeamPosition,
                    optimizeBeamNo,
                    image_key_flat,
                    index,
                )
            )  # flat
            index = index + 1
        scan_points.append((theta_pos, shutterOpen, inBeamPosition, optimizeBeamNo, image_key_project, index))  # first
        index = index + 1
        imageSinceDark = 1
        imageSinceFlat = 1
        optimizeBeam = 0
        for i in range(numberSteps):
            theta_pos = theta_points[i + 1]
            scan_points.append(
                (
                    theta_pos,
                    [shutterOpen, shutterNoChange][i != 0],
                    inBeamPosition,
                    optimizeBeamNo,
                    image_key_project,
                    index,
                )
            )  # main image
            index = index + 1

            imageSinceFlat = imageSinceFlat + 1
            if imageSinceFlat == flatFieldInterval and flatFieldInterval != 0:
                for i in range(imagesPerFlat):
                    scan_points.append(
                        (
                            theta_pos,
                            [shutterOpen, shutterNoChange][i != 0],
                            outOfBeamPosition,
                            optimizeBeamNo,
                            image_key_flat,
                            index,
                        )
                    )
                    index = index + 1
                    imageSinceFlat = 0

            imageSinceDark = imageSinceDark + 1
            if imageSinceDark == darkFieldInterval and darkFieldInterval != 0:
                for i in range(imagesPerDark):
                    scan_points.append(
                        (
                            theta_pos,
                            [shutterClosed, shutterNoChange][i != 0],
                            inBeamPosition,
                            optimizeBeamNo,
                            image_key_dark,
                            index,
                        )
                    )
                    index = index + 1
                    imageSinceDark = 0

            optimizeBeam = optimizeBeam + 1
            if optimizeBeam == optimizeBeamInterval and optimizeBeamInterval != 0:
                scan_points.append(
                    (
                        theta_pos,
                        [shutterOpen, shutterNoChange][i != 0],
                        inBeamPosition,
                        optimizeBeamYes,
                        image_key_project,
                        index,
                    )
                )
                index = index + 1
                optimizeBeam = 0

        # add dark and flat only if not done in last steps
        if imageSinceFlat != 0:
            for i in range(imagesPerFlat):
                scan_points.append(
                    (
                        theta_pos,
                        [shutterOpen, shutterNoChange][i != 0],
                        outOfBeamPosition,
                        optimizeBeamNo,
                        image_key_flat,
                        index,
                    )
                )  # flat
                index = index + 1
        if imageSinceDark != 0:
            for i in range(imagesPerDark):
                scan_points.append(
                    (
                        theta_pos,
                        [shutterClosed, shutterNoChange][i != 0],
                        inBeamPosition,
                        optimizeBeamNo,
                        image_key_dark,
                        index,
                    )
                )  # dark
                index = index + 1
        scan_points1 = generateScanPoints(
            inBeamPosition,
            outOfBeamPosition,
            theta_points,
            darkFieldInterval,
            flatFieldInterval,
            imagesPerDark,
            imagesPerFlat,
            optimizeBeamInterval,
            pattern=pattern,
        )
        if pattern == "default" or pattern == "DFPFD":
            i = 0
            for pt1 in scan_points1:
                pt = scan_points[i]
                if pt1 != pt:
                    print "Mismatch - please tell Kaz about your scan and its arguments!"
                    print "i = ", i
                    print "pt = ", pt
                    print "pt1 = ", pt1
                i += 1
        # return None
        positionProvider = tomoScan_positions(
            start,
            stop,
            step,
            darkFieldInterval,
            imagesPerDark,
            flatFieldInterval,
            imagesPerFlat,
            inBeamPosition,
            outOfBeamPosition,
            optimizeBeamInterval,
            scan_points,
        )
        scan_args = [
            tomoScanDevice,
            positionProvider,
            tomography_time,
            tomography_beammonitor,
            tomography_detector,
            exposureTime,
            tomography_camera_stage,
            tomography_sample_stage,
        ]
        # scan_args.append(RotationAxisScannable("approxCOR", tomoRotationAxis))
        # meta_add(RotationAxisScannable("approxCOR", tomoRotationAxis))
        # meta_add("RotationCoord_as_list", [tomoRotationAxis])
        meta_add("approxCOR", tomoRotationAxis)
        for scannable in additionalScannables:
            scan_args.append(scannable)
        for scannable in tomo_additional_scannables:
            scan_args.append(scannable)
        """ setting the description provided as the title"""
        if not description == None:
            setTitle(description)
        else:
            setTitle("undefined")

        dataFormat = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
        if not dataFormat == "NexusDataWriter":
            handle_messages.simpleLog(
                "Data format inconsistent. Setting 'gda.data.scan.datawriter.dataFormat' to 'NexusDataWriter'"
            )
            LocalProperties.set("gda.data.scan.datawriter.dataFormat", "NexusDataWriter")
        scanObject = createConcurrentScan(scan_args)
        if addNXEntry:
            addNXTomoSubentry(scanObject, tomography_detector.name, tomography_theta.name)
        scanObject.runScan()
        if autoAnalyse:
            lsdp = jns.lastScanDataPoint()
            OSCommandRunner.runNoWait(
                ["/dls_sw/apps/tomopy/tomopy/bin/gda/tomo_at_scan_end", lsdp.currentFilename],
                OSCommandRunner.LOGOPTION.ALWAYS,
                None,
            )
        return scanObject
    except InterruptedException:
        exceptionType, exception, traceback = sys.exc_info()
        handle_messages.log(None, "User interrupted the scan", exceptionType, exception, traceback, False)
        raise InterruptedException("User interrupted the scan")
    except:
        exceptionType, exception, traceback = sys.exc_info()
        handle_messages.log(None, "Error during tomography scan", exceptionType, exception, traceback, False)
        raise Exception("Error during tomography scan", exception)
    finally:
        handle_messages.simpleLog("Data Format reset to the original setting: " + dataFormat)
        LocalProperties.set("gda.data.scan.datawriter.dataFormat", dataFormat)
Ejemplo n.º 7
0
def tomoScanWithFrames(description,
                       inBeamPosition,
                       outOfBeamPosition,
                       exposureTime=1.,
                       start=0.,
                       stop=180.,
                       step=0.1,
                       darkFieldInterval=0,
                       flatFieldInterval=0,
                       imagesPerDark=10,
                       imagesPerFlat=10,
                       optimizeBeamInterval=0,
                       pattern="default",
                       nframes=1,
                       tomoRotationAxis=0,
                       addNXEntry=True,
                       autoAnalyse=True,
                       additionalScannables=[]):
    """
    Function to collect a tomography step scan with multiple projection frames per scan point 
    Arguments:
    description - description of the scan or the sample that is being scanned. This is generally user-specific information that may be used to map to this scan later and is available in the NeXus file)
    inBeamPosition - position of X drive to move sample into the beam to take a projection
    outOfBeamPosition - position of X drive to move sample out of the beam to take a flat field image
    exposureTime - exposure time in seconds (default=1.0)
    start - first rotation angle (default=0.0)
    stop  - last rotation angle (default=180.0)
    step - rotation step size (default=0.1)
    darkFieldInterval - number of projection-frame sub-series between each dark-field sub-series. 
        NOTE: at least 1 dark is ALWAYS taken both at the start and end of the scan, provided imagesPerDark>0 
        (default=0: use this value if you DON'T want to take any darks between projections)
    flatFieldInterval - number of projection-frame sub-series between each flat-field sub-series. 
        NOTE: at least 1 flat is ALWAYS taken both at the start and end the scan, provided imagesPerFlat>0 
        (default=0: use this value if you DON'T want to take any flats between projections)
    imagesPerDark - number of images to be taken in each dark-field sub-series (default=10)
    imagesPerFlat - number of images to be taken in each flat-field sub-series (default=10)
    nframes - number of projection frames per angular position (default=1)
    
    General scan sequence is: D, F, P,..., P, F, D
    where D stands for dark field, F - for flat field, and P - for projection.
    """
    dataFormat = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
    try:
        darkFieldInterval = int(darkFieldInterval)
        flatFieldInterval = int(flatFieldInterval)
        optimizeBeamInterval = int(optimizeBeamInterval)

        image_key_frame = 3
        nframes = int(nframes)
        if nframes < 1:
            nframes = 1

        jns = beamline_parameters.JythonNameSpaceMapping(
            InterfaceProvider.getJythonNamespace())
        tomography_theta = jns.tomography_theta
        if tomography_theta is None:
            raise NameError(
                "tomography_theta is not defined in Jython namespace")
        tomography_shutter = jns.tomography_shutter
        if tomography_shutter is None:
            raise NameError(
                "tomography_shutter is not defined in Jython namespace")
        tomography_translation = jns.tomography_translation
        if tomography_translation is None:
            raise NameError(
                "tomography_translation is not defined in Jython namespace")

        tomography_detector = jns.tomography_detector
        if tomography_detector is None:
            raise NameError(
                "tomography_detector is not defined in Jython namespace")

        tomography_optimizer = jns.tomography_optimizer
        if tomography_optimizer is None:
            raise NameError(
                "tomography_optimizer is not defined in Jython namespace")

        tomography_time = jns.tomography_time
        if tomography_time is None:
            raise NameError(
                "tomography_time is not defined in Jython namespace")

        tomography_beammonitor = jns.tomography_beammonitor
        if tomography_beammonitor is None:
            raise NameError(
                "tomography_beammonitor is not defined in Jython namespace")

        tomography_camera_stage = jns.tomography_camera_stage
        if tomography_camera_stage is None:
            raise NameError(
                "tomography_camera_stage is not defined in Jython namespace")

        tomography_sample_stage = jns.tomography_sample_stage
        if tomography_sample_stage is None:
            raise NameError(
                "tomography_sample_stage is not defined in Jython namespace")

        tomo_additional_scannables = jns.tomography_additional_scannables
        if tomo_additional_scannables is None:
            raise NameError(
                "tomo_additional_scannables is not defined in Jython namespace"
            )

        index = SimpleScannable()
        index.setCurrentPosition(0.0)
        index.setInputNames(["imageNumber"])
        index.setName("imageNumber")
        index.configure()

        image_key = SimpleScannable()
        image_key.setCurrentPosition(0.0)
        image_key.setInputNames(["image_key"])
        image_key.setName("image_key")
        image_key.configure()

        tomoScanDevice = make_tomoScanDevice(tomography_theta,
                                             tomography_shutter,
                                             tomography_translation,
                                             tomography_optimizer, image_key,
                                             index)

        #        return tomoScanDevice
        #generate list of positions
        numberSteps = ScannableUtils.getNumberSteps(tomography_theta, start,
                                                    stop, step)
        theta_points = []
        theta_points.append(start)
        previousPoint = start
        for i in range(numberSteps):
            nextPoint = ScannableUtils.calculateNextPoint(previousPoint, step)
            theta_points.append(nextPoint)
            previousPoint = nextPoint

        #generateScanPoints
        optimizeBeamNo = 0
        optimizeBeamYes = 1
        shutterOpen = 1
        shutterClosed = 0
        shutterNoChange = 2
        scan_points = []
        theta_pos = theta_points[0]
        index = 0
        #Added shutterNoChange state for the shutter. The scan points are added using the (pseudo) ternary operator,
        #if index is 0 then the shutterPosition is added to the scan point, else shutterNoChange is added to scan points.
        for i in range(imagesPerDark):
            scan_points.append(
                (theta_pos, [shutterClosed, shutterNoChange][i != 0],
                 inBeamPosition, optimizeBeamNo, image_key_dark, index))  #dark
            index = index + 1

        for i in range(imagesPerFlat):
            scan_points.append(
                (theta_pos, [shutterOpen,
                             shutterNoChange][i != 0], outOfBeamPosition,
                 optimizeBeamNo, image_key_flat, index))  #flat
            index = index + 1
        for frm in range(nframes):
            scan_points.append(
                (theta_pos, shutterOpen, inBeamPosition, optimizeBeamNo,
                 image_key_project if frm == 0 else image_key_frame,
                 index))  #first
            index = index + 1
        imageSinceDark = 1
        imageSinceFlat = 1
        optimizeBeam = 0
        for i in range(numberSteps):
            theta_pos = theta_points[i + 1]
            for frm in range(nframes):
                scan_points.append(
                    (theta_pos, [shutterOpen, shutterNoChange
                                 ][i != 0], inBeamPosition, optimizeBeamNo,
                     image_key_project if frm == 0 else image_key_frame,
                     index))  #main image
                index = index + 1

            imageSinceFlat = imageSinceFlat + 1
            if imageSinceFlat == flatFieldInterval and flatFieldInterval != 0:
                for i in range(imagesPerFlat):
                    scan_points.append(
                        (theta_pos, [shutterOpen, shutterNoChange
                                     ][i != 0], outOfBeamPosition,
                         optimizeBeamNo, image_key_flat, index))
                    index = index + 1
                    imageSinceFlat = 0

            imageSinceDark = imageSinceDark + 1
            if imageSinceDark == darkFieldInterval and darkFieldInterval != 0:
                for i in range(imagesPerDark):
                    scan_points.append(
                        (theta_pos, [shutterClosed,
                                     shutterNoChange][i != 0], inBeamPosition,
                         optimizeBeamNo, image_key_dark, index))
                    index = index + 1
                    imageSinceDark = 0

            optimizeBeam = optimizeBeam + 1
            if optimizeBeam == optimizeBeamInterval and optimizeBeamInterval != 0:
                scan_points.append(
                    (theta_pos, [shutterOpen,
                                 shutterNoChange][i != 0], inBeamPosition,
                     optimizeBeamYes, image_key_project, index))
                index = index + 1
                optimizeBeam = 0

        #add dark and flat only if not done in last steps
        if imageSinceFlat != 0:
            for i in range(imagesPerFlat):
                scan_points.append(
                    (theta_pos, [shutterOpen,
                                 shutterNoChange][i != 0], outOfBeamPosition,
                     optimizeBeamNo, image_key_flat, index))  #flat
                index = index + 1
        if imageSinceDark != 0:
            for i in range(imagesPerDark):
                scan_points.append(
                    (theta_pos, [shutterClosed,
                                 shutterNoChange][i != 0], inBeamPosition,
                     optimizeBeamNo, image_key_dark, index))  #dark
                index = index + 1


#        scan_points1 = generateScanPoints(inBeamPosition, outOfBeamPosition, theta_points, darkFieldInterval, flatFieldInterval,
#              imagesPerDark, imagesPerFlat, optimizeBeamInterval, pattern=pattern)
#        if pattern == 'default' or pattern == 'DFPFD':
#            i = 0
#            for pt1 in scan_points1:
#                pt = scan_points[i]
#                if pt1 != pt:
#                    print "Mismatch - please tell Kaz about your scan and its arguments!"
#                    print "i = ", i
#                    print "pt = ", pt
#                    print "pt1 = ", pt1
#                i += 1
#return None
        positionProvider = tomoScan_positions(start, stop, step, darkFieldInterval, imagesPerDark, flatFieldInterval, imagesPerFlat, \
                                               inBeamPosition, outOfBeamPosition, optimizeBeamInterval, scan_points)
        scan_args = [
            tomoScanDevice, positionProvider, tomography_time,
            tomography_beammonitor, tomography_detector, exposureTime,
            tomography_camera_stage, tomography_sample_stage
        ]
        #scan_args.append(RotationAxisScannable("approxCOR", tomoRotationAxis))
        #meta_add(RotationAxisScannable("approxCOR", tomoRotationAxis))
        #meta_add("RotationCoord_as_list", [tomoRotationAxis])
        meta_add("approxCOR", tomoRotationAxis)
        for scannable in additionalScannables:
            scan_args.append(scannable)
        for scannable in tomo_additional_scannables:
            scan_args.append(scannable)
        ''' setting the description provided as the title'''
        if not description == None:
            setTitle(description)
        else:
            setTitle("undefined")

        dataFormat = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
        if not dataFormat == "NexusDataWriter":
            handle_messages.simpleLog(
                "Data format inconsistent. Setting 'gda.data.scan.datawriter.dataFormat' to 'NexusDataWriter'"
            )
            LocalProperties.set("gda.data.scan.datawriter.dataFormat",
                                "NexusDataWriter")
        scanObject = createConcurrentScan(scan_args)
        if addNXEntry:
            addNXTomoSubentry(scanObject, tomography_detector.name,
                              tomography_theta.name)
        scanObject.runScan()
        if autoAnalyse:
            lsdp = jns.lastScanDataPoint()
            OSCommandRunner.runNoWait([
                "/dls_sw/apps/tomopy/tomopy/bin/gda/tomo_at_scan_end_kz",
                lsdp.currentFilename
            ], OSCommandRunner.LOGOPTION.ALWAYS, None)
        return scanObject
    except InterruptedException:
        exceptionType, exception, traceback = sys.exc_info()
        handle_messages.log(None, "User interrupted the scan", exceptionType,
                            exception, traceback, False)
        raise InterruptedException("User interrupted the scan")
    except:
        exceptionType, exception, traceback = sys.exc_info()
        handle_messages.log(None, "Error during tomography scan",
                            exceptionType, exception, traceback, False)
        raise Exception("Error during tomography scan", exception)
    finally:
        handle_messages.simpleLog(
            "Data Format reset to the original setting: " + dataFormat)
        LocalProperties.set("gda.data.scan.datawriter.dataFormat", dataFormat)
Ejemplo n.º 8
0
 def __init__(self, commandServer=None):
     if commandServer == None:
         commandServer = InterfaceProvider.getJythonNamespace()
     self.reload(commandServer)