コード例 #1
0
 def validateInputs(self):
     errors = dict()
     # Check that the input can be converted into the right state object
     state_property_manager = self.getProperty("SANSState").value
     try:
         state = Serializer.from_json(state_property_manager)
         state.validate()
     except ValueError as err:
         errors.update({"SANSCreateAdjustmentWorkspaces": str(err)})
     return errors
コード例 #2
0
    def PyExec(self):
        # Read the state
        state_json = self.getProperty("SANSState").value
        state = Serializer.from_json(state_json)

        # --------------------------------------
        # Get the monitor normalization workspace
        # --------------------------------------
        monitor_normalization_workspace = self._get_monitor_normalization_workspace(
            state)

        # --------------------------------------
        # Get the calculated transmission
        # --------------------------------------
        calculated_transmission_workspace, unfitted_transmission_workspace = \
            self._get_calculated_transmission_workspace(state)

        # --------------------------------------
        # Get the wide angle correction workspace
        # --------------------------------------
        wave_length_and_pixel_adjustment_workspace = self._get_wide_angle_correction_workspace(
            state, calculated_transmission_workspace)  # noqa

        # --------------------------------------------
        # Get the full wavelength and pixel adjustment
        # --------------------------------------------
        wave_length_adjustment_workspace, \
        pixel_length_adjustment_workspace = self._get_wavelength_and_pixel_adjustment_workspaces(monitor_normalization_workspace,
                                                                                                 # noqa
                                                                                                 calculated_transmission_workspace)  # noqa

        if wave_length_adjustment_workspace:
            self.setProperty("OutputWorkspaceWavelengthAdjustment",
                             wave_length_adjustment_workspace)
        if pixel_length_adjustment_workspace:
            self.setProperty("OutputWorkspacePixelAdjustment",
                             pixel_length_adjustment_workspace)
        if wave_length_and_pixel_adjustment_workspace:
            self.setProperty("OutputWorkspaceWavelengthAndPixelAdjustment",
                             wave_length_and_pixel_adjustment_workspace)

        self.setProperty("CalculatedTransmissionWorkspace",
                         calculated_transmission_workspace)
        self.setProperty("UnfittedTransmissionWorkspace",
                         unfitted_transmission_workspace)
コード例 #3
0
    def test_that_enum_list_can_be_serialized(self):
        original_obj = ExampleWrapper()
        original_obj.bar = [FakeEnumClass.BAR, FakeEnumClass.BAR]

        # Serializing test
        serialized = Serializer.to_json(original_obj)
        self.assertTrue("bar" in serialized)
        self.assertTrue("_foo" in serialized)
        self.assertTrue(isinstance(serialized, str))

        # Deserializing Test
        fake = JsonSerializerTest.FakeAlgorithm()
        fake.initialize()
        fake.setProperty("Args", serialized)
        property_manager = fake.getProperty("Args").value

        new_obj = Serializer.from_json(property_manager)
        self.assertEqual(original_obj.bar, new_obj.bar)
        self.assertEqual(original_obj._foo, new_obj._foo)
コード例 #4
0
ファイル: SANSLoad.py プロジェクト: stuartcampbell/mantid
    def PyExec(self):
        # Read the state
        state_property_manager = self.getProperty("SANSState").value
        state = Serializer.from_json(state_property_manager)

        # Run the appropriate SANSLoader and get the workspaces and the workspace monitors
        # Note that cache optimization is only applied to the calibration workspace since it is not available as a
        # return property and it is also something which is most likely not to change between different reductions.
        use_cached = self.getProperty("UseCached").value
        publish_to_ads = self.getProperty("PublishToCache").value

        data = state.data
        state_adjustment = state.adjustment
        progress = self._get_progress_for_file_loading(data, state_adjustment)

        # Get the correct SANSLoader from the SANSLoaderFactory
        load_factory = SANSLoadDataFactory()
        loader = load_factory.create_loader(state)

        workspaces, workspace_monitors = loader.execute(
            data_info=data,
            use_cached=use_cached,
            publish_to_ads=publish_to_ads,
            progress=progress,
            parent_alg=self,
            adjustment_info=state.adjustment)
        progress.report("Loaded the data.")

        progress_move = Progress(self, start=0.8, end=1.0, nreports=2)
        progress_move.report("Starting to move the workspaces.")
        self._perform_initial_move(workspaces, state)
        progress_move.report("Finished moving the workspaces.")

        # Set output workspaces
        for workspace_type, workspace in workspaces.items():
            self.set_output_for_workspaces(workspace_type, workspace)

        # Set the output monitor workspaces
        for workspace_type, workspace in workspace_monitors.items():
            self.set_output_for_monitor_workspaces(workspace_type, workspace)
