Skip to content

Commit

Permalink
DOC: Dcstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Jul 21, 2017
1 parent 10058ae commit 6f77d23
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 56 deletions.
13 changes: 7 additions & 6 deletions pims/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def raiser(*args, **kwargs):
return raiser


def wrap_fmt(reader, name, description, extensions=None, modes=None):
def register_fmt(reader, name, description, extensions=None, modes=None):
"""Registers a Format with the format manager. Returns a reader
for backwards compatibility."""
formats.add_format(reader(name, description, extensions, modes))
@wraps(reader)
def wrapper(filename, **kwargs):
Expand Down Expand Up @@ -92,11 +94,10 @@ def wrapper(filename, **kwargs):
if not pims.tiff_stack.tifffile_available():
TiffStack_tifffile = not_available("tifffile")
else:
TiffStack_tifffile = wrap_fmt(FormatTiffStack_tifffile,
'TIFF_tifffile',
'Reads TIFF files through tifffile.py.',
'tif tiff lsm stk',
'iIvV')
TiffStack_tifffile = register_fmt(FormatTiffStack_tifffile,
'TIFF_tifffile',
'Reads TIFF files through tifffile.py.',
'tif tiff lsm stk', 'iIvV')
if not pims.tiff_stack.libtiff_available():
TiffStack_libtiff = not_available("libtiff")
if not pims.tiff_stack.PIL_available():
Expand Down
79 changes: 31 additions & 48 deletions pims/base_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,72 +670,63 @@ def default_axes(sizes, mode):

class _PimsFormat(Format):
def _can_read(self, request):
"""Determine whether `request.filename` can be read using this
Format.Reader, judging from the imageio.core.Request object."""
if request.mode[1] in (self.modes + '?'):
if request.filename.lower().endswith(self.extensions):
return True

def _can_write(self, request):
"""Determine whether file type `request.filename` can be written using
this Format.Writer, judging from the imageio.core.Request object."""
return False

@Slicerator.from_class
class Reader(with_metaclass(ABCMeta, Format.Reader)):
def __getitem__(self, key):
return self.get_data(key)

@abstractmethod
def _get_length(self):
pass
def get_data(self, index, **kwargs):
# This function is a copy of the imageio Format.Reader,
# replacing the returned Image object with a PIMS Frame.
self._checkClosed()
self._BaseReaderWriter_last_index = index
im, meta = self._get_data(index, **kwargs)
return Frame(im, frame_no=index, metadata=meta)

def iter_data(self):
return iter(self[:])

def get_meta_data(self, i):
# can be overwritten by a reader for better performance
return self.get_data(i).metadata

@property
def shape(self):
return (len(self),) + tuple(self.frame_shape)

@abstractmethod
def _open(self, **kwargs):
pass

@abstractmethod
def _get_dtype(self):
def _get_data(self, i):
pass

@property
def dtype(self):
return self._get_dtype()

@property
def shape(self):
return (len(self),) + self.frame_shape
@abstractmethod
def __len__(self):
pass

@abstractproperty
def frame_shape(self):
""" Returns the shape of the frame as returned by get_frame. """
pass

@property
def ndim(self):
""" Returns the number of axes. """
return len(self.frame_shape) + 1

def get_data(self, index, **kwargs):
""" get_data(index, **kwargs)
Read image data from the file, using the image index. The
returned image has a 'meta' attribute with the meta data.
Some formats may support additional keyword arguments. These are
listed in the documentation of those formats.
"""
self._checkClosed()
self._BaseReaderWriter_last_index = index
im, meta = self._get_data(index, **kwargs)
return Frame(im, frame_no=index, metadata=meta)

def iter_data(self):
return iter(self[:])

@abstractmethod
def _get_data(self, i):
@abstractproperty
def pixel_type(self):
"""Returns a numpy.dtype for the data type of the pixel values"""
pass

def _get_meta_data(self, i):
return self.get_data(i).metadata


class PimsFormat(_PimsFormat):
class Reader(_PimsFormat.Reader):
Expand Down Expand Up @@ -775,14 +766,6 @@ def _init_axis(self, name, size, default=0):
self.default_coords[name] = int(default)

def get_data(self, index, **kwargs):
""" get_data(index, **kwargs)
Read image data from the file, using the image index. The
returned image has a 'meta' attribute with the meta data.
Some formats may support additional keyword arguments. These are
listed in the documentation of those formats.
"""
self._checkClosed()
self._BaseReaderWriter_last_index = index
return self._get_data(index, **kwargs)
Expand Down Expand Up @@ -821,7 +804,7 @@ def _get_data(self, i):
dict(axes=self.bundle_axes, coords=metadata_coords))
return Frame(result, frame_no=i, metadata=metadata)

def _get_length(self):
def __len__(self):
return int(np.prod([self._sizes[d] for d in self._iter_axes]))

@property
Expand Down Expand Up @@ -886,7 +869,7 @@ def bundle_axes(self, value):
# update the get_frame method
get_frame = _make_get_frame(self._bundle_axes,
self._get_frame_dict,
self.sizes, self.dtype)
self.sizes, self.pixel_type)
self._get_frame_wrapped = get_frame

@property
Expand Down
4 changes: 2 additions & 2 deletions pims/tiff_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def _open(self, **kwargs):

self.bundle_axes, self.iter_axes = default_axes(self.sizes,
self.request.mode)

def _get_dtype(self):
@property
def pixel_type(self):
return self._dtype

def _get_frame(self, **inds):
Expand Down

0 comments on commit 6f77d23

Please sign in to comment.