def pathscan(scannables, path, detector, exposure, *args): #@UndefinedVariable ''' Scan a group of scannables following the specified path and collect data at each point from specified detector and time''' sg = ScannableGroup() for each in scannables: sg.addGroupMember(each) sg.setName("pathgroup") scan([sg, path, detector, exposure] + list(args))
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
def pathscan(*args): #@UndefinedVariable ''' Scan a group of scannables following the specified path and collect data at each point from scannables args ''' 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 scan(newargs) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
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 start(self,filename, exposureTime): ''' kept for backward compatibility''' self.read_scan_path(filename) print self.pointid print self.path print self.exposuretime pathPositions=tuple(self.path) print pathPositions scan([self.sg, pathPositions, self.detector, exposureTime])
def pathscan(scannables, path, args=[]): #@UndefinedVariable ''' Scan a group of scannables following the specified path and collect data at each point from scannables args ''' sg = ScannableGroup() for each in scannables: sg.addGroupMember(each) sg.setName("pathgroup") scan([sg, path] + args)
def lde(t, collectionType=SAM, n=1.0): # @UndefinedVariable if (collectionType==NDR): #just collect raw image, no data reduction scan(ds, 1.0,n,1.0, pixium_hdf, t) # @UndefinedVariable else: if (collectionType==CAL): if (str(calibrantName.getPosition())=="Undefined"): # @UndefinedVariable raise Exception("Calibrant name is not defined.") datareduction.setCalibrant(True) # @UndefinedVariable else: datareduction.setCalibrant(False) # @UndefinedVariable scan(datareduction, 1.0,n,1.0, pixium_hdf, t) # @UndefinedVariable
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 ldescan(*args): MUSTADDDATAREDUCTIONATEND=False newargs=[] i=0 #processing 1st argument if (args[i] == NDR): i=1 if (isinstance(args[i], Detector)) : newargs.append(ds1) # @UndefinedVariable newargs.append(1.0) newargs.append(1.0) newargs.append(1.0) while i<len(args): newargs.append(args[i]) i=i+1 scan(newargs) else: if (args[i]==CAL): if (str(calName.getPosition())=="Undefined"): # @UndefinedVariable raise Exception("Calibrant name is not defined.") dr.setCalibrant(True) else: dr.setCalibrant(False) i=1 if (isinstance(args[i], Detector)) : newargs.append(dr) newargs.append(1.0) newargs.append(1.0) newargs.append(1.0) else: MUSTADDDATAREDUCTIONATEND=True while i<len(args): newargs.append(args[i]) i=i+1 if MUSTADDDATAREDUCTIONATEND: newargs.append(dr) scan(newargs)
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()
def analyserscan(*args): ''' a more generalised scan that extends standard GDA scan syntax to support 1. scannable tuple (e.g. (s1,s2,...) argument) as scannable group and 2. its corresponding path tuple (e.g. tuple of position lists), if exist, and 3. EW4000 analyser detector that takes a reion sequence file name as input, if exist, and 4. syntax 'analyserscan ew4000 "user.seq ...' for analyser scan only It parses input parameters described above before delegating to the standard GDA scan to do the actual data collection. Thus it can be used anywhere the standard GDA 'scan' is used. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if i == 0 and isinstance(arg, EW4000): newargs.append(zeroScannable) newargs.append(0) newargs.append(0) newargs.append(1) newargs.append(arg) elif type(arg) == TupleType: if allElementsAreScannable(arg): #parsing (scannable1, scannable2,...) as scannable group scannableGroup = ScannableGroup() for each in arg: scannableGroup.addGroupMember(each) scannableGroup.setName("pathgroup") newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreTuplesOfNumbers(arg): # This case is to fix BLIX-206 when using a scannable group with a tuple of tuples of positions newargs.append(arg) else: raise TypeError, "Only tuple of scannables, tuple of numbers, tuple of tuples of numbers, or list of numbers are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, EW4000): controller = Finder.find("SequenceFileObserver") xmldir = InterfaceProvider.getPathConstructor( ).getVisitSubdirectory('xml') + os.sep filename = xmldir + args[i] if (OsUtil.isWindows()): FilenameUtil.setPrefix("D:") filename = FilenameUtil.convertSeparator(filename) controller.update(controller, SequenceFileChangeEvent( filename)) #update client sequence view sleep(2.0) jythonServerStatus = InterfaceProvider.getJythonServerStatusProvider( ).getJythonServerStatus() while (jythonServerStatus.isScriptOrScanPaused()): sleep(1.0) # wait for user saving dirty file arg.setSequenceFilename(filename) sequence = arg.loadSequenceData(filename) if isinstance(arg.getCollectionStrategy(), EW4000CollectionStrategy): arg.getCollectionStrategy().setSequence(sequence) i = i + 1 scan(newargs) if ENABLEZEROSUPPLIES: zerosupplies() # @UndefinedVariable if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def startScan(self,filename, exposureTime): print self.pointid print self.exposuretime pathPositions=tuple(self.path) print pathPositions scan([self.sg, pathPositions, self.detector, exposureTime])
def pad_hdf(t,n=1.0): scan(ds, 1.0, n, 1.0, pixium_hdf, t) # @UndefinedVariable scaler2(1) # @UndefinedVariable
def psdrt(t, n=1.0): scan(ds, 1.0, n, 1.0, mythen, t, rocktheta, Io, t, Ie) # @UndefinedVariable scaler2(1) # @UndefinedVariable
def psd(t,n=1.0): scan(ds, 1.0, n, 1.0, mythen, t, Io, t, Ie, delta) # @UndefinedVariable scaler2(1) # @UndefinedVariable
def miscan(*args): ''' a more generalised scan that extends standard GDA scan syntax to support 1. scannable tuple (e.g. (s1,s2,...) argument) as scannable group, 2. its corresponding path tuple (e.g. list of position tuples), if exist, and 3. area detector that takes 2 input numbers - 1st one is detector exposure time which must be provided, 2nd one is number of image to be collected at each point which if omitted default to 1 4. syntax 'miscan pixis_summed 0.1 10 ...' is supported for collecting multiple images at a single point without scanning any scannable. It parses input parameters described above before delegating to the standard GDA scan to do the actual data collection. Thus it can be used anywhere the standard GDA 'scan' is used. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if i == 0 and isinstance(arg, NXDetector): newargs.append(zeroScannable) newargs.append(0) newargs.append(0) newargs.append(1) newargs.append(arg) elif type(arg) == TupleType: if allElementsAreScannable(arg): #parsing (scannable1, scannable2,...) as scannable group scannableGroup = ScannableGroup() for each in arg: scannableGroup.addGroupMember(each) scannableGroup.setName("pathgroup") newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreTuplesOfNumbers(arg): # This case is to fix BLIX-206 when using a scannable group with a tuple of tuples of positions newargs.append(arg) else: raise TypeError, "Only tuple of scannables, tuple of numbers, tuple of tuples of numbers, or list of numbers are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, NXDetector): decoratee = arg.getCollectionStrategy().getDecoratee() if isinstance(decoratee, AutoSummingProcessDecorator): #in dummy mode, AutoSummingProcessDecorator is 1st child decoratee.setAcquireTime(args[i]) elif isinstance(decoratee.getDecoratee(), AutoSummingProcessDecorator): #in live mode AutoSummingProcessDecorator is child's child decoratee.getDecoratee().setAcquireTime(args[i]) else: #exposure time is the last one in the scan command newargs.append(args[i]) #single image per data point if i < len(args) - 1: i = i + 1 # expecting number of images per data point if type(args[i]) == IntType: newargs.append(args[i - 1] * args[i]) elif type(args[i]) == FloatType: raise TypeError, "Number of image to collect per scan data point must be int type." i = i + 1 # scan(newargs) scan([e for e in newargs]) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def snap(*args): newargs = [ds, 1, 1, 1] # @UndefinedVariable for arg in args: newargs.append(arg) scan([e for e in newargs])
def miscan(*args): ''' a more generalised scan that extends standard GDA scan syntax to support 1. scannable tuple (e.g. (s1,s2,...) argument) as scannable group, 2. its corresponding path tuple (e.g. list of position tuples), if exist, and 3. area detector that takes 2 input numbers - 1st input is the number of images to be collected at each point, if omitted it default to 1, and 2nd input is detector exposure time which must be provided, 4. syntax 'miscan mpx 10 0.1 ...' is supported for collecting 10 images at a single point. It parses input parameters described above before delegating to the standard GDA scan to do the actual data collection. Thus it can be used anywhere the standard GDA 'scan' is used. ''' starttime = time.ctime() if PRINTTIME: print "=== Scan started: " + starttime newargs = [] i = 0 while i < len(args): arg = args[i] if i == 0 and isinstance(arg, NXDetector): newargs.append(zeroScannable) newargs.append(0) newargs.append(0) newargs.append(1) newargs.append(arg) elif type(arg) == TupleType: if allElementsAreScannable(arg): #parsing (scannable1, scannable2,...) as scannable group scannableGroup = ScannableGroup() for each in arg: scannableGroup.addGroupMember(each) scannableGroup.setName("pathgroup") newargs.append(scannableGroup) elif allElementsAreListOfNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreNumber(arg): #parsing scannable group's position lists newargs.append(arg) elif allElementsAreTuplesOfNumbers(arg): # This case is to fix BLIX-206 when using a scannable group with a tuple of tuples of positions newargs.append(arg) elif allElementsAreString(arg): newargs.append(arg) else: raise TypeError, "Only tuple of scannables, tuple of numbers, tuple of tuples of numbers, list of numbers, or tuple of Strings are supported." else: newargs.append(arg) i = i + 1 if isinstance(arg, NXDetector): decoratee = arg.getCollectionStrategy().getDecoratee() if isinstance(decoratee, ImageModeDecorator): if i < len( args) - 1: # more than 2 arguments following detector if type(args[i]) == IntType and ( type(args[i + 1]) == IntType or type(args[i + 1]) == FloatType): #support the miscan command - first input after detector is number of images per data point decoratee.setNumberOfImagesPerCollection(args[i]) elif type(args[i]) == FloatType and ( type(args[i + 1]) == IntType or type(args[i + 1]) == FloatType): raise TypeError, "Number of images to collect per scan data point must be Int type." elif type(args[i]) == FloatType and not ( type(args[i + 1]) == IntType or type(args[i + 1]) == FloatType): decoratee.setNumberOfImagesPerCollection(1) elif i == len( args ) - 1: #followed by only one argument - must be exposure time decoratee.setNumberOfImagesPerCollection(1) else: #exposure time is the last one in the scan command newargs.append(args[i]) #single image per data point i = i + 1 scan([e for e in newargs]) if PRINTTIME: print("=== Scan ended: " + time.ctime() + ". Elapsed time: %.0f seconds" % (time.time() - starttime))
def snap(*args): newargs = [dummy, 1, 1, 1] for arg in args: newargs.append(arg) scan([e for e in newargs])