Skip to content
Snippets Groups Projects
Commit 68b683fc authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

MonoPatchStackFromFile now contains file accessor as an object

parent 33f83235
No related branches found
No related tags found
No related merge requests found
from pathlib import Path
import numpy as np
from model_server.accessors import generate_file_accessor, InMemoryDataAccessor
class MonoPatchStack(InMemoryDataAccessor):
......@@ -48,11 +51,17 @@ class MonoPatchStack(InMemoryDataAccessor):
class MonoPatchStackFromFile(MonoPatchStack):
def __init__(self, fpath):
super().__init__(generate_file_accessor(fpath).data[:, :, 0, :])
if not Path(fpath).exists():
raise FileNotFoundError(f'Could not find {fpath}')
self.file_acc = generate_file_accessor(fpath)
super().__init__(self.file_acc.data[:, :, 0, :])
class Error(Exception):
pass
class InvalidDataForPatchStackError(Error):
pass
\ No newline at end of file
pass
class FileNotFoundError(Error):
pass
......@@ -2,7 +2,8 @@ import unittest
import numpy as np
from extensions.chaeo.accessors import MonoPatchStack
from conf.testing import monozstackmask
from extensions.chaeo.accessors import MonoPatchStack, MonoPatchStackFromFile
......@@ -26,4 +27,19 @@ class TestCziImageFileAccess(unittest.TestCase):
acc = MonoPatchStack([np.random.rand(h, w) for _ in range(0, 4)])
self.assertEqual(acc.count, n)
self.assertEqual(acc.hw, (h, w))
self.assertEqual(acc.make_tczyx().shape, (n, 1, 1, h, w))
\ No newline at end of file
self.assertEqual(acc.make_tczyx().shape, (n, 1, 1, h, w))
def test_make_patch_stack_from_file(self):
h = monozstackmask['h']
w = monozstackmask['w']
c = monozstackmask['c']
n = monozstackmask['z']
acc = MonoPatchStackFromFile(monozstackmask['path'])
self.assertEqual(acc.hw, (h, w))
self.assertEqual(acc.count, n)
self.assertEqual(acc.make_tczyx().shape, (n, c, 1, h, w))
def test_raises_filenotfound(self):
from extensions.chaeo.accessors import FileNotFoundError
with self.assertRaises(FileNotFoundError):
acc = MonoPatchStackFromFile('c:/fake/file/name.tif')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment