def test_full_setup_for_circular_apertures(self):
        # Arrange
        command_iface.Clean()
        command_iface.SANS2D()
        a1 = 2 # in mm
        a2 = 3 # in mm
        delta_r = 4 # in mm
        collimation_length = 10 # in m
        norm = reduction_steps.CalculateNormISIS()
        ReductionSingleton().to_Q = reduction_steps.ConvertToQISIS(norm)

        # Act
        command_iface.set_q_resolution_a1(a1 = a1)
        command_iface.set_q_resolution_a2(a2 = a2)
        command_iface.set_q_resolution_delta_r(delta_r = delta_r)
        command_iface.set_q_resolution_collimation_length(collimation_length = collimation_length)
        command_iface.set_q_resolution_use(use = True)
        ReductionSingleton().to_Q._set_up_q_resolution_parameters()

        # Assert
        a1_stored = ReductionSingleton().to_Q.get_q_resolution_a1() # in m 
        a1_expected = a1/1000.
        self.assertEqual(a1_stored, a1_expected)

        a2_stored = ReductionSingleton().to_Q.get_q_resolution_a2() # in m
        a2_expected = a2/1000.
        self.assertEqual(a2_stored, a2_expected)

        collimation_length_stored = ReductionSingleton().to_Q.get_q_resolution_collimation_length() # in m
        collimation_length_expected = collimation_length
        self.assertEqual(collimation_length_stored, collimation_length_expected)

        delta_r_stored = ReductionSingleton().to_Q.get_q_resolution_delta_r() # in m
        delta_r_expected = delta_r/1000.
        self.assertEqual(delta_r_stored, delta_r_expected)
