def TransmissionDirectBeamCenter(datafile): datafile = find_data(datafile, instrument=ReductionSingleton().get_instrument()) ReductionSingleton( ).reduction_properties["TransmissionBeamCenterMethod"] = "DirectBeam" ReductionSingleton( ).reduction_properties["TransmissionBeamCenterFile"] = datafile
def Background(datafile): if isinstance(datafile, list): datafile = ','.join(datafile) find_data(datafile, instrument=ReductionSingleton().get_instrument(), allow_multiple=True) ReductionSingleton().reduction_properties["BackgroundFiles"] = datafile
def DivideByThickness(thickness=1.0): if thickness is None or thickness == 1.0: if "SampleThickness" in ReductionSingleton().reduction_properties: del ReductionSingleton().reduction_properties["SampleThickness"] else: ReductionSingleton( ).reduction_properties["SampleThickness"] = thickness
def ScatteringBeamCenter(datafile, beam_radius=3.0): datafile = find_data(datafile, instrument=ReductionSingleton().get_instrument()) ReductionSingleton( ).reduction_properties["BeamCenterMethod"] = "Scattering" ReductionSingleton().reduction_properties["BeamRadius"] = beam_radius ReductionSingleton().reduction_properties["BeamCenterFile"] = datafile
def SensitivityDirectBeamCenter(datafile): datafile = find_data(datafile, instrument=ReductionSingleton().get_instrument()) ReductionSingleton( ).reduction_properties["SensitivityBeamCenterMethod"] = "DirectBeam" ReductionSingleton( ).reduction_properties["SensitivityBeamCenterFile"] = datafile
def SetBckTransmission(trans, error, theta_dependent=True): ReductionSingleton( ).reduction_properties["BckTransmissionMethod"] = "Value" ReductionSingleton().reduction_properties["BckTransmissionValue"] = trans ReductionSingleton().reduction_properties["BckTransmissionError"] = error ReductionSingleton( ).reduction_properties["BckThetaDependentTransmission"] = theta_dependent
def MaskDetectors(det_list): if "MaskedDetectorList" in ReductionSingleton().reduction_properties: ReductionSingleton().reduction_properties["MaskedDetectorList"].extend( det_list) else: ReductionSingleton( ).reduction_properties["MaskedDetectorList"] = det_list
def Mask(nx_low=0, nx_high=0, ny_low=0, ny_high=0, component_name=""): ''' Maks edges of a component_name By default is the main detector for both GPSANS and BioSans ''' ReductionSingleton().reduction_properties["MaskedEdges"] = [ nx_low, nx_high, ny_low, ny_high] ReductionSingleton().reduction_properties[ "MaskedComponent"] = component_name
def BckTransmissionDarkCurrent(dark_current=None): if dark_current is not None: dark_current = find_data( dark_current, instrument=ReductionSingleton().get_instrument()) ReductionSingleton( ).reduction_properties["BckTransmissionDarkCurrentFile"] = dark_current elif "BckTransmissionDarkCurrentFile" in ReductionSingleton( ).reduction_properties: del ReductionSingleton( ).reduction_properties["BckTransmissionDarkCurrentFile"]
def SetWedges(number_of_wedges=2, wedge_angle=30.0, wedge_offset=0.0): """ Set the wedge properties @param number_of_wedges: number of wedges to calculate @param wedge_angle: augular opening of each wedge, in degrees @param wedge_offset: angular offset for the wedges, in degrees """ ReductionSingleton( ).reduction_properties["NumberOfWedges"] = number_of_wedges ReductionSingleton().reduction_properties["WedgeAngle"] = wedge_angle ReductionSingleton().reduction_properties["WedgeOffset"] = wedge_offset
def SetDirectBeamAbsoluteScale(direct_beam, beamstop_diameter=0.0, attenuator_trans=1.0, apply_sensitivity=False): ReductionSingleton( ).reduction_properties["AbsoluteScaleMethod"] = "ReferenceData" ReductionSingleton( ).reduction_properties["AbsoluteScalingReferenceFilename"] = direct_beam ReductionSingleton( ).reduction_properties["AbsoluteScalingBeamDiameter"] = beamstop_diameter ReductionSingleton( ).reduction_properties["AbsoluteScalingAttenuatorTrans"] = attenuator_trans ReductionSingleton().reduction_properties[ "AbsoluteScalingApplySensitivity"] = apply_sensitivity
def update(self): """ Update data members according to reduction results """ if IS_IN_MANTIDPLOT: from mantid import PropertyManagerDataService from reduction_workflow.command_interface import ReductionSingleton property_manager_name = ReductionSingleton().get_reduction_table_name() property_manager = PropertyManagerDataService.retrieve(property_manager_name) if property_manager.existsProperty("LatestBeamCenterX"): self.x_position = property_manager.getProperty("LatestBeamCenterX").value if property_manager.existsProperty("LatestBeamCenterY"): self.y_position = property_manager.getProperty("LatestBeamCenterY").value if self.use_sample_beam_center: self.flood_x_position = self.x_position self.flood_y_position = self.y_position elif self.sensitivity_corr: if property_manager.existsProperty("SensitivityBeamCenterXUsed"): self.flood_x_position = property_manager.getProperty("SensitivityBeamCenterXUsed").value else: self.flood_x_position = self.x_position if property_manager.existsProperty("SensitivityBeamCenterYUsed"): self.flood_y_position = property_manager.getProperty("SensitivityBeamCenterYUsed").value else: self.flood_y_position = self.y_position
def GPSANS(): Clear() ReductionSingleton().set_instrument("GPSANS", "SetupHFIRReduction", "HFIRSANSReduction") TimeNormalization() SolidAngle() AzimuthalAverage()
def beam_center_gravitational_drop(beam_center_file, sdd=1.13): ''' This method is used for correcting for gravitational drop @param beam_center_file :: file where the beam center was found @param sdd :: sample detector distance to apply the beam center ''' def calculate_neutron_drop(path_length, wavelength): ''' Calculate the gravitational drop of the neutrons path_length in meters wavelength in Angstrom ''' wavelength *= 1e-10 neutron_mass = 1.674927211e-27 gravity = 9.80665 h_planck = 6.62606896e-34 l_2 = (gravity * neutron_mass**2 / (2.0 * h_planck**2 )) * path_length**2 return wavelength**2 * l_2 # Get beam center used in the previous reduction pm = mantid.PropertyManagerDataService[ReductionSingleton().property_manager] beam_center_x = pm['LatestBeamCenterX'].value beam_center_y = pm['LatestBeamCenterY'].value Logger("CommandInterface").information("Beam Center before: [%.2f, %.2f] pixels" % (beam_center_x, beam_center_y)) try: # check if the workspace still exists wsname = "__beam_finder_" + os.path.splitext(beam_center_file)[0] ws = mantid.mtd[wsname] Logger("CommandInterface").debug("Using Workspace: %s." % (wsname)) except KeyError: # Let's try loading the file. For some reason the beamcenter ws is not there... try: ws = Load(beam_center_file) Logger("CommandInterface").debug("Using filename %s." % (beam_center_file)) except IOError: Logger("CommandInterface").error("Cannot read input file %s." % beam_center_file) return i = ws.getInstrument() y_pixel_size_mm = i.getNumberParameter('y-pixel-size')[0] Logger("CommandInterface").debug("Y Pixel size = %.2f mm" % y_pixel_size_mm) y_pixel_size = y_pixel_size_mm * 1e-3 # In meters distance_detector1 = i.getComponentByName("detector1").getPos()[2] path_length = distance_detector1 - sdd Logger("CommandInterface").debug("SDD detector1 = %.3f meters. SDD for wing = %.3f meters." % (distance_detector1, sdd)) Logger("CommandInterface").debug("Path length for gravitational drop = %.3f meters." % (path_length)) r = ws.run() wavelength = r.getProperty("wavelength").value Logger("CommandInterface").debug("Wavelength = %.2f A." % (wavelength)) drop = calculate_neutron_drop(path_length, wavelength) Logger("CommandInterface").debug("Gravitational drop = %.6f meters." % (drop)) # 1 pixel -> y_pixel_size # x pixel -> drop drop_in_pixels = drop / y_pixel_size new_beam_center_y = beam_center_y + drop_in_pixels Logger("CommandInterface").information("Beam Center after: [%.2f, %.2f] pixels" % (beam_center_x, new_beam_center_y)) return beam_center_x, new_beam_center_y
def update(self): """ Update data member from reduction output """ if IS_IN_MANTIDPLOT: from mantid import PropertyManagerDataService from reduction_workflow.command_interface import ReductionSingleton property_manager_name = ReductionSingleton().get_reduction_table_name() property_manager = PropertyManagerDataService.retrieve(property_manager_name) if property_manager.existsProperty("MeasuredBckTransmissionValue"): self.bck_transmission = property_manager.getProperty("MeasuredBckTransmissionValue").value if property_manager.existsProperty("MeasuredBckTransmissionError"): self.bck_transmission_spread = property_manager.getProperty("MeasuredBckTransmissionError").value
def update(self): """ Update data members according to reduction results """ if IS_IN_MANTIDPLOT: from reduction_workflow.command_interface import ReductionSingleton self.log_text = ReductionSingleton().log_text try: if hasattr(ReductionSingleton(), "output_workspaces") \ and len(ReductionSingleton().output_workspaces)>0: for item in ReductionSingleton().output_workspaces: mantidplot.plotSpectrum(item, 0, True) else: iq_plots = [] for item in ReductionSingleton()._data_files.keys(): for ws in AnalysisDataService.Instance( ).getObjectNames(): if ws.startswith(item) and ws.endswith('_Iq'): iq_plots.append(ws) if len(iq_plots) > 0: mantidplot.plotSpectrum(iq_plots, 0, True) except: raise RuntimeError, "Could not plot resulting output\n %s" % sys.exc_value
def AzimuthalAverage(binning=None, suffix="_Iq", error_weighting=False, n_bins=100, n_subpix=1, log_binning=False, align_log_with_decades=False): # Suffix is no longer used but kept for backward compatibility ReductionSingleton().reduction_properties["DoAzimuthalAverage"] = True if binning is not None: ReductionSingleton().reduction_properties["IQBinning"] = binning elif "IQBinning" in ReductionSingleton().reduction_properties: del ReductionSingleton().reduction_properties["IQBinning"] ReductionSingleton().reduction_properties["IQNumberOfBins"] = n_bins ReductionSingleton().reduction_properties["IQLogBinning"] = log_binning ReductionSingleton().reduction_properties["NumberOfSubpixels"] = n_subpix ReductionSingleton( ).reduction_properties["ErrorWeighting"] = error_weighting ReductionSingleton( ).reduction_properties["IQAlignLogWithDecades"] = align_log_with_decades
def DirectBeamTransmission(sample_file, empty_file, beam_radius=3.0, theta_dependent=True, use_sample_dc=True): sample_file = find_data(sample_file, instrument=ReductionSingleton().get_instrument()) empty_file = find_data(empty_file, instrument=ReductionSingleton().get_instrument()) ReductionSingleton( ).reduction_properties["TransmissionMethod"] = "DirectBeam" ReductionSingleton( ).reduction_properties["TransmissionBeamRadius"] = beam_radius ReductionSingleton( ).reduction_properties["TransmissionSampleDataFile"] = sample_file ReductionSingleton( ).reduction_properties["TransmissionEmptyDataFile"] = empty_file ReductionSingleton( ).reduction_properties["ThetaDependentTransmission"] = theta_dependent ReductionSingleton( ).reduction_properties["TransmissionUseSampleDC"] = use_sample_dc
def SaveIq(output_dir=None, process=''): if output_dir is not None: ReductionSingleton( ).reduction_properties["OutputDirectory"] = output_dir ReductionSingleton().reduction_properties["ProcessInfo"] = process
def SensitivityCorrection(flood_data, min_sensitivity=0.5, max_sensitivity=1.5, dark_current=None, use_sample_dc=False): flood_data = find_data(flood_data, instrument=ReductionSingleton().get_instrument()) if dark_current is not None: dark_current = find_data( dark_current, instrument=ReductionSingleton().get_instrument()) ReductionSingleton().reduction_properties["SensitivityFile"] = flood_data ReductionSingleton( ).reduction_properties["MinEfficiency"] = min_sensitivity ReductionSingleton( ).reduction_properties["MaxEfficiency"] = max_sensitivity if dark_current is not None: ReductionSingleton( ).reduction_properties["SensitivityDarkCurrentFile"] = dark_current elif "SensitivityDarkCurrentFile" in ReductionSingleton( ).reduction_properties: del ReductionSingleton( ).reduction_properties["SensitivityDarkCurrentFile"] if "SensitivityBeamCenterX" in ReductionSingleton().reduction_properties: del ReductionSingleton().reduction_properties["SensitivityBeamCenterX"] if "SensitivityBeamCenterY" in ReductionSingleton().reduction_properties: del ReductionSingleton().reduction_properties["SensitivityBeamCenterY"] ReductionSingleton().reduction_properties["UseDefaultDC"] = use_sample_dc
def NoNormalization(): ReductionSingleton().reduction_properties["Normalisation"] = "None"
def MonitorNormalization(): ReductionSingleton().reduction_properties["Normalisation"] = "Monitor"
def TimeNormalization(): ReductionSingleton().reduction_properties["Normalisation"] = "Timer"
def SetBeamCenter(x, y): ReductionSingleton().reduction_properties["BeamCenterMethod"] = "Value" ReductionSingleton().reduction_properties["BeamCenterX"] = x ReductionSingleton().reduction_properties["BeamCenterY"] = y
def NoSaveIq(): if "ProcessInfo" in ReductionSingleton().reduction_properties: del ReductionSingleton().reduction_properties["ProcessInfo"]
def IQxQy(nbins=100, log_binning=False): ReductionSingleton().reduction_properties["Do2DReduction"] = True ReductionSingleton().reduction_properties["IQ2DNumberOfBins"] = nbins ReductionSingleton().reduction_properties["IQxQyLogBinning"] = log_binning
def NoIQxQy(): ReductionSingleton().reduction_properties["Do2DReduction"] = False
def SetAbsoluteScale(factor): ReductionSingleton().reduction_properties["AbsoluteScaleMethod"] = "Value" ReductionSingleton().reduction_properties["AbsoluteScalingFactor"] = factor
def MaskDetectorSide(side_to_mask=None): if side_to_mask is None: if "MaskedSide" in ReductionSingleton().reduction_properties: del ReductionSingleton().reduction_properties["MaskedSide"] else: ReductionSingleton().reduction_properties["MaskedSide"] = side_to_mask
def MaskComponent(component_name): ''' Masks a full component by name ''' ReductionSingleton( ).reduction_properties["MaskedFullComponent"] = component_name