示例#1
0
def test_GIVEN_variable_length_string_type_dataset_WHEN_getting_value_THEN_returned_as_str(
):
    wrapper = NexusWrapper(filename="test_read_vlen_str_dataset")
    dataset_name = "vlen_str_dataset"
    string_data = b"This is a string"
    wrapper.nexus_file.create_dataset(dataset_name,
                                      dtype=h5py.special_dtype(vlen=str),
                                      data=string_data)

    assert wrapper.get_field_value(wrapper.nexus_file,
                                   dataset_name) == string_data.decode("utf8")
    assert isinstance(
        wrapper.get_field_value(wrapper.nexus_file, dataset_name), str)
def _create_transformation_vectors_for_pixel_offsets(
        detector_group: h5py.Group,
        wrapper: nx.NexusWrapper) -> List[QVector3D]:
    """
    Construct a transformation (as a QVector3D) for each pixel offset
    """
    x_offsets = wrapper.get_field_value(detector_group, "x_pixel_offset")
    y_offsets = wrapper.get_field_value(detector_group, "y_pixel_offset")
    z_offsets = wrapper.get_field_value(detector_group, "z_pixel_offset")
    if x_offsets is None or y_offsets is None:
        raise Exception(
            "In pixel_shape_component expected to find x_pixel_offset and y_pixel_offset datasets"
        )
    if z_offsets is None:
        z_offsets = np.zeros_like(x_offsets)
    # offsets datasets can be 2D to match dimensionality of detector, so flatten to 1D
    return [
        QVector3D(x, y, z)
        for x, y, z in zip(x_offsets.flatten(), y_offsets.flatten(),
                           z_offsets.flatten())
    ]