コード例 #1
0
    def validateWorkspaces(self, valNames=None, mismatchName=None):
        '''
        Performs a check that two workspaces are equal using the CompareWorkspaces
        algorithm. Loads one workspace from a nexus file if appropriate.
        Returns true if: the workspaces match
                      OR the validate method has not been overridden.
        Returns false if the workspace do not match. The reason will be in the log.
        '''
        if valNames is None:
            valNames = self.validate()

        checker = AlgorithmManager.create("CompareWorkspaces")
        checker.setLogging(True)
        checker.setPropertyValue("Workspace1", valNames[0])
        checker.setPropertyValue("Workspace2", valNames[1])
        checker.setProperty("Tolerance", float(self.tolerance))
        if hasattr(self, 'tolerance_is_reller') and self.tolerance_is_reller:
            checker.setProperty("ToleranceRelerr", True)
        for d in self.disableChecking:
            checker.setProperty("Check"+d, False)
        checker.execute()
        if not checker.getProperty("Result").value:
            print(self.__class__.__name__)
            if mismatchName:
                SaveNexus(InputWorkspace=valNames[0],
                          Filename=self.__class__.__name__+mismatchName+'-mismatch.nxs')
            else:
                SaveNexus(InputWorkspace=valNames[0],
                          Filename=self.__class__.__name__+'-mismatch.nxs')
            return False

        return True
コード例 #2
0
ファイル: model.py プロジェクト: MORTAL2000/mantid
 def _save_focused_output_files_as_nexus(self, instrument, sample_path,
                                         bank, sample_workspace, rb_num):
     nexus_output_path = path.join(
         path_handling.get_output_path(), "Focus",
         self._generate_output_file_name(instrument, sample_path, bank,
                                         ".nxs"))
     SaveNexus(InputWorkspace=sample_workspace, Filename=nexus_output_path)
     if rb_num:
         nexus_output_path = path.join(
             path_handling.get_output_path(), "User", rb_num, "Focus",
             self._generate_output_file_name(instrument, sample_path, bank,
                                             ".nxs"))
         SaveNexus(InputWorkspace=sample_workspace,
                   Filename=nexus_output_path)
コード例 #3
0
def _save_correction_files(integration_workspace, integration_path, curves_workspace, curves_path):
    """
    Attempt to save the created workspaces to the filesystem.
    :param integration_workspace: The workspace for the vanadium integration.
    :param integration_path: The path to save the integration workspace to.
    :param curves_workspace: The workspace for the vanadium curves.
    :param curves_path: The path to save the curves workspace to.
    """
    try:
        SaveNexus(InputWorkspace=integration_workspace, Filename=integration_path)
        SaveNexus(InputWorkspace=curves_workspace, Filename=curves_path)
    except RuntimeError as e:  # If the files cannot be saved, continue with the execution of the algorithm anyway.
        logger.error(
            "Vanadium Correction files could not be saved to the filesystem. Description: " + str(e))
        return
