Skip to content

Commit

Permalink
NeuralEnsemble#278 Create neo.units module
Browse files Browse the repository at this point in the history
And remove Quantities import in the code (except for units module)
  • Loading branch information
joffreygonin committed Mar 13, 2017
1 parent a4bfa19 commit f63d38b
Show file tree
Hide file tree
Showing 30 changed files with 683 additions and 679 deletions.
2 changes: 1 addition & 1 deletion doc/source/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ API Reference
.. testsetup:: *

from neo import SpikeTrain
import quantities as pq
from neo import units as un
6 changes: 3 additions & 3 deletions doc/source/images/generate_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from datetime import datetime

import numpy as np
from neo.units import Units
Units = Units()
from neo import units as un

from matplotlib import pyplot
from matplotlib.patches import Rectangle, ArrowStyle, FancyArrowPatch
from matplotlib.font_manager import FontProperties
Expand Down Expand Up @@ -174,7 +174,7 @@ def generate_diagram(filename, rect_pos, rect_width, figsize):
else:
t1 = attrname

if attrtype == Units.Quantity:
if attrtype == un.Quantity:
if attr[2] == 0:
t2 = 'Quantity scalar'
else:
Expand Down
2 changes: 1 addition & 1 deletion neo/core/analogsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def rescale(self, units):
Return a copy of the AnalogSignal converted to the specified
units
'''
to_dims = Units.quantity.validate_dimensionality(units)
to_dims = un.quantity.validate_dimensionality(units)
if self.dimensionality == to_dims:
to_u = self.units
signal = np.array(self)
Expand Down
2 changes: 1 addition & 1 deletion neo/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Block(Container):
>>> from neo.core import (Block, Segment, ChannelIndex,
... AnalogSignal)
>>> from quantities import nA, kHz
>>> from neo.units import nA, kHz
>>> import numpy as np
>>>
>>> # create a Block with 3 Segment and 2 ChannelIndex objects
Expand Down
2 changes: 1 addition & 1 deletion neo/core/channelindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ChannelIndex(Container):
>>> from neo.core import (Block, Segment, ChannelIndex,
... AnalogSignal)
>>> from quantities import nA, kHz
>>> from neo.units import nA, kHz
>>> import numpy as np
>>>
>>> # create a Block with 3 Segment and 2 ChannelIndex objects
Expand Down
2 changes: 1 addition & 1 deletion neo/core/epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __new__(cls, times=None, durations=None, labels=None, units=None,
if hasattr(units, 'dimensionality'):
dim = units.dimensionality
else:
dim = Units.quantity.validate_dimensionality(units)
dim = un.quantity.validate_dimensionality(units)
# check to make sure the units are time
# this approach is much faster than comparing the
# reference dimensionality
Expand Down
2 changes: 1 addition & 1 deletion neo/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Event(BaseNeo, un.Quantity):
*Usage*::
>>> from neo.core import Event
>>> from quantities import s
>>> from neo.units import s
>>> import numpy as np
>>>
>>> evt = Event(np.arange(0, 30, 10)*s,
Expand Down
6 changes: 3 additions & 3 deletions neo/core/irregularlysampledsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IrregularlySampledSignal(BaseNeo, un.Quantity):
*Usage*::
>>> from neo.core import IrregularlySampledSignal
>>> from quantities import s, nA
>>> from neo.units import s, nA
>>>
>>> irsig0 = IrregularlySampledSignal([0.0, 1.23, 6.78], [1, 2, 3],
... units='mV', time_units='ms')
Expand Down Expand Up @@ -133,12 +133,12 @@ def __new__(cls, times, signal, units=None, time_units=None, dtype=None,
time_units = times.units
else:
raise ValueError("Time units must be specified")
elif isinstance(times, Units.Quantity):
elif isinstance(times, un.Quantity):
# could improve this test, what if units is a string?
if time_units != times.units:
times = times.rescale(time_units)
# should check time units have correct dimensions
obj = Units.Quantity.__new__(cls, signal, units=units,
obj = un.Quantity.__new__(cls, signal, units=units,
dtype=dtype, copy=copy)
if obj.ndim == 1:
obj = obj.reshape(-1, 1)
Expand Down
2 changes: 1 addition & 1 deletion neo/core/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Segment(Container):
*Usage*::
>>> from neo.core import Segment, SpikeTrain, AnalogSignal
>>> from quantities import Hz, s
>>> from neo.units import Hz, s
>>>
>>> seg = Segment(index=5)
>>>
Expand Down
2 changes: 1 addition & 1 deletion neo/core/spiketrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def __new__(cls, times, t_stop, units=None, dtype=None, copy=True,
if hasattr(units, 'dimensionality'):
dim = units.dimensionality
else:
dim = Units.quantity.validate_dimensionality(units)
dim = un.quantity.validate_dimensionality(units)

if hasattr(times, 'dimensionality'):
if times.dimensionality.items() == dim.items():
Expand Down
11 changes: 6 additions & 5 deletions neo/io/blackrockio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ def __transform_times(self, n, default_n):
"""
highest_res = self.__nev_params('event_unit')

if isinstance(n, Units.Quantity):
if isinstance(n, un.Quantity):
n = [n.rescale(highest_res)]
elif hasattr(n, "__len__"):
n = [tp.rescale(highest_res) if tp is not None
Expand Down Expand Up @@ -1867,16 +1867,16 @@ def __read_unit(self, unit_id, channel_idx):
desc = 'Unit from channel: {0}, id: {1}'.format(
channel_idx, self.__get_unit_classification(unit_id))

un = Unit(
unit_to_return = Unit(
name=name,
description=desc,
file_origin='.'.join([self._filenames['nev'], 'nev']))

# add additional annotations
un.annotate(ch_idx=int(channel_idx))
un.annotate(unit_id=int(unit_id))
unit_to_return.annotate(ch_idx=int(channel_idx))
unit_to_return.annotate(unit_id=int(unit_id))

return un
return unit_to_return

def __read_recordingchannelgroup(
self, channel_idx, index=None, channel_units=None, cascade=True):
Expand All @@ -1885,6 +1885,7 @@ def __read_recordingchannelgroup(
given index for the given channels containing a neo.core.unit.Unit
object list of the given units.
"""
from neo import units as un

rcg = ChannelIndex(
np.array([channel_idx]),
Expand Down
Loading

0 comments on commit f63d38b

Please sign in to comment.