コード例 #5
0
    def test_that_sans_state_can_be_serialized_and_deserialized_when_going_through_an_algorithm(
            self):
        # Arrange
        state = ComplexState()

        # Act
        serialized = Serializer.to_json(state)
        fake = JsonSerializerTest.FakeAlgorithm()
        fake.initialize()
        fake.setProperty("Args", serialized)
        property_manager = fake.getProperty("Args").value

        # Assert
        self.assertEqual(type(serialized), str)
        state_2 = Serializer.from_json(property_manager)

        # The direct sub state
        self.assertEqual(state.sub_state_1.float_list_parameter,
                         state_2.sub_state_1.float_list_parameter)

        # The regular parameters
        self.assertEqual(state_2.float_parameter, 23.)
        self.assertEqual(state_2.positive_float_with_none_parameter, 234.)
コード例 #6
0
    def _get_state(self):
        state_json = self.getProperty("SANSState").value
        state = Serializer.from_json(state_json)

        return state
コード例 #7
0
ファイル: SANSLoad.py プロジェクト: stuartcampbell/mantid
    def validateInputs(self):
        errors = dict()
        # Check that the input can be converted into the right state object
        state_json = self.getProperty("SANSState").value
        try:
            state = Serializer.from_json(state_json)
            state.validate()
        except ValueError as err:
            errors.update({"SANSState": str(err)})
            return errors

        # We need to validate that the for each expected output workspace of the SANSState a output workspace name
        # was supplied in the PyInit
        # For sample scatter
        sample_scatter = self.getProperty("SampleScatterWorkspace").value
        sample_scatter_as_string = self.getProperty(
            "SampleScatterWorkspace").valueAsStr
        if sample_scatter is None and not sample_scatter_as_string:
            errors.update({
                "SampleScatterWorkspace":
                "A sample scatter output workspace needs to be specified."
            })

        # For sample scatter monitor
        sample_scatter_monitor = self.getProperty(
            "SampleScatterMonitorWorkspace").value
        sample_scatter_monitor_as_string = self.getProperty(
            "SampleScatterMonitorWorkspace").valueAsStr
        if sample_scatter_monitor is None and not sample_scatter_monitor_as_string:
            errors.update({
                "SampleScatterMonitorWorkspace":
                "A sample scatter output workspace needs to be specified."
            })

        # ------------------------------------
        # Check the optional output workspaces
        # If they are specified in the SANSState, then we require them to be set on the output as well.
        data_info = state.data

        # For sample transmission
        sample_transmission = self.getProperty(
            "SampleTransmissionWorkspace").value
        sample_transmission_as_string = self.getProperty(
            "SampleTransmissionWorkspace").valueAsStr
        sample_transmission_was_set = sample_transmission is not None or len(
            sample_transmission_as_string) > 0

        sample_transmission_from_state = data_info.sample_transmission
        if not sample_transmission_was_set and sample_transmission_from_state is not None:
            errors.update({
                "SampleTransmissionWorkspace":
                "You need to set the output for the sample transmission"
                " workspace since it is specified to be loaded in your "
                "reduction configuration."
            })
        if sample_transmission_was_set and sample_transmission_from_state is None:
            errors.update({
                "SampleTransmissionWorkspace":
                "You set an output workspace for sample transmission, "
                "although none is specified in the reduction configuration."
            })

        # For sample direct
        sample_direct = self.getProperty("SampleDirectWorkspace").value
        sample_direct_as_string = self.getProperty(
            "SampleDirectWorkspace").valueAsStr
        sample_direct_was_set = sample_direct is not None or len(
            sample_direct_as_string) > 0

        sample_direct_from_state = data_info.sample_direct
        if not sample_direct_was_set and sample_direct_from_state is not None:
            errors.update({
                "SampleDirectWorkspace":
                "You need to set the output for the sample direct"
                " workspace since it is specified to be loaded in your "
                "reduction configuration."
            })
        if sample_direct_was_set and sample_direct_from_state is None:
            errors.update({
                "SampleDirectWorkspace":
                "You set an output workspace for sample direct, "
                "although none is specified in the reduction configuration."
            })

        # For can scatter + monitor
        can_scatter = self.getProperty("CanScatterWorkspace").value
        can_scatter_as_string = self.getProperty(
            "CanScatterWorkspace").valueAsStr
        can_scatter_was_set = can_scatter is not None or len(
            can_scatter_as_string) > 0

        can_scatter_from_state = data_info.can_scatter
        if not can_scatter_was_set and can_scatter_from_state is not None:
            errors.update({
                "CanScatterWorkspace":
                "You need to set the output for the can scatter"
                " workspace since it is specified to be loaded in your "
                "reduction configuration."
            })
        if can_scatter_was_set and can_scatter_from_state is None:
            errors.update({
                "CanScatterWorkspace":
                "You set an output workspace for can scatter, "
                "although none is specified in the reduction configuration."
            })

        # For can scatter monitor
        can_scatter_monitor = self.getProperty(
            "CanScatterMonitorWorkspace").value
        can_scatter_monitor_as_string = self.getProperty(
            "CanScatterMonitorWorkspace").valueAsStr
        can_scatter_monitor_was_set = can_scatter_monitor is not None or len(
            can_scatter_monitor_as_string) > 0
        if not can_scatter_monitor_was_set and can_scatter_from_state is not None:
            errors.update({
                "CanScatterMonitorWorkspace":
                "You need to set the output for the can scatter monitor"
                " workspace since it is specified to be loaded in your "
                "reduction configuration."
            })
        if can_scatter_monitor_was_set and can_scatter_from_state is None:
            errors.update({
                "CanScatterMonitorWorkspace":
                "You set an output workspace for can scatter monitor, "
                "although none is specified in the reduction configuration."
            })

        # For sample transmission
        can_transmission = self.getProperty("CanTransmissionWorkspace").value
        can_transmission_as_string = self.getProperty(
            "CanTransmissionWorkspace").valueAsStr
        can_transmission_was_set = can_transmission is not None or len(
            can_transmission_as_string) > 0
        can_transmission_from_state = data_info.can_transmission
        if not can_transmission_was_set and can_transmission_from_state is not None:
            errors.update({
                "CanTransmissionWorkspace":
                "You need to set the output for the can transmission"
                " workspace since it is specified to be loaded in your "
                "reduction configuration."
            })
        if can_transmission_was_set and can_transmission_from_state is None:
            errors.update({
                "CanTransmissionWorkspace":
                "You set an output workspace for can transmission, "
                "although none is specified in the reduction configuration."
            })

        # For can direct
        can_direct = self.getProperty("CanDirectWorkspace").value
        can_direct_as_string = self.getProperty(
            "CanDirectWorkspace").valueAsStr
        can_direct_was_set = can_direct is not None or len(
            can_direct_as_string) > 0
        can_direct_from_state = data_info.can_direct
        if not can_direct_was_set and can_direct_from_state is not None:
            errors.update({
                "CanDirectWorkspace":
                "You need to set the output for the can direct"
                " workspace since it is specified to be loaded in your "
                "reduction configuration."
            })
        if can_direct_was_set and can_direct_from_state is None:
            errors.update({
                "CanDirectWorkspace":
                "You set an output workspace for can direct, "
                "although none is specified in the reduction configuration."
            })
        return errors