From 27e8f6f2aaad08c7a0a1c706df985fc672a6de3b Mon Sep 17 00:00:00 2001 From: Chris Meyer Date: Wed, 8 Nov 2023 15:46:19 -0800 Subject: [PATCH] Fix #988. Add a radial profile menu item to Fourier processing sub-menu. --- nion/swift/DocumentController.py | 14 ++++++++++++++ nion/swift/model/DocumentModel.py | 5 +++++ nion/swift/resources/changes.json | 4 ++++ nion/swift/resources/menu_config.json | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/nion/swift/DocumentController.py b/nion/swift/DocumentController.py index 6ca319c71..e1e2ae656 100755 --- a/nion/swift/DocumentController.py +++ b/nion/swift/DocumentController.py @@ -4693,6 +4693,19 @@ def invoke(self, context: Window.ActionContext) -> Window.ActionResult: return self.invoke_processing(context, context.model.get_projection_new) +class RadialProfileAction(ProcessingAction): + action_id = "processing.radial_profile" + action_name = _("Radial Profile") + + def execute(self, context: Window.ActionContext) -> Window.ActionResult: + context = typing.cast(DocumentController.ActionContext, context) + return self.execute_processing(context, context.model.get_radial_profile_new) + + def invoke(self, context: Window.ActionContext) -> Window.ActionResult: + context = typing.cast(DocumentController.ActionContext, context) + return self.invoke_processing(context, context.model.get_radial_profile_new) + + class RebinAction(ProcessingAction): action_id = "processing.rebin" action_name = _("Rebin") @@ -4966,6 +4979,7 @@ def is_enabled(self, context: Window.ActionContext) -> bool: Window.register_action(PickAverageAction()) Window.register_action(PickSumAction()) Window.register_action(ProjectionSumAction()) +Window.register_action(RadialProfileAction()) Window.register_action(RebinAction()) Window.register_action(ResampleAction()) Window.register_action(ResizeAction()) diff --git a/nion/swift/model/DocumentModel.py b/nion/swift/model/DocumentModel.py index a910b44f6..d51eaa8f0 100644 --- a/nion/swift/model/DocumentModel.py +++ b/nion/swift/model/DocumentModel.py @@ -2573,6 +2573,8 @@ def _get_builtin_processing_descriptions(cls) -> typing.Dict[str, typing.Any]: line_profile_in_region = {"name": "line_region", "type": "line", "params": {"label": _("Line Profile")}} vs["line-profile"] = {"title": _("Line Profile"), "expression": "xd.line_profile(xd.absolute({src}.element_xdata) if {src}.element_xdata.is_data_complex_type else {src}.element_xdata, line_region.vector, line_region.line_width)", "sources": [{"name": "src", "label": _("Source"), "regions": [line_profile_in_region]}]} + vs["radial-profile"] = {"title": _("Radial Profile"), "expression": "xd.radial_profile({src}.display_xdata)", + "sources": [{"name": "src", "label": _("Source"), "requirements": [requirement_2d]}]} vs["filter"] = {"title": _("Filter"), "expression": "xd.real(xd.ifft({src}.filtered_xdata))", "sources": [{"name": "src", "label": _("Source"), "requirements": [requirement_2d]}]} vs["sequence-register"] = {"title": _("Shifts"), "expression": "xd.sequence_squeeze_measurement(xd.sequence_measure_relative_translation({src}.xdata, {src}.xdata[numpy.unravel_index(0, {src}.xdata.navigation_dimension_shape)], 100))", @@ -2733,6 +2735,9 @@ def get_subtract_region_average_new(self, display_item: DisplayItem.DisplayItem, def get_line_profile_new(self, display_item: DisplayItem.DisplayItem, data_item: DataItem.DataItem, crop_region: typing.Optional[Graphics.Graphic]=None, line_region: typing.Optional[Graphics.Graphic]=None) -> typing.Optional[DataItem.DataItem]: return self.__make_computation("line-profile", [(display_item, data_item, crop_region)], {"src": [line_region]}) + def get_radial_profile_new(self, display_item: DisplayItem.DisplayItem, data_item: DataItem.DataItem, crop_region: typing.Optional[Graphics.Graphic]=None) -> typing.Optional[DataItem.DataItem]: + return self.__make_computation("radial-profile", [(display_item, data_item, crop_region)]) + def get_fourier_filter_new(self, display_item: DisplayItem.DisplayItem, data_item: DataItem.DataItem, crop_region: typing.Optional[Graphics.Graphic]=None) -> typing.Optional[DataItem.DataItem]: display_data_item = display_item.data_item if display_data_item and display_item: diff --git a/nion/swift/resources/changes.json b/nion/swift/resources/changes.json index a50862c4b..ec1704b3d 100644 --- a/nion/swift/resources/changes.json +++ b/nion/swift/resources/changes.json @@ -2,6 +2,10 @@ { "version": "Unreleased", "notes": [ + { + "issues": ["https://github.com/nion-software/nionswift/issues/988"], + "summary": "Add a radial profile menu item to Fourier processing sub-menu." + }, { "summary": "Expand About Box to include release notes and recent changes." }, diff --git a/nion/swift/resources/menu_config.json b/nion/swift/resources/menu_config.json index bf277e221..47f3fa1d1 100644 --- a/nion/swift/resources/menu_config.json +++ b/nion/swift/resources/menu_config.json @@ -479,6 +479,10 @@ "type": "item", "action_id": "processing.cross_correlate" }, + { + "type": "item", + "action_id": "processing.radial_profile" + }, { "type": "item", "action_id": "processing.fourier_filter"