コード例 #4
0
def run_reduction(input_workspace: EventWorkspace, workspace_name: str,
                  settings_file: str, output_dir: str):  # Run reduction
    # Get the angle
    angle = get_angle(input_workspace)
    params = find_angle_parameters_from_settings_json(settings_file, angle)

    alg = AlgorithmManager.create("ReflectometryISISLoadAndProcess")
    properties = {
        "InputRunList": workspace_name,
        "FirstTransmissionRunList": params.first_transmission_run_list,
        "SecondTransmissionRunList": params.second_transmission_run_list,
        "ThetaIn": angle,
        "DetectorCorrectionType": params.detector_correction_type,
        "MonitorBackgroundWavelengthMin":
        params.monitor_background_wavelength_min,
        "MonitorBackgroundWavelengthMax":
        params.monitor_background_wavelength_max,
        "MonitorIntegrationWavelengthMin":
        params.monitor_integration_wavelength_min,
        "MonitorIntegrationWavelengthMax":
        params.monitor_integration_wavelength_max,
        "WavelengthMin": params.wavelength_min,
        "WavelengthMax": params.wavelength_max,
        "I0MonitorIndex": params.i_zero_monitor_index,
        "AnalysisMode": params.analysis_mode,
        "StartOverlap": params.start_overlap,
        "EndOverlap": params.end_overlap,
        "ScaleRHSWorkspace": params.scale_rhs_workspace,
        "TransmissionProcessingInstructions":
        params.transmission_processing_instructions,
        "ProcessingInstructions": params.processing_instructions
    }
    alg.setProperties(properties)
    alg.execute()

    # Save reduced data as Nexus files
    OutputWorkspace = alg.getPropertyValue("OutputWorkspace")
    OutputWorkspaceBinned = alg.getPropertyValue("OutputWorkspaceBinned")

    SaveNexus(OutputWorkspace,
              os.path.join(output_dir, OutputWorkspace + ".nxs"))
    SaveNexus(OutputWorkspaceBinned,
              os.path.join(output_dir, OutputWorkspaceBinned + ".nxs"))

    # Save a copy of the .json settings file
    copy(settings_file, output_dir)

    return OutputWorkspaceBinned
コード例 #5
0
def get_vanadium(run_number, npy=False):
    """
    Pre-process vanadium only the first time it's used
    """
    vanadiums = sorted(int(n.replace('HB2C_', '').replace('.nxs.h5', ''))
                       for n in os.listdir('/HFIR/HB2C/shared/Vanadium')
                       if 'HB2C_' in n and '.nxs.h5' in n)
    van_run_number = vanadiums[np.searchsorted(vanadiums, run_number, side='right')-1]
    upstream_van_file = '/HFIR/HB2C/shared/Vanadium/HB2C_{}.nxs.h5'.format(van_run_number)
    if npy:
        npy_van_file = '/HFIR/HB2C/shared/autoreduce/vanadium/HB2C_{}.npy'.format(van_run_number)
        if os.path.exists(npy_van_file):
            return np.load(npy_van_file)
        else:
            with h5py.File(upstream_van_file, 'r') as f:
                bc = np.zeros((512*480*8))
                for b in range(8):
                    bc += np.bincount(f['/entry/bank'+str(b+1)+'_events/event_id'].value,
                                      minlength=512*480*8)
                bc = bc.reshape((480*8, 512))
                bc = (bc[::4, ::4] + bc[1::4, ::4] + bc[2::4, ::4] + bc[3::4, ::4]
                      + bc[::4, 1::4] + bc[1::4, 1::4] + bc[2::4, 1::4] + bc[3::4, 1::4]
                      + bc[::4, 2::4] + bc[1::4, 2::4] + bc[2::4, 2::4] + bc[3::4, 2::4]
                      + bc[::4, 3::4] + bc[1::4, 3::4] + bc[2::4, 3::4] + bc[3::4, 3::4])
            np.save(npy_van_file, bc)
            return bc
    else:
        from mantid.simpleapi import LoadWAND, LoadNexus, SaveNexus
        nxs_van_file = '/HFIR/HB2C/shared/autoreduce/vanadium/HB2C_{}.nxs'.format(van_run_number)
        if os.path.exists(nxs_van_file):
            ws = LoadNexus(nxs_van_file)
        else:
            ws = LoadWAND(upstream_van_file, Grouping='4x4')
            SaveNexus(ws, nxs_van_file)
        return ws
コード例 #6
0
 def runTest(self):
     try:
         input_file = tempfile.gettempdir() + '/__refl_flood_cor_temp.nxs'
         x = [0, 100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000]
         y = [1, 9, 8, 3, 1, 1]
         ws = CreateWorkspace(x, y, NSpec=6)
         SaveNexus(ws, input_file)
         self.assertRaises(RuntimeError, CreateFloodWorkspace, input_file, Background='Quadratic', OutputWorkspace=self.flood_ws_name)
     finally:
         os.unlink(input_file)
