Skip to content

Commit

Permalink
fix file selection & test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasmarnold committed Nov 16, 2023
1 parent b8d7a43 commit 069b3fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/affinder/_tests/load_test/2D_test_affine.txt

This file was deleted.

18 changes: 9 additions & 9 deletions src/affinder/_tests/test_affinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ def test_apply_affine_nonimage():
widget(ref_layer, mov_layer)


def test_load_affine():
existing_affine = np.array([[0.9, 0.1, 5], [0.4, 0.2, 9], [0, 0, 1]])
def test_load_affine(tmp_path):
affile = tmp_path / 'test_affine.txt'
affine = np.array([[2, 0, 5], [0, 2, 5], [0, 0, 1]])
np.savetxt(affile, affine, delimiter=',')

layer = napari.layers.Image(np.random.random((5, 5)))
layer.affine = existing_affine

widget = load_affine(,
widget(layer, './src/affinder/_tests/load_test/2d_test_affine.txt')
widget = load_affine()
widget(layer, affile)

np.testing.assert_allclose(
layer.affine,
np.loadtxt('./src/affinder/_tests/load_test/2d_test_affine.txt',
delimiter=',') @ existing_affine
)
layer.affine, affine
)

8 changes: 5 additions & 3 deletions src/affinder/load_tf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from pathlib import Path

import numpy as np
from magicgui import magic_factory
from napari.layers import Layer


@magic_factory(call_button='Load')
def load_affine(layer: Layer, affine: str):
@magic_factory(call_button='Load', affine={'mode': 'r'})
def load_affine(layer: Layer, affine: Path):
"""Load affine from string.
Parameters
Expand All @@ -15,4 +17,4 @@ def load_affine(layer: Layer, affine: str):
Affine to load.
"""
affine = np.loadtxt(affine, delimiter=',')
layer.affine = affine @ layer.affine
layer.affine = affine

0 comments on commit 069b3fc

Please sign in to comment.