예제 #1
0
 def test_propertymanager_can_be_created_from_dict(self):
     values = {"int": 5, "float": 20.0, "str": 'a string'}
     pmgr = PropertyManager(values)
     self.assertEqual(len(pmgr), 3)
     self.assertEqual(5, pmgr["int"].value)
     self.assertEqual(20.0, pmgr["float"].value)
     self.assertEqual('a string', pmgr["str"].value)
예제 #2
0
 def get_hidden_logs(self):
     """Returns a list of log names that should be hidden and not displayed"""
     hidden_logs = []
     log_list = self.get_log_names()
     for log_name in log_list:
         if PropertyManager.isAnInvalidValuesFilterLog(log_name):
             hidden_logs.append(log_name)
     return hidden_logs
예제 #3
0
    def runTest(self):
        red_man = PropertyManager()
        red_man_name = "__dgs_reduction_properties"
        pmds[red_man_name] = red_man

        if 'detvan' in mtd:
            detvan = mtd['detvan']
        else:
            detvan = Load('MAP17186.raw')
        if 'sample' in mtd:
            sample = mtd['sample']
        else:
            sample = Load('MAP17269.raw')

        # Libisis values to check against
        # All PropertyManager properties need to be set
        red_man["LowCounts"] = 1e-10
        red_man["HighCounts"] = 1e10
        red_man["LowOutlier"] = 0.01
        red_man["HighOutlier"] = 100.
        red_man["ErrorBarCriterion"] = 0.0
        red_man["MedianTestLow"] = 0.1
        red_man["MedianTestHigh"] = 2.0
        red_man["SamBkgMedianTestLow"] = 0.0
        red_man["SamBkgMedianTestHigh"] = 1.5
        red_man["SamBkgErrorbarCriterion"] = 3.3
        red_man["RejectZeroBackground"] = True
        # Things needed to run vanadium reduction
        red_man["IncidentBeamNormalisation"] = "ToMonitor"
        red_man["DetVanIntRangeUnits"] = "Energy"
        #  properties affecting diagnostics:

        #reducer.wb_integr_range = [20,300]
        red_man["DetVanIntRangeLow"] = 20.
        red_man["DetVanIntRangeHigh"] = 300.
        red_man["BackgroundCheck"] = True
        red_man["BackgroundTofStart"] = 12000.
        red_man["BackgroundTofEnd"] = 18000.
        #reducer.bkgd_range=[12000,18000]

        diag_mask = DgsDiagnose(DetVanWorkspace=detvan,
                                SampleWorkspace=sample,
                                ReductionProperties=red_man_name)

        MaskDetectors(sample, MaskedWorkspace=diag_mask)
        # Save the masked spectra numbers to a simple ASCII file for comparison
        self.saved_diag_file = os.path.join(config['defaultsave.directory'],
                                            'CurrentDirectInelasticDiag2.txt')
        handle = file(self.saved_diag_file, 'w')
        for index in range(sample.getNumberHistograms()):
            if sample.getDetector(index).isMasked():
                spec_no = sample.getSpectrum(index).getSpectrumNo()
                handle.write(str(spec_no) + '\n')
        handle.close()
예제 #4
0
    def get_logs_with_invalid_data(self):
        """Returns a map of log names with invalid data, and the invalid filter logs
        The value of each log is the number of invalid entries,
         with -1 meaning all of the entries are invalid"""
        invalid_data_logs = {}
        log_list = self.get_log_names()
        for log_name in log_list:
            if PropertyManager.isAnInvalidValuesFilterLog(log_name):
                log = self.get_log(log_name)
                #determine if the entire log is invalid
                invalid_value_count = 0
                for log_value in log.value:
                    if not log_value:
                        invalid_value_count += 1
                if invalid_value_count == log.size():
                    invalid_value_count = -1

                filtered_log = PropertyManager.getLogNameFromInvalidValuesFilter(
                    log_name)
                if filtered_log:
                    invalid_data_logs[filtered_log] = invalid_value_count
        return invalid_data_logs
예제 #5
0
    def test_static_methods(self):
        test_log_name = "testLog"
        self.assertFalse(PropertyManager.isAnInvalidValuesFilterLog(test_log_name))
        self.assertEqual(PropertyManager.getInvalidValuesFilterLogName(test_log_name),
          test_log_name + "_invalid_values")

        self.assertTrue(PropertyManager.isAnInvalidValuesFilterLog(
            PropertyManager.getInvalidValuesFilterLogName(test_log_name)))

        # not a valid invalid values log
        self.assertEqual(
            PropertyManager.getLogNameFromInvalidValuesFilter(test_log_name), "")
        # A valid invalid values log
        self.assertEqual(
            PropertyManager.getLogNameFromInvalidValuesFilter(
                PropertyManager.getInvalidValuesFilterLogName(test_log_name)),
            test_log_name)
