Пример #1
0
 def __init__(self, name, idctrl, pgmenergy, lut="JIDEnergy2GapCalibrations.csv", energyConstant=False, polarisationConstant=False, gap_offset=None, feedbackPV=None):
     '''Constructor - Only succeed if it find the lookupTable table, otherwise raise exception.'''
     self.lut,self.header = load_lookup_table(LocalProperties.get("gda.config")+"/lookupTables/"+lut)
     self.idscannable = idctrl
     self.mono_energy = pgmenergy
     self.scannables = ScannableGroup(name, [pgmenergy, idctrl])
     self.detune = gap_offset
     self.feedbackPV = feedbackPV
     self._busy = 0
     self.setName(name)
     self.setLevel(3)
     self.setOutputFormat(["%10.6f"])
     self.setInputNames([name])
     self.setExtraNames([])
     self.polarisation = 'LH'
     self.gap = 50
     self.phase = 0
     self.energyConstant = energyConstant
     self.polarisationConstant = polarisationConstant
     self.SCANNING = False
     if self.energyConstant and self.polarisationConstant:
         raise RuntimeError("Cannot create an instance with both energy and polarisation being constant.")
     self.isConfigured = False
     self.inputSignSwitched = False
     self.beamlinename = LocalProperties.get(LocalProperties.GDA_BEAMLINE_NAME)
     self.logger = logger.getChild(self.__class__.__name__)
Пример #2
0
	def __init__(self, filespec=None, dir=None):
		
		self.format = LocalProperties.get("gda.data.scan.datawriter.dataFormat")
		if dir!=None and dir != "None":
			self.dir=dir
		else:
			self.dir = PathConstructor.createFromDefaultProperty()
		self.beamline = GDAMetadataProvider.getInstance().getMetadataValue("instrument", LocalProperties.GDA_INSTRUMENT, "tmp")
		if (self.format == "NexusDataWriter"):
			#really should use scanFileName prefix rather than forcing to beamline-
			self.prefix = LocalProperties.get("gda.data.filePrefix",self.beamline + "-")
			self.ext = "nxs"
			if filespec==None:
				filespec = "%d" % NumTracker(self.beamline).currentFileNumber
			
		else:
			self.prefix = ""
			self.ext = "dat"
			if filespec==None:
				filespec = "%d" % NumTracker().currentFileNumber
		
		filespec = filespec.__str__()
		
		self.filename = self.tryFiles([ filespec, self.dir+"/"+filespec, self.prefix+filespec+"."+self.ext, self.dir+"/"+self.prefix+filespec+"."+self.ext, self.dir+"/"+filespec+"."+self.ext ])
		
		if (self.filename == None):
			raise Exception("no file found for %s" % filespec)
Пример #3
0
    def __init__(self, filespec=None, dir=None):

        self.format = LocalProperties.get(
            "gda.data.scan.datawriter.dataFormat")
        if dir != None and dir != "None":
            self.dir = dir
        else:
            self.dir = PathConstructor.createFromDefaultProperty()
        self.beamline = GDAMetadataProvider.getInstance().getMetadataValue(
            "instrument", LocalProperties.GDA_INSTRUMENT, "tmp")
        if (self.format == "NexusDataWriter"):
            #really should use scanFileName prefix rather than forcing to beamline-
            self.prefix = LocalProperties.get("gda.data.filePrefix",
                                              self.beamline + "-")
            self.ext = "nxs"
            if filespec == None:
                filespec = "%d" % NumTracker(self.beamline).currentFileNumber

        else:
            self.prefix = ""
            self.ext = "dat"
            if filespec == None:
                filespec = "%d" % NumTracker().currentFileNumber

        filespec = filespec.__str__()

        self.filename = self.tryFiles([
            filespec, self.dir + "/" + filespec,
            self.prefix + filespec + "." + self.ext,
            self.dir + "/" + self.prefix + filespec + "." + self.ext,
            self.dir + "/" + filespec + "." + self.ext
        ])

        if (self.filename == None):
            raise Exception("no file found for %s" % filespec)
Пример #4
0
 def __init__(self, name, idctrl, pgmenergy, lut="JIDEnergy2GapCalibrations.txt", energyConstant=False, polarisationConstant=False):
     '''Constructor - Only succeed if it find the lookupTable table, otherwise raise exception.'''
     self.lut=loadLookupTable(LocalProperties.get("gda.config")+"/lookupTables/"+lut)
     self.idscannable=idctrl
     self.pgmenergy=pgmenergy
     self.scannables=ScannableGroup(name, [pgmenergy, idctrl])
     self._busy=0
     self.setName(name)
     self.setLevel(3)
     self.setOutputFormat(["%10.6f"])
     self.setInputNames([name])
     self.setExtraNames([])
     self.order=1
     self.polarisation=0.0
     self.gap=50
     self.polarisationMode='UNKNOWN'
     self.phase=0
     self.energyConstant=energyConstant
     self.polarisationConstant=polarisationConstant
     self.SCANNING=False
     if self.energyConstant and self.polarisationConstant:
         raise Exception("Cannot create an instance with both energy and polarisation being constant.")
     self.isConfigured=False
     self.inputSignSwitched=False
     self.beamlinename=LocalProperties.get(LocalProperties.GDA_BEAMLINE_NAME)
     self.logger = logger.getChild(self.__class__.__name__)
