From 7f6c7057ea62f9a78641296e817f76b688904d2c Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Mon, 22 Sep 2025 21:38:31 -0400 Subject: [PATCH 1/3] fix E402 E711 issue --- dpx/srxplanargui/datacontainer.py | 27 +------- dpx/srxplanargui/imageplot.py | 110 ++++++++++++++---------------- dpx/srxplanargui/live.py | 63 ++--------------- 3 files changed, 57 insertions(+), 143 deletions(-) diff --git a/dpx/srxplanargui/datacontainer.py b/dpx/srxplanargui/datacontainer.py index 16692cd..d8cab2b 100644 --- a/dpx/srxplanargui/datacontainer.py +++ b/dpx/srxplanargui/datacontainer.py @@ -14,32 +14,7 @@ import os -import numpy as np -from traits.api import ( - Any, - Array, - Bool, - Button, - CFloat, - CInt, - DelegatesTo, - Dict, - Directory, - Enum, - Event, - File, - Float, - HasTraits, - Instance, - Int, - List, - Property, - Range, - Str, - cached_property, - on_trait_change, - property_depends_on, -) +from traits.api import File, HasTraits, Property, property_depends_on class DataContainer(HasTraits): diff --git a/dpx/srxplanargui/imageplot.py b/dpx/srxplanargui/imageplot.py index 0d97f43..369dbfa 100644 --- a/dpx/srxplanargui/imageplot.py +++ b/dpx/srxplanargui/imageplot.py @@ -20,68 +20,37 @@ from chaco.tools.image_inspector_tool import ImageInspectorOverlay, ImageInspectorTool # Chaco imports -from enable.api import BaseTool, Component, ComponentEditor, KeySpec -from enable.colors import ColorTrait +from enable.api import Component, ComponentEditor, KeySpec from kiva.agg import points_in_polygon -from pyface.api import ImageResource, SplashScreen +from pyface.api import ImageResource # Enthought library imports from traits.api import ( Any, - Array, Bool, Button, - CFloat, - CInt, DelegatesTo, - Dict, - Directory, Enum, - Event, File, Float, HasTraits, Instance, Int, - List, - Property, - Range, Str, - cached_property, - on_trait_change, - property_depends_on, ) from traitsui.api import ( Action, ArrayEditor, - ButtonEditor, - CheckListEditor, - Controller, - EnumEditor, Group, Handler, HGroup, - HistoryEditor, - ImageEditor, - InstanceEditor, Item, RangeEditor, - Tabbed, - TableEditor, - TextEditor, - TitleEditor, VGroup, View, spring, ) -from traitsui.menu import ( - CancelButton, - Menu, - MenuBar, - OKButton, - OKCancelButtons, - ToolBar, -) +from traitsui.menu import CancelButton, OKButton class SaveLoadMaskHandler(Handler): @@ -129,34 +98,41 @@ class ImagePlot(HasTraits): ) avgmask = DelegatesTo( "srxconfig", - desc="Mask the pixels too bright or too dark compared to the average intensity at the similar diffraction angle", + desc="Mask the pixels too bright or too dark compared to" + "the average intensity at the similar diffraction angle", ) brightpixelr = DelegatesTo( "srxconfig", - desc="Pixels with intensity large than this relative threshold (times the local environment) value will be masked", + desc="Pixels with intensity large than this relative threshold" + "(times the local environment) value will be masked", ) brightpixelsize = DelegatesTo( "srxconfig", desc="Size of testing area for detecting bright pixels" ) darkpixelr = DelegatesTo( "srxconfig", - desc="Pixels with intensity less than this relative threshold (times the local environment) value will be masked", + desc="Pixels with intensity less than this relative threshold" + "(times the local environment) value will be masked", ) avgmaskhigh = DelegatesTo( "srxconfig", - desc="Comparing to the average intensity at similar diffraction angle, \npixels with intensity larger than avg_int*high will be masked", + desc="Comparing to the average intensity at similar diffraction angle," + "\npixels with intensity larger than avg_int*high will be masked", ) avgmasklow = DelegatesTo( "srxconfig", - desc="Comparing to the average intensity at similar diffraction angle, \npixels with intensity less than avg_int*low will be masked", + desc="Comparing to the average intensity at similar diffraction angle," + "\npixels with intensity less than avg_int*low will be masked", ) cropedges = DelegatesTo( "srxconfig", - desc="The number of pixels masked at each edge (left, right, top, bottom)", + desc="The number of pixels masked" + "at each edge (left, right, top, bottom)", ) def createPlot(self): - # image = np.log(self.srx.loadimage.loadImage(self.imagefile)) + # image = np.log(self.srx.loadimage. + # loadImage(self.imagefile)) image = self.srx.loadimage.loadImage(self.imagefile) self.maskfile = self.srxconfig.maskfile self.imageorg = image @@ -224,12 +200,13 @@ def refreshMaskFile(self): return def mergeMask(self, points, remove=None): + """Param points -- a Mx2 array of x,y point pairs (floating + point) that define the boundaries of a polygon. + + param remove -- True for remove the new mask from the existing + mask """ - :param points: an Mx2 array of x,y point pairs (floating point) that define the - boundaries of a polygon. - :param remove: True for remove the new mask from the existing mask - """ - if remove == None: + if remove is None: remove = self.removepolygonmask if len(points) > 2: mask = points_in_polygon(self.pts, points) @@ -273,7 +250,7 @@ def invertMask(self): def refreshMask(self, staticmask=None, draw=True): self.staticmask = ( - self.srx.mask.staticMask() if staticmask == None else staticmask + self.srx.mask.staticMask() if staticmask is None else staticmask ) self.dynamicmask = self.srx.mask.dynamicMask( self.imageorg, dymask=self.staticmask @@ -336,7 +313,9 @@ def _enableMaskEditing(self): self.plot.tools.remove(self.pan) self.plot.overlays.append(self.lstool) self.titlebak = self.plot.title - self.plot.title = "Click: add a vertex; +Click: remove a vertex; \n : finish the selection" + self.plot.title = ("Click: add a vertex;" + "+Click: remove a vertex;" + "\n : finish the selection") return def _disableMaskEditing(self): @@ -366,7 +345,7 @@ def _disablePointMaskEditing(self): def refreshImage(self, mask=None, draw=True): """Recalculate the image using self.mask or mask and refresh display.""" - mask = self.mask if mask == None else mask + mask = self.mask if mask is None else mask image = self.applyScale() image = image * np.logical_not(mask) + image.max() * mask self.pd.set_data("imagedata", image) @@ -380,14 +359,14 @@ def refreshImage(self, mask=None, draw=True): def applyScale(self, image=None): """Apply the scale to increase/decrease contrast.""" if self.scalemode == "linear": - if image == None: + if image is None: image = self.imageorg intmax = self.imageorgmax else: image = image intmax = image.max() elif self.scalemode == "log": - if image == None: + if image is None: image = self.imageorglog intmax = self.imageorglogmax else: @@ -506,7 +485,8 @@ def __init__(self, **kwargs): return hinttext = Str( - "Zoom: ; Reset: ; Pan: ; Toggle XY coordinates:

