示例#1
0
def _do_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, is_vanadium):
    previous_units = ws_to_correct.getAxis(0).getUnit().unitID()
    ws_units = common_enums.WORKSPACE_UNITS

    # Mayers Sample correction must be completed in TOF, convert if needed. Then back to original units afterwards
    if previous_units != ws_units.tof:
        ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, Target=ws_units.tof)

    if is_vanadium:
        ws_to_correct = mantid.MayersSampleCorrection(InputWorkspace=ws_to_correct,
                                                      MultipleScattering=multiple_scattering)
    else:
        # Ensure we never do multiple scattering if the sample is not isotropic (e.g. not a Vanadium)
        ws_to_correct = mantid.MayersSampleCorrection(InputWorkspace=ws_to_correct,
                                                      MultipleScattering=False)
    if previous_units != ws_units.tof:
        ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, Target=previous_units)
    return ws_to_correct
def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering,
                                            sample_details_obj):
    """
    Calculates vanadium absorption corrections for the specified workspace. The workspace
    should have any monitor spectra masked before being passed into this method. Additionally
    it takes details of the sample container and sets the sample geometry to a cylinder with
    the specified geometry. This function uses Mayers Sample Correction to perform the corrections.
    :param ws_to_correct: The workspace to apply the sample corrections to
    :param multiple_scattering: True if the effects of multiple scattering should be accounted for, else False
    :param sample_details_obj: The SampleDetails object in a checked state which describes the sample
    to ensure a none elemental formula has associated number density
    :return: The workspace with corrections applied
    """

    geometry_json = {
        'Shape': 'Cylinder',
        'Height': sample_details_obj.height,
        'Radius': sample_details_obj.radius,
        'Center': sample_details_obj.center
    }
    material = sample_details_obj.material_object
    # See SetSampleMaterial for documentation on this dictionary
    material_json = {'ChemicalFormula': material.chemical_formula}
    if material.number_density:
        material_json["SampleNumberDensity"] = material.number_density
    if material.absorption_cross_section:
        material_json[
            "AttenuationXSection"] = material.absorption_cross_section
    if material.scattering_cross_section:
        material_json["ScatteringXSection"] = material.scattering_cross_section

    mantid.SetSample(InputWorkspace=ws_to_correct,
                     Geometry=geometry_json,
                     Material=material_json)

    previous_units = ws_to_correct.getAxis(0).getUnit().unitID()
    ws_units = common_enums.WORKSPACE_UNITS

    # Mayers Sample correction must be completed in TOF, convert if needed. Then back to original units afterwards
    if previous_units != ws_units.tof:
        ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct,
                                            OutputWorkspace=ws_to_correct,
                                            Target=ws_units.tof)
    ws_to_correct = mantid.MayersSampleCorrection(
        InputWorkspace=ws_to_correct,
        OutputWorkspace=ws_to_correct,
        MultipleScattering=multiple_scattering)
    if previous_units != ws_units.tof:
        ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct,
                                            OutputWorkspace=ws_to_correct,
                                            Target=previous_units)

    return ws_to_correct