Пример #5
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)
Пример #8
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)))
Пример #9
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)
 def doCalibration(self, calibrant='Si', calibrant_x=0, calibrant_y=0, calibrant_exposure=1.0):
     if self.calibration_required:
         mycalibrant=Finder.getInstance().find("calibrant_name")
         mycalibrant.moveTo(calibrant)
         
         dummyScannable=DummyScannable("dummyScannable")
         
         #additional_plugin_list = pixium.getAdditionalPluginList()[0]
         #Detector calibration
         if self.calibration_required:
             self.stage_x.moveTo(calibrant_x)
             self.stage_y.moveTo(calibrant_y)
             scan([dummyScannable, 1, 1, 1, self.pixium, calibrant_exposure])
             #TODO GDA .nxs file, not EPICS h5 file
             scan_data_point_provider = InterfaceProvider.getScanDataPointProvider()
             self.calibrant_file_name = scan_data_point_provider.getLastScanDataPoint().getCurrentFilename()
             #calibrant_file_name = additional_plugin_list.getFullFileName()
             #do detector calibration on cluster serevrs
             builder = OSCommandRunnerBuilder.defaults()
             builder=builder.command([LocalProperties.get("org.opengda.lde.pixium.data.reduction.script","/dls_sw/apps/i11-scripts/bin/LDE-RunFromGDAAtEndOfScan.sh")])
             builder=builder.keepOutput(True)
             builder = builder.inputFilename(self.calibrant_file_name)
             builder = builder.outputFilename(os.path.splitext(self.calibrant_file_name)[0]+"_output.log")
             builder=builder.noTimeout()
             builder.build()
             self.calibration_required=False
Пример #11
0
def __getGdaModeProperty():
    mode = str(LocalProperties.get("gda.mode"))
    if mode not in ("live", "dummy", "simulation"):
        raise ValueError(
            "gda.mode LocalProperty (perhaps via a System property) must be 'live' or 'dummy' not:",
            mode)
    return mode
Пример #12
0
def getYFieldVisibleInScanPlot():
    '''return the indices of the current Y fields visible in Scan Plot
         -1 means the last index
         0 means no visible data trace
    '''
    return LocalProperties.getAsIntList(
        "gda.plot.ScanPlotSettings.YFieldIndicesVisible")
Пример #13
0
def loadEnergyFocus():
    stashFilePath = LocalProperties.get(
        "gda.var") + "/energyFocusFunction.json"
    print("Loading energy/focus parameters from " + abspath(stashFilePath))

    try:
        stashFile = open(stashFilePath, 'r')
        stashedValue = json.load(stashFile)
        stashFile.close()

        slopeDividend = stashedValue.get('slopeDividend')
        interception = stashedValue.get('interception')
        slopeDivisor = stashedValue.get('slopeDivisor')
    except:
        print("Cannot load stored energy focus values from " +
              abspath(stashFilePath) + ", using defaults")
        slopeDividend = u'0.0 µm'
        interception = u'0.0 µm'
        slopeDivisor = '1.0 eV'

    energyFocusFunction.setSlopeDividend(
        QuantityFactory.createFromString(slopeDividend))
    energyFocusFunction.setInterception(
        QuantityFactory.createFromString(interception))
    energyFocusFunction.setSlopeDivisor(
        QuantityFactory.createFromString(slopeDivisor))
    print("energyFocusFunction set to: " + energyFocusFunction.toString())
Пример #14
0
def setDir(proposal=None, visit=1):
    #get beamline name from GDA propertie
    #beamlineName = LocalProperties.get("gda.instrument");
    beamlineName = LocalProperties.get("gda.beamline.name")

    commissioningProposal = bpDict.get(beamlineName, 'unknownPorposal')

    if proposal is None:  # the default commissioning proposal
        proposal = commissioningProposal

    userDir = proposal + "-" + str(visit)
    #get current Year
    currentTime = localtime()
    currentYear = currentTime[0]

    userDir = "/dls/" + beamlineName + "/data/" + str(
        currentYear) + "/" + userDir
    symbolicLink = "/dls/" + beamlineName + "/data/operation"

    print "New user data directory is: " + userDir

    #remove the old symbolic link
    system("rm -f " + symbolicLink)

    #create the new symbolic link to point to the user data directory
    system("ln -s " + userDir + " " + symbolicLink)
