def ProcessVana(rnum, cycle): # Preparation of the V/Nd sphere run for SX normalization mantid.LoadRaw(Filename='/archive/NDXWISH/Instrument/data/cycle_' + cycle + '/WISH000' + str(rnum) + '.raw', OutputWorkspace='Vana', LoadMonitors='Separate') mantid.CropWorkspace(InputWorkspace='Vana', OutputWorkspace='Vana', XMin=6000, XMax=99000) mantid.NormaliseByCurrent(InputWorkspace='Vana', OutputWorkspace='Vana') mantid.ConvertUnits(InputWorkspace='Vana', OutputWorkspace='Vana', Target='Wavelength') # create Abs Correction for V shape = '''<sphere id="V-sphere"> <centre x="0.0" y="0.0" z="0.0" /> <radius val="0.0025"/> </sphere>''' mantid.CreateSampleShape('Vana', shape) mantid.SetSampleMaterial('Vana', SampleNumberDensity=0.0719, ScatteringXSection=5.197, AttenuationXSection=4.739, ChemicalFormula='V0.95 Nb0.05') mantid.AbsorptionCorrection(InputWorkspace='Vana', OutputWorkspace='Abs_corr', ElementSize=0.5) # SphericalAbsorption(InputWorkspace='WISH00038428', OutputWorkspace='Abs_corr_sphere', SphericalSampleRadius=0.25) # correct Vanadium run for absorption mantid.Divide(LHSWorkspace='Vana', RHSWorkspace='Abs_corr', OutputWorkspace='Vana_Abs') mantid.DeleteWorkspace('Vana') mantid.DeleteWorkspace('Abs_corr') # Smoot data with redius 3 mantid.SmoothNeighbours(InputWorkspace='Vana_Abs', OutputWorkspace='Vana_smoot', Radius=3) mantid.DeleteWorkspace('Vana_Abs') # SmoothData38428 mantid.SmoothData(InputWorkspace='Vana_smoot', OutputWorkspace='Vana_smoot1', NPoints=300) mantid.DeleteWorkspace('Vana_smoot')
def _ms_correction(self): """ Calculates the contributions from multiple scattering on the input data from the set of given options """ params_dict = TableWorkspaceDictionaryFacade( self.getProperty("FitParameters").value) atom_props = list() intensities = list() contains_hydrogen = False i = 0 for idx, mass in enumerate(self._masses): if str(idx) in self._index_to_symbol_map: symbol = self._index_to_symbol_map[str(idx)].value else: symbol = None if symbol == 'H' and self._back_scattering: contains_hydrogen = True continue intensity_prop = 'f%d.Intensity' % i c0_prop = 'f%d.C_0' % i if intensity_prop in params_dict: intensity = params_dict[intensity_prop] elif c0_prop in params_dict: intensity = params_dict[c0_prop] else: i = i + 1 continue # The program DINSMS_BATCH uses those sample parameters together with the sigma divided # by the sum absolute of scattering intensities for each detector (detector bank), # sigma/int_sum # Thus: # intensity = intensity/intensity_sum # In the thin sample limit, 1-exp(-n*dens*sigma) ~ n*dens*sigma, effectively the same # scattering power (ratio of double to single scatt.) is obtained either by using # relative intensities ( sigma/int_sum ) or density divided by the total intensity # However, in the realistic case of thick sample, the SampleDensity, dens, must be # obtained by iterative numerical solution of the Eq: # 1-exp(-n*dens*sigma) = measured scattering power of the sample. # For this, a program like THICK must be used. # The program THICK also uses sigma/int_sum to be consistent with the prgram # DINSMS_BATCH width_prop = 'f%d.Width' % i sigma_x_prop = 'f%d.SigmaX' % i sigma_y_prop = 'f%d.SigmaY' % i sigma_z_prop = 'f%d.SigmaZ' % i if width_prop in params_dict: width = params_dict['f%d.Width' % i] elif sigma_x_prop in params_dict: sigma_x = float(params_dict[sigma_x_prop]) sigma_y = float(params_dict[sigma_y_prop]) sigma_z = float(params_dict[sigma_z_prop]) width = math.sqrt((sigma_x**2 + sigma_y**2 + sigma_z**2) / 3.0) else: i = i + 1 continue atom_props.append(mass) atom_props.append(intensity) atom_props.append(width) intensities.append(intensity) # Check for NoneType is necessary as hydrogen constraints are # stored in a C++ PropertyManager object, not a dict; call to # __contains__ must match the C++ signature. if self._back_scattering and symbol is not None and symbol in self._hydrogen_constraints: self._hydrogen_constraints[symbol].value[ 'intensity'] = intensity i = i + 1 if self._back_scattering and contains_hydrogen: material_builder = MaterialBuilder() hydrogen = material_builder.setFormula('H').build() hydrogen_intensity = \ self._calculate_hydrogen_intensity(hydrogen, self._hydrogen_constraints) hydrogen_width = 5 atom_props.append(hydrogen.relativeMolecularMass()) atom_props.append(hydrogen_intensity) atom_props.append(hydrogen_width) intensities.append(hydrogen_intensity) intensity_sum = sum(intensities) # Create the sample shape # Input dimensions are expected in CM ms.CreateSampleShape(InputWorkspace=self._output_ws, ShapeXML=create_cuboid_xml( self.getProperty("SampleHeight").value / 100., self.getProperty("SampleWidth").value / 100., self.getProperty("SampleDepth").value / 100.)) # Massage options into how algorithm expects them total_scatter_correction = str( self._correction_wsg) + "_TotalScattering" multi_scatter_correction = str( self._correction_wsg) + "_MultipleScattering" # Calculation # In the thin sample limit, 1-exp(-n*dens*sigma) ~ n*dens*sigma, effectively the same # scattering power(ratio of double to single scatt.) is obtained either by using relative # intensities ( sigma/int_sum )or density divided by the total intensity. # However, in the realistic case of thick sample, the SampleDensity, dens, must be # obtained by iterative numerical solution of the Eq: # 1-exp(-n*dens*sigma) = measured scattering power of the sample. # For this, a program like THICK must be used. # The program THICK also uses sigma/int_sum to be consistent with the prgram DINSMS_BATCH # The algorithm VesuvioCalculateMs called by the algorithm VesuvioCorrections takes the # parameter AtomicProperties with the absolute intensities, contraty to DINSMS_BATCH which # takes in relative intensities. # To compensate for this, the thickness parameter, dens (SampleDensity), is divided in by # the sum of absolute intensities in VesuvioCorrections before being passed to # VesuvioCalculateMs. # Then, for the modified VesuvioCorrection algorithm one can use the thickenss parameter is # as is from the THICK command, i.e. 43.20552 # This works, however, only in the thin sample limit, contrary to the THICK program. Thus, # for some detectors (detector banks) the SampleDensiy parameter may be over(under) # estimated. ms.VesuvioCalculateMS( InputWorkspace=self._output_ws, NoOfMasses=int(len(atom_props) / 3), SampleDensity=self.getProperty("SampleDensity").value / intensity_sum, AtomicProperties=atom_props, BeamRadius=self.getProperty("BeamRadius").value, NumEventsPerRun=self.getProperty("NumEvents").value, TotalScatteringWS=total_scatter_correction, MultipleScatteringWS=multi_scatter_correction) # Smooth the output smooth_neighbours = self.getProperty("SmoothNeighbours").value ms.SmoothData(InputWorkspace=total_scatter_correction, OutputWorkspace=total_scatter_correction, NPoints=smooth_neighbours) ms.SmoothData(InputWorkspace=multi_scatter_correction, OutputWorkspace=multi_scatter_correction, NPoints=smooth_neighbours) return total_scatter_correction, multi_scatter_correction
def process_incidentmon(self, number, extension, spline_terms=20): if type(number) is int: filename = self.get_file_name(number, extension) works = "monitor{}".format(number) shared_load_files(extension, filename, works, 4, 4, True) if extension[:9] == "nxs_event": temp = "w{}_monitors".format(number) works = "w{}_monitor4".format(number) simple.Rebin(InputWorkspace=temp, OutputWorkspace=temp, Params='6000,-0.00063,110000', PreserveEvents=False) simple.ExtractSingleSpectrum(InputWorkspace=temp, OutputWorkspace=works, WorkspaceIndex=3) else: num_1, num_2 = split_run_string(number) works = "monitor{0}_{1}".format(num_1, num_2) filename = self.get_file_name(num_1, extension) works1 = "monitor{}".format(num_1) simple.LoadRaw(Filename=filename, OutputWorkspace=works1, SpectrumMin=4, SpectrumMax=4, LoadLogFiles="0") filename = self.get_file_name(num_2, extension) works2 = "monitor{}".format(num_2) simple.LoadRaw(Filename=filename, OutputWorkspace=works2, SpectrumMin=4, SpectrumMax=4, LoadLogFiles="0") simple.MergeRuns(InputWorkspaces=works1 + "," + works2, OutputWorkspace=works) simple.DeleteWorkspace(works1) simple.DeleteWorkspace(works2) simple.ConvertUnits(InputWorkspace=works, OutputWorkspace=works, Target="Wavelength", Emode="Elastic") lambda_min, lambda_max = Wish.LAMBDA_RANGE simple.CropWorkspace(InputWorkspace=works, OutputWorkspace=works, XMin=lambda_min, XMax=lambda_max) ex_regions = np.array([[4.57, 4.76], [3.87, 4.12], [2.75, 2.91], [2.24, 2.50]]) simple.ConvertToDistribution(works) for reg in range(0, 4): simple.MaskBins(InputWorkspace=works, OutputWorkspace=works, XMin=ex_regions[reg, 0], XMax=ex_regions[reg, 1]) simple.SplineBackground(InputWorkspace=works, OutputWorkspace=works, WorkspaceIndex=0, NCoeff=spline_terms) simple.SmoothData(InputWorkspace=works, OutputWorkspace=works, NPoints=40) simple.ConvertFromDistribution(works) return works
def process_vanadium(self, vanadium, empty, panel, height, radius, cycle_van="09_3", cycle_empty="09_3"): user_data_directory = self.use_folder + cycle_van + '/' self.set_data_directory(user_data_directory) self.datafile = self.get_file_name(vanadium, "raw") vanadium_ws = self.read(vanadium, panel, "raw") user_data_directory = self.use_folder + cycle_empty + '/' self.set_data_directory(user_data_directory) self.datafile = self.get_file_name(empty, "raw") empty_ws = self.read(empty, panel, "raw") simple.Minus(LHSWorkspace=vanadium_ws, RHSWorkspace=empty_ws, OutputWorkspace=vanadium_ws) simple.DeleteWorkspace(empty_ws) absorption_corrections(4.8756, height, 0.07118, radius, 5.16, vanadium_ws) vanfoc = self.focus(vanadium_ws, panel) panel_crop = { 1: (0.95, 53.3), 2: (0.58, 13.1), 3: (0.44, 7.77), 4: (0.38, 5.86), 5: (0.35, 4.99), 6: (0.35, 4.99), 7: (0.38, 5.86), 8: (0.44, 7.77), 9: (0.58, 13.1), 10: (0.95, 53.3) } d_min, d_max = panel_crop.get(panel) simple.CropWorkspace(InputWorkspace=vanfoc, OutputWorkspace=vanfoc, XMin=d_min, XMax=d_max) spline_coefficient = { 1: 120, 2: 120, 3: 120, 4: 130, 5: 140, 6: 140, 7: 130, 8: 120, 9: 120, 10: 120 } simple.SplineBackground(InputWorkspace=vanfoc, OutputWorkspace=vanfoc, NCoeff=spline_coefficient.get(panel)) smoothing_coefficient = "30" if panel == 3 else "40" simple.SmoothData(InputWorkspace=vanfoc, OutputWorkspace=vanfoc, NPoints=smoothing_coefficient) return
def _ms_correction(self): """ Calculates the contributions from multiple scattering on the input data from the set of given options """ masses = self.getProperty("Masses").value params_ws_name = self.getPropertyValue("FitParameters") params_dict = TableWorkspaceDictionaryFacade(mtd[params_ws_name]) atom_props = list() intensities = list() for i, mass in enumerate(masses): intentisty_prop = 'f%d.Intensity' % i c0_prop = 'f%d.C_0' % i if intentisty_prop in params_dict: intentisy = params_dict[intentisty_prop] elif c0_prop in params_dict: intentisy = params_dict[c0_prop] else: continue # The program DINSMS_BATCH uses those sample parameters together with the sigma divided # by the sum absolute of scattering intensities for each detector (detector bank), # sigma/int_sum # Thus: # intensity = intensity/intensity_sum # In the thin sample limit, 1-exp(-n*dens*sigma) ~ n*dens*sigma, effectively the same # scattering power (ratio of double to single scatt.) is obtained either by using # relative intensities ( sigma/int_sum ) or density divided by the total intensity # However, in the realistic case of thick sample, the SampleDensity, dens, must be # obtained by iterative numerical solution of the Eq: # 1-exp(-n*dens*sigma) = measured scattering power of the sample. # For this, a program like THICK must be used. # The program THICK also uses sigma/int_sum to be consistent with the prgram # DINSMS_BATCH width_prop = 'f%d.Width' % i sigma_x_prop = 'f%d.SigmaX' % i sigma_y_prop = 'f%d.SigmaY' % i sigma_z_prop = 'f%d.SigmaZ' % i if width_prop in params_dict: width = params_dict['f%d.Width' % i] elif sigma_x_prop in params_dict: sigma_x = float(params_dict[sigma_x_prop]) sigma_y = float(params_dict[sigma_y_prop]) sigma_z = float(params_dict[sigma_z_prop]) width = math.sqrt((sigma_x**2 + sigma_y**2 + sigma_z**2) / 3.0) else: continue atom_props.append(mass) atom_props.append(intentisy) atom_props.append(width) intensities.append(intentisy) intensity_sum = sum(intensities) # Create the sample shape # Input dimensions are expected in CM ms.CreateSampleShape(InputWorkspace=self._output_ws, ShapeXML=create_cuboid_xml( self.getProperty("SampleHeight").value / 100., self.getProperty("SampleWidth").value / 100., self.getProperty("SampleDepth").value / 100.)) # Massage options into how algorithm expects them total_scatter_correction = str( self._correction_wsg) + "_TotalScattering" multi_scatter_correction = str( self._correction_wsg) + "_MultipleScattering" # Calculation # In the thin sample limit, 1-exp(-n*dens*sigma) ~ n*dens*sigma, effectively the same # scattering power(ratio of double to single scatt.) is obtained either by using relative # intensities ( sigma/int_sum )or density divided by the total intensity. # However, in the realistic case of thick sample, the SampleDensity, dens, must be # obtained by iterative numerical solution of the Eq: # 1-exp(-n*dens*sigma) = measured scattering power of the sample. # For this, a program like THICK must be used. # The program THICK also uses sigma/int_sum to be consistent with the prgram DINSMS_BATCH # The algorithm VesuvioCalculateMs called by the algorithm VesuvioCorrections takes the # parameter AtomicProperties with the absolute intensities, contraty to DINSMS_BATCH which # takes in relative intensities. # To compensate for this, the thickness parameter, dens (SampleDensity), is divided in by # the sum of absolute intensities in VesuvioCorrections before being passed to # VesuvioCalculateMs. # Then, for the modified VesuvioCorrection algorithm one can use the thickenss parameter is # as is from the THICK command, i.e. 43.20552 # This works, however, only in the thin sample limit, contrary to the THICK program. Thus, # for some detectors (detector banks) the SampleDensiy parameter may be over(under) # estimated. ms.VesuvioCalculateMS( InputWorkspace=self._output_ws, NoOfMasses=len(atom_props) / 3, SampleDensity=self.getProperty("SampleDensity").value / intensity_sum, AtomicProperties=atom_props, BeamRadius=self.getProperty("BeamRadius").value, NumEventsPerRun=self.getProperty("NumEvents").value, TotalScatteringWS=total_scatter_correction, MultipleScatteringWS=multi_scatter_correction) # Smooth the output smooth_neighbours = self.getProperty("SmoothNeighbours").value ms.SmoothData(InputWorkspace=total_scatter_correction, OutputWorkspace=total_scatter_correction, NPoints=smooth_neighbours) ms.SmoothData(InputWorkspace=multi_scatter_correction, OutputWorkspace=multi_scatter_correction, NPoints=smooth_neighbours) return total_scatter_correction, multi_scatter_correction