" + "Zoom: ; Reset: ;" + "Pan: ; Toggle XY coordinates:

" ) traits_view = View( Group( @@ -689,14 +669,24 @@ def normal_left_down(self, event): class AdvHint(HasTraits): advhinttext = str( - """Notes: Advanced Masks are generated during the integration and refreshed for each image. -You can preview the masks here or apply the current masks to the static mask permanently. - -Edge mask: mask the pixels around the image edge. (left, right, top, bottom) -Dark pixel mask: mask the pixels too dark compared to their local environment -Bright pixel mask: mask the pixels too bright compared to their local environment -Average mask: Mask the pixels too bright or too dark compared to the average intensity - at the similar diffraction angle. Currect calibration information is required.""" + """Notes: Advanced Masks are generated during the integration + and refreshed for each image. + You can preview the masks here or apply the current masks + to the static mask permanently. + + Edge mask: mask the pixels around the image edge. + (left, right, top, bottom) + + Dark pixel mask: mask the pixels too dark + compared to their local environment. + + + Bright pixel mask: mask the pixels too bright + compared to their local environment. + + Average mask: Mask the pixels too bright or too dark + compared to the average intensity at the similar diffraction angle. + Currect calibration information is required.""" ) advhint_view = View( diff --git a/dpx/srxplanargui/live.py b/dpx/srxplanargui/live.py index d9a0a2b..f163a28 100644 --- a/dpx/srxplanargui/live.py +++ b/dpx/srxplanargui/live.py @@ -14,82 +14,31 @@ """Provide UI for srxplanar.""" import os -import re import sys -import threading -import time -from functools import partial -import numpy as np -from traits.etsconfig.api import ETSConfig - -ETSConfig.toolkit = "qt4" - -from diffpy.srxconfutils.tools import checkFileVal from diffpy.srxplanar.srxplanar import SrXplanar from pyface.api import GUI, ImageResource, SplashScreen -from traits.api import ( - Any, - Array, - Bool, - Button, - CFloat, - CInt, - DelegatesTo, - Dict, - Directory, - Enum, - Event, - File, - Float, - HasTraits, - Instance, - Int, - List, - Property, - Range, - Str, - cached_property, - on_trait_change, - property_depends_on, -) +from traits.api import Any, on_trait_change +from traits.etsconfig.api import ETSConfig from traitsui.api import ( Action, - ArrayEditor, - ButtonEditor, - CheckListEditor, - Controller, - EnumEditor, Group, - Handler, HGroup, - HistoryEditor, - ImageEditor, InstanceEditor, Item, - RangeEditor, - Tabbed, - TableEditor, - TextEditor, - TitleEditor, VGroup, View, spring, ) -from traitsui.menu import ( - CancelButton, - Menu, - MenuBar, - OKButton, - OKCancelButtons, - ToolBar, -) +from traitsui.menu import OKButton from dpx.srxplanargui.calibration import Calibration from dpx.srxplanargui.help import SrXguiHelp from dpx.srxplanargui.selectfiles import AddFiles from dpx.srxplanargui.srxconfig import SrXconfig -from dpx.srxplanargui.srxgui import LoadHandler, SaveHandler, SrXgui, SrXguiHandler +from dpx.srxplanargui.srxgui import SrXgui, SrXguiHandler + +ETSConfig.toolkit = "qt" class SrXguiLive(SrXgui): From 24b3f71ed4bd8c15b4c6a6028e8eb5fc03a15140 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 23 Sep 2025 12:29:33 -0400 Subject: [PATCH 2/3] Fix corrected version of string --- dpx/srxplanargui/imageplot.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dpx/srxplanargui/imageplot.py b/dpx/srxplanargui/imageplot.py index 369dbfa..0dee91b 100644 --- a/dpx/srxplanargui/imageplot.py +++ b/dpx/srxplanargui/imageplot.py @@ -99,12 +99,12 @@ class ImagePlot(HasTraits): avgmask = DelegatesTo( "srxconfig", desc="Mask the pixels too bright or too dark compared to" - "the average intensity at the similar diffraction angle", + + "the average intensity at the similar diffraction angle", ) brightpixelr = DelegatesTo( "srxconfig", desc="Pixels with intensity large than this relative threshold" - "(times the local environment) value will be masked", + + "(times the local environment) value will be masked", ) brightpixelsize = DelegatesTo( "srxconfig", desc="Size of testing area for detecting bright pixels" @@ -112,22 +112,22 @@ class ImagePlot(HasTraits): darkpixelr = DelegatesTo( "srxconfig", desc="Pixels with intensity less than this relative threshold" - "(times the local environment) value will be masked", + + "(times the local environment) value will be masked", ) avgmaskhigh = DelegatesTo( "srxconfig", desc="Comparing to the average intensity at similar diffraction angle," - "\npixels with intensity larger than avg_int*high will be masked", + + "\npixels with intensity larger than avg_int*high will be masked", ) avgmasklow = DelegatesTo( "srxconfig", desc="Comparing to the average intensity at similar diffraction angle," - "\npixels with intensity less than avg_int*low will be masked", + + "\npixels with intensity less than avg_int*low will be masked", ) cropedges = DelegatesTo( "srxconfig", desc="The number of pixels masked" - "at each edge (left, right, top, bottom)", + + "at each edge (left, right, top, bottom)", ) def createPlot(self): @@ -314,8 +314,8 @@ def _enableMaskEditing(self): self.plot.overlays.append(self.lstool) self.titlebak = self.plot.title self.plot.title = ("Click: add a vertex;" - "+Click: remove a vertex;" - "\n : finish the selection") + + "+Click: remove a vertex;" + + "\n : finish the selection") return def _disableMaskEditing(self): From 9e2b410dfaa92dfe231ad4f238d1b3eace8501c9 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 23 Sep 2025 13:55:10 -0400 Subject: [PATCH 3/3] change string representation --- dpx/srxplanargui/imageplot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dpx/srxplanargui/imageplot.py b/dpx/srxplanargui/imageplot.py index 0dee91b..67641ea 100644 --- a/dpx/srxplanargui/imageplot.py +++ b/dpx/srxplanargui/imageplot.py @@ -99,12 +99,12 @@ class ImagePlot(HasTraits): avgmask = DelegatesTo( "srxconfig", desc="Mask the pixels too bright or too dark compared to" - + "the average intensity at the similar diffraction angle", + + " the average intensity at the similar diffraction angle", ) brightpixelr = DelegatesTo( "srxconfig", desc="Pixels with intensity large than this relative threshold" - + "(times the local environment) value will be masked", + + " (times the local environment) value will be masked", ) brightpixelsize = DelegatesTo( "srxconfig", desc="Size of testing area for detecting bright pixels" @@ -112,7 +112,7 @@ class ImagePlot(HasTraits): darkpixelr = DelegatesTo( "srxconfig", desc="Pixels with intensity less than this relative threshold" - + "(times the local environment) value will be masked", + + " (times the local environment) value will be masked", ) avgmaskhigh = DelegatesTo( "srxconfig", @@ -127,7 +127,7 @@ class ImagePlot(HasTraits): cropedges = DelegatesTo( "srxconfig", desc="The number of pixels masked" - + "at each edge (left, right, top, bottom)", + + " at each edge (left, right, top, bottom)", ) def createPlot(self): @@ -314,8 +314,8 @@ def _enableMaskEditing(self): self.plot.overlays.append(self.lstool) self.titlebak = self.plot.title self.plot.title = ("Click: add a vertex;" - + "+Click: remove a vertex;" - + "\n : finish the selection") + "+Click: remove a vertex;" + "\n : finish the selection") return def _disableMaskEditing(self):