Skip to content

Commit

Permalink
First pass of documentation for the core module
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVinyard committed Sep 2, 2017
1 parent 9aeabe4 commit 747cf3e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
26 changes: 20 additions & 6 deletions zounds/core/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@ def __init__(self):

class ArrayWithUnits(np.ndarray):
"""
Blah Blah Blah
`ArrayWithUnits` is an :class:`numpy.ndarray` subclass that allows for
indexing by more semantically meaningful slices.
It supports most methods on :class:`numpy.ndarray`, and makes a best-effort
to maintain meaningful dimensions throughout those operations.
Args:
arr (ndarray): The :class:`numpy.ndarray` instance containing the raw
data for this instance
dimensions (iterable): iterable of :class:`Dimension`-derived classes
data for this instance
dimensions (list or tuple): list or tuple of :class:`Dimension`-derived
classes
Raises:
ValueError: when `arr.ndim` and `len(dimensions)` do not match
Examples:
>>> print 'hai'
>>> from zounds import ArrayWithUnits, TimeDimension, Seconds, TimeSlice
>>> import numpy as np
>>> data = np.zeros(100)
>>> awu = ArrayWithUnits(data, [TimeDimension(Seconds(1))])
>>> sliced = awu[TimeSlice(Seconds(10))]
>>> sliced.shape
(10,)
See Also:
:class:`IdentityDimension`
:class:`zounds.timeseries.TimeDimension`
:class:`zounds.spectral.FrequencyDimension`
:class:`~zounds.timeseries.TimeDimension`
:class:`~zounds.spectral.FrequencyDimension`
"""

def __new__(cls, arr, dimensions):
Expand Down
38 changes: 34 additions & 4 deletions zounds/core/dimensions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
class Dimension(object):
"""
Class representing one dimension of a numpy array, making custom slices
(e.g., time spans or frequency bands) possible
Common base class representing one dimension of a numpy array. Sub-classes
can define behavior making custom slices (e.g., time spans or
frequency bands) possible.
Implementors are primarily responsible for determining how custom slices
are transformed into integer indexes and slices that numpy can use directly.
See Also:
:class:`IdentityDimension`
:class:`~zounds.timeseries.TimeDimension`
:class:`~zounds.spectral.FrequencyDimension`
"""

def __init__(self):
Expand All @@ -11,23 +20,44 @@ def modified_dimension(self, size, windowsize, stepsize=None):
raise NotImplementedError()

def metaslice(self, index, size):
"""
Produce a new instance of this dimension, given a custom slice
"""
return self

def integer_based_slice(self, index):
"""
Transforms a custom, user-defined slice into integer indices that numpy
can understand
Subclasses define behavior that transforms a custom, user-defined slice
into integer indices that numpy can understand
Args:
index (custom slice): A user-defined slice instance
"""
raise NotImplementedError()

def validate(self, size):
"""
Subclasses check to ensure that the dimensions size does not validate
any assumptions made by this instance
"""
pass


class IdentityDimension(Dimension):
"""
A custom dimension that does not transform indices in any way, simply acting
as a pass-through.
Examples:
>>> from zounds import ArrayWithUnits, IdentityDimension
>>> import numpy as np
>>> data = np.zeros(100)
>>> arr = ArrayWithUnits(data, [IdentityDimension()])
>>> sliced = arr[4:6]
>>> sliced.shape
(2,)
"""

def __init__(self):
super(IdentityDimension, self).__init__()

Expand Down

0 comments on commit 747cf3e

Please sign in to comment.