Пример #1
0
def correctMisalignedTubes(ws, calibrationTable, peaksTable, spec, idealTube,
                           fitPar, threshold=10):
    """ Correct misaligned tubes due to poor fitting results
    during the first round of calibration.

    Misaligned tubes are first identified according to a tolerance
    applied to the absolute difference between the fitted tube
    positions and the mean across all tubes.

    The FindPeaks algorithm is then used to find a better fit
    with the ideal tube positions as starting parameters
    for the peak centers.

    From the refitted peaks the positions of the detectors in the
    tube are recalculated.

    @param ws: the workspace to get the tube geometry from
    @param calibrationTable: the calibration table ouput from running
    calibration
    @param peaksTable: the table containing the fitted peak centers from
    calibration
    @param spec: the tube spec for the instrument
    @param idealTube: the ideal tube for the instrument
    @param fitPar: the fitting parameters for calibration
    @param threshold: tolerance defining is a peak is outside of the acceptable
    range
    @return table of corrected detector positions
    """
    table_name = calibrationTable.name() + 'Corrected'
    corrections_table = CreateEmptyTableWorkspace(OutputWorkspace=table_name)
    corrections_table.addColumn('int', "Detector ID")
    corrections_table.addColumn('V3D', "Detector Position")

    mean_peaks, bad_tubes = findBadPeakFits(peaksTable, threshold)

    for index in bad_tubes:
        print("Refitting tube %s" % spec.getTubeName(index))
        tube_dets, _ = spec.getTube(index)
        getPoints(ws, idealTube.getFunctionalForms(), fitPar, tube_dets)
        tube_ws = mtd['TubePlot']
        fit_ws = FindPeaks(InputWorkspace=tube_ws, WorkspaceIndex=0,
                           PeakPositions=fitPar.getPeaks(),
                           PeaksList='RefittedPeaks')
        centers = [row['centre'] for row in fit_ws]
        detIDList, detPosList = \
            getCalibratedPixelPositions(ws, centers, idealTube.getArray(),
                                        tube_dets)

        for id, pos in zip(detIDList, detPosList):
            corrections_table.addRow({'Detector ID': id,
                                      'Detector Position': V3D(*pos)})

        cleanUpFit()

    return corrections_table
Пример #2
0
        def correctMisalignedTubes(ws, calibrationTable, peaksTable, spec, idealTube, fitPar, threshold=10):
            """ Correct misaligned tubes due to poor fitting results
            during the first round of calibration.

            Misaligned tubes are first identified according to a tolerance
            applied to the absolute difference between the fitted tube
            positions and the mean across all tubes.

            The FindPeaks algorithm is then used to find a better fit
            with the ideal tube positions as starting parameters
            for the peak centers.

            From the refitted peaks the positions of the detectors in the
            tube are recalculated.

            @param ws: the workspace to get the tube geometry from
            @param calibrationTable: the calibration table output from running calibration
            @param peaksTable: the table containing the fitted peak centers from calibration
            @param spec: the tube spec for the instrument
            @param idealTube: the ideal tube for the instrument
            @param fitPar: the fitting parameters for calibration
            @param threshold: tolerance defining is a peak is outside of the acceptable range
            @return table of corrected detector positions
            """
            table_name = calibrationTable.name() + 'Corrected'
            corrections_table = mantid.CreateEmptyTableWorkspace(OutputWorkspace=table_name)
            corrections_table.addColumn('int', "Detector ID")
            corrections_table.addColumn('V3D', "Detector Position")

            mean_peaks, bad_tubes = findBadPeakFits(peaksTable, threshold)

            for index in bad_tubes:
                print("Refitting tube %s" % spec.getTubeName(index))
                tube_dets, _ = spec.getTube(index)
                getPoints(ws, idealTube.getFunctionalForms(), fitPar, tube_dets)
                tube_ws = mantid.mtd['TubePlot']
                fit_ws = mantid.FindPeaks(InputWorkspace=tube_ws, WorkspaceIndex=0,
                                          PeakPositions=fitPar.getPeaks(), PeaksList='RefittedPeaks')
                centers = [row['centre'] for row in fit_ws]
                detIDList, detPosList = getCalibratedPixelPositions(ws, centers, idealTube.getArray(), tube_dets)

                for id, pos in zip(detIDList, detPosList):
                    corrections_table.addRow({'Detector ID': id, 'Detector Position': kernel.V3D(*pos)})

            return corrections_table