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..67641ea 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):