예제 #6
0
    def test_propertymanager_population(self):
        manager = PropertyManager()

        # check that it is empty
        self.assertEquals(manager.__len__(), 0)
        self.assertEquals(len(manager), 0)

        # add some values
        manager["f"] = 1.
        manager["i"] = 2
        manager["s"] = "3"

        self.assertEquals(len(manager), 3)
        self.assertEquals(manager.propertyCount(), 3)

        # confirm they are in there
        self.assertTrue("f" in manager)
        self.assertTrue("i" in manager)
        self.assertTrue("s" in manager)
        self.assertFalse("nonsense" in manager)

        # check string return values
        self.assertEquals(manager.getPropertyValue("f"), "1")
        self.assertEquals(manager.getPropertyValue("i"), "2")
        self.assertEquals(manager.getPropertyValue("s"), "3")

        # check actual values
        self.assertEquals(manager.getProperty("f").value, 1.)
        self.assertEquals(manager.getProperty("i").value, 2)
        self.assertEquals(manager.getProperty("s").value, "3")

        # ...and accessing them through dict interface
        self.assertEquals(manager["f"].value, 1.)
        self.assertEquals(manager["i"].value, 2)
        self.assertEquals(manager["s"].value, "3")

        # see that you can get keys and values
        self.assertTrue(len(manager.values()), 3)
        keys = manager.keys()
        self.assertEquals(len(keys), 3)
        self.assertTrue("f" in keys)
        self.assertTrue("i" in keys)
        self.assertTrue("s" in keys)

        # check for members
        self.assertTrue(manager.has_key("f"))
        self.assertTrue(manager.has_key("i"))
        self.assertTrue(manager.has_key("s"))
        self.assertFalse(manager.has_key("q"))

        self.assertTrue("f" in manager)
        self.assertTrue("i" in manager)
        self.assertTrue("s" in manager)
        self.assertFalse("q" in manager)

        # check for delete
        self.assertTrue(len(manager), 3)
        del manager["f"]
        self.assertTrue(len(manager), 2)
예제 #7
0
 def test_propertymanager_cannot_be_created_from_arbitrary_sequence(self):
     with self.assertRaises(Exception):
         PropertyManager((1,2,3,4,5))
예제 #8
0
    def test_propertymanager_population(self):
        manager = PropertyManager()

        # check that it is empty
        self.assertEquals(manager.__len__(), 0)
        self.assertEquals(len(manager), 0)

        # add some values
        manager["f"] = 1.
        manager["i"] = 2
        manager["s"] = "3"

        self.assertEquals(len(manager), 3)
        self.assertEquals(manager.propertyCount(), 3)

        # confirm they are in there
        self.assertTrue("f" in manager)
        self.assertTrue("i" in manager)
        self.assertTrue("s" in manager)
        self.assertFalse("nonsense" in manager)

        # check string return values
        self.assertEquals(manager.getPropertyValue("f"), "1")
        self.assertEquals(manager.getPropertyValue("i"), "2")
        self.assertEquals(manager.getPropertyValue("s"), "3")

        # check actual values
        self.assertEquals(manager.getProperty("f").value, 1.)
        self.assertEquals(manager.getProperty("i").value, 2)
        self.assertEquals(manager.getProperty("s").value, "3")

        # ...and accessing them through dict interface
        self.assertEquals(manager["f"].value, 1.)
        self.assertEquals(manager["i"].value, 2)
        self.assertEquals(manager["s"].value, "3")

        # see that you can get keys and values
        self.assertTrue(len(manager.values()), 3)
        keys = manager.keys()
        self.assertEquals(len(keys), 3)
        self.assertTrue("f" in keys)
        self.assertTrue("i" in keys)
        self.assertTrue("s" in keys)

        # check for members
        self.assertTrue(manager.has_key("f"))
        self.assertTrue(manager.has_key("i"))
        self.assertTrue(manager.has_key("s"))
        self.assertFalse(manager.has_key("q"))

        self.assertTrue("f" in manager)
        self.assertTrue("i" in manager)
        self.assertTrue("s" in manager)
        self.assertFalse("q" in manager)

        # check for delete
        self.assertTrue(len(manager), 3)
        del manager["f"]
        self.assertTrue(len(manager), 2)
예제 #9
0
 def test_add_existing_mgr_object(self):
     name = "PropertyManagerDataServiceTest_test_add_existing_mgr_object"
     values = {'key': 100.5}
     mgr = PropertyManager(values)
     self._do_add_test(name, mgr)
 def test_set_property_on_algorithm_property_manager(self):
     # set the property directly from a PropertyManager
     fake = FakeAlgorithm()
     fake.initialize()
     fake.setProperty("Args", PropertyManager())