예제 #1
0
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')
예제 #2
0
def create_slab_geometry(ws_name,vertical_width, horizontal_width, thickness):
    half_height, half_width, half_thick = 0.5*vertical_width, 0.5*horizontal_width, 0.5*thickness
    xml_str = \
        " <cuboid id=\"sample-shape\"> " \
        + "<left-front-bottom-point x=\"%f\" y=\"%f\" z=\"%f\" /> " % (half_width,-half_height,half_thick) \
        + "<left-front-top-point x=\"%f\" y=\"%f\" z=\"%f\" /> " % (half_width, half_height, half_thick) \
        + "<left-back-bottom-point x=\"%f\" y=\"%f\" z=\"%f\" /> " % (half_width, -half_height, -half_thick) \
        + "<right-front-bottom-point x=\"%f\" y=\"%f\" z=\"%f\" /> " % (-half_width, -half_height, half_thick) \
        + "</cuboid>"
    sapi.CreateSampleShape(ws_name, xml_str)
    return
예제 #3
0
def generate_vanadium_absorb_corrections(van_ws, output_filename):
    shape_ws = mantid.CloneWorkspace(InputWorkspace=van_ws)
    shape_ws = mantid.ConvertUnits(InputWorkspace=shape_ws, OutputWorkspace=shape_ws, Target="Wavelength")
    mantid.CreateSampleShape(InputWorkspace=shape_ws, ShapeXML='<sphere id="sphere_1"> <centre x="0" y="0" z= "0" />\
                                                      <radius val="0.005" /> </sphere>')

    absorb_ws = \
        mantid.AbsorptionCorrection(InputWorkspace=shape_ws, AttenuationXSection="5.08",
                                    ScatteringXSection="5.1", SampleNumberDensity="0.072",
                                    NumberOfWavelengthPoints="25", ElementSize="0.05")
    mantid.SaveNexus(Filename=output_filename,
                     InputWorkspace=absorb_ws, Append=False)
    common.remove_intermediate_workspace(shape_ws)
    return absorb_ws
예제 #4
0
def generate_vanadium_absorb_corrections(van_ws):
    raise NotImplementedError("Generating absorption corrections needs to be implemented correctly")

    # TODO are these values applicable to all instruments
    shape_ws = mantid.CloneWorkspace(InputWorkspace=van_ws)
    mantid.CreateSampleShape(InputWorkspace=shape_ws, ShapeXML='<sphere id="sphere_1"> <centre x="0" y="0" z= "0" />\
                                                      <radius val="0.005" /> </sphere>')

    calibration_full_paths = None
    absorb_ws = \
        mantid.AbsorptionCorrection(InputWorkspace=shape_ws, AttenuationXSection="5.08",
                                    ScatteringXSection="5.1", SampleNumberDensity="0.072",
                                    NumberOfWavelengthPoints="25", ElementSize="0.05")
    mantid.SaveNexus(Filename=calibration_full_paths["vanadium_absorption"],
                     InputWorkspace=absorb_ws, Append=False)
    common.remove_intermediate_workspace(shape_ws)
    return absorb_ws
예제 #5
0
def _generate_vanadium_absorb_corrections(calibration_full_paths, ws_to_match):
    # TODO are these values applicable to all instruments
    shape_ws = mantid.CloneWorkspace(InputWorkspace=ws_to_match)
    mantid.CreateSampleShape(
        InputWorkspace=shape_ws,
        ShapeXML='<sphere id="sphere_1"> <centre x="0" y="0" z= "0" />\
                                                      <radius val="0.005" /> </sphere>'
    )

    absorb_ws = \
        mantid.AbsorptionCorrection(InputWorkspace=shape_ws, AttenuationXSection="5.08",
                                    ScatteringXSection="5.1", SampleNumberDensity="0.072",
                                    NumberOfWavelengthPoints="25", ElementSize="0.05")
    mantid.SaveNexus(Filename=calibration_full_paths["vanadium_absorption"],
                     InputWorkspace=absorb_ws,
                     Append=False)
    remove_intermediate_workspace(shape_ws)
    return absorb_ws
예제 #6
0
    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
예제 #7
0
    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