def test_GIVEN_single_scalar_field_and_string_WHEN_adding_fields_to_component_THEN_field_appears_in_component_fields_with_correct_name_and_value(): file = NexusWrapper("test_fields_2") component_group = file.nexus_file.create_group("test_component") component = Component(file, component_group) field_name = "test_field" field_value = np.string_(b"some_value") field = DummyField(field_name, field_value, field_value.dtype) list_widget = DummyListWidget() list_widget.addItem(field) add_fields_to_component(component, list_widget) assert component.get_field(field_name) assert bytes(component.get_field(field_name), encoding="ASCII") == field_value
def fill_existing_entries(self, component_to_edit: Component): """ Populate the pixel fields based on what is already stored in the NeXus file. """ self.reset_pixel_mapping_list() if component_to_edit.get_field("x_pixel_offset") is not None: self.single_pixel_radio_button.setChecked(True) self.update_pixel_layout_visibility(True, False) self._fill_single_pixel_fields(component_to_edit) elif component_to_edit.get_field("detector_number") is not None: self.entire_shape_radio_button.setChecked(True) self.update_pixel_layout_visibility(False, True) self._fill_entire_shape_fields(component_to_edit) else: self.no_pixels_button.setChecked(True) self.pixel_options_stack.setVisible(False)
def test_GIVEN_single_scalar_field_and_float_WHEN_adding_fields_to_component_THEN_field_appears_in_component_fields_with_correct_name_and_value( nexus_wrapper, ): component_group = nexus_wrapper.nexus_file.create_group("test_component") component = Component(nexus_wrapper, component_group) field_name = "test_field" field_dtype = np.float32 field_value = field_dtype(32.123) field = DummyField(field_name, field_value, field_dtype) list_widget = DummyListWidget() list_widget.addItem(field) add_fields_to_component(component, list_widget) assert component.get_field(field_name) assert component.get_field(field_name).dtype == field_dtype assert component.get_field(field_name)[...] == field_value
def _fill_single_pixel_fields(self, component_to_edit: Component): """ Fill the "single pixel" fields of a component that's being edited and contains pixel information. :param component_to_edit: The component that's being edited. """ # Retrieve the pixel offsets and detector number from the component x_pixel_offset = component_to_edit.get_field("x_pixel_offset") y_pixel_offset = component_to_edit.get_field("y_pixel_offset") detector_numbers = component_to_edit.get_field("detector_number") # Check that x offset is more than one value if data_is_an_array_with_more_than_one_element(x_pixel_offset): # Set the number of rows and the row height n_rows, row_height = self._get_row_information(y_pixel_offset) self.row_count_spin_box.setValue(n_rows) self.row_height_spin_box.setValue(row_height) # Set the number of columns and the column width n_cols, col_width = self._get_column_information(x_pixel_offset) self.column_count_spin_box.setValue(n_cols) self.column_width_spin_box.setValue(col_width) # Set the first ID, start counting option, and the count direction option ( first_id, start_counting_text, count_along_text, ) = self._get_detector_number_information(detector_numbers) self.first_id_spin_box.setValue(first_id) self.start_counting_combo_box.setCurrentText(start_counting_text) self.count_first_combo_box.setCurrentText(count_along_text) else: # If the pixel offset information represents a single pixel pass