コード例 #7
0
ファイル: model.py プロジェクト: stuartcampbell/mantid
 def _save_focused_output_files_as_nexus(self, instrument, sample_run,
                                         van_run, bank, sample_workspace,
                                         rb_num, unit):
     file_name = self._generate_output_file_name(instrument, sample_run,
                                                 van_run, bank, unit,
                                                 ".nxs")
     nexus_output_path = path.join(output_settings.get_output_path(),
                                   "Focus", file_name)
     AddSampleLog(Workspace=sample_workspace,
                  LogName="Vanadium Run",
                  LogText=van_run)
     SaveNexus(InputWorkspace=sample_workspace, Filename=nexus_output_path)
     if rb_num:
         nexus_output_path = path.join(output_settings.get_output_path(),
                                       "User", rb_num, "Focus", file_name)
         SaveNexus(InputWorkspace=sample_workspace,
                   Filename=nexus_output_path)
     if unit == "TOF":
         self._last_focused_files.append(nexus_output_path)
コード例 #8
0
 def runTest(self):
     try:
         input_file = tempfile.gettempdir() + '/__refl_flood_cor_temp.nxs'
         x = [0, 5, 6, 10] * 6
         y = [1, 2, 1] + [9, 3, 9] + [8, 0, 8] + [3, 5, 3] + [14, 6, 14] + [15, 7, 15]
         ws = CreateWorkspace(x, y, NSpec=6)
         SaveNexus(ws, input_file)
         self.assertRaises(RuntimeError, CreateFloodWorkspace, input_file,
                           CentralPixelSpectrum=3, RangeLower=3, RangeUpper=7, OutputWorkspace=self.flood_ws_name)
     finally:
         os.unlink(input_file)
コード例 #9
0
 def _save_t0(self, run_number, name='_t_ws'):
     """
     Create temporary events file with delayed emission time from
     moderator removed
     :param run: run number
     :param name: name for the output workspace
     :return: file name of event file with events treated with algorithm
     ModeratorTzeroLinear.
     """
     ws = LoadEventNexus(Filename=self._makeRunFile(run_number),
                         NXentryName='entry-diff',
                         OutputWorkspace=name)
     ws = ModeratorTzeroLinear(InputWorkspace=ws.name(),
                               OutputWorkspace=ws.name())
     file_name = self._spawn_tempnexus()
     SaveNexus(ws, file_name)
     return file_name
コード例 #10
0
 def runTest(self):
     try:
         input_file = tempfile.gettempdir() + '/__refl_flood_cor_temp.nxs'
         x = [0, 100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000]
         y = [1, 9, 8, 3, 14, 15]
         ws = CreateWorkspace(x, y, NSpec=6)
         SaveNexus(ws, input_file)
         CreateFloodWorkspace(input_file, CentralPixelSpectrum=3, StartSpectrum=2, EndSpectrum=4, OutputWorkspace=self.flood_ws_name)
         out = mtd[self.flood_ws_name]
         self.assertAlmostEqual(out.readY(0)[0], 1.0)
         self.assertAlmostEqual(out.readY(1)[0], 9.0/8)
         self.assertAlmostEqual(out.readY(2)[0], 1.0)
         self.assertAlmostEqual(out.readY(3)[0], 3.0/8)
         self.assertAlmostEqual(out.readY(4)[0], 1.0)
         self.assertAlmostEqual(out.readY(5)[0], 1.0)
     finally:
         os.unlink(input_file)
