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)) class Map4DExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.map_4d" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__menu_item_ref = api.create_menu_item(Map4DMenuItem(api)) def close(self): self.__menu_item_ref.close() Symbolic.register_computation_type('nion.map_4d.2', Map4D)
"fit_interval_graphics": fit_interval_graphics, "signal_interval_graphic": signal_interval_graphic, "background_model": background_model, }, outputs={"map": map}) window.display_data_item(map) break def subtract_background_from_signal(api, window): window._document_controller.event_loop.create_task( use_interval_as_background(api, window)) Symbolic.register_computation_type("eels.background_subtraction3", EELSBackgroundSubtraction) Symbolic.register_computation_type("eels.mapping3", EELSMapping) BackgroundModel = Schema.entity("background_model", None, None, {}) def component_registered(component, component_types): if "background-model" in component_types: # when a background model is registered, create an empty (for now) entity type, and register it with the data # structure so that an entity for use with the UI and computations can be created when the data structure loads. background_model_entity = Schema.entity(component.background_model_id, BackgroundModel, None, {}) DataStructure.DataStructure.register_entity( background_model_entity, entity_name=component.title, entity_package_name=component.package_title)
'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)) class DarkCorrection4DExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.4d_dark_correction" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__menu_item_ref = api.create_menu_item(DarkCorrection4DMenuItem(api)) def close(self): self.__menu_item_ref.close() Symbolic.register_computation_type('nion.total_bin_4d_SI', TotalBin4D) Symbolic.register_computation_type('nion.dark_correction_4d', DarkCorrection4D)
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)) class Map4DExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.map_4d_rgb" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__menu_item_ref = api.create_menu_item(Map4DRGBMenuItem(api)) def close(self): self.__menu_item_ref.close() Symbolic.register_computation_type('nion.map_4d_rgb.2', Map4DRGB)
self.computation.set_referenced_xdata("gain_data_item", self.__gain_xdata) self.computation.set_referenced_xdata("gain_fit_data_item", self.__gain_fit_xdata) self.computation.set_referenced_xdata("difference_data_item", self.__difference_xdata) gain_fit_display_item = self.computation.get_result( "gain_fit_data_item").display._display_item gain_fit_display_item._set_display_layer_properties( 0, label= _(f"Fit T = {self.__fit[0] - 273.15:.0f} °C \nZLP shift = {self.__fit[1]*1000.0:.2f} meV" )) Symbolic.register_computation_type("eels.measure_temperature", MeasureTemperature) def measure_temperature(api: API.API, window: API.DocumentWindow): selected_display_items = window._document_controller._get_two_data_sources( ) document_model = window._document_controller.document_model error_msg = "Select two data items each containing one EEL spectrum in order to use this computation." assert selected_display_items[0][0] is not None, error_msg assert selected_display_items[1][0] is not None, error_msg assert selected_display_items[0][0].data_item is not None, error_msg assert selected_display_items[1][0].data_item is not None, error_msg assert selected_display_items[0][0].data_item.is_data_1d, error_msg assert selected_display_items[1][0].data_item.is_data_1d, error_msg # First find out which data item is near and which is far. Far should have the higher maximum.
aligned_haadf = api.library.create_data_item_from_data(numpy.zeros((1,1,1)), title="Aligned {}".format(haadf_sequence_data_item.title)) aligned_si = api.library.create_data_item_from_data(numpy.zeros((1,1,1)), title="Aligned {}".format(si_sequence_data_item.title)) inputs = {"si_sequence_data_item": api._new_api_object(si_sequence_data_item), "haadf_sequence_data_item": api._new_api_object(haadf_sequence_data_item), "align_index": align_index} if align_region: inputs["align_region"] = api._new_api_object(align_region) computation = api.library.create_computation("eels.align_multi_si", inputs=inputs, outputs={"aligned_haadf": aligned_haadf, "aligned_si": aligned_si}) computation._computation.source = aligned_si._data_item window.display_data_item(aligned_haadf) window.display_data_item(aligned_si) Symbolic.register_computation_type("eels.align_multi_si", AlignMultiSI) class AlignMultiSIMenuItemDelegate: def __init__(self, api): self.__api = api self.menu_id = "eels_menu" # required, specify menu_id where this item will go self.menu_name = _("EELS") # optional, specify default name if not a standard menu self.menu_before_id = "window_menu" # optional, specify before menu_id if not a standard menu self.menu_item_name = _("Align sequence of spectrum images") # menu item name def menu_item_execute(self, window): align_multi_si(self.__api, window)
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)) class FramewiseDarkExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.framewise_dark_correction" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__menu_item_ref = api.create_menu_item(FramewiseDarkMenuItem(api)) def close(self): self.__menu_item_ref.close() Symbolic.register_computation_type('nion.calculate_4d_average', CalculateAverage4D) Symbolic.register_computation_type('nion.framewise_dark_correction', FramewiseDarkCorrection)
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 class SequenceSplitJoinExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.sequence_split_join" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__join_menu_item_ref = api.create_menu_item( SequenceJoinMenuItem(api)) self.__split_menu_item_ref = api.create_menu_item( SequenceSplitMenuItem(api)) def close(self): self.__join_menu_item_ref.close() self.__split_menu_item_ref.close() Symbolic.register_computation_type("nion.join_sequence", SequenceJoin) Symbolic.register_computation_type("nion.split_sequence", SequenceSplit)
# required for Swift to recognize this as an extension class. extension_id = "nion.extension.make_color_com" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__idpc_menu_item_ref = api.create_menu_item( MakeColorCOMMenuItem(api)) def close(self): self.__idpc_menu_item_ref.close() Symbolic.register_computation_type("nion.make_color_com", MakeColorCOM) hsv_cyclic_colormap = numpy.array( [[255, 0, 0], [255, 6, 0], [255, 12, 0], [255, 18, 0], [255, 24, 0], [255, 30, 0], [255, 35, 0], [255, 41, 0], [255, 47, 0], [255, 53, 0], [255, 59, 0], [255, 65, 0], [255, 71, 0], [255, 77, 0], [255, 83, 0], [255, 89, 0], [255, 95, 0], [255, 100, 0], [255, 106, 0], [255, 112, 0], [255, 118, 0], [255, 124, 0], [255, 130, 0], [255, 136, 0], [255, 142, 0], [255, 148, 0], [255, 154, 0], [255, 159, 0], [255, 165, 0], [255, 171, 0], [255, 177, 0], [255, 183, 0], [255, 189, 0], [255, 195, 0], [255, 201, 0], [255, 207, 0], [255, 213, 0], [255, 219, 0], [255, 224, 0], [255, 230, 0], [255, 236, 0], [254, 241, 0], [252, 245, 0], [250, 249, 0], [248, 253, 0], [244, 255, 0], [238, 255, 0], [232, 255, 0], [226, 255, 0], [221, 255, 0], [215, 255, 0], [209, 255, 0], [203, 255, 0], [197, 255, 0], [191, 255, 0], [185, 255, 0], [179, 255, 0], [173, 255, 0], [167, 255, 0], [162, 255, 0], [156, 255, 0], [150, 255, 0], [144, 255, 0], [138, 255, 0], [132, 255, 0],
dimensional_calibrations = src_xdata.dimensional_calibrations[0:-1] return DataAndMetadata.new_data_and_metadata(data, dimensional_calibrations=dimensional_calibrations) class EELSThicknessMapping: def __init__(self, computation, **kwargs): self.computation = computation def execute(self, spectrum_image_data_item): def progress(row): print(f"Processing row {row} (thickness)") self.__mapped_xdata = map_thickness_xdata(spectrum_image_data_item.xdata, progress) def commit(self): self.computation.set_referenced_xdata("map", self.__mapped_xdata) 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) Symbolic.register_computation_type("eels.thickness_mapping", EELSThicknessMapping)
} computation = api.library.create_computation("nion.align_multi_d_sequence", inputs=inputs, outputs={ "aligned_haadf": aligned_haadf, "aligned_si": aligned_si }) computation._computation.source = aligned_si._data_item window.display_data_item(aligned_haadf) window.display_data_item(aligned_si) print('here3') Symbolic.register_computation_type("nion.align_multi_d_sequence", AlignMultiDimensionalSequence) class AlignSequenceMenuItemDelegate: def __init__(self, api): self.__api = api self.menu_id = "processing_menu" # required, specify menu_id where this item will go self.menu_name = _( "Processing" ) # optional, specify default name if not a standard menu self.menu_before_id = "window_menu" # optional, specify before menu_id if not a standard menu self.menu_item_name = _( "Align sequence of multi-dimensional data") # menu item name def menu_item_execute(self, window): align_multi_si(self.__api, window)
display_item._display_item._set_display_layer_properties( 2, label=_("Data"), fill_color="#1E90FF") display_item._display_item.set_display_property("legend_position", "top-right") def fit_zero_loss_peak(api: Facade.API_1, window: Facade.DocumentWindow) -> None: target_data_item = window.target_data_item target_display_item = window.target_display if target_data_item: add_peak_fitting_computation(api, window.library, target_display_item, target_data_item) Symbolic.register_computation_type("eels.fit_zlp", FitZeroLossPeak) ZeroLossPeakModel = Schema.entity("zlp_model", None, None, {}) def component_registered(component, component_types): if "zlp-model" in component_types: # when a background model is registered, create an empty (for now) entity type, and register it with the data # structure so that an entity for use with the UI and computations can be created when the data structure loads. zlp_model_entity = Schema.entity(component.zero_loss_peak_model_id, ZeroLossPeakModel, None, {}) DataStructure.DataStructure.register_entity( zlp_model_entity, entity_name=component.title, entity_package_name=component.package_title)
signal_interval_graphic = target_interval api.library.create_computation( "eels.mapping3", inputs={ "spectrum_image_data_item": spectrum_image, "fit_interval_graphics": fit_interval_graphics, "signal_interval_graphic": signal_interval_graphic, "background_model": background_model, }, outputs={"map": map}) window.display_data_item(map) break Symbolic.register_computation_type("eels.background_subtraction3", EELSFitBackground) Symbolic.register_computation_type("eels.mapping3", EELSMapBackgroundSubtractedSignal) Symbolic.register_computation_type("eels.subtract_background", EELSSubtractBackground) BackgroundModelEntity = Schema.entity("background_model", None, None, {}) def component_registered(component, component_types): if "background-model" in component_types: # when a background model is registered, create an empty (for now) entity type, and register it with the data # structure so that an entity for use with the UI and computations can be created when the data structure loads. background_model_entity = Schema.entity(component.background_model_id, BackgroundModelEntity, None, {})
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) class MakeIDPCExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.make_idpc" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__idpc_menu_item_ref = api.create_menu_item(MakeIDPCMenuItem(api)) def close(self): self.__idpc_menu_item_ref.close() Symbolic.register_computation_type("nion.make_idpc", MakeIDPC)
def register_computation(self) -> None: Symbolic.register_computation_type( self.processing_id, functools.partial(ProcessingComputation, self))
data_descriptor=data_item.xdata.data_descriptor), title="Affine Transformed {}".format(data_item.title)) self.__api.library.create_computation( "nion.affine_transform_image", inputs={ "src_data_item": data_item, "vector_a": [vector_a], "vector_b": [vector_b] }, outputs={"target": result_data_item}) window.display_data_item(result_data_item) class AffineTransformExtension: extension_id = "nion.extension.affine_transform" def __init__(self, api_broker): api = api_broker.get_api(version="1", ui_version="1") self.__affine_transform_menu_item_ref = api.create_menu_item( AffineTransformMenuItem(api)) self.__copy_affine_transform_menu_item_ref = api.create_menu_item( CopyAffineTransformMenuItem(api)) def close(self): self.__affine_transform_menu_item_ref.close() self.__copy_affine_transform_menu_item_ref.close() Symbolic.register_computation_type("nion.affine_transform_image", AffineTransformImage)
class FloatTupleToIntTupleConverter: def __init__(self, axis_size, axis_index): self.axis_size = axis_size self.axis_index = axis_index def convert(self, value): return int(value * self.axis_size) def convert_back(self, value): return (value[self.axis_index] + 0.5) / self.axis_size class Map4DExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.libertem_map_4d" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__menu_item_ref = api.create_menu_item(Map4DMenuItem(api)) def close(self): self.__menu_item_ref.close() Symbolic.register_computation_type('nion.libertem.map_4d', Map4D)
class FloatTupleToIntTupleConverter: def __init__(self, axis_size, axis_index): self.axis_size = axis_size self.axis_index = axis_index def convert(self, value): return int(value * self.axis_size) def convert_back(self, value): return (value[self.axis_index] + 0.5) / self.axis_size class Map4DExtension: # required for Swift to recognize this as an extension class. extension_id = "nion.extension.center_of_mass_4d" def __init__(self, api_broker): # grab the api object. api = api_broker.get_api(version="1", ui_version="1") # be sure to keep a reference or it will be closed immediately. self.__menu_item_ref = api.create_menu_item( CenterOfMass4DMenuItem(api)) def close(self): self.__menu_item_ref.close() Symbolic.register_computation_type('nion.center_of_mass_4d.2', CenterOfMass4D)