Skip to content

Commit

Permalink
Merge pull request #22 from ngergihun/imagedatatype
Browse files Browse the repository at this point in the history
[ENH] Signal type attribute usage in preprocessors + fixes for linelevel combobox
  • Loading branch information
markotoplak authored Oct 3, 2024
2 parents 31c76b8 + ca8c022 commit 11da7b9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 46 deletions.
9 changes: 5 additions & 4 deletions orangecontrib/snom/widgets/preprocessors/background_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from orangecontrib.spectroscopy.widgets.preprocessors.utils import BaseEditorOrange
from orangecontrib.spectroscopy.widgets.gui import lineEditIntRange

from pySNOM.images import BackgroundPolyFit
from pySNOM.images import BackgroundPolyFit, DataTypes

from orangecontrib.snom.preprocess.utils import (
PreprocessImageOpts2DOnlyWhole,
Expand All @@ -17,9 +17,10 @@ def __init__(self, xorder=1, yorder=1):
self.yorder = yorder

def transform_image(self, image, data):
d, b = BackgroundPolyFit(xorder=self.xorder, yorder=self.yorder).transform(
image
)
datatype = data.attributes.get("measurement.signaltype", "Phase")
d, b = BackgroundPolyFit(
xorder=self.xorder, yorder=self.yorder, datatype=DataTypes[datatype]
).transform(image)
return d


Expand Down
23 changes: 15 additions & 8 deletions orangecontrib/snom/widgets/preprocessors/linelevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from orangewidget.gui import comboBox

from pySNOM.images import LineLevel
from pySNOM.images import LineLevel, DataTypes

from orangecontrib.spectroscopy.widgets.preprocessors.utils import BaseEditorOrange

Expand All @@ -17,7 +17,10 @@ def __init__(self, method="median"):
self.method = method

def transform_image(self, image, data):
return LineLevel(method=self.method).transform(image)
datatype = data.attributes.get("measurement.signaltype", "Phase")
return LineLevel(method=self.method, datatype=DataTypes[datatype]).transform(
image
)


class LineLevelEditor(BaseEditorOrange):
Expand All @@ -30,22 +33,26 @@ def __init__(self, parent=None, **kwargs):
self.method = 'median'

form = QFormLayout()
levelmethod = comboBox(self, self, "method", callback=self.edited.emit)
levelmethod.addItems(['median', 'mean', 'difference'])
form.addRow("Leveling method", levelmethod)
self.levelmethod_cb = comboBox(self, self, "method", callback=self.setmethod)
self.levelmethod_cb.addItems(['median', 'mean', 'difference'])
form.addRow("Leveling method", self.levelmethod_cb)
self.controlArea.setLayout(form)

def activateOptions(self):
pass # actions when user starts changing options

def setmethod(self):
self.method = self.levelmethod_cb.currentText()
self.edited.emit()

def setParameters(self, params):
self.levelmethod = params.get("levelmethod", "median")
self.method = params.get("method", "median")

@classmethod
def createinstance(cls, params):
params = dict(params)
levelmethod = params.get("levelmethod", "median")
return LineLevelProcessor(method=levelmethod)
method = params.get("method", "median")
return LineLevelProcessor(method=method)

def set_preview_data(self, data):
if data:
Expand Down
8 changes: 5 additions & 3 deletions orangecontrib/snom/widgets/preprocessors/self_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
REFERENCE_DATA_PARAM,
)

from pySNOM.images import SelfReference
from pySNOM.images import SelfReference, DataTypes

from orangecontrib.snom.preprocess.utils import (
PreprocessImageOpts2DOnlyWholeReference,
Expand All @@ -21,8 +21,10 @@ def __init__(self, reference):
raise MissingReferenceException("Self-referencing needs a reference")

def transform_image(self, image, ref_image, data):
d = SelfReference(referencedata=ref_image).transform(image)
return d
datatype = data.attributes.get("measurement.signaltype", "Phase")
return SelfReference(
referencedata=ref_image, datatype=DataTypes[datatype]
).transform(image)


class SelfRefEditor(BaseEditorOrange):
Expand Down
43 changes: 12 additions & 31 deletions orangecontrib/snom/widgets/preprocessors/simple_normalize.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
from AnyQt.QtWidgets import QFormLayout

from Orange.data import Domain
from Orange.preprocess import Preprocess
from orangecontrib.snom.widgets.preprocessors.registry import preprocess_image_editors

from orangecontrib.spectroscopy.preprocess import SelectColumn, CommonDomain

from orangecontrib.spectroscopy.widgets.preprocessors.utils import BaseEditorOrange
from orangecontrib.spectroscopy.widgets.gui import lineEditFloatRange
from orangewidget.gui import comboBox

from pySNOM.images import SimpleNormalize


class AddFeature(SelectColumn):
InheritEq = True
from pySNOM.images import SimpleNormalize, DataTypes


class _SimpleNormCommon(CommonDomain):
def __init__(self, method, value, domain):
super().__init__(domain)
self.method = method
self.value = value
# print(value,method)

def transformed(self, data):
return SimpleNormalize(method=self.method, value=self.value).transform(data.X)
from orangecontrib.snom.widgets.preprocessors.registry import preprocess_image_editors
from orangecontrib.snom.preprocess.utils import (
PreprocessImageOpts2DOnlyWhole,
)


class SimpleNorm(Preprocess):
def __init__(self, method='median', value=1.0):
class SimpleNorm(PreprocessImageOpts2DOnlyWhole):
def __init__(self, method, value):
self.method = method
self.value = value

def __call__(self, data):
common = _SimpleNormCommon(self.method, self.value, data.domain)
atts = [
a.copy(compute_value=AddFeature(i, common))
for i, a in enumerate(data.domain.attributes)
]
domain = Domain(atts, data.domain.class_vars, data.domain.metas)
return data.from_table(domain, data)
def transform_image(self, image, data):
datatype = data.attributes.get("measurement.signaltype", "Phase")
return SimpleNormalize(
method=self.method, value=self.value, datatype=DataTypes[datatype]
).transform(image)


class SimpleNormEditor(BaseEditorOrange):
Expand Down

0 comments on commit 11da7b9

Please sign in to comment.