コード例 #1
0
    def setUp(self):
        config['default.facility'] = 'ILL'
        config['default.instrument'] = 'D22'
        config['logging.loggers.root.level'] = 'Warning'
        config.appendDataSearchSubDir('ILL/D22/')

        MaskBTP(Instrument='D22', Pixel='0-12,245-255')
        MaskBTP(Workspace='D22MaskBTP', Tube='54-75', Pixel='108-150')
        RenameWorkspace(InputWorkspace='D22MaskBTP', OutputWorkspace='D22_mask_central')
コード例 #2
0
ファイル: bank.py プロジェクト: stuartcampbell/mantid
def mask_bank(bank_name: str, tubes_fit_success: np.ndarray, output_table: str) -> Optional[TableWorkspace]:
    r"""
    Creates a single-column `TableWorkspace` object containing the detector ID's of the
    unsuccessfully fitted tubes

    If all tubes were fit successfully, no `TableWorkspace` is created, and `None` is returned.

    :param bank_name: a string of the form 'bankI' where 'I' is a bank number
    :param tubes_fit_success: array of boolean containing a True/False entry for each tube, indicating wether
    the tube was successfully calibrated.
    :param output_table: name of the output TableWorkspace containing one column for detector ID from tubes
    not successfully calibrated.

    :raise AssertionError: the string bank_name does not follow the pattern 'bankI' where 'I' in an integer
    :return: name of the mask TableWorkspace. Returns `None` if no TableWorkspace is created.
    """
    assert re.match(r'^bank\d+$', bank_name), 'The bank name must be of the form "bankI" where "I" in an integer'
    if False not in tubes_fit_success:
        return None  # al tubes were fit successfully
    bank_number = bank_name[4:]  # drop 'bank' from bank_name
    tube_numbers = 1 + np.where(tubes_fit_success == False)[0]  # noqa E712 unsuccessfully fitted tube numbers
    tube_numbers = ','.join([str(n) for n in tube_numbers])  # failing tubes as a string
    detector_ids = MaskBTP(Instrument='CORELLI', Bank=bank_number, Tube=tube_numbers)
    table = CreateEmptyTableWorkspace(OutputWorkspace=output_table)
    table.addColumn('long64', 'Detector ID')
    [table.addRow([detector_id]) for detector_id in detector_ids.tolist()]
    if AnalysisDataService.doesExist('CORELLIMaskBTP'):
        DeleteWorkspaces(['CORELLIMaskBTP'])
    return mtd[output_table]
コード例 #3
0
    def setUp(self):
        config['default.facility'] = 'ILL'
        config['default.instrument'] = 'D11'
        config['logging.loggers.root.level'] = 'Warning'
        config.appendDataSearchSubDir('ILL/D11/')

        # prepare mask for instrument edges first:
        MaskBTP(Instrument='D11', Tube='1-3,253-256')
        RenameWorkspace(InputWorkspace='D11MaskBTP', OutputWorkspace='mask_vertical')
        MaskBTP(Instrument='D11', Pixel='1-3,253-256')
        Plus(LHSWorkspace='mask_vertical', RHSWorkspace='D11MaskBTP', OutputWorkspace='edge_masks')
        # the edges mask can be used as a default mask for all distances and wavelengths
        MaskBTP(Instrument='D11', Tube='116-139', Pixel='90-116')
        RenameWorkspace(InputWorkspace='D11MaskBTP', OutputWorkspace='mask_39m_10A')
        MaskBTP(Instrument='D11', Tube='115-140', Pixel='115-140')
        RenameWorkspace(InputWorkspace='D11MaskBTP', OutputWorkspace='mask_8m_4_6A')
        MaskBTP(Instrument='D11', Tube='105-145', Pixel='105-145')
        RenameWorkspace(InputWorkspace='D11MaskBTP', OutputWorkspace='mask_1m_4_6A')
コード例 #4
0
ファイル: LoadWAND.py プロジェクト: freephys/mantid
    def PyExec(self):
        filename = self.getProperty("Filename").value
        wavelength = self.getProperty("wavelength").value
        outWS = self.getPropertyValue("OutputWorkspace")

        LoadEventNexus(Filename=filename,
                       OutputWorkspace=outWS,
                       LoadMonitors=True)
        Integration(InputWorkspace=outWS, OutputWorkspace=outWS)

        if self.getProperty("ApplyMask").value:
            MaskBTP(outWS, Bank='8', Tube='449-480')
            MaskBTP(outWS, Pixel='1,2,511,512')

        mtd[outWS].getAxis(0).setUnit("Wavelength")
        w = [wavelength - 0.001, wavelength + 0.001]
        for idx in range(mtd[outWS].getNumberHistograms()):
            mtd[outWS].setX(idx, w)

        SetGoniometer(outWS, Axis0="HB2C:Mot:s1,0,1,0,1")
        AddSampleLog(outWS,
                     LogName="gd_prtn_chrg",
                     LogType='Number',
                     NumberType='Double',
                     LogText=str(mtd[outWS + '_monitors'].getNumberEvents()))
        DeleteWorkspace(outWS + '_monitors')

        AddSampleLog(outWS,
                     LogName="Wavelength",
                     LogType='Number',
                     NumberType='Double',
                     LogText=str(wavelength))
        AddSampleLog(outWS,
                     LogName="Ei",
                     LogType='Number',
                     NumberType='Double',
                     LogText=str(
                         UnitConversion.run('Wavelength', 'Energy', wavelength,
                                            0, 0, 0, Elastic, 0)))

        self.setProperty('OutputWorkspace', outWS)
