Exemplo n.º 1
0
 def load_data(self, file_path):
     r"""
     # type: (unicode) -> WorkspaceGroup
     @brief Load one or more data sets according to the needs ot the instrument.
     @details This function assumes that when loading more than one data file, the files are congruent and their
     events will be added together.
     @param file_path: absolute path to one or more data files. If more than one, paths should be concatenated
     with the plus symbol '+'.
     @returns WorkspaceGroup with any number of cross-sections
     """
     fp_instance = FilePath(file_path)
     xs_list = list()
     temp_workspace_root_name = ''.join(
         random.sample(string.ascii_letters,
                       12))  # random string of 12 characters
     workspace_root_name = fp_instance.run_numbers(
         string_representation='short')
     for path in fp_instance.single_paths:
         is_legacy = path.endswith(".nxs")
         if is_legacy or not USE_SLOW_FLIPPER_LOG:
             _path_xs_list = api.MRFilterCrossSections(
                 Filename=path,
                 PolState=self.pol_state,
                 AnaState=self.ana_state,
                 PolVeto=self.pol_veto,
                 AnaVeto=self.ana_veto,
                 CrossSectionWorkspaces="%s_entry" %
                 temp_workspace_root_name)
             # Only keep good workspaces, and get rid of the rejected events
             path_xs_list = [
                 ws for ws in _path_xs_list if
                 not ws.getRun()['cross_section_id'].value == 'unfiltered'
             ]
         else:
             ws = api.LoadEventNexus(Filename=path,
                                     OutputWorkspace="raw_events")
             path_xs_list = self.dummy_filter_cross_sections(
                 ws, name_prefix=temp_workspace_root_name)
         if len(
                 xs_list
         ) == 0:  # initialize xs_list with the cross sections of the first data file
             xs_list = path_xs_list
             for ws in xs_list:  # replace the temporary names with the run number(s)
                 name_new = str(ws).replace(temp_workspace_root_name,
                                            workspace_root_name)
                 api.RenameWorkspace(str(ws), name_new)
         else:
             for i, ws in enumerate(xs_list):
                 api.Plus(LHSWorkspace=str(ws),
                          RHSWorkspace=str(path_xs_list[i]),
                          OutputWorkspace=str(ws))
     # Insert a log indicating which run numbers contributed to this cross-section
     for ws in xs_list:
         api.AddSampleLog(
             Workspace=str(ws),
             LogName='run_numbers',
             LogText=fp_instance.run_numbers(string_representation='short'),
             LogType='String')
     return xs_list
Exemplo n.º 2
0
 def test_run_numbers(self):
     assert_equal_arrays(
         FilePath(u'/SNS/REF_M_3.nxs+/SNS/REF_M_1.nxs').run_numbers(),
         [1, 3])
     file_path = FilePath(
         u'/SNS/REF_M_3.nxs+/SNS/REF_M_1.nxs+/SNS/REF_M_6.nxs+/SNS/REF_M_2.nxs'
     )
     assert file_path.run_numbers(string_representation='long') == '1+2+3+6'
     assert file_path.run_numbers(string_representation='short') == '1:3+6'