-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
626664d
commit 68b1e73
Showing
4 changed files
with
69 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import numpy as np | ||
|
||
from Orange.data import Domain | ||
from Orange.preprocess import Preprocess | ||
from orangecontrib.spectroscopy.utils import InvalidAxisException, values_to_linspace, index_values | ||
|
||
|
||
class PreprocessImageOpts(Preprocess): | ||
pass | ||
|
||
|
||
def axes_to_ndim_linspace(coordinates): | ||
# modified to avoid domains as much as possible | ||
ls = [] | ||
indices = [] | ||
|
||
for i in range(coordinates.shape[1]): | ||
coor = coordinates[:, i] | ||
lsa = values_to_linspace(coor) | ||
if lsa is None: | ||
raise InvalidAxisException(i) | ||
ls.append(lsa) | ||
indices.append(index_values(coor, lsa)) | ||
|
||
return ls, tuple(indices) | ||
|
||
|
||
def get_ndim_hyperspec(data, attrs): | ||
# mostly copied from orangecontrib.spectroscopy.utils, | ||
# but returns the indices too | ||
# also avoid Orange domains as much as possible | ||
coordinates = np.hstack([data.get_column(a).reshape(-1, 1) for a in attrs]) | ||
|
||
ls, indices = axes_to_ndim_linspace(coordinates) | ||
|
||
# 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 | ||
|
||
|
||
def domain_with_single_attribute_in_x(attribute, domain): | ||
"""Create a domain with only the attribute in domain.attributes and ensure | ||
that the same attribute is removed from metas and class_vars if it was present | ||
there. """ | ||
class_vars = [a for a in domain.class_vars if a.name != attribute.name] | ||
metas = [a for a in domain.metas if a.name != attribute.name] | ||
return Domain([attribute], class_vars, metas) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
import numpy as np | ||
|
||
from Orange.preprocess import Preprocess | ||
|
||
|
||
def reshape_to_image(data, x, y): | ||
xres = np.size(np.unique(x)) | ||
yres = np.size(np.unique(y)) | ||
|
||
return np.reshape(data, (yres, xres)) | ||
|
||
|
||
class PreprocessImageOpts(Preprocess): | ||
pass |