Пример #15
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)
Пример #16
0
def setDir(proposal, visit, LocalProperties=LocalProperties):
    
    #get beamline name from GDA propertie
    #beamlineName = LocalProperties.get("gda.beamline.name");
    beamlineName = LocalProperties.get("gda.instrument.name");
    
    commissioningProposal = bpDict.get(beamlineName, 'unknownPorposal');
    
    if proposal == commissioningProposal: # the default commissioning proposal
        userDir = proposal;
    else:
        userDir = proposal + "-" + str(visit);
    #get current Year
    currentTime = time.localtime();
    currentYear = currentTime[0];


    userDir="/dls/" + beamlineName + "/data/" + str(currentYear) + "/" + userDir;
    symbolicLink = "/dls/" + beamlineName + "/data/operation";

    print "New user data directory is: " + userDir;

    #remove the old symbolic link
    os.system("rm -f " + symbolicLink);
    
    #create the new symbolic link to point to the user data directory
    os.system("ln -s " + userDir + " " + symbolicLink);
Пример #17
0
 def __init__(self,
              name,
              idgap,
              dcmenergy,
              lut,
              gap_offset=None,
              feedbackPVs=None):
     """
     Constructor - Only succeeds if it finds the lookup table,
     otherwise raises exception.
     """
     self.lut = readLookupTable(
         LocalProperties.get("gda.config") + "/lookupTables/" + lut)
     self.gap = idgap
     self.mono_energy = dcmenergy
     self.lambdau = 27  # undulator period
     self.scannables = ScannableGroup(name, [dcmenergy, idgap])
     self.detune = gap_offset
     self.feedbackPVs = feedbackPVs
     self._busy = 0
     self.setName(name)
     self.setLevel(3)
     self.setOutputFormat(["%10.6f"])
     self.inputNames = [name]
     self.order = 3
     self.SCANNING = False
     self.logger = logger.getChild(self.__class__.__name__)
Пример #18
0
 def reload(self, commandServer):
     self.commandServer = commandServer
     self.jythonNamespaceMapping = {}
     self.jythonNamespaceMapFilePath = LocalProperties.get(
         JYTHON_NAMESPACE_MAPPING_FILE_PROPERTY)
     if (self.jythonNamespaceMapFilePath != None):
         self.jythonNamespaceMapping = readDictionaryFromFile(
             self.jythonNamespaceMapFilePath, self.jythonNamespaceMapping)
Пример #19
0
 def reload(self, finder):
     self.finder = finder
     self.finderNameMapping = {}
     self.finderNameMapFilePath = LocalProperties.get(
         FINDER_NAME_MAPPING_FILE_PROPERTY)
     if (self.finderNameMapFilePath != None):
         self.finderNameMapping = readDictionaryFromFile(
             self.finderNameMapFilePath, self.finderNameMapping)
def dataCollection(samples=[]):
    lookuptable=readLookupTable(LocalProperties.get("gda.function.lookupTable.dir")+os.path.sep+"lde_stages_home_positions.txt")
    
    for each in lookuptable.keys:
        stage=StageDataCollection(each)
        for sample in samples:
            if sample["cell_ID"].contains(each):
                stage.addSample(sample)
        stage.processSamples()
 def __init__(self, stageName):
     self.name=stageName
     self.calibrant_file_name=None
     self.stage_x=Finder.getInstance().find(stageName+"x")
     self.stage_y=Finder.getInstance().find(stageName+"y")
     self.stage_rot=Finder.getInstance().find(stageName+"rot")
     self.lookup_table = readLookupTable(LocalProperties.get("gda.function.lookupTable.dir")+os.path.sep+"lde_stages_home_positions.txt")
     self.samples=[]
     self.calibration_required=True
     self.pixium=Finder.getInstance().find('pixium_hdf')
Пример #22
0
 def __init__(self, name):
     logger.debug("Camera Setup")
     self.pin = -1
     self.device = name
     self.setName(name)
     self.currentPosition = 0
     self.lastPosition = 0  # required
     self.busyStatus = False
     beamlineName = LocalProperties.get("gda.beamline.name")
     self.numTracker = data.NumTracker(beamlineName)
     rpiComms.rpiCommunicator.scannables.append(self)
Пример #23
0
 def reload(self, parametersFilePath=None):
     if parametersFilePath == None:
         self.parametersFilePath = LocalProperties.get(
             BEAMLINE_PARAMETERS_FILE_PROPERTY)
         if (self.parametersFilePath == None):
             raise AttributeError, "property " + BEAMLINE_PARAMETERS_FILE_PROPERTY + " is not set"
     else:
         self.parametersFilePath = parametersFilePath
     self.parameters = {}
     self.parameters = readDictionaryFromFile(self.parametersFilePath,
                                              self.parameters)
 def __init__(self, name):
     logger.debug("Camera Setup")
     self.pin = -1 
     self.device = name
     self.setName(name)
     self.currentPosition = 0
     self.lastPosition = 0                                         # required
     self.busyStatus = False
     beamlineName = LocalProperties.get("gda.beamline.name")
     self.numTracker = data.NumTracker(beamlineName)
     rpiComms.rpiCommunicator.scannables.append(self)