Exemple #2
0
    def _init_steps(self):
        """
            Initialises the steps that are not initialised by (ISIS)CommandInterface.
        """
        #these steps are not executed by reduce
        self.user_settings = None
        self._out_name = isis_reduction_steps.GetOutputName()

        #except self.prep_normalize all the steps below are used by the reducer
        self.event2hist = isis_reduction_steps.SliceEvent()
        self.crop_detector = isis_reduction_steps.CropDetBank()
        self.mask = isis_reduction_steps.Mask_ISIS()
        self.to_wavelen = isis_reduction_steps.UnitsConvert('Wavelength')
        self.norm_mon = isis_reduction_steps.NormalizeToMonitor()
        self.transmission_calculator =\
                               isis_reduction_steps.TransmissionCalc(loader=None)
        self._corr_and_scale = isis_reduction_steps.AbsoluteUnitsISIS()

        # note CalculateNormISIS does not inherit from ReductionStep
        # so currently do not understand why it is in isis_reduction_steps
        # Also the main purpose of this class is to use it as an input argument
        # to ConvertToQ below
        self.prep_normalize = isis_reduction_steps.CalculateNormISIS(
            [self.norm_mon, self.transmission_calculator])

        self.to_Q = isis_reduction_steps.ConvertToQISIS(self.prep_normalize)
        self._background_subtracter = isis_reduction_steps.CanSubtraction()
        self.geometry_correcter = isis_reduction_steps.SampleGeomCor()
        #        self._zero_error_flags=isis_reduction_steps.ReplaceErrors()
        self._rem_nans = isis_reduction_steps.StripEndNans()

        self.set_Q_output_type(self.to_Q.output_type)
        # keep information about event slicing
        self._slices_def = []
        self._slice_index = 0
    def test_full_setup_for_rectangular_apertures(self):
        # Arrange
        command_iface.Clean()
        command_iface.SANS2D()
        a1 = 2  # in mm
        a2 = 3  # in mm
        delta_r = 4  # in mm
        collimation_length = 10  # in m
        h1 = 9  # in mm
        w1 = 8  # in mm
        h2 = 7  # in mm
        w2 = 5  # in mm
        norm = reduction_steps.CalculateNormISIS()
        ReductionSingleton().to_Q = reduction_steps.ConvertToQISIS(norm)

        # Act
        command_iface.set_q_resolution_a1(a1=a1)
        command_iface.set_q_resolution_a2(a2=a2)
        command_iface.set_q_resolution_delta_r(delta_r=delta_r)
        command_iface.set_q_resolution_h1(h1=h1)
        command_iface.set_q_resolution_w1(w1=w1)
        command_iface.set_q_resolution_h2(h2=h2)
        command_iface.set_q_resolution_w2(w2=w2)
        command_iface.set_q_resolution_collimation_length(
            collimation_length=collimation_length)
        command_iface.set_q_resolution_use(use=True)
        ReductionSingleton().to_Q._set_up_q_resolution_parameters()

        # Assert
        a1_stored = ReductionSingleton().to_Q.get_q_resolution_a1()  # in m
        a1_expected = 2 * math.sqrt(
            (h1 / 1000. * h1 / 1000. + w1 / 1000. * w1 / 1000.) / 6)
        self.assertEqual(a1_stored, a1_expected)

        a2_stored = ReductionSingleton().to_Q.get_q_resolution_a2()  # in m
        a2_expected = 2 * math.sqrt(
            (h2 / 1000. * h2 / 1000. + w2 / 1000. * w2 / 1000.) / 6)
        self.assertEqual(a2_stored, a2_expected)

        collimation_length_stored = ReductionSingleton(
        ).to_Q.get_q_resolution_collimation_length()  # in m
        collimation_length_expected = collimation_length
        self.assertEqual(collimation_length_stored,
                         collimation_length_expected)

        delta_r_stored = ReductionSingleton().to_Q.get_q_resolution_delta_r(
        )  # in m
        delta_r_expected = delta_r / 1000.
        self.assertEqual(delta_r_stored, delta_r_expected)
    def test_full_setup_for_rectangular_apertures_which_are_only_partially_specified(
            self):
        # Arrange
        command_iface.Clean()
        command_iface.SANS2D()
        a1 = 2  # in mm
        a2 = 3  # in mm
        delta_r = 4  # in mm
        collimation_length = 10  # in m
        h1 = 9  # in mm
        w1 = 8  # in mm
        h2 = 7  # in mm
        # We take out w2, hence we don't have a full rectangular spec
        norm = reduction_steps.CalculateNormISIS()
        ReductionSingleton().to_Q = reduction_steps.ConvertToQISIS(norm)

        # Act
        command_iface.set_q_resolution_a1(a1=a1)
        command_iface.set_q_resolution_a2(a2=a2)
        command_iface.set_q_resolution_delta_r(delta_r=delta_r)
        command_iface.set_q_resolution_h1(h1=h1)
        command_iface.set_q_resolution_w1(w1=w1)
        command_iface.set_q_resolution_h2(h2=h2)

        command_iface.set_q_resolution_collimation_length(
            collimation_length=collimation_length)
        command_iface.set_q_resolution_use(use=True)
        ReductionSingleton().to_Q._set_up_q_resolution_parameters()

        # Assert
        a1_stored = ReductionSingleton().to_Q.get_q_resolution_a1()  # in m
        a1_expected = a1 / 1000.
        self.assertEqual(a1_stored, a1_expected)

        a2_stored = ReductionSingleton().to_Q.get_q_resolution_a2()  # in m
        a2_expected = a2 / 1000.
        self.assertEqual(a2_stored, a2_expected)

        collimation_length_stored = ReductionSingleton(
        ).to_Q.get_q_resolution_collimation_length()  # in m
        collimation_length_expected = collimation_length
        self.assertEqual(collimation_length_stored,
                         collimation_length_expected)

        delta_r_stored = ReductionSingleton().to_Q.get_q_resolution_delta_r(
        )  # in m
        delta_r_expected = delta_r / 1000.
        self.assertEqual(delta_r_stored, delta_r_expected)