示例#1
0
 def test_display_item_is_added_to_same_project_as_data_item(self):
     with create_memory_profile_context() as profile_context:
         profile = profile_context.create_profile()
         profile.add_project_memory()
         document_model = DocumentModel.DocumentModel(profile=profile)
         with contextlib.closing(document_model):
             data_item = DataItem.DataItem(
                 numpy.ones((16, 16), numpy.uint32))
             document_model.append_data_item(data_item,
                                             project=profile.projects[0])
             document_model.append_display_item(
                 DisplayItem.DisplayItem(data_item=data_item))
             data_item = DataItem.DataItem(
                 numpy.ones((16, 16), numpy.uint32))
             document_model.append_data_item(data_item,
                                             project=profile.projects[1])
             document_model.append_display_item(
                 DisplayItem.DisplayItem(data_item=data_item))
         document_model = DocumentModel.DocumentModel(
             profile=profile_context.create_profile())
         with contextlib.closing(document_model):
             self.assertEqual(2, len(document_model.data_items))
             self.assertEqual(4, len(document_model.display_items))
             self.assertEqual(
                 2, len(document_model.profile.projects[0].display_items))
             self.assertEqual(
                 2, len(document_model.profile.projects[1].display_items))
示例#2
0
 def test_inserting_display_data_channel_updates_display_layer_data_indexes(
         self):
     with TestContext.create_memory_context() as test_context:
         document_model = test_context.create_document_model()
         data_item1 = DataItem.DataItem(numpy.zeros((8, ), numpy.uint32))
         document_model.append_data_item(data_item1)
         data_item2 = DataItem.DataItem(numpy.zeros((8, ), numpy.uint32))
         document_model.append_data_item(data_item2)
         data_item3 = DataItem.DataItem(numpy.zeros((8, ), numpy.uint32))
         document_model.append_data_item(data_item3)
         display_item = document_model.get_display_item_for_data_item(
             data_item1)
         display_item.append_display_data_channel_for_data_item(data_item2)
         display_item._set_display_layer_property(0, "ref", "A")
         display_item._set_display_layer_property(1, "ref", "B")
         self.assertEqual(2, len(display_item.display_data_channels))
         self.assertEqual(
             display_item.display_data_channels[0],
             display_item.get_display_layer_display_data_channel(0))
         self.assertEqual(
             display_item.display_data_channels[1],
             display_item.get_display_layer_display_data_channel(1))
         display_item.insert_display_data_channel(
             1, DisplayItem.DisplayDataChannel(data_item=data_item3))
         self.assertEqual(3, len(display_item.display_data_channels))
         self.assertEqual(
             display_item.display_data_channels[0],
             display_item.get_display_layer_display_data_channel(0))
         self.assertEqual(
             display_item.display_data_channels[2],
             display_item.get_display_layer_display_data_channel(1))
         self.assertEqual("A",
                          display_item.get_display_layer_property(0, "ref"))
         self.assertEqual("B",
                          display_item.get_display_layer_property(1, "ref"))
示例#3
0
 def test_inserting_display_data_channel_updates_display_layer_data_indexes(
         self):
     document_model = DocumentModel.DocumentModel()
     with contextlib.closing(document_model):
         data_item1 = DataItem.DataItem(numpy.zeros((8, ), numpy.uint32))
         document_model.append_data_item(data_item1)
         data_item2 = DataItem.DataItem(numpy.zeros((8, ), numpy.uint32))
         document_model.append_data_item(data_item2)
         data_item3 = DataItem.DataItem(numpy.zeros((8, ), numpy.uint32))
         document_model.append_data_item(data_item3)
         display_item = document_model.get_display_item_for_data_item(
             data_item1)
         display_item.append_display_data_channel_for_data_item(data_item2)
         display_item._set_display_layer_property(0, "ref", "A")
         display_item._set_display_layer_property(1, "ref", "B")
         self.assertEqual(2, len(display_item.display_data_channels))
         self.assertEqual(
             0, display_item.get_display_layer_property(0, "data_index"))
         self.assertEqual(
             1, display_item.get_display_layer_property(1, "data_index"))
         display_item.insert_display_data_channel(
             1, DisplayItem.DisplayDataChannel(data_item=data_item3))
         self.assertEqual(3, len(display_item.display_data_channels))
         self.assertEqual(
             0, display_item.get_display_layer_property(0, "data_index"))
         self.assertEqual(
             2, display_item.get_display_layer_property(1, "data_index"))
         self.assertEqual("A",
                          display_item.get_display_layer_property(0, "ref"))
         self.assertEqual("B",
                          display_item.get_display_layer_property(1, "ref"))