Пример #25
0
 def __init__(self, name):  #setup stuff
     logger.debug("Camera Setup")
     #self.pin = -1
     self.device = name
     self.setName(
         name)  #this is setting up the name passed in localstation.py
     self.currentPosition = 0
     self.lastPosition = 0  # required
     self.busyStatus = False
     beamlineName = LocalProperties.get("gda.beamline.name")
     self.numTracker = data.NumTracker(beamlineName)
     print "camera setup"
Пример #26
0
	def getLastCommand(self):
		#jsf=InterfaceProvider.getJythonNamespace()
		jsf=JythonServerFacade.getInstance();
		
		historyFilePath = LocalProperties.get("gda.jythonTerminal.commandHistory.path", jsf.getDefaultScriptProjectFolder());
		historyFileName = os.path.join(historyFilePath, ".cmdHistory.txt")
		
		if not os.path.exists(historyFileName):
			print "No history found"
			strCmd=''
		else:
			historyFile=open(historyFileName, 'r');
			strCmd=( historyFile.readlines() )[-1];
			historyFile.close();
			
		#print "The last command is: " + strCmd;
		return strCmd
Пример #27
0
def loadsampleinformationfile(filename, LocalProperties=LocalProperties):
    """Load sample information from users provided Excel spreadsheet into GDA system.
    
    usage:
            loadsampleinformationfile('/absolute/File/Path/To/Excel/Spreadsheet')
    """

    vardir = LocalProperties.get("gda.config") + "/var";
    defaulfFilename = vardir + "/SampleInfo.xls";
    #copy user supplied file over to GDA system
    val=os.system("cp -f " + filename + " " + defaulfFilename);
    
    if val == 0:
        print "load completed."
    else:
        raise Exception("File load failed.")
    # health check on file read/write permissions
    si.setSampleInfoFile(defaulfFilename) #@UndefinedVariable
Пример #28
0
 def __init__(self, name, lut):
     """
     Constructor - Only succeeds if it finds the lookup table,
     otherwise raises exception.
     """
     self.lut = readLookupTable(
         LocalProperties.get("gda.config") + "/lookupTables/" + lut)
     self.gap = "igap"
     self.dcm = "dcmenergy"
     self.lambdau = 27  # undulator period
     self.scannableNames = ["dcmenergy", "igap"]
     self.scannables = ScannableGroup(
         name, [Finder.find(x) for x in self.scannableNames])
     self._busy = 0
     self.setName(name)
     self.setLevel(3)
     self.setOutputFormat(["%10.6f"])
     self.inputNames = [name]
     self.order = 3
     self.logger = logger.getChild(self.__class__.__name__)
Пример #29
0
def getDir(proposal, visit, LocalProperties=LocalProperties):
    
    #get beamline name from GDA propertie
    #beamlineName = LocalProperties.get("gda.beamline.name");
    beamlineName = LocalProperties.get("gda.instrument.name");
    
    commissioningProposal = bpDict.get(beamlineName, 'unknownPorposal');
    
    if proposal == commissioningProposal: # the default commissioning proposal
        userDir = proposal;
    else:
        userDir = proposal + "-" + str(visit);

    #get current Year
    currentTime = time.localtime();
    currentYear = currentTime[0];

    userDir="/dls/" + beamlineName + "/data/" + str(currentYear) + "/" + userDir;
    symbolicLink = "/dls/" + beamlineName + "/data/operation";

    print userDir + " is the user data directory for this proposal and visit.";
Пример #30
0
 def __init__(self, name, idgap, pgmenergy, lut, gap_offset=None, feedbackPV=None):
     """
     Constructor -
     Only succeeds if it finds the lookup table, otherwise raises exception.
     """
     self.lut = readLookupTable(LocalProperties.get("gda.config") + "/lookupTables/" + lut)
     self.gap = idgap
     self.mono_energy = pgmenergy
     self.scannables = ScannableGroup(name, [pgmenergy, idgap])
     self.detune=gap_offset
     self.feedbackPV=feedbackPV
     self._busy = 0
     self.setName(name)
     self.setLevel(3)
     self.setOutputFormat(["%10.6f"])
     self.inputNames = [name]
     self.SCANNING=False
     self.order = 1
     self.polarisation = 'LH'
     self.jidphase = Finder.find("jidphase")
     self.logger = logger.getChild(self.__class__.__name__)
