Ejemplo n.º 1
0
def setProperty(propertyName, propertyValue):
    LocalProperties.set(propertyName, propertyValue)
    eventAdmin=Finder.getInstance().find("eventadmin")
    if eventAdmin is None:
        print "Cannot find 'eventAdmin' on the GDA server. Please create a Spring bean using 'Scriptcontroller' Java class"
    else:
        eventAdmin.update(propertyName, propertyValue)
def prepareEmptyGdaVarFolder():
    vartest_dir = os.path.join(os.getcwd(), 'var_test')
    LocalProperties.set('gda.var', vartest_dir)
    if os.path.exists(vartest_dir):
        print "Removing existing gda.var: ", vartest_dir
        shutil.rmtree(vartest_dir)
    print "Creating gda.var: ", vartest_dir
    os.mkdir(vartest_dir)
def prepareEmptyGdaVarFolder():
    vartest_dir = os.path.join(os.getcwd(), 'var_test')
    LocalProperties.set('gda.var', vartest_dir)
    if os.path.exists(vartest_dir):
        print "Removing existing gda.var: ", vartest_dir
        shutil.rmtree(vartest_dir)
    print "Creating gda.var: ", vartest_dir
    os.mkdir(vartest_dir)
Ejemplo n.º 4
0
def setYFieldVisibleInScanPlot(indices=[-1]):
    '''set the Y fields visible in Scan Plot using indices starting from 1.
       this setting will be in effect as default until next update.
    @param indices - a list of indices to be visible in the plot
           GAD scan default is -1, means the last index
           0 index means nothing visible
    '''
    LocalProperties.set("gda.plot.ScanPlotSettings.YFieldIndicesVisible",
                        ":".join(map(str, indices)))
Ejemplo n.º 5
0
def datadir(newpath=None):
	"""
	Reads or sets the data directory. May also need to configure some detectors.
	"""
	if newpath==None:
		return LocalProperties.getPath("gda.data.scan.datawriter.datadir",None)
	else:
		if not os.path.exists(newpath):
			raise ValueError("The directory %s does NOT exist!"%newpath)

		print "Setting gda.data.scan.datawriter.datadir preference..."
		LocalProperties.set("gda.data.scan.datawriter.datadir", newpath)
#		Save to localShelf
		return LocalProperties.getPath("gda.data.scan.datawriter.datadir",None)
Ejemplo n.º 6
0
def datadir(newpath=None):
    """
	Reads or sets the data directory. May also need to configure some detectors.
	"""
    if newpath == None:
        return LocalProperties.getPath("gda.data.scan.datawriter.datadir",
                                       None)
    else:
        if not os.path.exists(newpath):
            raise ValueError("The directory %s does NOT exist!" % newpath)

        print "Setting gda.data.scan.datawriter.datadir preference..."
        LocalProperties.set("gda.data.scan.datawriter.datadir", newpath)
        #		Save to localShelf
        return LocalProperties.getPath("gda.data.scan.datawriter.datadir",
                                       None)
Ejemplo n.º 7
0
def setDataWriterToSrs():
    oldDW = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
    LocalProperties.set("gda.data.scan.datawriter.dataFormat", "SrsDataFile")
    newDW = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
    print "Old DataWriter: ", oldDW
    print "New DataWriter: ", newDW
Ejemplo n.º 8
0
from gda.configuration.properties import LocalProperties
from gda.factory import Finder
from gda.observable import IObserver
from uk.ac.diamond.daq.persistence.jythonshelf import LocalParameters
from gda.data.metadata import GDAMetadataProvider
BSL_CONVERSION_CONFIGURED = 'gda.scan.processing.bsl.configured'

RUNNER = Finder.getInstance().find('bslConversion')

class BslConversionUpdater(IObserver):
    def update(self, source, arg):
        print 'Visit changed to ' + str(arg)
        restore()

if not LocalProperties.contains(BSL_CONVERSION_CONFIGURED):
    LocalProperties.set(BSL_CONVERSION_CONFIGURED, 'True')
    for meta in GDAMetadataProvider.getInstance().getMetadataEntries():
        if meta.name == 'visit':
            break
    if meta:
        meta.addIObserver(BslConversionUpdater())


CONFIGURATION_FILE = 'bslUsers'
DEFAULT = False

STORE = LocalParameters.getXMLConfiguration(CONFIGURATION_FILE)

def isConvertingOn():
    """Check whether new files will be converted automatically"""
    return RUNNER.enabled