示例#4
0
    def build_multiprofile(self, document_controller):
        document_model = document_controller.document_model
        model_data_item = self.__model_data_item
        if not model_data_item:
            return
        project = document_model._project
        multiprofile_display_item = None
        line_profile_regions = list()

        colors = ("rgba(0, 0, 255, 0.5)", "rgba(255, 0, 0, 0.5)",
                  "rgba(0, 255, 0, 0.5)")

        for index, dependent_data_item in enumerate(
                document_model.get_dependent_data_items(model_data_item)):
            if self.__is_calibrated_map(dependent_data_item):
                dependent_display_item = document_model.get_display_item_for_data_item(
                    dependent_data_item)
                if not multiprofile_display_item:
                    multiprofile_display_item = DisplayItem.DisplayItem()
                    multiprofile_display_item.title = _("Multi-profile")
                    multiprofile_display_item.display_type = "line_plot"
                    multiprofile_display_item.set_display_property(
                        "legend_position", "top-right")
                    document_model.append_display_item(
                        multiprofile_display_item)
                line_profile_data_item = document_model.get_line_profile_new(
                    dependent_display_item, dependent_display_item.data_item)
                line_profile_display_item = document_model.get_display_item_for_data_item(
                    line_profile_data_item)
                line_profile_display_data_channel = line_profile_display_item.get_display_data_channel_for_data_item(
                    line_profile_data_item)
                line_profile_region = dependent_display_item.graphics[0]
                line_profile_region.vector = (0.5, 0.2), (0.5, 0.8)
                line_profile_regions.append(line_profile_region)
                multiprofile_display_item.append_display_data_channel_for_data_item(
                    line_profile_data_item)
                layer_label = dependent_data_item.title[dependent_data_item.
                                                        title.index(" of ") +
                                                        4:]
                multiprofile_display_item._set_display_layer_properties(
                    index,
                    label=layer_label,
                    fill_color=colors[index % len(colors)])
        if multiprofile_display_item:
            for line_profile_region in line_profile_regions[1:]:
                document_model.append_connection(
                    Connection.PropertyConnection(
                        line_profile_regions[0],
                        "vector",
                        line_profile_region,
                        "vector",
                        parent=multiprofile_display_item))
                document_model.append_connection(
                    Connection.PropertyConnection(
                        line_profile_regions[0],
                        "width",
                        line_profile_region,
                        "width",
                        parent=multiprofile_display_item))
            document_controller.show_display_item(multiprofile_display_item)