コード例 #5
0
    def setUp(self):
        config['default.facility'] = 'ILL'
        config['default.instrument'] = 'D11'
        config['logging.loggers.root.level'] = 'Warning'
        config.appendDataSearchSubDir('ILL/D11/')
        # prepare mask for instrument edges first:
        MaskBTP(Instrument='D11', Tube='0-6,250-256')
        RenameWorkspace(InputWorkspace='D11MaskBTP',
                        OutputWorkspace='mask_vertical')
        MaskBTP(Instrument='D11', Pixel='0-6,250-256')
        Plus(LHSWorkspace='mask_vertical',
             RHSWorkspace='D11MaskBTP',
             OutputWorkspace='edge_masks')
        # the edges mask can be used as a default mask for all distances and wavelengths

        MaskBTP(Instrument='D11', Tube='114-142,', Pixel='114-142')
        RenameWorkspace(InputWorkspace='D11MaskBTP',
                        OutputWorkspace='mask_8m_4_6A_center')
        MaskBTP(Instrument='D11', Tube='3-14', Pixel='240-256')
        Plus(LHSWorkspace='D11MaskBTP',
             RHSWorkspace='mask_8m_4_6A_center',
             OutputWorkspace='mask_8m_4_6A')
        MaskBTP(Instrument='D11', Tube='103-147', Pixel='103-147')
        RenameWorkspace(InputWorkspace='D11MaskBTP',
                        OutputWorkspace='mask_1m_4_6A_center')
        MaskBTP(Instrument='D11', Tube='3-14', Pixel='240-256')
        Plus(LHSWorkspace='D11MaskBTP',
             RHSWorkspace='mask_1m_4_6A_center',
             OutputWorkspace='mask_1m_4_6A')
