예제 #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
파일: EnginX.py 프로젝트: gemmaguest/mantid
def _run_focus(input_workspace,
               tof_output_name,
               vanadium_integration_ws,
               vanadium_curves_ws,
               df_kwarg,
               full_calib,
               region_calib):
    simple.NormaliseByCurrent(InputWorkspace=input_workspace, OutputWorkspace=input_workspace)
    input_workspace /= vanadium_integration_ws
    simple.ReplaceSpecialValues(InputWorkspace=input_workspace, OutputWorkspace=input_workspace, NaNValue=0,
                                InfinityValue=0)
    simple.ApplyDiffCal(InstrumentWorkspace=input_workspace, CalibrationWorkspace=full_calib)
    ws_d = simple.ConvertUnits(InputWorkspace=input_workspace, Target='dSpacing')
    focused_sample = simple.DiffractionFocussing(InputWorkspace=ws_d, **df_kwarg)
    curves_rebinned = simple.RebinToWorkspace(WorkspaceToRebin=vanadium_curves_ws, WorkspaceToMatch=focused_sample)
    normalised = simple.Divide(LHSWorkspace=focused_sample, RHSWorkspace=curves_rebinned,
                               AllowDifferentNumberSpectra=True)
    simple.ApplyDiffCal(InstrumentWorkspace=normalised, CalibrationWorkspace=region_calib)
    dspacing_output_name = tof_output_name + "_dSpacing"
    simple.CloneWorkspace(InputWorkspace=normalised, OutputWorkspace=dspacing_output_name)
    simple.ConvertUnits(InputWorkspace=normalised, OutputWorkspace=tof_output_name, Target='TOF')
    simple.DeleteWorkspace(curves_rebinned)
    simple.DeleteWorkspace(focused_sample)
    simple.DeleteWorkspace(normalised)
    simple.DeleteWorkspace(ws_d)
def extract_roi(workspace, step='0.01', roi=[162, 175, 112, 145]):
    """
        Returns a spectrum (Counts/proton charge vs lambda) given a filename
        or run number and the lambda step size and the corner of the ROI.

        :param str workspace: Mantid workspace name
        :param float step: wavelength bin width for rebinning
        :param list roi: [x_min, x_max, y_min, y_max] pixels
    """
    _workspace = str(workspace)
    if mantid.mtd[_workspace].getRun()['gd_prtn_chrg'].value > 0:
        api.NormaliseByCurrent(InputWorkspace=_workspace,
                               OutputWorkspace=_workspace)
    api.ConvertUnits(InputWorkspace=_workspace,
                     Target='Wavelength',
                     OutputWorkspace=_workspace)
    api.Rebin(InputWorkspace=_workspace,
              Params=step,
              OutputWorkspace=_workspace)
    api.RefRoi(InputWorkspace=_workspace,
               NXPixel=304,
               NYPixel=256,
               SumPixels=True,
               XPixelMin=roi[0],
               XPIxelMax=roi[1],
               YPixelMin=roi[2],
               YPixelMax=roi[3],
               IntegrateY=True,
               ConvertToQ=False,
               OutputWorkspace=_workspace)
    api.SumSpectra(InputWorkspace=_workspace, OutputWorkspace=_workspace)
    return _workspace
예제 #4
0
파일: common.py 프로젝트: liquidmet/mantid
def run_normalise_by_current(ws):
    """
    Runs the Normalise By Current algorithm on the input workspace
    :param ws: The workspace to run normalise by current on
    :return: The current normalised workspace
    """
    ws = mantid.NormaliseByCurrent(InputWorkspace=ws, OutputWorkspace=ws)
    return ws
예제 #5
0
def run_normalise_by_current(ws):
    """
    Runs the Normalise By Current algorithm on the input workspace. If the workspace has no current, return it unchanged
    :param ws: The workspace to run normalise by current on
    :return: The current normalised workspace
    """
    if workspace_has_current(ws):
        ws = mantid.NormaliseByCurrent(InputWorkspace=ws, OutputWorkspace=ws)
    else:
        warnings.warn(
            "Run {} had no current. NormaliseByCurrent will not be run on it, and empty will not be subtracted"
            .format(ws.getRunNumber()))
    return ws