示例#5
0
 def read_project(self) -> None:
     properties = self._raw_properties
     self.__project_version = properties.get("version", None)
     if not self._raw_properties:
         self.__project_state = "missing"
     elif self.__project_version is not None and self.__project_version in (
             FileStorageSystem.PROJECT_VERSION, 2):
         for item_d in properties.get("data_items", list()):
             data_item = DataItem.DataItem()
             data_item.begin_reading()
             data_item.read_from_dict(item_d)
             data_item.finish_reading()
             if not self.get_item_by_uuid("data_items", data_item.uuid):
                 self.load_item("data_items", len(self.data_items),
                                data_item)
         for item_d in properties.get("display_items", list()):
             display_item = DisplayItem.DisplayItem()
             display_item.begin_reading()
             display_item.read_from_dict(item_d)
             display_item.finish_reading()
             if not self.get_item_by_uuid("display_items",
                                          display_item.uuid):
                 self.load_item("display_items", len(self.display_items),
                                display_item)
         for item_d in properties.get("data_structures", list()):
             data_structure = DataStructure.DataStructure()
             data_structure.begin_reading()
             data_structure.read_from_dict(item_d)
             data_structure.finish_reading()
             if not self.get_item_by_uuid("data_structures",
                                          data_structure.uuid):
                 self.load_item("data_structures",
                                len(self.data_structures), data_structure)
         for item_d in properties.get("computations", list()):
             computation = Symbolic.Computation()
             computation.begin_reading()
             computation.read_from_dict(item_d)
             computation.finish_reading()
             if not self.get_item_by_uuid("computations", computation.uuid):
                 self.load_item("computations", len(self.computations),
                                computation)
                 # TODO: handle update script and bind after reload in document model
                 computation.update_script(
                     self.container.container.container.
                     _processing_descriptions)
         for item_d in properties.get("connections", list()):
             connection = Connection.connection_factory(item_d.get)
             connection.begin_reading()
             connection.read_from_dict(item_d)
             connection.finish_reading()
             if not self.get_item_by_uuid("connections", connection.uuid):
                 self.load_item("connections", len(self.connections),
                                connection)
         self.__project_state = "loaded"
     elif self.__project_version is not None:
         self.__project_state = "needs_upgrade"
     else:
         self.__project_state = "missing"
 def test_line_plot_with_no_data_handles_clicks(self):
     with TestContext.create_memory_context() as test_context:
         document_controller = test_context.create_document_controller()
         document_model = document_controller.document_model
         display_item = DisplayItem.DisplayItem()
         document_model.append_display_item(display_item)
         display_item.display_type = "line_plot"
         display_panel = document_controller.selected_display_panel
         display_panel.set_display_panel_display_item(display_item)
         display_panel.display_canvas_item.layout_immediate((640, 480))
         display_panel.display_canvas_item.simulate_click((240, 16))
 def test_line_plot_with_no_data_handles_clicks(self):
     document_model = DocumentModel.DocumentModel()
     document_controller = DocumentController.DocumentController(self.app.ui, document_model, workspace_id="library")
     with contextlib.closing(document_controller):
         display_item = DisplayItem.DisplayItem()
         document_model.append_display_item(display_item)
         display_item.display_type = "line_plot"
         display_panel = document_controller.selected_display_panel
         display_panel.set_display_panel_display_item(display_item)
         display_panel.display_canvas_item.layout_immediate((640, 480))
         display_panel.display_canvas_item.simulate_click((240, 16))
 def test_cursor_over_1d_composite_image(self):
     with TestContext.create_memory_context() as test_context:
         document_model = test_context.create_document_model()
         data_item = DataItem.DataItem(numpy.zeros((32,)))
         data_item2 = DataItem.DataItem(numpy.zeros((32,)))
         document_model.append_data_item(data_item)
         document_model.append_data_item(data_item2, False)
         display_item = document_model.get_display_item_for_data_item(data_item)
         display_item.display_type = "line_plot"
         display_item.append_display_data_channel(DisplayItem.DisplayDataChannel(data_item=data_item2))
         display_item.calibration_style_id = "pixels-top-left"
         p, v = display_item.get_value_and_position_text(display_item.display_data_channel, (25, ))
         self.assertEqual(p, "25")
         self.assertEqual(v, "")
示例#9
0
 def test_display_item_with_multiple_display_data_channels_has_sensible_properties(
         self):
     document_model = DocumentModel.DocumentModel()
     with contextlib.closing(document_model):
         data_item = DataItem.DataItem(numpy.zeros((8, 8), numpy.uint32))
         data_item2 = DataItem.DataItem(numpy.zeros((8, 8), numpy.uint32))
         document_model.append_data_item(data_item)
         document_model.append_data_item(data_item2, False)
         display_item = document_model.get_display_item_for_data_item(
             data_item)
         display_item.append_display_data_channel(
             DisplayItem.DisplayDataChannel(data_item=data_item2))
         self.assertIsNotNone(display_item.size_and_data_format_as_string)
         self.assertIsNotNone(display_item.date_for_sorting)
         self.assertIsNotNone(display_item.date_for_sorting_local_as_string)
         self.assertIsNotNone(display_item.status_str)
         self.assertIsNotNone(display_item.used_display_type)
示例#10
0
 def test_display_item_with_multiple_display_data_channels_has_sensible_properties(
         self):
     with TestContext.create_memory_context() as test_context:
         document_model = test_context.create_document_model()
         data_item = DataItem.DataItem(numpy.zeros((8, 8), numpy.uint32))
         data_item2 = DataItem.DataItem(numpy.zeros((8, 8), numpy.uint32))
         document_model.append_data_item(data_item)
         document_model.append_data_item(data_item2, False)
         display_item = document_model.get_display_item_for_data_item(
             data_item)
         display_item.append_display_data_channel(
             DisplayItem.DisplayDataChannel(data_item=data_item2))
         self.assertIsNotNone(display_item.size_and_data_format_as_string)
         self.assertIsNotNone(display_item.date_for_sorting)
         self.assertIsNotNone(display_item.date_for_sorting_local_as_string)
         self.assertIsNotNone(display_item.status_str)
         self.assertIsNotNone(display_item.project_str)
         self.assertIsNotNone(display_item.used_display_type)