コード例 #6
0
ファイル: LoadWAND.py プロジェクト: luzpaz/mantid
    def PyExec(self):
        runs = self.getProperty("Filename").value

        if not runs:
            ipts = self.getProperty("IPTS").value
            runs = [
                '/HFIR/HB2C/IPTS-{}/nexus/HB2C_{}.nxs.h5'.format(ipts, run)
                for run in self.getProperty("RunNumbers").value
            ]

        wavelength = self.getProperty("wavelength").value
        outWS = self.getPropertyValue("OutputWorkspace")
        group_names = []

        grouping = self.getProperty("Grouping").value
        if grouping == 'None':
            grouping = 1
        else:
            grouping = 2 if grouping == '2x2' else 4

        for i, run in enumerate(runs):
            data = np.zeros((512 * 480 * 8), dtype=np.int64)
            with h5py.File(run, 'r') as f:
                monitor_count = f['/entry/monitor1/total_counts'].value[0]
                run_number = f['/entry/run_number'].value[0]
                for b in range(8):
                    data += np.bincount(f['/entry/bank' + str(b + 1) +
                                          '_events/event_id'].value,
                                        minlength=512 * 480 * 8)
            data = data.reshape((480 * 8, 512))
            if grouping == 2:
                data = data[::2, ::2] + data[
                    1::2, ::2] + data[::2, 1::2] + data[1::2, 1::2]
            elif grouping == 4:
                data = (data[::4, ::4] + data[1::4, ::4] + data[2::4, ::4] +
                        data[3::4, ::4] + data[::4, 1::4] + data[1::4, 1::4] +
                        data[2::4, 1::4] + data[3::4, 1::4] + data[::4, 2::4] +
                        data[1::4, 2::4] + data[2::4, 2::4] +
                        data[3::4, 2::4] + data[::4, 3::4] + data[1::4, 3::4] +
                        data[2::4, 3::4] + data[3::4, 3::4])

            CreateWorkspace(DataX=[wavelength - 0.001, wavelength + 0.001],
                            DataY=data,
                            DataE=np.sqrt(data),
                            UnitX='Wavelength',
                            YUnitLabel='Counts',
                            NSpec=1966080 // grouping**2,
                            OutputWorkspace='__tmp_load',
                            EnableLogging=False)
            LoadNexusLogs('__tmp_load', Filename=run, EnableLogging=False)
            AddSampleLog('__tmp_load',
                         LogName="monitor_count",
                         LogType='Number',
                         NumberType='Double',
                         LogText=str(monitor_count),
                         EnableLogging=False)
            AddSampleLog('__tmp_load',
                         LogName="gd_prtn_chrg",
                         LogType='Number',
                         NumberType='Double',
                         LogText=str(monitor_count),
                         EnableLogging=False)
            AddSampleLog('__tmp_load',
                         LogName="Wavelength",
                         LogType='Number',
                         NumberType='Double',
                         LogText=str(wavelength),
                         EnableLogging=False)
            AddSampleLog('__tmp_load',
                         LogName="Ei",
                         LogType='Number',
                         NumberType='Double',
                         LogText=str(
                             UnitConversion.run('Wavelength', 'Energy',
                                                wavelength, 0, 0, 0, Elastic,
                                                0)),
                         EnableLogging=False)
            AddSampleLog('__tmp_load',
                         LogName="run_number",
                         LogText=run_number,
                         EnableLogging=False)

            if grouping > 1:  # Fix detector IDs per spectrum before loading instrument
                __tmp_load = mtd['__tmp_load']
                for n in range(__tmp_load.getNumberHistograms()):
                    s = __tmp_load.getSpectrum(n)
                    for i in range(grouping):
                        for j in range(grouping):
                            s.addDetectorID(
                                int(n * grouping % 512 + n //
                                    (512 / grouping) * 512 * grouping + j +
                                    i * 512))

                LoadInstrument('__tmp_load',
                               InstrumentName='WAND',
                               RewriteSpectraMap=False,
                               EnableLogging=False)
            else:
                LoadInstrument('__tmp_load',
                               InstrumentName='WAND',
                               RewriteSpectraMap=True,
                               EnableLogging=False)

            SetGoniometer('__tmp_load',
                          Axis0="HB2C:Mot:s1,0,1,0,1",
                          EnableLogging=False)

            if self.getProperty("ApplyMask").value:
                MaskBTP('__tmp_load', Pixel='1,2,511,512', EnableLogging=False)
                if mtd['__tmp_load'].getRunNumber(
                ) > 26600:  # They changed pixel mapping and bank name order here
                    MaskBTP('__tmp_load',
                            Bank='1',
                            Tube='479-480',
                            EnableLogging=False)
                    MaskBTP('__tmp_load',
                            Bank='8',
                            Tube='1-2',
                            EnableLogging=False)
                else:
                    MaskBTP('__tmp_load',
                            Bank='8',
                            Tube='475-480',
                            EnableLogging=False)

            if len(runs) == 1:
                RenameWorkspace('__tmp_load', outWS, EnableLogging=False)
            else:
                outName = outWS + "_" + str(mtd['__tmp_load'].getRunNumber())
                group_names.append(outName)
                RenameWorkspace('__tmp_load', outName, EnableLogging=False)

        if len(runs) > 1:
            GroupWorkspaces(group_names,
                            OutputWorkspace=outWS,
                            EnableLogging=False)

        self.setProperty('OutputWorkspace', outWS)
コード例 #7
0
 def runTest(self):
     # Load Empty Instrument
     ws = LoadEmptyInstrument(InstrumentName='WISH', OutputWorkspace='WISH')
     axis = ws.getAxis(0)
     axis.setUnit("TOF")  # need this to add peak to table
     # CreatePeaksWorkspace with peaks in specific detectors
     peaks = CreatePeaksWorkspace(InstrumentWorkspace=ws,
                                  NumberOfPeaks=0,
                                  OutputWorkspace='peaks')
     AddPeak(PeaksWorkspace=peaks,
             RunWorkspace=ws,
             TOF=20000,
             DetectorID=1707204,
             Height=521,
             BinCount=0)  # pixel in first tube in panel 1
     AddPeak(PeaksWorkspace=peaks,
             RunWorkspace=ws,
             TOF=20000,
             DetectorID=1400510,
             Height=1,
             BinCount=0)  # pixel at top of a central tube in panel 1
     AddPeak(PeaksWorkspace=peaks,
             RunWorkspace=ws,
             TOF=20000,
             DetectorID=1408202,
             Height=598,
             BinCount=0)  # pixel in middle of bank 1 (not near edge)
     AddPeak(PeaksWorkspace=peaks,
             RunWorkspace=ws,
             TOF=20000,
             DetectorID=1100173,
             Height=640,
             BinCount=0)  # pixel in last tube of panel 1 (next to panel 2)
     # create dummy MD workspace for integration (don't need data as checking peak shape)
     MD = CreateMDWorkspace(Dimensions='3',
                            Extents='-1,1,-1,1,-1,1',
                            Names='Q_lab_x,Q_lab_y,Q_lab_z',
                            Units='U,U,U',
                            Frames='QLab,QLab,QLab',
                            SplitInto='2',
                            SplitThreshold='50')
     # Integrate peaks masking all pixels at tube end (built into IntegratePeaksMD)
     self._peaks_pixels = IntegratePeaksMD(InputWorkspace=MD,
                                           PeakRadius='0.02',
                                           PeaksWorkspace=peaks,
                                           IntegrateIfOnEdge=False,
                                           OutputWorkspace='peaks_pixels',
                                           MaskEdgeTubes=False)
     # Apply masking to specific tubes next to beam in/out (subset of all edge tubes) and integrate again
     MaskBTP(Workspace='peaks', Bank='5-6', Tube='152')
     MaskBTP(Workspace='peaks', Bank='1,10', Tube='1')
     self._peaks_pixels_beamTubes = IntegratePeaksMD(
         InputWorkspace='MD',
         PeakRadius='0.02',
         PeaksWorkspace=peaks,
         IntegrateIfOnEdge=False,
         OutputWorkspace='peaks_pixels_beamTubes',
         MaskEdgeTubes=False)
     # Integrate masking all edge tubes
     self._peaks_pixels_edgeTubes = IntegratePeaksMD(
         InputWorkspace='MD',
         PeakRadius='0.02',
         PeaksWorkspace='peaks',
         IntegrateIfOnEdge=False,
         OutputWorkspace='peaks_pixels_edgeTubes',
         MaskEdgeTubes=True)
