コード例 #1
0
    def validate_chopper(self) -> bool:
        """
        Performs the following checks in order to determine if the chopper input is valid:
        1) Checks that the required fields are present,
        2) Checks that the fields have the correct type,
        3) Checks that the field data can be converted to the corresponding numpy type,
        4) Checks that the slit edges array is 1D, and
        5) Checks that the overall chopper geometry is valid (no overlapping slits, repeated angles, etc).
        :return: True if the chopper is valid, False otherwise.
        """
        if SLIT_EDGES_NAME in self.fields_dict and isinstance(
                self.fields_dict[SLIT_EDGES_NAME].values, list):
            self.fields_dict[SLIT_EDGES_NAME].values = np.array(
                self.fields_dict[SLIT_EDGES_NAME].values)
        if not (self.required_fields_present() and self._data_has_correct_type(
        ) and self._data_can_be_converted() and _units_are_valid(
                self.units_dict
        ) and _edges_array_has_correct_shape(
                self.fields_dict[SLIT_EDGES_NAME].values.ndim,  # type: ignore
                self.fields_dict[SLIT_EDGES_NAME].values.shape,  # type: ignore
        )):
            return False

        self._chopper_details = ChopperDetails(
            self.converted_values[SLITS_NAME],
            self.fields_dict[SLIT_EDGES_NAME].values,
            self.converted_values[RADIUS_NAME],
            self.converted_values[SLIT_HEIGHT_NAME],
            self.units_dict[SLIT_EDGES_NAME],
            self.units_dict[SLIT_HEIGHT_NAME],
            self.units_dict[RADIUS_NAME],
        )

        return _input_describes_valid_chopper(
            self._chopper_details, self.fields_dict[SLIT_EDGES_NAME].values)
コード例 #2
0
    def validate_chopper(self) -> bool:
        """
        Performs the following checks in order to determine if the chopper input is valid: 1) Checks that the required
        fields are present, 2) Checks that the fields have the correct type, 3) Checks that the slit edges array is 1D,
        and 4) Checks that the overall chopper geometry is valid (no overlapping slits, repeated angles, etc).
        :return: True if the chopper is valid. False otherwise.
        """
        if not (self.required_fields_present() and self.data_has_correct_type(
                self.fields_dict, self.units_dict) and self.units_are_valid(
                    self.units_dict) and self.edges_array_has_correct_shape(
                        self.fields_dict[SLIT_EDGES_NAME].ndim,
                        self.fields_dict[SLIT_EDGES_NAME].shape,
                    )):
            return False

        self._chopper_details = ChopperDetails(
            self.fields_dict[SLITS_NAME],
            self.fields_dict[SLIT_EDGES_NAME],
            self.fields_dict[RADIUS_NAME],
            self.fields_dict[SLIT_HEIGHT_NAME],
            self.units_dict[SLIT_EDGES_NAME],
            self.units_dict[SLIT_HEIGHT_NAME],
            self.units_dict[RADIUS_NAME],
        )

        return self.input_describes_valid_chopper(
            self._chopper_details, self.fields_dict[SLIT_EDGES_NAME])
コード例 #3
0
def chopper_details():
    return ChopperDetails(
        slits=N_SLITS,
        slit_edges=np.copy(RADIANS_EDGES_ARR),
        radius=RADIUS_LENGTH,
        slit_height=SLIT_HEIGHT_LENGTH,
        angle_units="rad",
        slit_height_units="m",
        radius_units="m",
    )
コード例 #4
0
def test_GIVEN_radius_length_in_cm_WHEN_initialising_chopper_details_THEN_radius_is_converted_to_m(
):
    chopper_details = ChopperDetails(
        slits=N_SLITS,
        slit_edges=DEGREES_EDGES_ARR,
        radius=RADIUS_LENGTH,
        slit_height=SLIT_HEIGHT_LENGTH,
        angle_units="deg",
        radius_units="cm",
        slit_height_units="m",
    )

    assert chopper_details.radius * 100 == pytest.approx(RADIUS_LENGTH)
コード例 #5
0
def test_GIVEN_angles_in_degrees_WHEN_initialising_chopper_details_object_THEN_angles_are_converted_to_radians(
):
    edges_array = np.array([i * 30 for i in range(4)])

    chopper_details = ChopperDetails(
        slits=N_SLITS,
        slit_edges=np.array([i * 30 for i in range(4)]),
        radius=RADIUS_LENGTH,
        slit_height=SLIT_HEIGHT_LENGTH,
        angle_units="deg",
        slit_height_units="m",
        radius_units="m",
    )

    assert np.allclose(chopper_details.slit_edges,
                       CONVERT_DEGREES_TO_RADIANS(edges_array))
