Exemple #1
0
def test_GIVEN_pixel_mapping_WHEN_setting_off_geometry_shape_THEN_off_geometry_is_called_with_pixel_data(
    component,
):
    pixel_mapping = PixelMapping()
    off_geometry = OFFGeometryNoNexus(vertices=[], faces=[])
    units = "m"
    filename = "somefile.off"

    with patch(
        "nexus_constructor.component.component.OFFGeometryNexus"
    ) as mock_off_geometry_constructor:

        component.set_off_shape(
            loaded_geometry=off_geometry,
            units=units,
            filename=filename,
            pixel_data=pixel_mapping,
        )
        mock_off_geometry_constructor.assert_called_once_with(
            component.file,
            component.group[SHAPE_GROUP_NAME],
            units,
            filename,
            pixel_mapping,
        )
Exemple #2
0
def test_GIVEN_component_with_pixel_mapping_WHEN_removing_pixel_data_THEN_pixel_mapping_is_cleared(
    component,
):

    pixel_mapping = PixelMapping([i for i in range(6)])
    component.record_pixel_mapping(pixel_mapping)

    component.clear_pixel_data()
    assert component.get_field("detector_number") is None
Exemple #3
0
def test_GIVEN_pixel_mapping_WHEN_recording_pixel_data_to_nxdetector_THEN_pixel_ids_in_nexus_file_match_pixel_ids_in_mapping_object(
    component,
):
    pixel_id_list = [i for i in range(5)]
    pixel_mapping = PixelMapping(pixel_id_list)
    component.record_pixel_mapping(pixel_mapping)

    assert np.array_equal(
        component.get_field("detector_number"), np.array(pixel_id_list)
    )
Exemple #4
0
def test_GIVEN_pixel_mapping_WHEN_setting_cylinder_shape_THEN_cylindrical_geometry_is_called_with_pixel_data(
    component,
):
    pixel_mapping = PixelMapping()

    with patch(
        "nexus_constructor.component.component.CylindricalGeometry"
    ) as mock_cylindrical_geometry_constructor:
        component.set_cylinder_shape(pixel_data=pixel_mapping)
        mock_cylindrical_geometry_constructor.assert_called_once_with(
            component.file, component.group[SHAPE_GROUP_NAME], pixel_mapping
        )
def test_GIVEN_pixel_ids_WHEN_initialising_cylindrical_geometry_THEN_ids_in_geometry_match_ids_in_mapping(
        nexus_wrapper, nx_cylindrical_geometry):

    num_detectors = 6
    expected_dataset = [i for i in range(num_detectors)]
    pixel_mapping = PixelMapping(expected_dataset)

    # Patch the validation method so that it doesn't mind information being absent from the NeXus group
    with patch(
            "nexus_constructor.geometry.cylindrical_geometry.CylindricalGeometry._verify_in_file"
    ):
        cylindrical_geometry = CylindricalGeometry(nexus_wrapper,
                                                   nx_cylindrical_geometry,
                                                   pixel_mapping)

    actual_dataset = cylindrical_geometry.detector_number

    assert array_equal(array(expected_dataset), actual_dataset)
Exemple #6
0
def test_GIVEN_pixel_mapping_WHEN_initialising_off_geometry_THEN_mapping_in_nexus_file_matches_mapping_in_pixel_data_object(
    nexus_wrapper, nx_geometry_group
):
    num_detectors = 6
    ids = [i for i in range(num_detectors)]
    pixel_mapping = PixelMapping(ids)
    expected_dataset = [(id, id) for id in ids]

    # Patch the validation method so that it doesn't mind information being absent from the NeXus group
    with patch(
        "nexus_constructor.geometry.off_geometry.OFFGeometryNexus._verify_in_file"
    ):
        off_geometry = OFFGeometryNexus(
            nexus_wrapper, nx_geometry_group, "m", "path", pixel_mapping
        )

    actual_dataset = off_geometry.detector_faces

    assert array_equal(array(expected_dataset), actual_dataset)
Exemple #7
0
    def generate_pixel_data(self) -> PixelData:
        """
        Creates the appropriate PixelData object depending on user selection then gives it the information that the
        user entered in the relevant fields. If the "No Pixel" button has been pressed then the method returns None.
        In the case of a PixelGrid where either rows/columns has been set to zero, this also causes the matching
        distance value to be recorded as zero.
        :return: A PixelData object or None.
        """
        if self.single_pixel_radio_button.isChecked():

            return PixelGrid(
                rows=self.row_count_spin_box.value(),
                columns=self.column_count_spin_box.value(),
                row_height=self.row_height_spin_box.value(),
                col_width=self.column_width_spin_box.value(),
                first_id=self.first_id_spin_box.value(),
                count_direction=COUNT_DIRECTION[
                    self.count_first_combo_box.currentText()],
                initial_count_corner=INITIAL_COUNT_CORNER[
                    self.start_counting_combo_box.currentText()],
            )

        if self.entire_shape_radio_button.isChecked():
            return PixelMapping(self.get_pixel_mapping_ids())
Exemple #8
0
def pixel_mapping():
    ids_with_some_that_are_none = [
        i if i % 3 != 0 else None for i in range(10)
    ]
    return PixelMapping(ids_with_some_that_are_none)
def pixel_mapping_with_single_pixel():
    return PixelMapping([3])
def pixel_mapping_with_six_pixels():
    return PixelMapping([i if i % 3 != 0 else None for i in range(CORRECT_CUBE_FACES)])