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

Merged in changes with accessor convenience methods

parent b8382eca
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,9 @@ class GenericImageDataAccessor(ABC): ...@@ -51,6 +51,9 @@ class GenericImageDataAccessor(ABC):
def get_zi(self, zi: int): def get_zi(self, zi: int):
"""
Return a new accessor of a specific z-coordinate
"""
return self._derived_accessor( return self._derived_accessor(
self.data.take( self.data.take(
indices=[zi], indices=[zi],
...@@ -58,8 +61,14 @@ class GenericImageDataAccessor(ABC): ...@@ -58,8 +61,14 @@ class GenericImageDataAccessor(ABC):
) )
) )
def get_mip(self):
"""
Return a new accessor of maximum intensity projection (MIP) along z-axis
"""
return self.apply(lambda x: x.max(axis=self._ga('Z'), keepdims=True))
def get_mono(self, channel: int, mip: bool = False, squeeze=False): def get_mono(self, channel: int, mip: bool = False):
return self.get_channels([channel], mip=mip) return self.get_channels([channel], mip=mip)
@property @property
...@@ -79,7 +88,7 @@ class GenericImageDataAccessor(ABC): ...@@ -79,7 +88,7 @@ class GenericImageDataAccessor(ABC):
def _gc(self, channels): def _gc(self, channels):
return self.get_channels(list(channels)) return self.get_channels(list(channels))
def _unique(self): def unique(self):
return np.unique(self.data, return_counts=True) return np.unique(self.data, return_counts=True)
@property @property
...@@ -153,6 +162,14 @@ class GenericImageDataAccessor(ABC): ...@@ -153,6 +162,14 @@ class GenericImageDataAccessor(ABC):
func(self.data) func(self.data)
) )
@property
def info(self):
return {
'shape_dict': self.shape_dict,
'dtype': str(self.dtype),
'filepath': '',
}
class InMemoryDataAccessor(GenericImageDataAccessor): class InMemoryDataAccessor(GenericImageDataAccessor):
def __init__(self, data): def __init__(self, data):
self._data = self.conform_data(data) self._data = self.conform_data(data)
...@@ -172,6 +189,12 @@ class GenericImageFileAccessor(GenericImageDataAccessor): # image data is loaded ...@@ -172,6 +189,12 @@ class GenericImageFileAccessor(GenericImageDataAccessor): # image data is loaded
def read(fp: Path): def read(fp: Path):
return generate_file_accessor(fp) return generate_file_accessor(fp)
@property
def info(self):
d = super().info
d['filepath'] = self.fpath.__str__()
return d
class TifSingleSeriesFileAccessor(GenericImageFileAccessor): class TifSingleSeriesFileAccessor(GenericImageFileAccessor):
def __init__(self, fpath: Path): def __init__(self, fpath: Path):
super().__init__(fpath) super().__init__(fpath)
...@@ -273,7 +296,7 @@ class CziImageFileAccessor(GenericImageFileAccessor): ...@@ -273,7 +296,7 @@ class CziImageFileAccessor(GenericImageFileAccessor):
def write_accessor_data_to_file(fpath: Path, acc: GenericImageDataAccessor, mkdir=True) -> bool: def write_accessor_data_to_file(fpath: Path, acc: GenericImageDataAccessor, mkdir=True) -> bool:
""" """
Export an image accessor to file. Export an image accessor to file
:param fpath: complete path including filename and extension :param fpath: complete path including filename and extension
:param acc: image accessor to be written :param acc: image accessor to be written
:param mkdir: create any needed subdirectories in fpath if True :param mkdir: create any needed subdirectories in fpath if True
...@@ -320,7 +343,7 @@ def write_accessor_data_to_file(fpath: Path, acc: GenericImageDataAccessor, mkdi ...@@ -320,7 +343,7 @@ def write_accessor_data_to_file(fpath: Path, acc: GenericImageDataAccessor, mkdi
def generate_file_accessor(fpath): def generate_file_accessor(fpath):
""" """
Given an image file path, return an image accessor, assuming the file is a supported format and represents Given an image file path, return an image accessor, assuming the file is a supported format and represents
a single position array, which may be single or multi-channel, single plane or z-stack. a single position array, which may be single or multichannel, single plane or z-stack.
""" """
if str(fpath).upper().endswith('.TIF') or str(fpath).upper().endswith('.TIFF'): if str(fpath).upper().endswith('.TIF') or str(fpath).upper().endswith('.TIFF'):
return TifSingleSeriesFileAccessor(fpath) return TifSingleSeriesFileAccessor(fpath)
...@@ -470,7 +493,6 @@ def make_patch_stack_from_file(fpath): # interpret t-dimension as patch positio ...@@ -470,7 +493,6 @@ def make_patch_stack_from_file(fpath): # interpret t-dimension as patch positio
return PatchStack(pyxcz) return PatchStack(pyxcz)
class Error(Exception): class Error(Exception):
pass pass
......
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