def create_and_display_data_item(library, data_and_metadata, scan_data_list, scan_hardware_source, camera_hardware_source): camera_hardware_source_id = camera_hardware_source._hardware_source.hardware_source_id # data_item = library.get_data_item_for_hardware_source(scan_hardware_source, channel_id=camera_hardware_source_id, processor_id="summed", create_if_needed=True, large_format=True) data_item = Facade.DataItem(DataItem.DataItem(large_format=True)) library._document_model.append_data_item(data_item._data_item) data_item._data_item.session_id = library._document_model.session_id data_item.title = _("Spectrum Image {}".format(" x ".join([str(d) for d in data_and_metadata.dimensional_shape]))) # the data item should not have any other 'clients' at this point; so setting the # data and metadata will immediately unload the data (and write to disk). this is important, # because the data (up to this point) can be shared data from the DLL. data_item.set_data_and_metadata(data_and_metadata) # assert not data_item._data_item.is_data_loaded # now to display it will reload the data (presumably from an HDF5 or similar on-demand format). document_window.display_data_item(data_item) for scan_data_and_metadata in scan_data_list: scan_channel_id = scan_data_and_metadata.metadata["hardware_source"]["channel_id"] scan_channel_name = scan_data_and_metadata.metadata["hardware_source"]["channel_name"] channel_id = camera_hardware_source_id + "_" + scan_channel_id # data_item = library.get_data_item_for_hardware_source(scan_hardware_source, channel_id=channel_id, create_if_needed=True) data_item = Facade.DataItem(DataItem.DataItem()) library._document_model.append_data_item(data_item._data_item) data_item._data_item.session_id = library._document_model.session_id data_item.title = "{} ({})".format(_("Spectrum Image"), scan_channel_name) data_item.set_data_and_metadata(scan_data_and_metadata) document_window.display_data_item(data_item)
def init(): document_controller = self.__api.application.document_controllers[ 0]._document_controller computation_data_items = document_controller.ui.get_persistent_string( 'libertem_map4d_data_items_0') self.__computation_data_items = json.loads( computation_data_items) if computation_data_items else dict() self.__tool_tip_boxes = list() document_model = self.__api.application._application.document_model for computation in document_model.computations: src = computation.get_input('src') if src and self.__computation_data_items.get(str( src.uuid)) == 'source': target = computation.get_output('target') if target is None: continue target_api = Facade.DataItem(target) pick_graphic = None for graphic in target_api.graphics: if graphic.label == 'Pick': pick_graphic = graphic break if pick_graphic is not None: self.__connect_pick_graphic(Facade.DataItem(src), target_api, pick_graphic, computation) self.__display_item_changed_event_listener = ( document_controller.focused_display_item_changed_event.listen( self.__display_item_changed))
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller selected_display_item = document_controller.selected_display_item data_item = (selected_display_item.data_items[0] if selected_display_item and len(selected_display_item.data_items) > 0 else None) if data_item: api_data_item = Facade.DataItem(data_item) if not api_data_item.xdata.is_data_4d: self.__show_tool_tips('wrong_shape') return total_bin_data_item = self.__api.library.create_data_item(title='Total bin 4D of ' + data_item.title) computation = self.__api.library.create_computation('nion.total_bin_4d_SI', inputs={'src': api_data_item}, outputs={'target': total_bin_data_item}) computation._computation.source = total_bin_data_item._data_item #computation._computation.mark_update() total_bin_display_item = document_controller.document_model.get_display_item_for_data_item( total_bin_data_item._data_item) document_controller.show_display_item(total_bin_display_item) dark_subtract_area_graphic = total_bin_data_item.add_rectangle_region(0.8, 0.5, 0.4, 1.0) dark_subtract_area_graphic.label = 'Dark subtract area' crop_region = api_data_item.add_rectangle_region(0.5, 0.5, 1.0, 1.0) crop_region.label = 'Crop' dark_subtract_area_graphic._graphic.is_bounds_constrained = True crop_region._graphic.is_bounds_constrained = True dark_corrected_data_item = Facade.DataItem(DataItem.DataItem(large_format=True)) self.__api.library._document_model.append_data_item(dark_corrected_data_item._data_item) dark_corrected_data_item._data_item.session_id = self.__api.library._document_model.session_id dark_corrected_data_item.title = '4D dark correction of ' + data_item.title computation = self.__api.library.create_computation('nion.dark_correction_4d', inputs={'src1': api_data_item, 'src2': total_bin_data_item, 'dark_area_region': dark_subtract_area_graphic, 'crop_region': crop_region, 'bin_spectrum': True, 'gain_image': [], 'gain_mode': 'custom'}, outputs={'target': dark_corrected_data_item}) computation._computation.source = dark_corrected_data_item._data_item dark_corrected_display_item = document_controller.document_model.get_display_item_for_data_item( dark_corrected_data_item._data_item) document_controller.show_display_item(dark_corrected_display_item) self.__computation_data_items.update({data_item: 'source', total_bin_data_item._data_item: 'total bin', dark_corrected_data_item._data_item: 'corrected'}) self.__show_tool_tips() self.__display_item_changed_event_listener = ( document_controller.focused_display_item_changed_event.listen(self.__display_item_changed))
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller display_item = document_controller.selected_display_item data_item = display_item.data_items[0] if display_item and len( display_item.data_items) > 0 else None if not data_item: return api_data_item = Facade.DataItem(data_item) if api_data_item.xdata.is_sequence and api_data_item.xdata.datum_dimension_count == 2: result_data_item = { "output": self.__api.library.create_data_item( title="Color COM image of " + data_item.title) } self.__api.library.create_computation("nion.make_color_com", inputs={ "src": api_data_item, "com_x_index": 0, "com_y_index": 1, "magnitude_min": 0, "magnitude_max": 100, "rotation": "None" }, outputs=result_data_item)
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller selected_display_items = document_controller.selected_display_items data_items = list() # Check if it makes sense to copy display properties from the source to the result display item. # For line plots with multiple display layers we want to copy the display properties so that the joined item # look like the original display items. We copy the display properties of the first display item, but only # if the number of display layers is the same for all input display items. display_layers = None legend_position = None display_type = None copy_display_properties = False for i, display_item in enumerate(selected_display_items): data_item = display_item.data_items[0] if display_item and len( display_item.data_items) > 0 else None if data_item: data_items.append(data_item) if (len(display_item.data_items) == 1 and len(data_item.data_shape) > 1 and (data_item.xdata.datum_dimension_count == 1 or display_item.display_type == 'line_plot')): if i == 0: display_layers = copy.deepcopy( display_item.display_layers) legend_position = display_item.get_display_property( 'legend_position') display_type = display_item.display_type copy_display_properties = True elif display_layers is not None: copy_display_properties &= len(display_layers) == len( display_item.display_layers) if not data_items: return api_data_items = [ Facade.DataItem(data_item) for data_item in data_items ] result_data_item = self.__api.library.create_data_item( title="Joined " + data_items[0].title) computation = self.__api.library.create_computation( "nion.join_sequence", inputs={"src_list": api_data_items}, outputs={"target": result_data_item}) computation._computation.source = result_data_item._data_item result_display_item = document_controller.document_model.get_display_item_for_data_item( result_data_item._data_item) document_controller.show_display_item(result_display_item) if copy_display_properties: if display_layers is not None: result_display_item.display_layers = display_layers if legend_position is not None: result_display_item.set_display_property( 'legend_position', legend_position) if display_type is not None: result_display_item.display_type = display_type
def menu_item_execute(self, window: API.DocumentWindow) -> None: try: document_controller = window._document_controller display_specifier = document_controller.selected_display_specifier if display_specifier.data_item: average_data_item = document_controller.document_model.make_data_item_with_computation( "nion.calculate_4d_average", [(display_specifier.data_item, None)], {'src': []}) new_display_specifier = DataItem.DisplaySpecifier.from_data_item(average_data_item) document_controller.display_data_item(new_display_specifier) api_average_data_item = Facade.DataItem(average_data_item) spectrum_graphic = api_average_data_item.add_rectangle_region(0.5, 0.5, 0.1, 1.0) spectrum_graphic.label = 'Spectrum' bottom_dark_graphic = api_average_data_item.add_rectangle_region(0.7, 0.5, 0.1, 1.0) bottom_dark_graphic.label = 'Bottom dark area' top_dark_graphic = api_average_data_item.add_rectangle_region(0.3, 0.5, 0.1, 1.0) top_dark_graphic.label = 'Top dark area' dark_corrected_data_item = document_controller.document_model.make_data_item_with_computation( "nion.framewise_dark_correction", [(display_specifier.data_item, None), (average_data_item, None)], {"src1": [], "src2": [spectrum_graphic._graphic, top_dark_graphic._graphic, bottom_dark_graphic._graphic]}) new_display_specifier2 = DataItem.DisplaySpecifier.from_data_item(dark_corrected_data_item) document_controller.display_data_item(new_display_specifier2) spectrum_graphic._graphic.is_bounds_constrained = True bottom_dark_graphic._graphic.is_bounds_constrained = True top_dark_graphic._graphic.is_bounds_constrained = True except Exception as e: print(e) raise
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller selected_display_item = document_controller.selected_display_item data_item = (selected_display_item.data_items[0] if selected_display_item and len(selected_display_item.data_items) > 0 else None) if data_item: api_data_item = Facade.DataItem(data_item) if not api_data_item.xdata.metadata.get('libertem-io'): self.__show_tool_tips('wrong_shape') return map_data_item = self.__api.library.create_data_item( title='Map 4D of ' + data_item.title) display_item = document_controller.document_model.get_display_item_for_data_item( map_data_item._data_item) show_display_item(window, display_item) map_regions = list() for graphic in api_data_item.graphics: if graphic._graphic.role == 'mask': map_regions.append(graphic) computation = self.__api.library.create_computation( 'nion.libertem.map_4d', inputs={ 'src': api_data_item, 'map_regions': map_regions }, outputs={'target': map_data_item}) computation._computation.source = data_item map_display_item = document_controller.document_model.get_display_item_for_data_item( map_data_item) document_controller.show_display_item(map_display_item) pick_graphic = map_data_item.add_point_region(0.5, 0.5) pick_graphic.label = 'Pick' self.__connect_pick_graphic(api_data_item, map_data_item, pick_graphic, computation._computation) # def collection_index_changed(key): # if key == 'collection_index': # collection_index = selected_display_item.display_data_channel.collection_index # if int(pick_graphic.position[0]*data_item.data.shape[0]) != collection_index[0]: # computation.pick_graphic_binding_0.update_source(collection_index) # if int(pick_graphic.position[1]*data_item.data.shape[1]) != collection_index[1]: # computation.pick_graphic_binding_1.update_source(collection_index) #computation.collection_index_changed_event_listener = selected_display_item.display_data_channel.property_changed_event.listen(collection_index_changed) self.__computation_data_items.update({ str(data_item.uuid): 'source', str(map_data_item._data_item.uuid): 'map_4d' }) self.__api.application.document_controllers[ 0]._document_controller.ui.set_persistent_string( 'libertem_map4d_data_items_0', json.dumps(self.__computation_data_items)) self.__show_tool_tips()
def map_thickness(api, window): target_display = window.target_display target_data_item_ = target_display._display_item.data_items[0] if target_display and len(target_display._display_item.data_items) > 0 else None if target_data_item_ and target_display: spectrum_image = Facade.DataItem(target_data_item_) map = api.library.create_data_item_from_data(numpy.zeros_like(spectrum_image.display_xdata.data), title="{} Thickness Map".format(spectrum_image.title)) computation = api.library.create_computation("eels.thickness_mapping", inputs={"spectrum_image_data_item": spectrum_image}, outputs={"map": map}) computation._computation.source = spectrum_image._data_item window.display_data_item(map)
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller display_item = document_controller.selected_display_item data_item = display_item.data_items[0] if display_item and len( display_item.data_items) > 0 else None if not data_item: return # Check if it makes sense to copy display properties from the source to the result display item. # For line plots with multiple display layers we want to copy the display properties so that the split items # look like the original display item. Exclude case where the display layers are generated from the sequence # dimension because in this case the display layers are not valid anymore. display_layers = None legend_position = None display_type = None if (len(display_item.data_items) == 1 and len(data_item.data_shape) > 2 and (data_item.xdata.datum_dimension_count == 1 or display_item.display_type == 'line_plot')): display_layers = copy.deepcopy(display_item.display_layers) legend_position = display_item.get_display_property( 'legend_position') display_type = display_item.display_type api_data_item = Facade.DataItem(data_item) if api_data_item.xdata.is_sequence: if api_data_item.xdata.data_shape[0] > 100: logging.error( "Splitting sequences of more than 100 items is disabled for performance reasons." ) return result_data_items = { f"target_{i}": self.__api.library.create_data_item(title=f"Split ({i}) of " + data_item.title) for i in range(api_data_item.xdata.data_shape[0]) } computation = self.__api.library.create_computation( "nion.split_sequence", inputs={"src": api_data_item}, outputs=result_data_items) computation._computation.source = result_data_items[ "target_0"]._data_item for result_data_item in result_data_items.values(): result_display_item = document_controller.document_model.get_display_item_for_data_item( result_data_item._data_item) document_controller.show_display_item(result_display_item) if display_layers is not None: result_display_item.display_layers = display_layers if legend_position is not None: result_display_item.set_display_property( 'legend_position', legend_position) if display_type is not None: result_display_item.display_type = display_type
def menu_item_execute(self, window: API.DocumentWindow) -> None: try: document_controller = window._document_controller display_specifier = document_controller.selected_display_specifier if display_specifier.data_item: total_bin_data_item = document_controller.document_model.make_data_item_with_computation( "nion.total_bin_4d_SI", [(display_specifier.data_item, None)], {'src': []}) new_display_specifier = DataItem.DisplaySpecifier.from_data_item( total_bin_data_item) document_controller.display_data_item(new_display_specifier) api_total_bin_data_item = Facade.DataItem(total_bin_data_item) api_data_item = Facade.DataItem(display_specifier.data_item) dark_subtract_area_graphic = api_total_bin_data_item.add_rectangle_region( 0.8, 0.5, 0.4, 1.0) dark_subtract_area_graphic.label = 'Dark subtract area' crop_region = api_data_item.add_rectangle_region( 0.5, 0.5, 1.0, 1.0) crop_region.label = 'Crop' dark_corrected_data_item = document_controller.document_model.make_data_item_with_computation( "nion.4d_dark_correction", [(display_specifier.data_item, None), (total_bin_data_item, None)], { "src1": [crop_region._graphic], "src2": [dark_subtract_area_graphic._graphic] }) new_display_specifier2 = DataItem.DisplaySpecifier.from_data_item( dark_corrected_data_item) document_controller.display_data_item(new_display_specifier2) dark_subtract_area_graphic._graphic.is_bounds_constrained = True crop_region._graphic.is_bounds_constrained = True except Exception as e: print(e) raise
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller selected_display_item = document_controller.selected_display_item data_item = (selected_display_item.data_items[0] if selected_display_item and len(selected_display_item.data_items) > 0 else None) if data_item: api_data_item = Facade.DataItem(data_item) if not api_data_item.xdata.is_data_4d: self.__show_tool_tips('wrong_shape') return map_data_item = self.__api.library.create_data_item( title='Map 4D of ' + data_item.title) # the following uses internal API and should not be used as example code. computation = document_controller.document_model.create_computation( ) computation.create_input_item( "src", Symbolic.make_item( selected_display_item. get_display_data_channel_for_data_item(data_item))) computation.create_input_item("map_regions", Symbolic.make_item_list([])) computation.processing_id = "nion.map_4d.2" document_controller.document_model.set_data_item_computation( map_data_item._data_item, computation) map_display_item = document_controller.document_model.get_display_item_for_data_item( map_data_item._data_item) document_controller.show_display_item(map_display_item) graphic = Graphics.PointGraphic() graphic.label = "Pick" graphic.role = "collection_index" map_display_item.add_graphic(graphic) # see note above. self.__computation_data_items.update({ str(data_item.uuid): 'source', str(map_data_item._data_item.uuid): 'map_4d' }) self.__show_tool_tips() self.__display_item_changed_event_listener = ( document_controller.focused_display_item_changed_event.listen( self.__display_item_changed))
def select_button_clicked(): graphics = Facade.DataItem( self.computation._computation.source).graphics if not graphics: return graphics_variable = self.computation._computation._get_variable( 'map_regions') graphics_variable.disconnect_items() if graphics_variable.bound_items_model is None: return num_items = len(graphics_variable.bound_items_model.items) for _ in range(num_items): self.computation._computation.remove_item_from_objects( 'map_regions', 0) for graphic in graphics: if graphic._graphic.role == 'mask': self.computation._computation.insert_item_into_objects( 'map_regions', 0, Symbolic.make_item(graphic._graphic, type='graphic'))
def create_and_display_data_item(document_window, data_and_metadata: DataAndMetadata.DataAndMetadata) -> None: # create the data item; large format if it's a collection data_item = Facade.DataItem(DataItem.DataItem(large_format=data_and_metadata.is_collection)) document_window.library._document_model.append_data_item(data_item._data_item) # update the session id data_item._data_item.session_id = document_window.library._document_model.session_id # set the title channel_name = data_and_metadata.metadata.get("hardware_source", dict()).get("channel_name", data_and_metadata.metadata.get("hardware_source", dict()).get("hardware_source_name", "Data")) dimension_str = (" " + " x ".join([str(d) for d in data_and_metadata.collection_dimension_shape])) if data_and_metadata.is_collection else str() data_item.title = f"{title_base}{dimension_str} ({channel_name})" # if the last dimension is 1, squeeze the data (1D SI) if data_and_metadata.data_shape[0] == 1: data_and_metadata = xd.squeeze(data_and_metadata) # the data item should not have any other 'clients' at this point; so setting the # data and metadata will immediately unload the data (and write to disk). this is important, # because the data (up to this point) can be shared data from the DLL. data_item.set_data_and_metadata(data_and_metadata) # now to display it will reload the data (presumably from an HDF5 or similar on-demand format). document_window.display_data_item(data_item)
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller display_item = document_controller.selected_display_item data_item = display_item.data_items[0] if display_item and len( display_item.data_items) > 0 else None if not data_item: return api_data_item = Facade.DataItem(data_item) if api_data_item.xdata.is_sequence and api_data_item.xdata.datum_dimension_count == 2: result_data_item = { "output": self.__api.library.create_data_item(title="iDPC of " + data_item.title) } self.__api.library.create_computation("nion.make_idpc", inputs={ "src": api_data_item, "gradient_x_index": 0, "gradient_y_index": 1 }, outputs=result_data_item)
def start(self, processing: ScanAcquisitionProcessing) -> None: document_window = self.__document_controller scan_hardware_source = typing.cast(scan_base.ScanHardwareSource, self.__scan_hardware_source._hardware_source) scan_frame_parameters = scan_hardware_source.get_frame_parameters(2) scan_hardware_source.apply_scan_context_subscan(scan_frame_parameters, self.__scan_specifier.size) scan_frame_parameters["scan_id"] = str(uuid.uuid4()) # useful code for testing to exit cleanly at this point. # self.acquisition_state_changed_event.fire(SequenceState.scanning) # self.acquisition_state_changed_event.fire(SequenceState.idle) # return camera_hardware_source = typing.cast(camera_base.CameraHardwareSource, self.__camera_hardware_source._hardware_source) camera_frame_parameters = camera_hardware_source.get_frame_parameters(0) camera_frame_parameters["processing"] = processing.value.processing_id grab_sync_info = scan_hardware_source.grab_synchronized_get_info( scan_frame_parameters=scan_frame_parameters, camera=camera_hardware_source, camera_frame_parameters=camera_frame_parameters) camera_data_channel = CameraDataChannel(self.__document_controller.library._document_model, camera_hardware_source.display_name, grab_sync_info) self.__document_controller.display_data_item(Facade.DataItem(camera_data_channel.data_item)) camera_data_channel.start() drift_correction_behavior : typing.Optional[DriftCorrectionBehavior] = None section_height = None if self.__scan_specifier.drift_interval_lines > 0: drift_correction_behavior = DriftCorrectionBehavior(document_window.library._document_model, scan_hardware_source, scan_frame_parameters) section_height = self.__scan_specifier.drift_interval_lines def grab_synchronized(): self.acquisition_state_changed_event.fire(SequenceState.scanning) try: combined_data = scan_hardware_source.grab_synchronized(scan_frame_parameters=scan_frame_parameters, camera=camera_hardware_source, camera_frame_parameters=camera_frame_parameters, camera_data_channel=camera_data_channel, scan_behavior=drift_correction_behavior, section_height=section_height) if combined_data is not None: scan_data_list, camera_data_list = combined_data def create_and_display_data_item_task(): # this will be executed in UI thread for data_and_metadata in scan_data_list: create_and_display_data_item(document_window, data_and_metadata) # queue the task to be executed in UI thread document_window.queue_task(create_and_display_data_item_task) finally: def stop_channel(): camera_data_channel.stop() document_window.queue_task(stop_channel) self.acquisition_state_changed_event.fire(SequenceState.idle) self.__thread = threading.Thread(target=grab_synchronized) self.__thread.start()
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller selected_display_item = document_controller.selected_display_item data_item = (selected_display_item.data_items[0] if selected_display_item and len(selected_display_item.data_items) > 0 else None) if data_item: api_data_item = Facade.DataItem(data_item) if not api_data_item.xdata.is_data_4d: self.__show_tool_tips('wrong_shape') return average_data_item = self.__api.library.create_data_item( title='Frame average of ' + data_item.title) computation = self.__api.library.create_computation( 'nion.calculate_4d_average', inputs={'src': api_data_item}, outputs={'target': average_data_item}) computation._computation.source = average_data_item._data_item average_display_item = document_controller.document_model.get_display_item_for_data_item( average_data_item._data_item) document_controller.show_display_item(average_display_item) spectrum_graphic = average_data_item.add_rectangle_region( 0.5, 0.5, 0.1, 1.0) spectrum_graphic.label = 'Spectrum' bottom_dark_graphic = average_data_item.add_rectangle_region( 0.7, 0.5, 0.1, 1.0) bottom_dark_graphic.label = 'Bottom dark area' top_dark_graphic = average_data_item.add_rectangle_region( 0.3, 0.5, 0.1, 1.0) top_dark_graphic.label = 'Top dark area' spectrum_graphic._graphic.is_bounds_constrained = True bottom_dark_graphic._graphic.is_bounds_constrained = True top_dark_graphic._graphic.is_bounds_constrained = True dark_corrected_data_item = Facade.DataItem( DataItem.DataItem(large_format=True)) self.__api.library._document_model.append_data_item( dark_corrected_data_item._data_item) dark_corrected_data_item._data_item.session_id = self.__api.library._document_model.session_id dark_corrected_data_item.title = 'Framewise dark correction of ' + data_item.title computation = self.__api.library.create_computation( 'nion.framewise_dark_correction', inputs={ 'src1': api_data_item, 'src2': average_data_item, 'spectrum_region': spectrum_graphic, 'top_dark_region': top_dark_graphic, 'bottom_dark_region': bottom_dark_graphic, 'bin_spectrum': True, 'gain_image': [], 'gain_mode': 'custom' }, outputs={'target': dark_corrected_data_item}) computation._computation.source = dark_corrected_data_item._data_item dark_corrected_display_item = document_controller.document_model.get_display_item_for_data_item( dark_corrected_data_item._data_item) document_controller.show_display_item(dark_corrected_display_item) self.__computation_data_items.update({ data_item: 'source', average_data_item._data_item: 'average', dark_corrected_data_item._data_item: 'corrected' }) self.__show_tool_tips() self.__display_item_changed_event_listener = ( document_controller.focused_display_item_changed_event.listen( self.__display_item_changed))
def menu_item_execute(self, window: API.DocumentWindow) -> None: document_controller = window._document_controller selected_display_item = document_controller.selected_display_item data_item = (selected_display_item.data_items[0] if selected_display_item and len(selected_display_item.data_items) > 0 else None) if data_item: api_data_item = Facade.DataItem(data_item) ds = None if not api_data_item.xdata.metadata.get('libertem-io'): executor = Registry.get_component('libertem_executor') if not executor: return ds = LiberTEMAdapter( self.__api, executor).niondata_to_libertemdata(api_data_item) if not api_data_item.xdata.metadata.get('libertem-io'): self.__show_tool_tips('wrong_shape') return map_data_item = self.__api.library.create_data_item( title='Map 4D of ' + data_item.title) display_item = document_controller.document_model.get_display_item_for_data_item( map_data_item._data_item) show_display_item(window, display_item) map_regions = list() for graphic in api_data_item.graphics: if graphic._graphic.role == 'mask': map_regions.append(graphic) computation = self.__api.library.create_computation( 'nion.libertem.map_4d', inputs={ 'src': api_data_item, 'map_regions': map_regions }, outputs={'target': map_data_item}) computation._computation.source = data_item if ds is not None: computation._computation.ds = ds map_display_item = document_controller.document_model.get_display_item_for_data_item( map_data_item) document_controller.show_display_item(map_display_item) pick_graphic = map_data_item.add_point_region(0.5, 0.5) pick_graphic.label = 'Pick' threading.Thread(target=self.__connect_pick_graphic, args=(api_data_item, map_data_item, pick_graphic, computation._computation, 30), daemon=True).start() self.__computation_data_items.update({ str(data_item.uuid): 'source', str(map_data_item._data_item.uuid): 'map_4d' }) self.__api.application.document_controllers[ 0]._document_controller.ui.set_persistent_string( 'libertem_map4d_data_items_0', json.dumps(self.__computation_data_items)) self.__show_tool_tips()
def display_data_item( document_controller: DocumentController.DocumentController, data_item: DataItem.DataItem) -> None: Facade.DocumentWindow(document_controller).display_data_item( Facade.DataItem(data_item))