예제 #6
0
def _load_run_and_convert_to_dSpacing(filepath, instrument, full_calib):
    runno = path_handling.get_run_number_from_path(filepath, instrument)
    ws = mantid.Load(Filename=filepath, OutputWorkspace=str(runno))
    if ws.getRun().getProtonCharge() > 0:
        ws = mantid.NormaliseByCurrent(InputWorkspace=ws,
                                       OutputWorkspace=ws.name())
    else:
        logger.warning(f"Run {ws.name()} has invalid proton charge.")
        mantid.DeleteWorkspace(ws)
        return None
    mantid.ApplyDiffCal(InstrumentWorkspace=ws,
                        CalibrationWorkspace=full_calib)
    ws = mantid.ConvertUnits(InputWorkspace=ws,
                             OutputWorkspace=ws.name(),
                             Target='dSpacing')
    return ws
예제 #7
0
def Norm_data(rnum, cycle):
    # Load and normalize SX data
    mantid.LoadRaw(
        Filename='/archive/Instruments$/NDXWISH/Instrument/data/cycle_' +
        cycle + '/WISH000' + str(rnum) + '.raw',
        OutputWorkspace='WISH000' + str(rnum),
        LoadMonitors='Separate')
    # ConvertToEventWorkspace(InputWorkspace='WISH000'+str(rnum), OutputWorkspace='WISH000'+str(rnum))
    mantid.CropWorkspace(InputWorkspace='WISH000' + str(rnum),
                         OutputWorkspace='WISH000' + str(i),
                         XMin=6000,
                         XMax=99000)
    mantid.ConvertUnits(InputWorkspace='WISH000' + str(rnum),
                        OutputWorkspace='WISH000' + str(rnum),
                        Target='Wavelength')
    mantid.NormaliseByCurrent(InputWorkspace='WISH000' + str(rnum),
                              OutputWorkspace='WISH000' + str(rnum))
    # normalize By vanadium PredictPeaks
    mantid.CropWorkspace(InputWorkspace='WISH000' + str(rnum),
                         OutputWorkspace='WISH000' + str(rnum),
                         XMin=0.75,
                         XMax=9.3)
    mantid.RebinToWorkspace(WorkspaceToRebin='Vana_smoot1',
                            WorkspaceToMatch='WISH000' + str(rnum),
                            OutputWorkspace='Vana_smoot1')
    mantid.Divide(LHSWorkspace='WISH000' + str(rnum),
                  RHSWorkspace='Vana_smoot1',
                  OutputWorkspace='WISH000' + str(rnum))
    # remove spike in the data above 1e15 and -1e15
    mantid.ReplaceSpecialValues(InputWorkspace='WISH000' + str(rnum),
                                OutputWorkspace='WISH000' + str(rnum),
                                NaNValue=0,
                                InfinityValue=0,
                                BigNumberThreshold=1e15,
                                SmallNumberThreshold=-1e15)
    # Convert to Diffraction MD and Lorentz Correction
    mantid.ConvertToDiffractionMDWorkspace(
        InputWorkspace='WISH000' + str(rnum),
        OutputWorkspace='WISH000' + str(rnum) + '_MD',
        LorentzCorrection=True)
예제 #8
0
파일: EnginX.py 프로젝트: gemmaguest/mantid
def create_vanadium_integration(van_run, calibration_directory):
    """
    create the vanadium integration for the run number set of the object

    @param van_run :: the run number for the vanadium
    @param calibration_directory :: the directory to save the output to
    """
    # find and load the vanadium
    van_file = _gen_filename(van_run)
    _, van_int_file = _get_van_names(van_run, calibration_directory)
    van_name = "eng_vanadium_ws"
    van_ws = simple.Load(van_file, OutputWorkspace=van_name)

    # make the integration workspace
    simple.NormaliseByCurrent(InputWorkspace=van_ws, OutputWorkspace=van_ws)
    # sensitivity correction for van
    ws_van_int = simple.Integration(InputWorkspace=van_ws)
    ws_van_int /= van_ws.blocksize()
    # save out the vanadium and delete the original workspace
    simple.SaveNexus(ws_van_int, van_int_file)
    simple.DeleteWorkspace(van_name)
    simple.DeleteWorkspace(ws_van_int)