コード例 #6
0
def test_GIVEN_simple_chopper_details_WHEN_creating_disk_chopper_THEN_chopper_mesh_has_expected_shape():
    radius = 1
    slit_height = 0.5
    resolution = 5
    chopper_details = ChopperDetails(
        slits=1,
        slit_edges=np.array([0.0, np.deg2rad(90)]),
        radius=radius,
        slit_height=slit_height,
        angle_units="rad",
        slit_height_units="m",
        radius_units="m",
    )
    geometry_creator = DiskChopperGeometryCreator(chopper_details)
    geometry_creator.resolution = resolution
    z = geometry_creator.z

    angles = np.linspace(0, np.pi * 2, resolution + 1)[:-1]

    def find_x(r, theta):
        return r * np.cos(theta)

    def find_y(r, theta):
        return r * np.sin(theta)

    def check_cake_slice_faces(indices):
        assert indices in geometry_creator.faces
        assert [0, indices[0], indices[-1]] in geometry_creator.faces
        assert [1, indices[-2], indices[1]] in geometry_creator.faces

    geometry_creator.convert_chopper_details_to_off()

    # Check the centre points
    assert geometry_creator.points[0] == Point(0, 0, z)
    assert geometry_creator.points[1] == Point(0, 0, -z)

    # Check the next four points that make form the "right" slit boundary
    assert geometry_creator.points[2] == Point(radius, 0, z)
    assert geometry_creator.points[3] == Point(radius, 0, -z)
    assert geometry_creator.points[4] == Point(slit_height, 0, z)
    assert geometry_creator.points[5] == Point(slit_height, 0, -z)

    assert [4, 2, 3, 5] in geometry_creator.faces

    # Check the next four points that make form the "left" slit boundary
    assert geometry_creator.points[6] == Point(0, radius, z)
    assert geometry_creator.points[7] == Point(0, radius, -z)
    assert geometry_creator.points[8] == Point(0, slit_height, z)
    assert geometry_creator.points[9] == Point(0, slit_height, -z)

    assert [9, 7, 6, 8] in geometry_creator.faces

    # Test the intermediate points in the slit
    x, y = find_x(slit_height, angles[1]), find_y(slit_height, angles[1])
    assert geometry_creator.points[10] == Point(x, y, z)
    assert geometry_creator.points[11] == Point(x, y, -z)

    # Test for the faces connected to the points 10 and 11
    check_cake_slice_faces([4, 5, 11, 10])
    check_cake_slice_faces([10, 11, 9, 8])

    # Test for the next pair of points
    x, y = find_x(radius, angles[2]), find_y(radius, angles[2])
    assert geometry_creator.points[12] == Point(x, y, z)
    assert geometry_creator.points[13] == Point(x, y, -z)

    # Test for the faces connected to points 12 and 13
    check_cake_slice_faces([6, 7, 13, 12])

    # Test for the next pair of points
    x, y = find_x(radius, angles[3]), find_y(radius, angles[3])
    assert geometry_creator.points[14] == Point(x, y, z)
    assert geometry_creator.points[15] == Point(x, y, -z)

    # Test for the faces connected to points 14 and 15
    check_cake_slice_faces([12, 13, 15, 14])

    # Test for the next pair of points
    x, y = find_x(radius, angles[4]), find_y(radius, angles[4])
    assert geometry_creator.points[16] == Point(x, y, z)
    assert geometry_creator.points[17] == Point(x, y, -z)

    # Test for the faces connected to points 14 and 15
    check_cake_slice_faces([14, 15, 17, 16])

    # Test for the remaining connection in the chopper
    check_cake_slice_faces([16, 17, 3, 2])

    # Test for the points in the top dead centre arrow
    assert geometry_creator.points[18] == Point(radius, 0, z)
    assert geometry_creator.points[19] == Point(
        radius + geometry_creator.arrow_size, 0, z + geometry_creator.arrow_size
    )
    assert geometry_creator.points[20] == Point(
        radius - geometry_creator.arrow_size, 0, z + geometry_creator.arrow_size
    )

    # Test for the top dead centre arrow face
    assert [18, 19, 20] in geometry_creator.faces