Пример #31
0
 def __init__(self, name, gap="jgap", dcm="pgmenergy", undulatorperiod=27, lut="JIDCalibrationTable.txt"):
     '''Constructor - Only succeed if it find the lookup table, otherwise raise exception.'''
     self.lut=readLookupTable(LocalProperties.get("gda.config")+"/lookupTables/"+lut)
     self.gap=gap
     self.dcm=dcm
     self.lambdau=undulatorperiod
     if dcm is None:
         self.scannableNames=[gap]
     else:
         self.scannableNames=[dcm,gap]
     self.scannables=ScannableGroup(name, [Finder.find(x) for x in self.scannableNames])
     self._busy=0
     self.setName(name)
     self.setLevel(3)
     self.setOutputFormat(["%10.6f"])
     self.inputNames=[name]
     if self.dcm == "dcmenergy":
         self.order=3
     else:
         self.order=1
     self.energy=self.scannables.getGroupMember(self.scannableNames[0]).getPosition()
     self.polarisation='H'
Пример #32
0
def getDir(proposal, visit, LocalProperties=LocalProperties):

    #get beamline name from GDA propertie
    #beamlineName = LocalProperties.get("gda.beamline.name");
    beamlineName = LocalProperties.get("gda.instrument.name")

    commissioningProposal = bpDict.get(beamlineName, 'unknownPorposal')

    if proposal == commissioningProposal:  # the default commissioning proposal
        userDir = proposal
    else:
        userDir = proposal + "-" + str(visit)

    #get current Year
    currentTime = time.localtime()
    currentYear = currentTime[0]

    userDir = "/dls/" + beamlineName + "/data/" + str(
        currentYear) + "/" + userDir
    symbolicLink = "/dls/" + beamlineName + "/data/operation"

    print userDir + " is the user data directory for this proposal and visit."
 def doSampleDataCollection(self, sample_x_start=None, sample_x_stop=None, sample_x_step=None, sample_y_start=None, sample_y_stop=None, sample_y_step=None, sample_exposure=1.0):
     # sample diffraction data
     args=[]
     
     if sample_x_start is not None or sample_x_stop is not None or sample_x_step is not None:
         args.append(self.stage_x)
     if sample_y_start is not None:
         args.append(sample_x_start)
     if sample_y_stop is not None:
         args.append(sample_x_stop)
     if sample_y_step is not None:
         args.append(sample_x_step)
     
     if sample_y_start is not None or sample_y_stop is not None or sample_y_step is not None:
         args.append(self.stage_y)
     if sample_y_start is not None:
         args.append(sample_y_start)
     if sample_y_stop is not None:
         args.append(sample_y_stop)
     if sample_y_step is not None:
         args.append(sample_y_step)
     if args.count!=0:
         args.append(self.pixium)
         args.append(sample_exposure)
     scan(args)
     #sample_file_name = additional_plugin_list.getFullFileName()
     scan_data_point_provider = InterfaceProvider.getScanDataPointProvider()
     sample_file_name = scan_data_point_provider.getLastScanDataPoint().getCurrentFilename()
     #builder = OSCommandRunnerBuilder.defaults()
     builder = OSCommandRunnerBuilder.defaults()
     builder=builder.command([LocalProperties.get("org.opengda.lde.pixium.data.reduction.script","/dls_sw/apps/i11-scripts/bin/LDE-RunFromGDAAtEndOfScan.sh"),self.calibrant_file_name])
     builder=builder.keepOutput(True)
     builder = builder.inputFilename(sample_file_name)
     builder = builder.outputFilename(os.path.splitext(sample_file_name)[0]+"_output.log")
     builder=builder.noTimeout()
     builder.build()
Пример #34
0
def getDataWriter():
    return LocalProperties.get("gda.data.scan.datawriter.dataFormat")
Пример #35
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
Пример #36
0
fileHeader = MetadataHeaderDeviceClass("fileHeader")

import __main__  # @UnresolvedImport

blList = [__main__.beamenergy, __main__.ringcurrent]
fileHeader.add(blList)

#bpmList= [xbpm1x, xbpm1y, xbpm2x, xbpm2y, xbpm1anglex, xbpm1angley]; fileHeader.add(bpmList);

idList = [
    __main__.iddgap, __main__.iddtrp, __main__.iddbrp, __main__.idugap,
    __main__.idutrp, __main__.idubrp, __main__.pugap
]
fileHeader.add(idList)

beamline = LocalProperties.get(LocalProperties.GDA_BEAMLINE_NAME)

if installation.isLive() and beamline != "lab44":
    pgmList = [
        __main__.pgmpitch, __main__.pgmgratpitch, __main__.cff,
        __main__.grating, __main__.pgmenergy
    ]
else:
    #grating requires EPICS access
    pgmList = [
        __main__.pgmpitch, __main__.pgmgratpitch, __main__.cff,
        __main__.pgmenergy
    ]