예제 #9
0
def run_calibration(ceria_ws, calibration, full_instrument_cal_ws):
    """
    Creates Engineering calibration files with PDCalibration
    :param ceria_ws: The workspace with the ceria data.
    :param bank: The bank to crop to, both if none.
    :param calfile: The custom calibration file to crop to, not used if none.
    :param spectrum_numbers: The spectrum numbers to crop to, no crop if none.
    :return: dict containing calibrated diffractometer constants, and copy of the raw ceria workspace
    """

    # initial process of ceria ws
    mantid.NormaliseByCurrent(InputWorkspace=ceria_ws,
                              OutputWorkspace=ceria_ws)
    mantid.ApplyDiffCal(InstrumentWorkspace=ceria_ws,
                        CalibrationWorkspace=full_instrument_cal_ws)
    mantid.ConvertUnits(InputWorkspace=ceria_ws,
                        OutputWorkspace=ceria_ws,
                        Target='dSpacing')

    # get grouping workspace and focus
    grp_ws = calibration.get_group_ws()  # (creates if doesn't exist)
    focused_ceria = mantid.DiffractionFocussing(InputWorkspace=ceria_ws,
                                                GroupingWorkspace=grp_ws)
    mantid.ApplyDiffCal(
        InstrumentWorkspace=focused_ceria,
        ClearCalibration=True)  # DIFC of detector in middle of bank
    focused_ceria = mantid.ConvertUnits(InputWorkspace=focused_ceria,
                                        Target='TOF')

    # Run mantid.PDCalibration to fit peaks in TOF
    foc_name = focused_ceria.name(
    )  # PDCal invalidates ptr during rebin so keep track of ws name
    cal_table_name = "engggui_calibration_" + calibration.get_group_suffix()
    diag_ws_name = "diag_" + calibration.get_group_suffix()
    cal_table, diag_ws, mask = mantid.PDCalibration(
        InputWorkspace=foc_name,
        OutputCalibrationTable=cal_table_name,
        DiagnosticWorkspaces=diag_ws_name,
        PeakPositions=default_ceria_expected_peaks(final=True),
        TofBinning=[12000, -0.0003, 52000],
        PeakWindow=default_ceria_expected_peak_windows(final=True),
        MinimumPeakHeight=0.5,
        PeakFunction='BackToBackExponential',
        CalibrationParameters='DIFC+TZERO+DIFA',
        UseChiSq=True)
    mantid.ApplyDiffCal(InstrumentWorkspace=foc_name,
                        CalibrationWorkspace=cal_table)

    # warn user which spectra were unsuccessfully calibrated
    focused_ceria = ADS.retrieve(foc_name)
    masked_detIDs = mask.getMaskedDetectors()
    for ispec in range(focused_ceria.getNumberHistograms()):
        if focused_ceria.getSpectrum(
                ispec).getDetectorIDs()[0] in masked_detIDs:
            logger.warning(
                f'mantid.PDCalibration failed for spectrum index {ispec} - proceeding with uncalibrated DIFC.'
            )

    # store cal_table in calibration
    calibration.set_calibration_table(cal_table_name)

    return focused_ceria, cal_table, diag_ws
예제 #10
0
파일: EnginX.py 프로젝트: gemmaguest/mantid
 def ws_initial_process(ws):
     """Run some processing common to both the sample and vanadium workspaces"""
     simple.NormaliseByCurrent(InputWorkspace=ws, OutputWorkspace=ws)
     simple.ApplyDiffCal(InstrumentWorkspace=ws, CalibrationWorkspace=full_inst_calib)
     simple.ConvertUnits(InputWorkspace=ws, OutputWorkspace=ws, Target='dSpacing')
     return ws