def setSubdirectory(dirname): '''create a new sub-directory for data collection that follows''' Finder.find("GDAMetadata").setMetadataValue("subdirectory", dirname) try: os.mkdir(pwd()) except: pass
def setSubdirectory(dirname): '''create a new sub-directory under current data directory for data collection that follows''' if os.sep not in dirname: subdirectory = getSubdirectory() if subdirectory: dirname = str(subdirectory) + os.sep + str(dirname) Finder.find("GDAMetadata").setMetadataValue("subdirectory", dirname) try: os.mkdir(pwd()) except: exceptionType, exception = sys.exc_info()[:2] print "Error Type: ", exceptionType print "Error value: ", exception
def reconnect(self): try: #have to close the old one if it's not broken self.leem_com.sendCmdNoReply("clo") except DeviceException: pass #we expect this new_com = SocketBidiAsciiCommunicator() new_com.setAddress( self.leem_com.address ) new_com.setPort( self.leem_com.port ) new_com.setCmdTerm( self.leem_com.cmdTerm ) new_com.setReplyTerm( self.leem_com.replyTerm ) new_finder_map = {"leem2000_com" : new_com} Finder.find("leem2000_objects").setMap(new_finder_map) self.leem_com = new_com
def analyserpathscan_v1(scannables, path, *args): ''' perform a single region analyser data collection at each point on the specified path, and produce a single scan data files recording scannables' poistions and metadata, and analyser data for the active region defined in your sequence definition file under ew4001 node. implementation details: This function pre-process sequence file to set up Region Position Provider for scannable 'regions' ready for data collection using analyser 'ew4001', then delegate the scan process to 'pathscan'. ''' newargs = [] i = 0 while i < len(args): arg = args[i] newargs.append(arg) i = i + 1 if isinstance(arg, RegionScannable): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).createFromDefaultProperty() + "xml" + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent(filename)) sleep(1.0) while (InterfaceProvider.getScanStatusHolder().getScanStatus() == JythonStatus.PAUSED): sleep(1.0) newargs.append(RegionPositionProvider(filename)) #newargs.append( arg ) # to read the actual position i = i + 1 pathscan(scannables, path, newargs)
def __init__(self, name): self.setName(name) self.setInputNames([name]) self.setExtraNames([]) # self.Units=[strUnit]; self.setLevel(7) self.uview = Finder.find("uview")
def __init__(self, name, roi): self.setName(name) self.setInputNames([]) self.setExtraNames([name]) # self.Units=[strUnit]; self.setLevel(7) self.roi = Finder.find(roi)
def setDof(self, dof): if dof in MOTORS.keys(): self.motor = Finder.find(MOTORS[dof]) else: raise ValueError("No Motor found Error") self.dof = dof self.backupMotor()
def setTerminalLogger(self, newLoggerName="gda_terminal.log"): tlPath = InterfaceProvider.getPathConstructor( ).createFromDefaultProperty() tlFile = os.path.join(tlPath, newLoggerName) tlpp = Finder.find("terminallog_path_provider") tlpp.setTemplate(str(tlFile))
def __init__(self): self.ccWaveFormHead = CAClient(pvWaveFormHead) self.ccSubArraySize = CAClient(pvSubArraySize) self.ccSubArrayIndex = CAClient(pvSubArrayIndex) self.ccUpdate = CAClient(pvUpdate) self.ccCh01 = CAClient(pvCh01) self.ccCh02 = CAClient(pvCh02) self.ccCh03 = CAClient(pvCh03) self.ccCh04 = CAClient(pvCh04) self.ccCh05 = CAClient(pvCh05) self.ccCh06 = CAClient(pvCh06) self.ccWaveFormHead.configure() self.ccSubArraySize.configure() self.ccSubArrayIndex.configure() self.ccUpdate.configure() self.ccCh01.configure() self.ccCh02.configure() self.ccCh03.configure() self.ccCh04.configure() self.ccCh05.configure() self.ccCh06.configure() self.length = 0 self.head = 0 self.dataSetCh01 = dnp.zeros([maxLength]) self.dataSetCh01.setName("Channel 1") self.js = Finder.find("command_server")
def analyserscan_v1(*args): starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] newargs.append(arg) i = i + 1 if isinstance(arg, RegionScannable): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).createFromDefaultProperty() + "xml" + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent(filename)) sleep(1.0) while (InterfaceProvider.getScanStatusHolder().getScanStatus() == JythonStatus.PAUSED): sleep(1.0) newargs.append(RegionPositionProvider(filename)) #newargs.append( arg ) # to read the actual position i = i + 1 scan(newargs) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def __init__(self, name, rootPV, channelList, extraChannelList=[], elementCounter="iddFastScanElementCounter"): self.numberOfChannels=len(channelList); self.setupEpics(rootPV); self.setName(name); self.setInputNames(["pIndex"]); self.setLevel(7); en=[]; of=["%5.0f"]; for c in channelList + extraChannelList: en.append( str(c) ); of.append("%20.12f"); self.setExtraNames(en); self.setOutputFormat(of); self.timeout=30; self.defaultSize = 100; self.low = 0; self.high = 1000; self.keyChannel=None; # self.fastScanElementCounter = None; self.fastScanElementCounter = Finder.find(elementCounter); self.reset();
def setProperty(propertyName, propertyValue): LocalProperties.set(propertyName, propertyValue) eventAdmin=Finder.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 __init__(self, name, scannableX, scannableY, deviceFun): '''constructor parameters: name: Name of the new device scannableX: Name of the scannable on X-axis (for example: "energy") scannableY: Name of the scannable on Y-axis (for example: "mac15") deviceFun: Name of the function to calculate the new position based on scannableX and scannableY positions''' self.setName(name) self.setInputNames([name]) #self.Units=[strUnit] #self.setOutputFormat([strFormat]) #self.setLevel(8); self.x1 = 0.0 self.x2 = 0.0 self.y = 0.0 self.refObj1 = Finder.find(scannableX) self.refObj2 = Finder.find(scannableY) self.deviceFun = deviceFun
def __init__(self, name): self.setName(name) self.setInputNames([name]) self.setExtraNames([]) self.setOutputFormat(["%5.5g"]) my_pgm_energy = Finder.find("pgm_energy") self.currentposition = (float)(my_pgm_energy.getPosition( )) # this template scannable represents a single number self.iambusy = 0 # flag to hold the status of the scannable
def __init__(self, name, index): self.setName(name) self.setInputNames([]) self.setExtraNames([name]) # self.Units=[strUnit]; self.setLevel(7) self.peem = Finder.find("leem") self.index = index self.value = 0
def getDataDir(self): opc = ObservablePathConstructor() opc.setName("opc") opc.setTemplate("${gda.data}/$year$/$visit$/$subdirectory$") opc.setGdaMetadata(Finder.find("GDAMetadata")) opc.configure() dataDir = opc.getPath() return dataDir
def __init__(self): self.comms_started=False try: self.leem_com=(Finder.find("leem2000_objects")).get("leem2000_com") self.leem_com.setReplyTerm('\0') self.leem_com.setCmdTerm('\0') except: exceptionType, exception, traceback=sys.exc_info(); handle_messages.log(None, "Error getting leem2000_com from leem2000_objects", exceptionType, exception, traceback, True)
def __init__(self, detectorList=None): # EXAFS PANEL CODE self.scannableNamesVector = Vector() self.scannableNamesVector.add("dcm_mono") self.detectorNamesVector = Vector() self.detectorNamesVector.add("counterTimer01") self.detectorNamesVector.add("counterTimer02") self.controller = Finder.find("ExafsController") self.mcontroller = Finder.find("MicroFocusController") self.title = "TITLE" self.condition1 = "CONDITION1" self.condition2 = "CONDITION2" self.condition3 = "CONDITION3" # Script code self.das = Finder.find("daserver") self.ionchambers = SlaveCounterTimer() self.converter = Finder.find("auto_mDeg_idGap_mm_converter") self.windowValues = [[0, 4095]] * 9 self.windowName = 'ALL' self.ionchamberData = [] self.mcaList = [] self.scalarList = [] self.runs = NumTracker("tmp") self.runprefix = 'i18exafs' self.runext = '.dat' self.fileno = self.runs.getCurrentFileNumber() + 1 self.runs.incrementNumber() self.datadir = InterfaceProvider.getPathConstructor( ).createFromProperty("gda.data.scan.datawriter.datadir") self.datafilename = self.datadir + '/' + str(self.fileno) + self.runext if (detectorList != None): self.detectorMask = detectorList else: self.detectorMask = [1, 1, 1, 1, 1, 1, 1, 1, 1] self.mcadir = self.datadir + '/mca/' + str(self.fileno) + '/' self.mcarootname = self.mcadir + str(self.fileno) if not os.path.isdir(self.mcadir): os.mkdir(self.mcadir) self.tag = 1 self.facade = JythonServerFacade.getInstance() self.scanList = [] self.noOfRepeats = 1 self.noOfPoints = 0
def initialise_zpz_osa_function(): # Set the parameters of the linear function that combines ZonePlateZ & OSA Z motion # # Assuming the current positions of the motors are correct, we always want the OSA to move an equal # and opposite distance to the zone plate. zpz_osa_function = Finder.find('zpz_osa_coupling_function') zpz_osa_function.setSlopeDividend(Quantities.getQuantity('-1 mm')) zpz_osa_function.setSlopeDivisor(Quantities.getQuantity('1 mm')) zpz_osa_function.setInterception(Quantities.getQuantity('0 mm')) print(u'zpz_osa_function: {}'.format(zpz_osa_function))
def runExperiment(self): print "I am now running the experiment using parameters in the bean", str( self.bean), "..." time.sleep(2) print "...and now the experiment is over." scriptController = Finder.find("MyExperimentScriptController") if scriptController != None: print "Broadcasting experiment complete message..." scriptController.update("MyExperiment Script", "Experiment Complete!")
def analyserpathscan(*args): ''' perform single/multiple regions analyser data collection at each point on the specified path, and produce a single scan file recording all scannables' poistions and metadata, along with analyser scan data under region's name as NXdetector node. implementation details: This function pre-process sequence file to set up analyser 'ew4000' ready for data collection. It creates scannable group to support point-to-point concurrent scan. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if type(arg) == TupleType: if allElementsAreScannable(arg): scannableGroup = ScannableGroup("pathgroup") for each in arg: scannableGroup.addGroupMember(each) newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): newargs.append(arg) else: raise TypeError, "Only tuple of scannables and tuple of list of numbers are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, EW4000): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).createFromDefaultProperty() + "xml" + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent(filename)) sleep(2.0) jythonServerStatus = InterfaceProvider.getJythonServerStatusProvider( ).getJythonServerStatus() while (jythonServerStatus.isScriptOrScanPaused()): sleep(1.0) arg.setSequenceFilename(filename) sequence = arg.loadSequenceData(filename) if isinstance(arg.getCollectionStrategy(), EW4000CollectionStrategy): arg.getCollectionStrategy().setSequence(sequence) i = i + 1 scan(newargs) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def __init__(self, name, lowLimit, highLimit, refObj, delay): self.setName(name); self.setInputNames([name]); self.setExtraNames([name]); #self.Units=[strUnit] #self.setOutputFormat([strFormat]) self.setLevel(5); self.value = 0.0; self.lowLimit = lowLimit; self.highLimit = highLimit; self.refObj = Finder.find(refObj); self.delay = delay;
def writefile(scannable1Name, scannable2Name, filepath): """ add a line with 2 column for calibration scannable1 versus scannable2 """ Scannable1 = Finder.find("photoDiode1") Scannable1Position = Scannable1.getPosition() print "Scannable1Position", Scannable1Position values = [] f = open(filepath) lines = f.readlines() f.close()
def __init__(self, name, refCA): self.setName(name) self.setInputNames([name + "_sum"]) self.setExtraNames([name + "_average"]) # self.Units=[strUnit]; self.setLevel(7) self.sum = 0 self.average = 0 self.total = 1 #default number of counts # self.refCA = globals()[refCA]; self.refCA = Finder.find(refCA)
def setupAreaDetectorROIs(self, rois, roi_provider_name='pco_roi'): '''update ROIs list in GDA but not yet set to EPICS This must be called when ROI is changed, and before self.prepareAreaDetectorForCollection(areadet) @param rois: list of rois i.e. [[x_start,y_start,x_size,y_size],[x_start,y_start,x_size,y_size],[x_start,y_start,x_size,y_size],[x_start,y_start,x_size,y_size]] ''' if not type(rois)== ListType: raise Exception("Input must be a list of ROIs, each provides a list specifies [x_start,y_start,x_size,y_size]") i=1 newRois=[] for roi in rois: newRoi=ImutableRectangularIntegerROI(roi[0],roi[1],roi[2],roi[3],'Region'+str(i)) i +=1 newRois.append(newRoi) roi_provider=Finder.find(roi_provider_name) roi_provider.updateRois(newRois)
def __init__(self, name, lutObj='energytable', objType=0, rootNameSpace={}): '''Constructor - Only succeed if it find the lookup table, otherwise raise exception.''' self.lut = Finder.find(lutObj) if self.lut == None: raise Exception, "Can not find the Lookup Table object" self.rootNameSpace = rootNameSpace self.scannableNames = self.lut.getScannableNames() self._busy = 0 self.scannables = [self.rootNameSpace[x] for x in self.scannableNames] self.setName(name) self.setLevel(3) self.objType = objType self.inputNames = ['energy']
def analyserpathscan(scannables, path, *args): ''' perform single/multiple regions analyser data collection at each point on the specified path, and produce a single scan file recording all scannables' poistions and metadata, along with analyser scann data under region's name as NXdetector node. implementation details: This function pre-process sequence file to set up analyser 'ew4000' ready for data collection, then delegate the scan process to 'pathscan'. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] newargs.append(arg) i = i + 1 if isinstance(arg, EW4000): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).createFromDefaultProperty() + "xml" + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent(filename)) sleep(2.0) jythonServerStatus = InterfaceProvider.getJythonServerStatusProvider( ).getJythonServerStatus() while (jythonServerStatus.isScriptOrScanPaused()): sleep(1.0) arg.setSequenceFilename(filename) sequence = arg.loadSequenceData(filename) if isinstance(arg.getCollectionStrategy(), EW4000CollectionStrategy): arg.getCollectionStrategy().setSequence(sequence) i = i + 1 pathscan(scannables, path, newargs) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
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__)
def __init__(self, rois, leem_fov, leem_rot, m4fpitch, m5fpitch, m4fpitchRead, m5fpitchRead, psphi, roistat_index=[1, 2, 3, 4], pvRootName="BL06I-EA-DET-01", detector=pcotif, roi_provider_name='pco_roi'): '''use the 1st 4 area detector's ROI-STAT pairs ''' BeamStabilisation.__init__(self, rois, leem_fov, leem_rot, m4fpitch, m5fpitch, m4fpitchRead, m5fpitchRead, psphi, roistat_index, pvRootName) self.detector = detector self.roiProvider = Finder.find(roi_provider_name)
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__)