def test_save_file_check_contents(self):
        save_file(self.wksp, self.out_ascii)
        out_wksp = LoadAscii(self.out_ascii, Separator='Space')
        out_wksp = ConvertToHistogram(out_wksp)

        self.assertEqual(out_wksp.blocksize(),
                         self.wksp.blocksize())
        self.assertEqual(out_wksp.getNumberHistograms(),
                         self.wksp.getNumberHistograms())
        self.assertTrue(np.allclose(out_wksp.getAxis(0).extractValues(),
                                    self.wksp.getAxis(0).extractValues())
                        )
예제 #2
0
    def setUp(self):
        '''
        This file is the back-calculated spectrum of polyethylene moderator (ambient 300K)
        prior to the efficiency correction described in Eq (3) of:
          Mildner et al. "A cooled polyethylene moderator on a pulsed neutron source",
          Nucl. Instr. Meth. 152, 1978, doi:/10.1016/0029-554X(78)90043-5

        After the correction is applied, the workspace will replicated (b) in Fig. 2 of this article.

        Similar results are shown in Fig 1.a for "ambient (300K)" in:
          S. Howells, "On the choice of moderator for a liquids diffractometer on a pulsed neutron source",
          Nucl. Instr. Meth. Phys. Res. 223, 1984, doi:10.1016/0167-5087(84)90256-4
        '''
        LoadAscii(
            OutputWorkspace=self._input_wksp,
            Filename=
            "CalculateEfficiencyCorrection_milder_moderator_polyethlyene_300K.txt",
            Unit="Wavelength")
        ConvertToPointData(InputWorkspace=self._input_wksp,
                           OutputWorkspace=self._input_wksp)
예제 #3
0
    def runTest(self):
        prefix = 'mU6g7vP92_'  # pseudo-random string to prefix workspace names
        LoadAscii(Filename='SNAP_51984_peakcenters_tof.dat',
                  Separator='Tab',
                  Unit='Dimensionless', OutputWorkspace=prefix + 'peak_centers')
        LoadEmptyInstrument(InstrumentName='SNAP', OutputWorkspace=prefix + 'snap')

        with capture_logs(level='debug') as logs:
            AlignComponents(PeakCentersTofTable=prefix + 'peak_centers',
                            PeakPositions='1.3143, 1.3854,1.6967, 1.8587, 2.0781',
                            AdjustmentsTable=prefix + 'adjustments',
                            DisplacementsTable=prefix + 'displacements',
                            InputWorkspace=prefix + 'snap',
                            OutputWorkspace=prefix + 'snap_modified',
                            FitSourcePosition=False, FitSamplePosition=False,
                            ComponentList='Column1',
                            XPosition=False, YPosition=False, ZPosition=True,
                            AlphaRotation=False, BetaRotation=False, GammaRotation=False)
            assert 'First and last detectorID for Column1 are 0, 196607' in logs.getvalue()

        # Clean up workspaces
        temporary = ['peak_centers', 'snap', 'adjustments', 'displacements', 'snap_modified']
        DeleteWorkspaces([prefix + suffix for suffix in temporary])
예제 #4
0
    def load_gudrun_file(self, input_file, output_workspace, number_of_columns,
                         first_data_line):
        """
        Loads the gudrun file using the mantid LoadAscii algorithm
        :param input_file: The file to load
        :param output_workspace: The workspace to be the result of the load
        :param number_of_columns: The number of columns in the file being loaded
        :param first_data_line: The first line to expect data on
        :return: The outputWorkspace of the Load Algorithm
        """

        if number_of_columns % 2 == 0:
            print(number_of_columns)
            raise ValueError(
                'Incorrect data format: The input file {} must have an odd number '
                'of columns in the format X , Y , E, Y1, E1, Y2, E2, ...'.
                format(input_file))
        elif number_of_columns == 3:
            LoadAscii(Filename=input_file,
                      OutputWorkspace=output_workspace,
                      CommentIndicator='#')
        else:
            self.load_multi_column_file(input_file, output_workspace,
                                        first_data_line)