コード例 #8
0
corelli = LoadEmptyInstrument(InstrumentName='CORELLI')
corelli = CalculateDIFC(corelli)
difc0 = corelli.extractY().flatten()
ApplyCalibration('corelli', 'CalibTable')
corelli = CalculateDIFC(corelli)
difc = corelli.extractY().flatten()

plt.plot(difc / difc0)
plt.show()

LoadDiffCal(
    Filename='../cal_Si_C60/cal_Si2_47327-47334_TubeCal_sum16_mask_lt_2.cal',
    InstrumentName='CORELLI',
    WorkspaceName='si')
MaskBTP(Workspace='si_mask', Pixel="1-16,241-256")

LoadDiffCal(
    Filename='../cal_Si_C60/cal_C60_2_47367-47382_TubeCal_sum16_mask_lt_2.h5',
    InstrumentName='CORELLI',
    WorkspaceName='c60')
MaskBTP(Workspace='c60_mask', Pixel="1-16,241-256")

si = mtd['si_cal']
c60 = mtd['c60_cal']
si_mask = mtd['si_mask']
c60_mask = mtd['c60_mask']

plt.plot(corelli.extractY())
plt.plot(si.column(0), si.column(1))
plt.plot(c60.column(0), c60.column(1))
コード例 #9
0
    row.append(leftbound)
    row.append(rightbound)

fitwinws.addRow(row)

for run in range(first, last + 1):
    LoadEventNexus(Filename='CORELLI_' + str(run), OutputWorkspace='data')
    if tube_cal:
        ApplyCalibration('data', 'CalibTable')
    SetInstrumentParameter(Workspace="data",
                           ParameterName="t0_formula",
                           Value="(23.5 * exp(-incidentEnergy/205.8))")
    ModeratorTzero(InputWorkspace="data",
                   OutputWorkspace="data",
                   EMode="Elastic")
    MaskBTP(Workspace='data', Pixel="1-16,241-256")
    ConvertUnits(InputWorkspace='data',
                 OutputWorkspace='data',
                 Target='dSpacing')
    Rebin(InputWorkspace='data',
          OutputWorkspace='data',
          Params='0.5,-0.004,10')
    SumNeighbours(InputWorkspace="data",
                  OutputWorkspace="data",
                  SumX=1,
                  SumY=SumY)
    GetDetOffsetsMultiPeaks(InputWorkspace='data',
                            DReference=FinalDReference,
                            FitwindowTableWorkspace='fitwinws',
                            PeakFunction="Gaussian",
                            BackgroundType="Linear",
コード例 #10
0
ファイル: createMask.py プロジェクト: rosswhitfield/corelli
from mantid.simpleapi import LoadEmptyInstrument, MaskBTP, SaveMask

LoadEmptyInstrument(InstrumentName='CORELLI', OutputWorkspace='CORELLI')

# Missing banks
MaskBTP('CORELLI', Bank='1-6,29,30,62,63-68,91')

# End of tubes
MaskBTP('CORELLI', Pixel='1-15,242-256')

# Beam center
MaskBTP('CORELLI', Bank='58', Tube='13-16', Pixel='80-130')
MaskBTP('CORELLI', Bank='59', Tube='1-4', Pixel='80-130')

SaveMask('CORELLI', 'corelli_mask.xml')