Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions dpx/srxplanargui/datacontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete unused imports

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):
Expand Down
110 changes: 50 additions & 60 deletions dpx/srxplanargui/imageplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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; <Ctrl>+Click: remove a vertex; \n <Enter>: finish the selection"
self.plot.title = ("Click: add a vertex;"
"<Ctrl>+Click: remove a vertex;"
"\n <Enter>: finish the selection")
return

def _disableMaskEditing(self):
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -506,7 +485,8 @@ def __init__(self, **kwargs):
return

hinttext = Str(
"Zoom: <z>; Reset: <Esc>; Pan: <drag/drop>; Toggle XY coordinates: <P>"
"Zoom: <z>; Reset: <Esc>;"
"Pan: <drag/drop>; Toggle XY coordinates: <P>"
)
traits_view = View(
Group(
Expand Down Expand Up @@ -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(
Expand Down
63 changes: 6 additions & 57 deletions dpx/srxplanargui/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down