Skip to content

Commit

Permalink
linelevel: arrange results too
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Sep 26, 2024
1 parent 266f904 commit 626664d
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions orangecontrib/snom/widgets/preprocessors/linelevel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from AnyQt.QtWidgets import QFormLayout

from Orange.data import Domain
from orangecontrib.spectroscopy.utils import get_hypercube

from orangewidget.gui import comboBox

Expand All @@ -14,6 +14,25 @@
from orangecontrib.snom.widgets.preprocessors.utils import PreprocessImageOpts


def get_ndim_hyperspec(data, attrs):
# mostly copied from orangecontrib.spectroscopy.utils,
# but returns the indices too
ndom = Domain(attrs)
datam = data.transform(ndom)

from orangecontrib.spectroscopy.utils import axes_to_ndim_linspace

ls, indices = axes_to_ndim_linspace(datam, attrs)

# set data
new_shape = tuple([lsa[2] for lsa in ls]) + (data.X.shape[1],)
hyperspec = np.ones(new_shape) * np.nan

hyperspec[indices] = data.X

return hyperspec, ls, indices


class _LineLevelCommon(CommonDomain):
def __init__(self, method, domain, image_opts):
super().__init__(domain)
Expand All @@ -26,11 +45,10 @@ def transformed(self, data):
data = data.transform(ndom)
xat = data.domain[self.image_opts["attr_x"]]
yat = data.domain[self.image_opts["attr_y"]]
hypercube, lsx, lsy = get_hypercube(data, xat, yat)
hypercube, _, indices = get_ndim_hyperspec(data, (xat, yat))
transformed = LineLevel(method=self.method).transform(hypercube[:, :, 0])
print(transformed)
# TODO transform the resulting matrix back to original indices;
# for this the get_hypercube will need to return an actual index matrix
out = transformed[indices].reshape(len(data), -1)
return out


class LineLevelProcessor(PreprocessImageOpts):
Expand Down

0 comments on commit 626664d

Please sign in to comment.