Ejemplo n.º 9
0
    alias("createPVScannable")
    alias("caput")
    alias("caget")
    
    from gda.scan.RepeatScan import create_repscan, repscan
    vararg_alias("repscan")

    #setup tools to create metadata in Nexus files
    from gdascripts.metadata.metadata_commands import setTitle, meta_add, meta_ll, meta_ls, meta_rm
    alias("setTitle")
    alias("meta_add")
    alias("meta_ll")
    alias("meta_ls")
    alias("meta_rm")
    from gda.data.scan.datawriter import NexusDataWriter
    LocalProperties.set(NexusDataWriter.GDA_NEXUS_METADATAPROVIDER_NAME,"metashop")
    
    #create time scannables
    from gdascripts.pd.time_pds import waittimeClass2, showtimeClass, showincrementaltimeClass, actualTimeClass
    waittime=waittimeClass2('waittime')
    showtime=showtimeClass('showtime')
    inctime=showincrementaltimeClass('inctime')
    actualTime=actualTimeClass("actualTime")

    #run user editable startup script 
    if isLive():
        run("localStationUser.py")

except:
    exceptionType, exception, traceback = sys.exc_info()
    handle_messages.log(None, "Error in localStation", exceptionType, exception, traceback, False)
Ejemplo n.º 10
0
def asciiformat():
    LocalProperties.set(LocalProperties.GDA_DATA_SCAN_DATAWRITER_DATAFORMAT,
                        "SrsDataFile")
Ejemplo n.º 11
0
def nexusformat():
    LocalProperties.set(LocalProperties.GDA_DATA_SCAN_DATAWRITER_DATAFORMAT,
                        "NexusDataWriter")
Ejemplo n.º 12
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.º 13
0
from gda.observable import IObserver
from uk.ac.diamond.daq.persistence.jythonshelf import LocalParameters
from gda.data.metadata import GDAMetadataProvider
BSL_CONVERSION_CONFIGURED = 'gda.scan.processing.bsl.configured'

RUNNER = Finder.getInstance().find('bslConversion')


class BslConversionUpdater(IObserver):
    def update(self, source, arg):
        print 'Visit changed to ' + str(arg)
        restore()


if not LocalProperties.contains(BSL_CONVERSION_CONFIGURED):
    LocalProperties.set(BSL_CONVERSION_CONFIGURED, 'True')
    for meta in GDAMetadataProvider.getInstance().getMetadataEntries():
        if meta.name == 'visit':
            break
    if meta:
        meta.addIObserver(BslConversionUpdater())

CONFIGURATION_FILE = 'bslUsers'
DEFAULT = False

STORE = LocalParameters.getXMLConfiguration(CONFIGURATION_FILE)


def isConvertingOn():
    """Check whether new files will be converted automatically"""
    return RUNNER.enabled
Ejemplo n.º 14
0
 #   alias("createPVScannable")
  #  alias("caput")
   # alias("caget")
    
    from gda.scan.RepeatScan import create_repscan, repscan
    vararg_alias("repscan")

    #setup tools to create metadata in Nexus files
    from gdascripts.metadata.metadata_commands import setTitle, meta_add, meta_ll, meta_ls, meta_rm
    alias("setTitle")
    alias("meta_add")
    alias("meta_ll")
    alias("meta_ls")
    alias("meta_rm")
    from gda.data.scan.datawriter import NexusDataWriter
    LocalProperties.set(NexusDataWriter.GDA_NEXUS_METADATAPROVIDER_NAME,"metashop")
    
    #create time scannables
    from gdascripts.pd.time_pds import waittimeClass2, showtimeClass, showincrementaltimeClass, actualTimeClass
    waittime=waittimeClass2('waittime')
    showtime=showtimeClass('showtime')
    inctime=showincrementaltimeClass('inctime')
    actualTime=actualTimeClass("actualTime")
    
    #===================================================
    #Raspberry Pi Specific Objects
    #===================================================
    #RPi Communication Interface
    #rpiComms.initaliseCommunicator("127.23.31.56") #enter the Pi's IP address, 127.0.0.1 (localhost) should work

    #PiCamera Interface
Ejemplo n.º 15
0
def useSingleYAxis():
    ''' use the same Y axis for all Y fields in the Scan Plot
    '''
    LocalProperties.set("gda.plot.ScanPlotSettings.separateYAxes",
                        Boolean.toString(False))
Ejemplo n.º 16
0
def useSeparateYAxes():
    '''use separate Y axes for each Y field in the Scan Plot
    '''
    LocalProperties.set("gda.plot.ScanPlotSettings.separateYAxes",
                        Boolean.toString(True))
Ejemplo n.º 17
0
def setXFieldInScanPlot(index):
    '''set the X field to be used as X-axis in the Scan Plot.
        GDA scan default to -1, the last index to be scanned
    '''
    LocalProperties.set("gda.plot.ScanPlotSettings.XFieldIndex", str(index))
Ejemplo n.º 18
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.º 19
0
def asciiformat():
    LocalProperties.set(LocalProperties.GDA_DATA_SCAN_DATAWRITER_DATAFORMAT,
                        "SixdSrsDataWriter")