Пример #1
0
    def depends_on(self, transformation: Transformation):
        existing_depends_on = self.file.get_attribute_value(
            self.group, CommonAttrs.DEPENDS_ON
        )
        if existing_depends_on is not None:
            create_transformation(
                self.file, self.file[existing_depends_on]
            ).deregister_dependent(self)

        if transformation is None:
            self.file.set_field_value(self.group, CommonAttrs.DEPENDS_ON, ".", str)
        else:
            self.file.set_field_value(
                self.group, CommonAttrs.DEPENDS_ON, transformation.absolute_path, str
            )
            transformation.register_dependent(self)
Пример #2
0
    def _create_transform(
        self,
        name: str,
        transformation_type: TransformationType,
        angle_or_magnitude: float,
        units: str,
        vector: QVector3D,
        depends_on: Transformation,
    ):
        transforms_group = self.file.create_transformations_group_if_does_not_exist(
            self.group
        )
        if name is None:
            name = _generate_incremental_name(transformation_type, transforms_group)

        field = self.file.set_field_value(
            transforms_group, name, angle_or_magnitude, float
        )
        self.file.set_attribute_value(field, CommonAttrs.UNITS, units)
        self.file.set_attribute_value(
            field, CommonAttrs.VECTOR, qvector3d_to_numpy_array(vector)
        )
        self.file.set_attribute_value(
            field, CommonAttrs.TRANSFORMATION_TYPE, transformation_type
        )
        transform = create_transformation(self.file, field)
        transform.ui_value = angle_or_magnitude
        transform.depends_on = depends_on
        return transform
Пример #3
0
 def refresh_depends_on(_, node):
     """
     Refresh the depends_on attribute of each transformation, which also results in registering dependents
     """
     if isinstance(node, h5py.Group):
         if get_nx_class(node) == "NXtransformations":
             for transformation_name, transformation_node in node.items(
             ):
                 transform = create_transformation(
                     self.nexus, node[transformation_name])
                 transform.depends_on = transform.depends_on
Пример #4
0
 def _get_transform(
     self,
     depends_on: str,
     transforms: List[Transformation],
     local_only: bool = False,
 ):
     """
     Recursive function, appends each transform in depends_on chain to transforms list
     :param depends_on: The next depends_on string to find the next transformation in the chain
     :param transforms: The list to populate with transformations
     :param local_only: If True then only add transformations which are stored within this component
     """
     if depends_on is not None and depends_on != ".":
         if (
             transforms
             and depends_on
             == self.file.get_attribute_value(
                 transforms[-1].dataset, CommonAttrs.DEPENDS_ON
             )
             and depends_on
             in [get_name_of_node(x) for x in transforms[-1].dataset.parent.values()]
         ):
             # depends_on is recursive, ie one transformation in this group depends on another transformation in the group, and it is also relative
             transform_dataset = self.file.nexus_file[
                 f"{transforms[-1].dataset.parent.name}/{depends_on}"
             ]
         elif f"{self.group.name}/{depends_on}" in self.file.nexus_file:
             transform_dataset = self.file.nexus_file[
                 f"{self.group.name}/{depends_on}"
             ]
         else:
             transform_dataset = self.file.nexus_file[depends_on]
         if (
             local_only
             and transform_dataset.parent.parent.name != self.absolute_path
         ):
             # We're done, the next transformation is not stored in this component
             return
         new_transform = create_transformation(self.file, transform_dataset)
         new_transform.parent = transforms
         transforms.append(new_transform)
         if (
             self.file.get_attribute_value(transform_dataset, CommonAttrs.DEPENDS_ON)
             is not None
         ):
             self._get_transform(
                 self.file.get_attribute_value(
                     transform_dataset, CommonAttrs.DEPENDS_ON
                 ),
                 transforms,
                 local_only,
             )
Пример #5
0
 def depends_on(self) -> Optional[Transformation]:
     depends_on_path = self.file.get_field_value(self.group, CommonAttrs.DEPENDS_ON)
     if depends_on_path in [None, "."]:
         return None
     return create_transformation(self.file, self.file.nexus_file[depends_on_path])