예제 #5
0
파일: model.py 프로젝트: MORTAL2000/mantid
 def focus_run(self, sample_paths, banks, plot_output, instrument, rb_num,
               spectrum_numbers):
     """
     Focus some data using the current calibration.
     :param sample_paths: The paths to the data to be focused.
     :param banks: The banks that should be focused.
     :param plot_output: True if the output should be plotted.
     :param instrument: The instrument that the data came from.
     :param rb_num: The experiment number, used to create directories. Can be None
     :param spectrum_numbers: The specific spectra that should be focused. Used instead of banks.
     """
     if not Ads.doesExist(vanadium_corrections.INTEGRATED_WORKSPACE_NAME
                          ) and not Ads.doesExist(
                              vanadium_corrections.CURVES_WORKSPACE_NAME):
         return
     integration_workspace = Ads.retrieve(
         vanadium_corrections.INTEGRATED_WORKSPACE_NAME)
     curves_workspace = Ads.retrieve(
         vanadium_corrections.CURVES_WORKSPACE_NAME)
     output_workspaces = []  # List of collated workspaces to plot.
     full_calib_path = get_setting(path_handling.INTERFACES_SETTINGS_GROUP,
                                   path_handling.ENGINEERING_PREFIX,
                                   "full_calibration")
     if full_calib_path is not None and path.exists(full_calib_path):
         full_calib_workspace = LoadAscii(full_calib_path,
                                          OutputWorkspace="det_pos",
                                          Separator="Tab")
     else:
         full_calib_workspace = None
     if spectrum_numbers is None:
         for sample_path in sample_paths:
             sample_workspace = path_handling.load_workspace(sample_path)
             run_no = path_handling.get_run_number_from_path(
                 sample_path, instrument)
             workspaces_for_run = []
             for name in banks:
                 output_workspace_name = str(
                     run_no) + "_" + FOCUSED_OUTPUT_WORKSPACE_NAME + str(
                         name)
                 self._run_focus(sample_workspace, output_workspace_name,
                                 integration_workspace, curves_workspace,
                                 name, full_calib_workspace)
                 workspaces_for_run.append(output_workspace_name)
                 # Save the output to the file system.
                 self._save_output(instrument, sample_path, name,
                                   output_workspace_name, rb_num)
             output_workspaces.append(workspaces_for_run)
     else:
         for sample_path in sample_paths:
             sample_workspace = path_handling.load_workspace(sample_path)
             run_no = path_handling.get_run_number_from_path(
                 sample_path, instrument)
             output_workspace_name = str(
                 run_no) + "_" + FOCUSED_OUTPUT_WORKSPACE_NAME + "cropped"
             self._run_focus(sample_workspace, output_workspace_name,
                             integration_workspace, curves_workspace, None,
                             full_calib_workspace, spectrum_numbers)
             output_workspaces.append([output_workspace_name])
             self._save_output(instrument, sample_path, "cropped",
                               output_workspace_name, rb_num)
     # Plot the output
     if plot_output:
         for ws_names in output_workspaces:
             self._plot_focused_workspaces(ws_names)
예제 #6
0
 def format_workspace(self, inputs):
     """ inputs is a dict mapping filepaths to output names """
     for path, output in inputs.items():
         workspace = LoadAscii(path, OutputWorkspace=output)
         workspace.getAxis(0).setUnit("Label").setLabel("Energy", "keV")
예제 #7
0
파일: model.py 프로젝트: MORTAL2000/mantid
    def create_new_calibration(self,
                               vanadium_path,
                               sample_path,
                               plot_output,
                               instrument,
                               rb_num=None,
                               bank=None,
                               spectrum_numbers=None):
        """
        Create a new calibration from a vanadium run and sample run
        :param vanadium_path: Path to vanadium data file.
        :param sample_path: Path to sample (CeO2) data file
        :param plot_output: Whether the output should be plotted.
        :param instrument: The instrument the data relates to.
        :param rb_num: The RB number for file creation.
        :param bank: Optional parameter to crop by bank
        :param spectrum_numbers: Optional parameter to crop using spectrum numbers.
        """
        van_integration, van_curves = vanadium_corrections.fetch_correction_workspaces(
            vanadium_path, instrument, rb_num=rb_num)
        sample_workspace = path_handling.load_workspace(sample_path)
        full_calib_path = get_setting(path_handling.INTERFACES_SETTINGS_GROUP,
                                      path_handling.ENGINEERING_PREFIX, "full_calibration")
        if full_calib_path is not None and path.exists(full_calib_path):
            full_calib = LoadAscii(full_calib_path, OutputWorkspace="det_pos", Separator="Tab")
            output = self.run_calibration(sample_workspace,
                                          van_integration,
                                          van_curves,
                                          bank,
                                          spectrum_numbers,
                                          full_calib_ws=full_calib)
        else:
            output = self.run_calibration(sample_workspace, van_integration, van_curves, bank,
                                          spectrum_numbers)
        if plot_output:
            self._plot_vanadium_curves()
            for i in range(len(output)):
                if spectrum_numbers:
                    bank_name = "cropped"
                elif bank is None:
                    bank_name = str(i + 1)
                else:
                    bank_name = bank
                difa = output[i].DIFA
                difc = output[i].DIFC
                tzero = output[i].TZERO
                self._generate_tof_fit_workspace(difa, difc, tzero, bank_name)
            if bank is None and spectrum_numbers is None:
                self._plot_tof_fit()
            elif spectrum_numbers is None:
                self._plot_tof_fit_single_bank_or_custom(bank)
            else:
                self._plot_tof_fit_single_bank_or_custom("cropped")
        difa = [i.DIFC for i in output]
        difc = [i.DIFC for i in output]
        tzero = [i.TZERO for i in output]

        params_table = []

        for i in range(len(difc)):
            params_table.append([i, difc[i], difa[i], tzero[i]])
        self.update_calibration_params_table(params_table)

        calib_dir = path.join(path_handling.get_output_path(), "Calibration", "")
        self.create_output_files(calib_dir, difa, difc, tzero, sample_path, vanadium_path, instrument,
                                 bank, spectrum_numbers)
        if rb_num:
            user_calib_dir = path.join(path_handling.get_output_path(), "User", rb_num,
                                       "Calibration", "")
            self.create_output_files(user_calib_dir, difa, difc, tzero, sample_path, vanadium_path,
                                     instrument, bank, spectrum_numbers)