Example #1
0
    def test_that_subtracts_correct_added_file_type(self):
        # Arrange
        use_time = False
        use_mean = False
        use_mon = False
        mon_number = None

        # Create added workspace and have it saved out
        import SANSadd2
        SANSadd2.add_runs(('SANS2D00028827_removed_spectra.nxs','SANS2D00028797_removed_spectra.nxs'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = False)
        run_number = r'SANS2D00028797_removed_spectra-add.nxs'
        settings = []
        setting = self._get_dark_run_settings_object(run_number, use_time, use_mean, use_mon, mon_number)
        settings.append(setting)

        # Act + Assert
        is_event_ws = True
        scatter_workspace, monitor_workspace = self._do_test_valid(settings, is_event_ws, run_number)
        expected_num_spectr_ws = 20 - 9 + 1
        self.assertEqual(scatter_workspace.getNumberHistograms(),  expected_num_spectr_ws, "Should have 8 spectra")

        # Since in this test we use the same file for the scatterer and the dark run, we expect
        # that the detectors are 0. This is because we subtract bin by bin when using UAMP
        y = scatter_workspace.extractY()
        self.assertFalse(np.greater(y, 1e-14).any(), "Detector entries should all be 0")
        # The monitors should not be affected, but we only have data in ws_index 0-3
        for i in [0,3]:
            self.assertTrue(monitor_workspace.dataY(i).any(), "Monitor entries should not all be 0")

        os.remove(os.path.join(config['defaultsave.directory'],run_number))
Example #2
0
    def runTest(self):
        UseCompatibilityMode()
        SANS2DTUBES()
        MaskFile('USER_SANS2D_143ZC_2p4_4m_M4_Knowles_12mm.txt')
        SetDetectorOffsets('REAR', -16.0, 58.0, 0.0, 0.0, 0.0, 0.0)
        SetDetectorOffsets('FRONT', -44.0, -20.0, 47.0, 0.0, 1.0, 1.0)
        Gravity(False)
        Set1D()

        # add files (SAMPLE and CAN)
        SANSadd2.add_runs(('28827', '28797'),
                          'SANS2DTUBES',
                          '.nxs',
                          rawTypes=('.add', '.raw', '.s*'),
                          lowMem=False,
                          saveAsEvent=True,
                          isOverlay=False)
        SANSadd2.add_runs(('28823', '28793'),
                          'SANS2DTUBES',
                          '.nxs',
                          rawTypes=('.add', '.raw', '.s*'),
                          lowMem=False,
                          saveAsEvent=True,
                          isOverlay=False)

        AssignSample(r'SANS2D00028797-add.nxs', reload=True)
        AssignCan(r'SANS2D00028793-add.nxs', reload=True)
        TransmissionSample(r'SANS2D00028808.nxs', r'SANS2D00028784.nxs')
        TransmissionCan(r'SANS2D00028823.nxs', r'SANS2D00028784.nxs')

        WavRangeReduction()
Example #3
0
    def runTest(self):
        #here we are testing the LOQ setup
        ici.LOQ()
        #rear detector
        ici.Detector("main-detector-bank")
        #test batch mode, although only the analysis from the last line is checked
        # Find the file , this should really be in the BatchReduce reduction step

        f = open(self.csv_file, 'w')
        print >> f, "sample_sans,99630-add,output_as, %s" % self.output_file
        f.close()
        runnum = '99630'
        sansadd.add_runs((runnum, runnum), 'LOQ', '.RAW')

        ici.Set1D()
        ici.MaskFile('MASK.094AA')
        batch.BatchReduce(self.csv_file,
                          'nxs',
                          plotresults=False,
                          saveAlgs={'SaveNexus': 'nxs'})

        print ' reduction without'

        ici._refresh_singleton()

        ici.LOQ()
        ici.Detector("main-detector-bank")
        ici.Set1D()
        ici.MaskFile('MASK.094AA')
        LOQ99630 = Load(runnum)
        LOQ99630 += LOQ99630
        ici.AssignSample(LOQ99630, reload=False)
        self.result = ici.WavRangeReduction()
Example #4
0
    def runTest(self):
    #here we are testing the LOQ setup
        ici.LOQ()
    #rear detector
        ici.Detector("main-detector-bank")
    #test batch mode, although only the analysis from the last line is checked
    # Find the file , this should really be in the BatchReduce reduction step

        f = open(self.csv_file,'w')
        print("sample_sans,99630-add,output_as, %s"%self.output_file, file=f)
        f.close()
        runnum = '99630'
        sansadd.add_runs((runnum, runnum),'LOQ','.RAW')

        ici.Set1D()
        ici.MaskFile('MASK.094AA')
        batch.BatchReduce(self.csv_file, 'nxs', plotresults=False, saveAlgs={'SaveNexus':'nxs'})

        print(' reduction without')

        ici._refresh_singleton()

        ici.LOQ()
        ici.Detector("main-detector-bank")
        ici.Set1D()
        ici.MaskFile('MASK.094AA')
        LOQ99630 = Load(runnum)
        LOQ99630 += LOQ99630
        ici.AssignSample(LOQ99630, reload=False)
        self.result = ici.WavRangeReduction()
    def test_that_subtracts_correct_added_file_type(self):
        # Arrange
        use_time = False
        use_mean = False
        use_mon = False
        mon_number = None

        # Create added workspace and have it saved out
        import SANSadd2
        SANSadd2.add_runs(('SANS2D00028827_removed_spectra.nxs','SANS2D00028797_removed_spectra.nxs'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = False)
        run_number = r'SANS2D00028797_removed_spectra-add.nxs'
        settings = []
        setting = self._get_dark_run_settings_object(run_number, use_time, use_mean, use_mon, mon_number)
        settings.append(setting)

        # Act + Assert
        is_event_ws = True
        scatter_workspace, monitor_workspace = self._do_test_valid(settings, is_event_ws, run_number)
        expected_num_spectr_ws = 20 - 9 + 1
        self.assertTrue(scatter_workspace.getNumberHistograms() == expected_num_spectr_ws, "Should have 8 spectra")

        # Since in this test we use the same file for the scatterer and the dark run, we expect
        # that the detectors are 0. This is because we subtract bin by bin when using UAMP
        all_entries_zero = lambda ws, index : all([0.0 == element for element in ws.dataY(index)])

        for i in range(0, scatter_workspace.getNumberHistograms()):
            self.assertTrue(all_entries_zero(scatter_workspace, i), "Detector entries should all be 0")

        # The monitors should not be affected, but we only have data in ws_index 0-3
        for i in [0,3]:
            self.assertFalse(all_entries_zero(monitor_workspace, i), "Monitor entries should not all be 0")

        os.remove(os.path.join(config['defaultsave.directory'],run_number))
Example #6
0
    def runTest(self):
        self.initialization()

        self.checkFirstPart()

        # add files (SAMPLE and CAN)
        import SANSadd2
        SANSadd2.add_runs(('22048','22048'),'SANS2D', '.nxs', rawTypes=('.add','.raw','.s*'), lowMem=False)
        SANSadd2.add_runs(('22023','22023'),'SANS2D', '.nxs', rawTypes=('.add','.raw','.s*'), lowMem=False)

        # load values:
        i.SetCentre('155.45','-169.6','rear')
        i.SetCentre('155.45','-169.6','front')
        SCATTER_SAMPLE, logvalues = i.AssignSample(r'SANS2D00022048-add.nxs', reload = True, period = 1)
        SCATTER_SAMPLE, logvalues = i.AssignCan(r'SANS2D00022023-add.nxs', reload = True, period = 1)
        i.TransmissionSample(r'SANS2D00022041.nxs', r'SANS2D00022024.nxs', period_t=1, period_d=1)
        i.TransmissionCan(r'SANS2D00022024.nxs', r'SANS2D00022024.nxs', period_t=1, period_d=1)

        self.checkAfterLoad()

        self.applyGUISettings()

        self.applySampleSettings()
        _user_settings_copy = copy.deepcopy(i.ReductionSingleton().user_settings)

        reduced = i.WavRangeReduction(full_trans_wav=False, resetSetup=False)
        RenameWorkspace(reduced, OutputWorkspace='trans_test_rear')

        self.checkFittingSettings()
        self.cleanReduction(_user_settings_copy)
Example #7
0
    def runTest(self):

        i.SANS2DTUBES()
        i.MaskFile('USER_SANS2D_143ZC_2p4_4m_M4_Knowles_12mm.txt')
        i.SetDetectorOffsets('REAR', -16.0, 58.0, 0.0, 0.0, 0.0, 0.0)
        i.SetDetectorOffsets('FRONT', -44.0, -20.0, 47.0, 0.0, 1.0, 1.0)
        i.Gravity(False)
        i.Set1D()

        # add files (SAMPLE and CAN)
        time_shifts=[1]
        import SANSadd2
        SANSadd2.add_runs(('28827','28797'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = True, time_shifts = time_shifts)
        SANSadd2.add_runs(('28823','28793'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = True, time_shifts = time_shifts)

        i.AssignSample(r'SANS2D00028797-add.nxs', reload = True)
        i.AssignCan(r'SANS2D00028793-add.nxs', reload = True)
        i.TransmissionSample(r'SANS2D00028808.nxs', r'SANS2D00028784.nxs')
        i.TransmissionCan(r'SANS2D00028823.nxs', r'SANS2D00028784.nxs')

        i.WavRangeReduction()
    def runTest(self):

        i.SANS2DTUBES()
        i.MaskFile('USER_SANS2D_143ZC_2p4_4m_M4_Knowles_12mm.txt')
        i.SetDetectorOffsets('REAR', -16.0, 58.0, 0.0, 0.0, 0.0, 0.0)
        i.SetDetectorOffsets('FRONT', -44.0, -20.0, 47.0, 0.0, 1.0, 1.0)
        i.Gravity(False)
        i.Set1D()

        # add files (SAMPLE and CAN)
        time_shifts=[1]
        import SANSadd2
        SANSadd2.add_runs(('28827','28797'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = True, time_shifts = time_shifts)
        SANSadd2.add_runs(('28823','28793'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = True, time_shifts = time_shifts)

        i.AssignSample(r'SANS2D00028797-add.nxs', reload = True)
        i.AssignCan(r'SANS2D00028793-add.nxs', reload = True)
        i.TransmissionSample(r'SANS2D00028808.nxs', r'SANS2D00028784.nxs')
        i.TransmissionCan(r'SANS2D00028823.nxs', r'SANS2D00028784.nxs')

        i.WavRangeReduction()
Example #9
0
    def test_that_subtracts_correct_added_file_type_when_only_monitor_subtracted(
            self):
        # Arrange
        use_time = False
        use_mean = False
        use_mon = True
        mon_number = [
            2
        ]  # We are selecting detector ID 2 this corresponds to workspace index 1
        ws_index = [1]

        # Create added workspace and have it saved out
        import SANSadd2
        SANSadd2.add_runs(('SANS2D00028827_removed_spectra.nxs',
                           'SANS2D00028797_removed_spectra.nxs'),
                          'SANS2DTUBES',
                          '.nxs',
                          rawTypes=('.add', '.raw', '.s*'),
                          lowMem=False,
                          saveAsEvent=True,
                          isOverlay=False)
        run_number = r'SANS2D00028797_removed_spectra-add.nxs'
        settings = []
        setting = self._get_dark_run_settings_object(run_number, use_time,
                                                     use_mean, use_mon,
                                                     mon_number)
        settings.append(setting)

        # Act + Assert
        is_event_ws = True
        scatter_workspace, monitor_workspace = self._do_test_valid(
            settings, is_event_ws, run_number)

        expected_num_spectr_ws = 20 - 9 + 1  # Total number of spectra in the original workspace from 9 to 245798
        self.assertTrue(
            scatter_workspace.getNumberHistograms() == expected_num_spectr_ws,
            "Should have 8 spectra")

        # Since in this test we use the same file for the scatterer and the dark run, we expect
        # that the detectors are 0. This is because we subtract bin by bin when using UAMP

        # Some spectra might be zero, so we have to check that there is something which is not zero
        self.assertTrue(scatter_workspace.extractY().any(),
                        "There should be some detectors which are not zero")

        # The monitors should not be affected, but we only have data in ws_index 0-3
        for i in [0, 2, 3]:
            self.assertTrue(
                monitor_workspace.dataY(i).any(),
                "Monitor1, Monitor3, Monitor4 entries should not all be 0")

        # Monitor 2 (workspace index 1 should be 0
        for i in ws_index:
            y = monitor_workspace.dataY(i)
            self.assertFalse(
                np.greater(y, 1e-14).any(),
                "Monitor2 entries should  all be 0")

        os.remove(os.path.join(config['defaultsave.directory'], run_number))
 def runTest(self):
     # created after issue reported in #8156
     ws = Load('LOQ54432')
     self.assertTrue('Data/SystemTest/LOQ/LOQ54432.raw' in unixLikePathFromWorkspace(ws))
     ws = Load('LOQ99618.RAW')
     self.assertTrue('Data/SystemTest/LOQ/LOQ99618.RAW' in unixLikePathFromWorkspace(ws))
     add.add_runs(('LOQ54432','LOQ54432'),'LOQ','.raw')
     ws = Load('LOQ54432-add')
     file_path =  unixLikePathFromWorkspace(ws)
     logger.information("File Path from -add: "+str(file_path))
     file_path = file_path.replace('-ADD','-add') # MAC seems to report that the file is LOQ54432-ADD.nxs
     self.assertTrue('LOQ54432-add' in file_path)
     os.remove(file_path)
Example #11
0
 def runTest(self):
     # created after issue reported in #8156
     ws = Load("LOQ54432")
     self.assertTrue("Data/SystemTest/LOQ/LOQ54432.raw" in unixLikePathFromWorkspace(ws))
     ws = Load("LOQ99618.RAW")
     self.assertTrue("Data/SystemTest/LOQ/LOQ99618.RAW" in unixLikePathFromWorkspace(ws))
     add.add_runs(("LOQ54432", "LOQ54432"), "LOQ", ".raw")
     ws = Load("LOQ54432-add")
     file_path = unixLikePathFromWorkspace(ws)
     logger.information("File Path from -add: " + str(file_path))
     file_path = file_path.replace("-ADD", "-add")  # MAC seems to report that the file is LOQ54432-ADD.nxs
     self.assertTrue("LOQ54432-add" in file_path)
     os.remove(file_path)
Example #12
0
 def runTest(self):
     # created after issue reported in #8156
     ws = Load('LOQ54432')
     self.assertTrue('LOQ/LOQ54432.raw' in unixLikePathFromWorkspace(ws))
     ws = Load('LOQ99618.RAW')
     self.assertTrue('LOQ/LOQ99618.RAW' in unixLikePathFromWorkspace(ws))
     add.add_runs(('LOQ54432','LOQ54432'),'LOQ','.raw')
     ws = Load('LOQ54432-add')
     file_path =  unixLikePathFromWorkspace(ws)
     logger.information("File Path from -add: "+str(file_path))
     file_path = file_path.replace('-ADD','-add') # MAC seems to report that the file is LOQ54432-ADD.nxs
     self.assertTrue('LOQ54432-add' in file_path)
     os.remove(file_path)
    def runTest(self):
        self.initialization()

        self.checkFirstPart()

        # add files (SAMPLE and CAN)
        import SANSadd2
        SANSadd2.add_runs(('22048', '22048'),
                          'SANS2D',
                          '.nxs',
                          rawTypes=('.add', '.raw', '.s*'),
                          lowMem=False)
        SANSadd2.add_runs(('22023', '22023'),
                          'SANS2D',
                          '.nxs',
                          rawTypes=('.add', '.raw', '.s*'),
                          lowMem=False)

        # load values:
        i.SetCentre('155.45', '-169.6', 'rear')
        i.SetCentre('155.45', '-169.6', 'front')
        i.AssignSample(r'SANS2D00022048-add.nxs', reload=True, period=1)
        i.AssignCan(r'SANS2D00022023-add.nxs', reload=True, period=1)
        i.TransmissionSample(r'SANS2D00022041.nxs',
                             r'SANS2D00022024.nxs',
                             period_t=1,
                             period_d=1)
        i.TransmissionCan(r'SANS2D00022024.nxs',
                          r'SANS2D00022024.nxs',
                          period_t=1,
                          period_d=1)

        self.checkAfterLoad()

        self.applyGUISettings()

        self.applySampleSettings()
        _user_settings_copy = copy.deepcopy(
            i.ReductionSingleton().user_settings)

        reduced = i.WavRangeReduction(full_trans_wav=False, resetSetup=False)
        RenameWorkspace(reduced, OutputWorkspace='trans_test_rear')

        self.checkFittingSettings()
        self.cleanReduction(_user_settings_copy)
    def test_that_subtracts_correct_added_file_type_when_only_monitor_subtracted(self):
        # Arrange
        use_time = False
        use_mean = False
        use_mon = True
        mon_number = [2] # We are selecting detector ID 2 this corresponds to workspace index 1
        ws_index = [1]

        # Create added workspace and have it saved out
        import SANSadd2
        SANSadd2.add_runs(('SANS2D00028827_removed_spectra.nxs','SANS2D00028797_removed_spectra.nxs'),'SANS2DTUBES', '.nxs',
                          rawTypes=('.add','.raw','.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay = False)
        run_number = r'SANS2D00028797_removed_spectra-add.nxs'
        settings = []
        setting = self._get_dark_run_settings_object(run_number, use_time, use_mean, use_mon, mon_number)
        settings.append(setting)

        # Act + Assert
        is_event_ws = True
        scatter_workspace, monitor_workspace = self._do_test_valid(settings, is_event_ws, run_number)

        expected_num_spectr_ws = 20 - 9 + 1 # Total number of spectra in the original workspace from 9 to 245798
        self.assertTrue(scatter_workspace.getNumberHistograms() == expected_num_spectr_ws, "Should have 8 spectra")

        # Since in this test we use the same file for the scatterer and the dark run, we expect
        # that the detectors are 0. This is because we subtract bin by bin when using UAMP
        all_entries_zero = lambda ws, index : all([0.0 == element for element in ws.dataY(index)])

        # Some spectra might be zero, so we have to check that there is something which is not zero
        all_detectors_zero = True
        for i in range(0, scatter_workspace.getNumberHistograms()):
            all_detectors_zero = all_detectors_zero & all_entries_zero(scatter_workspace, i)
        self.assertFalse(all_detectors_zero, "There should be some detectors which are not zero")

        # The monitors should not be affected, but we only have data in ws_index 0-3
        for i in [0,2,3]:
            self.assertFalse(all_entries_zero(monitor_workspace, i), "Monitor1, Monitor3, Monitor4 entries should not all be 0")

        # Monitor 2 (workspace index 1 should be 0
        for i in ws_index:
            self.assertTrue(all_entries_zero(monitor_workspace, i), "Monitor2 entries should  all be 0")

        os.remove(os.path.join(config['defaultsave.directory'],run_number))
Example #15
0
    def run(self, run_selection, settings, base_file_name):
        run_selection = self._run_selection_as_path_list(run_selection)
        binning = self._bin_settings_or_monitors(settings)
        additional_time_shifts = self._time_shifts_or_empty_string(settings)
        overlay_event_workspaces = self._is_overlay_event_workspaces_enabled(settings)
        save_as_event = self._should_save_as_event_workspaces(settings)

        file_name = base_file_name + '.nxs'
        monitors_file_name = base_file_name + '_monitors.nxs'

        SANSadd2.add_runs(
            tuple(run_selection),
            settings.instrument(),
            lowMem=True,
            binning=binning,
            isOverlay=overlay_event_workspaces,
            saveAsEvent=save_as_event,
            time_shifts=additional_time_shifts,
            outFile=file_name,
            outFile_monitors=monitors_file_name)
Example #16
0
    def run(self, run_selection, settings, base_file_name):
        run_selection = self._run_selection_as_path_list(run_selection)
        binning = self._bin_settings_or_monitors(settings)
        additional_time_shifts = self._time_shifts_or_empty_string(settings)
        overlay_event_workspaces = self._is_overlay_event_workspaces_enabled(
            settings)
        save_as_event = self._should_save_as_event_workspaces(settings)

        file_name = base_file_name + '.nxs'
        monitors_file_name = base_file_name + '_monitors.nxs'

        SANSadd2.add_runs(tuple(run_selection),
                          settings.instrument(),
                          lowMem=True,
                          binning=binning,
                          isOverlay=overlay_event_workspaces,
                          saveAsEvent=save_as_event,
                          time_shifts=additional_time_shifts,
                          outFile=file_name,
                          outFile_monitors=monitors_file_name)
    def runTest(self):
        UseCompatibilityMode()
        SANS2DTUBES()
        MaskFile('USER_SANS2D_143ZC_2p4_4m_M4_Knowles_12mm.txt')
        SetDetectorOffsets('REAR', -16.0, 58.0, 0.0, 0.0, 0.0, 0.0)
        SetDetectorOffsets('FRONT', -44.0, -20.0, 47.0, 0.0, 1.0, 1.0)
        Gravity(False)
        Set1D()

        # add files (SAMPLE and CAN)
        SANSadd2.add_runs(('28827', '28797'), 'SANS2DTUBES', '.nxs',
                          rawTypes=('.add', '.raw', '.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay=False)
        SANSadd2.add_runs(('28823', '28793'), 'SANS2DTUBES', '.nxs',
                          rawTypes=('.add', '.raw', '.s*'), lowMem=False,
                          saveAsEvent=True, isOverlay=False)

        AssignSample(r'SANS2D00028797-add.nxs', reload=True)
        AssignCan(r'SANS2D00028793-add.nxs', reload=True)
        TransmissionSample(r'SANS2D00028808.nxs', r'SANS2D00028784.nxs')
        TransmissionCan(r'SANS2D00028823.nxs', r'SANS2D00028784.nxs')

        WavRangeReduction()
# rotating SDS 6m data
SANSadd999.add_runs(path, [769,776,782])
SaveNexusProcessed("added","c:/mantidinstall/data/SANS2d10000782.nxs")


# 17/03/10 new version of adding files, writes to U:/user/processed which should be in search list, see notes in SANSadd2.py
# to find SANSadd2 may need 
import sys
sys.path.append("U:/Mantidscripts")
print sys.path
import SANSadd2

path="O:/cycle_09_5/"
path="I:/"
# 6m data
SANSadd2.add_runs(path, [3333,3339])
#SaveNexusProcessed("added","i:/SANS2d00003362-add.nxs")



import SANSadd

#path="//isis/inst$/NDXSANS2D/Instrument/cycle_09_4/"
path="N:/cycle_09_5/"
#path="I:/"
# 6m data
SANSadd.add_runs(path, [3323,3362])
SaveNexusProcessed("added","i:/SANS2d00003362-add.nxs")
SANSadd.add_runs(path, [3324,3327])
SaveNexusProcessed("added","i:/SANS2d00003327-add.nxs")
# rotating SDS 6m data
SANSadd999.add_runs(path, [769,776,782])
SaveNexusProcessed("added","c:/mantidinstall/data/SANS2d10000782.nxs")


# 17/03/10 new version of adding files, writes to U:/user/processed which should be in search list, see notes in SANSadd2.py
# to find SANSadd2 may need 
import sys
sys.path.append("U:/Mantidscripts")
print sys.path
import SANSadd2

path="O:/cycle_09_5/"
path="I:/"
# 6m data
SANSadd2.add_runs(path, [3333,3339])
#SaveNexusProcessed("added","i:/SANS2d00003362-add.nxs")


# new version, simpler, writes to z:/processed/sans2d/
# beware, not passing these params through ????
path="X:/"
import SANSadd2
SANSadd2.add_runs(path,[11971,11980,11984])


# MUST DO THIS BEFORE CREATING     D_T     ELSE SUMSPECTRA FLAGS AN ERROR!  
from ISISCommandInterface import *
from math import *

wksp="12364_sans_nxs"