예제 #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 runTest(self):
     self.setup()
     mantid.LoadSampleShape(InputWorkspace="ws", OutputWorkspace="ws",
                            Filename=os.path.join(data_dir, "cylinder.stl"), scale="mm")
     mantid.SetSampleMaterial(InputWorkspace="ws", ChemicalFormula="V", SampleNumberDensity=0.1)
     self.handleEnvironment()
     mantid.MonteCarloAbsorption(InputWorkspace="ws", OutputWorkspace="ws", EventsPerPoint=5000)
 def runTest(self):
     self.setup()
     mantid.LoadSampleShape(InputWorkspace="ws",
                            OutputWorkspace="ws",
                            Filename=os.path.join(data_dir, "cylinder.stl"))
     mantid.SetSampleMaterial(InputWorkspace="ws",
                              ChemicalFormula="V",
                              SampleNumberDensity=0.1)
     mantid.MonteCarloAbsorption(InputWorkspace="ws",
                                 OutputWorkspace="ws",
                                 NumberOfWavelengthPoints=50)
 def runTest(self):
     self.setup()
     mantid.LoadSampleShape(InputWorkspace="ws",
                            OutputWorkspace="ws",
                            Filename="cylinder.stl",
                            scale="mm")
     mantid.SetSampleMaterial(InputWorkspace="ws",
                              ChemicalFormula="V",
                              SampleNumberDensity=0.1)
     self.handleEnvironment()
     mantid.MonteCarloAbsorption(InputWorkspace="ws",
                                 OutputWorkspace="ws",
                                 NumberOfWavelengthPoints=50)
예제 #5
0
def create_van(instrument, run_details, absorb):
    """
    Creates a splined vanadium run for the following instrument. Requires the run_details for the
    vanadium workspace we will process and whether to apply absorption corrections.
    :param instrument: The instrument object that will be used to supply various instrument specific methods
    :param run_details: The run details associated with this vanadium run
    :param absorb: Boolean flag whether to apply absorption corrections
    :return: Processed workspace group in dSpacing (but not splined)
    """
    van = run_details.vanadium_run_numbers
    # Always sum a range of inputs as its a vanadium run over multiple captures
    input_van_ws_list = common.load_current_normalised_ws_list(run_number_string=van, instrument=instrument,
                                                               input_batching=INPUT_BATCHING.Summed)
    input_van_ws = input_van_ws_list[0]  # As we asked for a summed ws there should only be one returned

    corrected_van_ws = common.subtract_summed_runs(ws_to_correct=input_van_ws,
                                                   empty_sample_ws_string=run_details.empty_runs,
                                                   instrument=instrument)

    # Crop the tail end of the data on PEARL if they are not capturing slow neutrons
    corrected_van_ws = instrument._crop_raw_to_expected_tof_range(ws_to_crop=corrected_van_ws)

    if absorb:
        corrected_van_ws = instrument._apply_absorb_corrections(run_details=run_details,
                                                                ws_to_correct=corrected_van_ws)
    else:
        # Assume that create_van only uses Vanadium runs
        mantid.SetSampleMaterial(InputWorkspace=corrected_van_ws, ChemicalFormula='V')

    aligned_ws = mantid.AlignDetectors(InputWorkspace=corrected_van_ws,
                                       CalibrationFile=run_details.offset_file_path)
    focused_vanadium = mantid.DiffractionFocussing(InputWorkspace=aligned_ws,
                                                   GroupingFileName=run_details.grouping_file_path)

    focused_spectra = common.extract_ws_spectra(focused_vanadium)
    focused_spectra = instrument._crop_van_to_expected_tof_range(focused_spectra)

    d_spacing_group, tof_group = instrument._output_focused_ws(processed_spectra=focused_spectra,
                                                               run_details=run_details)

    _create_vanadium_splines(focused_spectra, instrument, run_details)

    common.keep_single_ws_unit(d_spacing_group=d_spacing_group, tof_group=tof_group,
                               unit_to_keep=instrument._get_unit_to_keep())

    common.remove_intermediate_workspace(corrected_van_ws)
    common.remove_intermediate_workspace(aligned_ws)
    common.remove_intermediate_workspace(focused_vanadium)
    common.remove_intermediate_workspace(focused_spectra)

    return d_spacing_group