コード例 #11
0
 def runTest(self):
     try:
         input_file = tempfile.gettempdir() + '/__refl_flood_cor_temp.nxs'
         x = [0, 5, 6, 10] * 6
         y = [1, 2, 1] + [9, 3, 9] + [8, 4, 8] + [3, 5, 3] + [14, 6, 14] + [15, 7, 15]
         ws = CreateWorkspace(x, y, NSpec=6)
         SaveNexus(ws, input_file)
         CreateFloodWorkspace(input_file, CentralPixelSpectrum=3, RangeLower=3, RangeUpper=7, OutputWorkspace=self.flood_ws_name)
         out = mtd[self.flood_ws_name]
         self.assertAlmostEqual(out.readY(0)[0], 2.0/4)
         self.assertAlmostEqual(out.readY(1)[0], 3.0/4)
         self.assertAlmostEqual(out.readY(2)[0], 1.0)
         self.assertAlmostEqual(out.readY(3)[0], 5.0/4)
         self.assertAlmostEqual(out.readY(4)[0], 6.0/4)
         self.assertAlmostEqual(out.readY(5)[0], 7.0/4)
     finally:
         os.unlink(input_file)
コード例 #12
0
 def _save_t0(self, run_number, name='_t_ws'):
     """
     Create temporary events file with delayed emission time from
     moderator removed
     :param run: run number
     :param name: name for the output workspace
     :return: file name of event file with events treated with algorithm
     ModeratorTzeroLinear.
     """
     ws = self._load_single_run(run_number, name)
     ws = ModeratorTzeroLinear(InputWorkspace=ws.name(),
                               Gradient=self._tzero['gradient'],
                               Intercept=self._tzero['intercept'],
                               OutputWorkspace=ws.name())
     # Correct old DAS shift of fast neutrons. See GitHub issue 23855
     if self._das_version == VDAS.v1900_2018:
         ws = self.add_previous_pulse(ws)
     file_name = self._spawn_tempnexus()
     SaveNexus(ws, file_name)
     return file_name
コード例 #13
0
ファイル: model.py プロジェクト: gemmaguest/mantid
 def save_pdcal_output_file(ws_name_suffix, bank_name):
     file_path = calibration_dir + EnggUtils.generate_output_file_name(
         ceria_path, instrument, bank=bank_name, ext=".nxs")
     ws_name = "engggui_calibration_" + ws_name_suffix
     SaveNexus(InputWorkspace=ws_name, Filename=file_path)
コード例 #14
0
ファイル: convert.py プロジェクト: rosswhitfield/corelli
from mantid.simpleapi import SaveNexus
import tube

tube.readCalibrationFile(
    'CalibTable',
    '/SNS/users/rwp/corelli/tube_calibration/calib_quad_new3.txt')
SaveNexus('CalibTable',
          '/SNS/users/rwp/corelli/tube_calibration/calibtable.nxs')
コード例 #15
0
 def _saveNexusFiles(self):
     for wsName in self.wsNames:
         outfile = os.path.join(self.outFolder, wsName + ".nxs")
         print "Saving ", outfile
         SaveNexus(wsName, outfile)
コード例 #16
0
from mantid.simpleapi import Load, mtd, CloneWorkspace, Integration, SaveNexus, RemoveLogs
import numpy as np

ws_list = np.genfromtxt('/SNS/users/rwp/corelli/tube_calibration/list',
                        delimiter=',',
                        dtype=[('runs', '|S11'), ('banks', '5i8'),
                               ('height', 'i8')])

for run, banks, height in ws_list:
    banks = np.asarray(banks)
    banks = banks[np.nonzero(banks)]
    bank_names = ','.join('bank' + str(b) for b in banks)
    data = Load(Filename='CORELLI_' + run,
                BankName=bank_names,
                SingleBankPixelsOnly=False)
    pc = sum(data.getRun()['proton_charge'].value)
    data = Integration(data)
    data /= pc
    RemoveLogs(data)
    if 'accum' in mtd:
        accum += data
    else:
        accum = CloneWorkspace(data)

SaveNexus(accum, '/SNS/users/rwp/corelli/tube_calibration/all_banks.nxs')