fileHeader.add(pgmList)
'''
Created on 29 Jan 2014

@author: fy65
'''
from time import sleep
from gda.configuration.properties import LocalProperties
from gda.data import NumTracker
scanNumTracker=NumTracker(LocalProperties.get(LocalProperties.GDA_BEAMLINE_NAME))
scanNumTracker.incrementNumber()

EXPOSURETIME=120 #seconds
TARGETCOUNT=100000
ONEMINUTECOUNT=1000
DELTAMIN=-15.0
DELTAMAX=77.0
scancount=0
Tolerance=0.1
NUMBEROFSCANS=TARGETCOUNT/ONEMINUTECOUNT*60/EXPOSURETIME
print "Number of scans to do: %d, total time taken: %f" % (NUMBEROFSCANS, NUMBEROFSCANS*EXPOSURETIME)
mythen.configure()  # @UndefinedVariable
mythen.atScanStart()  # @UndefinedVariable
mythen.setCollectionTime(EXPOSURETIME+10)  # @UndefinedVariable
delta.moveTo(DELTAMIN)  # @UndefinedVariable
delta.setSpeed((DELTAMAX-DELTAMIN)/(EXPOSURETIME))  # @UndefinedVariable
target=DELTAMAX
for i in range(NUMBEROFSCANS):
    sleep(5)
    if scancount % 2==0:
        target=DELTAMAX
    else:
Пример #38
0
"""Utility script to help manage BSL file conversion"""
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"""
Пример #39
0
    from gda.device.scannable.scannablegroup import ScannableGroup
    from gdascripts.scannable.dummy import SingleInputDummy as Dummy
    from diffcmd.diffcmd_utils import alias_commands
    GDA = True  
except ImportError:
    # Not running in gda environment so fall back to minigda emulation
    from diffcalc.gdasupport.minigda.scannable import ScannableGroup
    from diffcalc.gdasupport.minigda.scannable import SingleFieldDummyScannable as Dummy
    GDA = False


HELP_STRING = \
"""Quick:  https://github.com/DiamondLightSource/diffcalc/blob/master/README.rst
Manual: http://diffcalc.readthedocs.io/en/latest/youmanual.html
Type:   > help ub
        > help hkl"""


if GDA:
    from gda.configuration.properties import LocalProperties
    var_folder = LocalProperties.get("gda.var")
    diffcalc_persistance_path = os.path.join(var_folder, 'diffcalc')
    if not os.path.exists(diffcalc_persistance_path):
        print "Making diffcalc var folder:'%s'" % diffcalc_persistance_path
        os.makedirs(diffcalc_persistance_path)
    settings.ubcalc_persister = UBCalculationJSONPersister(diffcalc_persistance_path)
# else: should have been set if outside GDA



Пример #40
0
# See notes in: http://wiki.diamond.ac.uk/Wiki/Wiki.jsp?page=I06_Diffcalc

try:
    import diffcalc
except ImportError:
    from gda.configuration.properties import LocalProperties
    import sys
    diffcalc_path = LocalProperties.get(
        "gda.install.git.loc") + '/diffcalc.git'
    sys.path = [diffcalc_path] + sys.path
    print diffcalc_path + ' added to GDA Jython path.'
    import diffcalc

from gdascripts.pd.dummy_pds import DummyPD
from diffcalc.gdasupport.factory import create_objects, add_objects_to_namespace

CREATE_DUMMY_AXES = False
if CREATE_DUMMY_AXES:
    print "!!! Starting dummy diffcalc with tth, th, chi, phi and en."
    tth = DummyPD('tth')
    th = DummyPD('th')
    en = DummyPD('en')
    en(1500)
    diffcalc_energy = en
else:
    print "!!! Starting LIVE diffcalc with th(dd2th), th(ddth), chi(dummy), phi(dummy) and denergy."
    tth = dd2th
    th = ddth
    diffcalc_energy = denergy

chi = DummyPD('chi')
Пример #41
0
import sys

from gda.jython import InterfaceProvider
from gda.jython.commands.GeneralCommands import alias

from Diamond.Utility.UtilFun import UtilFunctions
from Diamond.Utility.BeamlineFunctions import BeamlineFunctionClass, logger

from Diamond.PseudoDevices.FastEnergyScan import FastEnergyScanControlClass, FastEnergyScanIDModeClass
from Diamond.PseudoDevices.FastEnergyScan import FastEnergyDeviceClass
#from Diamond.PseudoDevices.FastEnergyScan import EpicsScandataDeviceClass;
from Diamond.PseudoDevices.FastEnergyScan import EpicsWaveformDeviceClass
from gda.configuration.properties import LocalProperties

uuu = UtilFunctions()
beamline_name = LocalProperties.get(LocalProperties.GDA_BEAMLINE_NAME, "i06")
beamlineutil = BeamlineFunctionClass(beamline_name)

# Change rootPV to switch zacscan between IDs. (search for "switch zacscan" to find other changes needed)
rootPV = "BL06J-MO-FSCAN-01"
fastScanElementCounter = "iddFastScanElementCounter"
#rootPV = "BL06J-MO-FSCAN-02";
#fastScanElementCounter="iduFastScanElementCounter"
fesController = FastEnergyScanControlClass("fesController", rootPV)
zacmode = FastEnergyScanIDModeClass("zacmode", fesController)
#fesData = EpicsScandataDeviceClass("fesData", rootPV);
fesData = EpicsWaveformDeviceClass(
    "fesData",
    rootPV, ['C1', 'C2', 'C3', 'C4', 'iddenergy', 'pgmenergy', 'C5', 'C6'],
    ['idio', 'ifio'],
    elementCounter=fastScanElementCounter)
Пример #42
0
'''
Scannable defines the X-ray source mode to be one of ['idd','idu','dpu','dmu'] in GDA only. 
It enables and disable 'zacscan' support when sets the mode value.

Created on 13 Apr 2017

@author: fy65
'''
from gda.device.scannable import ScannableBase
from gda.configuration.properties import LocalProperties
from time import sleep
from gda.jython.commands import GeneralCommands
from i06shared import installation

gda_git_loc = LocalProperties.get(LocalProperties.GDA_GIT_LOC)


class SourceMode(ScannableBase):
    '''
    implements the 4 X-ray beam source modes
        1. Single operation of HU64a - specified by value 'idd'
        2. Single operation of HU64b - specified by value 'idu'
        3. Operation of HU64a and HU64b in the same polarisation - specified by value 'dpu'
        4. Operation of HU64a and HU64b, but with different polarisations - specified by value 'dmu'
        
    Instance of this Scannable set/get source mode value in GDA only which 
        - enables 'zacscan' for the single source modes - 'idd' and 'idu'
        - disables 'zacscan' for combined source modes - 'dpu' and 'dmu'
    '''
    SOURCE_MODES = ['idd', 'idu', 'dpu', 'dmu', 'unknown']
Пример #43
0
'''
Created on 17 Apr 2018

@author: fy65
'''
from gda.configuration.properties import LocalProperties

lookup_tables_dir = LocalProperties.get("gda.function.lookupTable.dir")
Пример #44
0
def isLive():
    mode = LocalProperties.get("gda.mode")
    return mode =="live"
Пример #45
0
def FindScanPeak2(ordinateName, printNameList=[], abscissaNameList=[], scanID=0, peakRatio=-1, ToPrint=1, LocalProperties=LocalProperties):
	""" Values= FindScanPeak(ordinateName, printNameList=[], scanID='null', ToPrint=1)
	Finds the peak value within a scan (currently just the maximum value). Returns all
	values from this line as dictionary. If enabled prints some values from this line.
	
	Will return only a peak that extends at least peakRatio*noise_rate above the Poisson noise floor. If no
	peak large enougth exists then Values returned is empty.
  
	Keyword arguements:
	ordinateName -- the header name of the value whose peak is to be found
	printNameList -- a list of header names to print (if enabled),
                  abscissaNameList --  NOT USED. may later be used for more advanced peak finding algorithms
	scanID -- leave empty to read most recent scan. Else a scan number or an absolute
		file path. If negative (-n), will find the peak of the scan n scans old.
	peakRatio -- If non-negative, this is the factor that a peak must extend above the Poisson noise floor to count.
		i.e. (peakValue-noise) >= peakRatio*noise, where noise is the avergae poisson noise floor.
		Be warned that the measured poisson noise floor is calculated without accounting 
		for any real signal that may be present, so will be an overestimate.
	ToPrint -- Set to 0 to disable printing

	Returns:
	The values of all elements from the selected line in a dictionary with header
	names as keys (or an empty dictionary if peakRatio is ser, and no peak was found)

	Example:
	run FindScanPeak  (as import is dodgy!)
	peakValues = FindScanPeak("y", ["x","y"], scanID = 15) #loads scan number 15, finds the maximum y,
		prints x and y, and returns all values.
	peakValues = FindScanPeak("y", ["x","y"], peakRatio=5) #loads the most recent scan and finds the maximum
		y if it large enougth, prints x and y, and returns all values.
	
	"""

 	# ----- Generate path -----
    
	# Use scanID as path if it is a string
	if type(scanID) == type('gda rocks'):
    		filepath = scanID 
	else:  # Assemble a path from the scan number, using current scan if not given
		# If no scanID given, use current scan number
		if scanID <= 0:
			import gda.data.NumTracker
			numtracker = gda.data.NumTracker('tmp')
			scanID = numtracker.getCurrentFileNumber() + scanID
		
		# Implicit else: scanID must be a positive number
        
		# scanID now contains the number of a scan
		filepath = LocalProperties.get("gda.data.scan.datawriter.datadir")
		filepath = filepath + '/' + str(scanID) + '.dat'  
                    
	if ToPrint == 1:    
		print "In file: %s" % filepath


	# ----- Read the file -----
	(headerList, columnList) = readSRSDataFile(filepath)

     
	# ----- Turn these into dictionary objects with header names as keys -----
	dataDict = {}

	for i in range(0, len(headerList)):
		dataDict[headerList[i]]=columnList[i]


	# ----- Find the index of the point -----
	iPeak = findMaxPointNonInterp(dataDict[ordinateName])
	# Get the value of the peak
	tempList = dataDict[ordinateName]
 	peakValue = tempList[iPeak] 
    
	# ----- Calculate statistics -----


	y_array = dataDict[ordinateName]
	calc_noPoints = len(y_array)
	# Normal distribution statistics
	calc_mean = average(y_array)
	calc_stdDev = standardDeviation(y_array)
	# Poisson distribution statistics
	calc_lambda = calc_mean
	calc_poisson_stddev = math.sqrt(calc_lambda)
	# Threshold based on Poisson statistics
	calc_threshold =  peakRatio*calc_poisson_stddev + calc_lambda


	# ----- Print some stuff unless ToPrint passed in as 0 -----
	if ToPrint == 1:   
		print "Max %s occurs at point %i (starting from 0) where:" % (ordinateName, iPeak)
		for i in range(0, len(printNameList)):
			tempList = dataDict[printNameList[i]]                    
			print "%s  =  %f" % (printNameList[i],tempList[iPeak])
		print ""
		if (peakRatio >=0):	# Show statistics as a peak threshold exists
			print "Number points: %i" % calc_noPoints
			print "Normal:\tmean: %f \t stddev: %f" % ( calc_mean, calc_stdDev)
			print "Poisson:\tlambda: %f \t stddev(noise): %f" % ( calc_lambda, calc_poisson_stddev)
	    		print "Threshold (%f*%f+%f) is:%f" % (peakRatio, calc_poisson_stddev, calc_lambda, calc_threshold)
			if peakValue>=calc_threshold:
				print "*Peak found*: The peak value of %f is greater than the threshold" % peakValue	
			else:
				print "*No peak found* The peak value of %f less than the threshold" % peakValue
	
	# ----- Return a dict object of values line where max occured -----
	# If threshold is exceeded...
	if ((peakValue>=calc_threshold) or peakRatio<0):
		maxPeak = {}
		for i in range(0, len(headerList)):
			tempList = dataDict[headerList[i]]
			maxPeak[headerList[i]] = tempList[iPeak]
		return maxPeak
	else: # Return an empty dictionary
		return {}
Пример #46
0
from gda.oe import OE
from gda.oe.dofs import DOF
from gda.device import ScannableMotion
from gda.oe import OE
from gda.device.epicsdevice import IEpicsDevice
from gda.util.converters import IReloadableQuantitiesConverter

# Channel access commands
from gda.epics import CAClient
from gda.epics.CAClient import *
from org.pf.joi import Inspector

# Get the location of the GDA beamline script directory
from gda.configuration.properties import LocalProperties
LocalProperties=LocalProperties
gdaScriptDir = LocalProperties.get("gda.jython.gdaScriptDir")
gdaScriptDir  = gdaScriptDir + "/"
userScriptDir = LocalProperties.get("gda.jython.userScriptDir")
userScriptDir = userScriptDir + "/"
commonScriptDir = LocalProperties.get("gda.jython.commonScriptDir")
commonScriptDir = commonScriptDir + "/"

# we need all OEs and their DOFs to be available in the
# namespace, by wrapping references to them in Adapter objects
finder = Finder.getInstance()
OEs = []
DOFs=[]
OEs = finder.listAllNames("OE");
for fullName in OEs:
	objRef = finder.find(fullName)
	# create an OE adapter object
Пример #47
0
def _getCurrentFileName(filenumber):
    ''' convert relative file number to its absolute path to the file with file extension as ".dat"'''
    filename = str(filenumber)
    if long(filenumber) < 0:
        filename = os.path.join(PathConstructor.createFromDefaultProperty(),str(int(NumTracker(LocalProperties.get(LocalProperties.GDA_BEAMLINE_NAME)).getCurrentFileNumber()+int(filenumber)))+".dat")
    else:
        filename = os.path.join(PathConstructor.createFromDefaultProperty(),str(filenumber)+ ".dat")
    return filename
def parkingAllDevices():
    '''move all stages to parking positions'''
    lookuptable=readLookupTable(LocalProperties.get("gda.function.lookupTable.dir")+os.path.sep+"lde_stages_home_positions.txt")
    for each in lookuptable.keys:
        stage=StageDataCollection(each)
        stage.moveToSafePosition()
Пример #49
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
Пример #50
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)
Пример #51
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)
Пример #52
0
def isLive():
    mode = LocalProperties.get("gda.mode")
    return mode =="live"