예제 #6
0
    def _compute_partial_ion_workflow(self, partial_ions, frequencies,
                                      eigenvectors, weights):
        """
        Computes the partial DoS workspaces for a given set of ions (optionally scaling them by
        the cross scattering sections) and sums them into a single spectra.

        Both the partial workspaces and the summed total are returned.

        @param partial_ions Dict of ions to caculate DoS for
        @param frequencies Frequencies read from file
        @param eigenvectors Eigenvectors read from file
        @param weights Weights for each frequency block
        @returns Tuple of list of partial workspace names and summed contribution workspace name
        """
        logger.debug('Computing partial DoS for: ' + str(partial_ions))

        partial_workspaces = []
        total_workspace = None

        # Output each contribution to it's own workspace
        for ion_name, ions in partial_ions.items():
            partial_ws_name = self._out_ws_name + '_'

            partial_ws = self._compute_partial(ions, frequencies, eigenvectors,
                                               weights)

            # Set correct units on partial workspace
            partial_ws.setYUnit('(D/A)^2/amu')
            partial_ws.setYUnitLabel('Intensity')

            # Add the sample material to the workspace
            match = re.search(r'\d', ion_name)
            element_index = ion_name
            if match:
                element_index = ion_name[:match.start()]
            chemical, ws_suffix = self._parse_chemical_and_ws_name(
                ion_name, self._element_isotope[element_index])
            partial_ws_name += ws_suffix

            s_api.SetSampleMaterial(InputWorkspace=self._out_ws_name,
                                    ChemicalFormula=chemical)

            # Multiply intensity by scatttering cross section
            if self._scale_by_cross_section == 'Incoherent':
                scattering_x_section = partial_ws.mutableSample().getMaterial(
                ).incohScatterXSection()
            elif self._scale_by_cross_section == 'Coherent':
                scattering_x_section = partial_ws.mutableSample().getMaterial(
                ).cohScatterXSection()
            elif self._scale_by_cross_section == 'Total':
                scattering_x_section = partial_ws.mutableSample().getMaterial(
                ).totalScatterXSection()

            if self._scale_by_cross_section != 'None':
                scale_alg = self.createChildAlgorithm('Scale')
                scale_alg.setProperty('InputWorkspace', self._out_ws_name)
                scale_alg.setProperty('OutputWorkspace', self._out_ws_name)
                scale_alg.setProperty('Operation', 'Multiply')
                scale_alg.setProperty('Factor', scattering_x_section)
                scale_alg.execute()

            rename_alg = self.createChildAlgorithm('RenameWorkspace')
            rename_alg.setProperty('InputWorkspace', self._out_ws_name)
            rename_alg.setProperty('OutputWorkspace', partial_ws_name)
            rename_alg.execute()
            partial_workspaces.append(
                rename_alg.getProperty('OutputWorkspace').value)

        total_workspace = self._out_ws_name + "_Total"

        # If there is more than one partial workspace need to sum first spectrum of all
        if len(partial_workspaces) > 1:
            initial_partial_ws = partial_workspaces[0]
            data_x = initial_partial_ws.dataX(0)
            dos_specs = np.zeros_like(initial_partial_ws.dataY(0))
            stick_specs = np.zeros_like(initial_partial_ws.dataY(0))

            for partial_ws in partial_workspaces:
                dos_specs += partial_ws.dataY(0)
                stick_specs += partial_ws.dataY(1)

            stick_specs[stick_specs > 0.0] = self.getProperty(
                'StickHeight').value

            total_ws = self._create_dos_workspace(data_x, dos_specs,
                                                  stick_specs, total_workspace)

            # Set correct units on total workspace
            total_ws.setYUnit('(D/A)^2/amu')
            total_ws.setYUnitLabel('Intensity')

        # Otherwise just repackage the WS we have as the total
        else:
            s_api.CloneWorkspace(InputWorkspace=partial_workspaces[0],
                                 OutputWorkspace=total_workspace)

        logger.debug('Partial workspaces: ' + str(partial_workspaces))
        logger.debug('Summed workspace: ' + str(total_workspace))

        return partial_workspaces, total_workspace