示例#11
0
def display_item_factory(lookup_id):
    display_item_uuid = uuid.UUID(lookup_id("uuid"))
    return DisplayItem.DisplayItem(item_uuid=display_item_uuid)
示例#12
0
 def read_project(self) -> None:
     if callable(self.handle_start_read):
         self.handle_start_read()
     properties = self._raw_properties
     if properties:
         project_version = properties.get("version", None)
         if project_version is not None and project_version == FileStorageSystem.PROJECT_VERSION:
             for item_d in properties.get("data_items", list()):
                 data_item = DataItem.DataItem()
                 data_item.begin_reading()
                 data_item.read_from_dict(item_d)
                 data_item.finish_reading()
                 if not self.get_item_by_uuid("data_items", data_item.uuid):
                     self.load_item("data_items", len(self.data_items),
                                    data_item)
                 else:
                     data_item.close()
             for item_d in properties.get("display_items", list()):
                 display_item = DisplayItem.DisplayItem()
                 display_item.begin_reading()
                 display_item.read_from_dict(item_d)
                 display_item.finish_reading()
                 if not self.get_item_by_uuid("display_items",
                                              display_item.uuid):
                     self.load_item("display_items",
                                    len(self.display_items), display_item)
                 else:
                     display_item.close()
             for item_d in properties.get("data_structures", list()):
                 data_structure = DataStructure.DataStructure()
                 data_structure.begin_reading()
                 data_structure.read_from_dict(item_d)
                 data_structure.finish_reading()
                 if not self.get_item_by_uuid("data_structures",
                                              data_structure.uuid):
                     self.load_item("data_structures",
                                    len(self.data_structures),
                                    data_structure)
                 else:
                     data_structure.close()
             for item_d in properties.get("computations", list()):
                 computation = Symbolic.Computation()
                 computation.begin_reading()
                 computation.read_from_dict(item_d)
                 computation.finish_reading()
                 if not self.get_item_by_uuid("computations",
                                              computation.uuid):
                     self.load_item("computations", len(self.computations),
                                    computation)
                     # TODO: handle update script and bind after reload in document model
                     computation.update_script(
                         Project._processing_descriptions)
                     computation.reset()
                 else:
                     computation.close()
             for item_d in properties.get("connections", list()):
                 connection = Connection.connection_factory(item_d.get)
                 connection.begin_reading()
                 connection.read_from_dict(item_d)
                 connection.finish_reading()
                 if not self.get_item_by_uuid("connections",
                                              connection.uuid):
                     self.load_item("connections", len(self.connections),
                                    connection)
                 else:
                     connection.close()
             for item_d in properties.get("data_groups", list()):
                 data_group = DataGroup.data_group_factory(item_d.get)
                 data_group.begin_reading()
                 data_group.read_from_dict(item_d)
                 data_group.finish_reading()
                 if not self.get_item_by_uuid("data_groups",
                                              data_group.uuid):
                     self.load_item("data_groups", len(self.data_groups),
                                    data_group)
                 else:
                     data_group.close()
             for item_d in properties.get("workspaces", list()):
                 workspace = WorkspaceLayout.factory(item_d.get)
                 workspace.begin_reading()
                 workspace.read_from_dict(item_d)
                 workspace.finish_reading()
                 if not self.get_item_by_uuid("workspaces", workspace.uuid):
                     self.load_item("workspaces", len(self.workspaces),
                                    workspace)
                 else:
                     workspace.close()
             workspace_uuid_str = properties.get("workspace_uuid", None)
             if workspace_uuid_str:
                 self._set_persistent_property_value(
                     "workspace_uuid", uuid.UUID(workspace_uuid_str))
             self._set_persistent_property_value(
                 "data_item_references",
                 properties.get("data_item_references", dict()))
             self._set_persistent_property_value(
                 "mapped_items", properties.get("mapped_items", list()))
             self.__has_been_read = True
     if callable(self.handle_finish_read):
         self.handle_finish_read()
示例#13
0
def display_item_factory(
        lookup_id: typing.Callable[[str], str]) -> DisplayItem.DisplayItem:
    display_item_uuid = uuid.UUID(lookup_id("uuid"))
    return DisplayItem.DisplayItem(item_uuid=display_item_uuid)