def test_linspace(self):
     v = values_to_linspace(np.array([1, 2, 3]))
     np.testing.assert_equal(np.linspace(*v), [1, 2, 3])
     v = values_to_linspace(np.array([1, 2, 3, float("nan")]))
     np.testing.assert_equal(np.linspace(*v), [1, 2, 3])
     v = values_to_linspace(np.array([1]))
     np.testing.assert_equal(np.linspace(*v), [1])
     v = values_to_linspace(np.array([1.001, 2, 3.002]))
     np.testing.assert_equal(np.linspace(*v), [1.001, 2.0015, 3.002])
 def test_linspace(self):
     v = values_to_linspace(np.array([1, 2, 3]))
     np.testing.assert_equal(np.linspace(*v), [1, 2, 3])
     v = values_to_linspace(np.array([1, 2, 3, float("nan")]))
     np.testing.assert_equal(np.linspace(*v), [1, 2, 3])
     v = values_to_linspace(np.array([1]))
     np.testing.assert_equal(np.linspace(*v), [1])
     v = values_to_linspace(np.array([1.001, 2, 3.002]))
     np.testing.assert_equal(np.linspace(*v), [1.001, 2.0015, 3.002])
def process_stack(data,
                  xat,
                  yat,
                  upsample_factor=100,
                  use_sobel=False,
                  ref_frame_num=0):
    ndom = Domain([xat, yat])
    datam = Table(ndom, data)
    coorx = datam.X[:, 0]
    coory = datam.X[:, 1]

    lsx = values_to_linspace(coorx)
    lsy = values_to_linspace(coory)
    lsz = data.X.shape[1]

    if lsx is None:
        raise InvalidAxisException("x")
    if lsy is None:
        raise InvalidAxisException("y")

    # set data
    hypercube = np.ones((lsy[2], lsx[2], lsz)) * np.nan

    xindex = index_values(coorx, lsx)
    yindex = index_values(coory, lsy)
    hypercube[yindex, xindex] = data.X

    if np.any(np.isnan(hypercube)):
        raise NanInsideHypercube(np.sum(np.isnan(hypercube)))

    calculate_shift = RegisterTranslation(upsample_factor=upsample_factor)
    filterfn = sobel if use_sobel else lambda x: x
    shifts, aligned_stack = alignstack(hypercube.T,
                                       shiftfn=calculate_shift,
                                       ref_frame_num=ref_frame_num,
                                       filterfn=filterfn)

    xmin, ymin = shifts[:, 0].min(), shifts[:, 1].min()
    xmax, ymax = shifts[:, 0].max(), shifts[:, 1].max()
    xmin, xmax = int(round(xmin)), int(round(xmax))
    ymin, ymax = int(round(ymin)), int(round(ymax))

    shape = hypercube.shape
    slicex = slice(max(xmax, 0), min(shape[1], shape[1] + xmin))
    slicey = slice(max(ymax, 0), min(shape[0], shape[0] + ymin))
    cropped = np.array(aligned_stack).T[slicey, slicex]

    # transform numpy array back to Orange.data.Table
    return shifts, build_spec_table(
        *_spectra_from_image(cropped, getx(data),
                             np.linspace(*lsx)[slicex],
                             np.linspace(*lsy)[slicey]))
 def test_index(self):
     a = np.array([1, 2, 3])
     v = values_to_linspace(a)
     iv = index_values(a, v)
     np.testing.assert_equal(iv, [0, 1, 2])
     a = np.array([1, 2, 3, 4])
     v = values_to_linspace(a)
     iv = index_values(a, v)
     np.testing.assert_equal(iv, [0, 1, 2, 3])
     a = np.array([1, 2, 3, 6, 5])
     v = values_to_linspace(a)
     iv = index_values(a, v)
     np.testing.assert_equal(iv, [0, 1, 2, 5, 4])
 def test_index(self):
     a = np.array([1,2,3])
     v = values_to_linspace(a)
     iv = index_values(a, v)
     np.testing.assert_equal(iv, [0, 1, 2])
     a = np.array([1, 2, 3, 4])
     v = values_to_linspace(a)
     iv = index_values(a, v)
     np.testing.assert_equal(iv, [0, 1, 2, 3])
     a = np.array([1, 2, 3, 6, 5])
     v = values_to_linspace(a)
     iv = index_values(a, v)
     np.testing.assert_equal(iv, [0, 1, 2, 5, 4])
 def test_location(self):
     lsc = values_to_linspace(np.array([1, 1, 1]))  # a constant
     lv = location_values([0, 1, 2], lsc)
     np.testing.assert_equal(lv, [-1, 0, 1])
 def test_location(self):
     lsc = values_to_linspace(np.array([1, 1, 1]))  # a constant
     lv = location_values([0,1,2], lsc)
     np.testing.assert_equal(lv, [-1, 0, 1])