-
Notifications
You must be signed in to change notification settings - Fork 264
neo.units module (Issue278) #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a10ef15
Compartimentation of quantities inside units.py module. issue390
joffreygonin a4bfa19
Partly removed
joffreygonin f63d38b
#278 Create `neo.units` module
joffreygonin 62816c4
Small precision :
joffreygonin c1b1710
Merge branch 'master' into issue278
joffreygonin ba47c04
Compartimentation of quantities inside units.py module. issue390
joffreygonin 78693d8
(test with git)
joffreygonin 762e2f9
quantities to units for the new commits
joffreygonin 5ec7bbf
Merge remote-tracking branch 'origin/issue278' into issue278
joffreygonin 8ccee64
Merge branch 'master' into issue278
joffreygonin ace6853
Merge remote-tracking branch 'upstream/master' into issue278
joffreygonin c99c929
Merge remote-tracking branch 'origin/issue278' into issue278
joffreygonin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ API Reference | |
| .. testsetup:: * | ||
|
|
||
| from neo import SpikeTrain | ||
| import quantities as pq | ||
| from neo import units as un | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ | |
| from datetime import datetime | ||
|
|
||
| import numpy as np | ||
| import quantities as pq | ||
| from neo import units as un | ||
|
|
||
| from matplotlib import pyplot | ||
| from matplotlib.patches import Rectangle, ArrowStyle, FancyArrowPatch | ||
| from matplotlib.font_manager import FontProperties | ||
|
|
@@ -173,7 +174,7 @@ def generate_diagram(filename, rect_pos, rect_width, figsize): | |
| else: | ||
| t1 = attrname | ||
|
|
||
| if attrtype == pq.Quantity: | ||
| if attrtype == un.Quantity: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the |
||
| if attr[2] == 0: | ||
| t2 = 'Quantity scalar' | ||
| else: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,12 @@ | |
| import logging | ||
|
|
||
| import numpy as np | ||
| import quantities as pq | ||
|
|
||
| from neo.core.baseneo import BaseNeo, MergeError, merge_annotations | ||
| from neo.core.channelindex import ChannelIndex | ||
|
|
||
| from neo import units as un | ||
|
|
||
| logger = logging.getLogger("Neo") | ||
|
|
||
|
|
||
|
|
@@ -49,7 +50,7 @@ def _get_sampling_rate(sampling_rate, sampling_period): | |
|
|
||
|
|
||
| def _new_AnalogSignalArray(cls, signal, units=None, dtype=None, copy=True, | ||
| t_start=0*pq.s, sampling_rate=None, | ||
| t_start=0*un.s, sampling_rate=None, | ||
| sampling_period=None, name=None, file_origin=None, | ||
| description=None, | ||
| annotations=None): | ||
|
|
@@ -64,7 +65,7 @@ def _new_AnalogSignalArray(cls, signal, units=None, dtype=None, copy=True, | |
| **annotations) | ||
|
|
||
|
|
||
| class AnalogSignal(BaseNeo, pq.Quantity): | ||
| class AnalogSignal(BaseNeo, un.Quantity): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should stay as |
||
| ''' | ||
| Array of one or more continuous analog signals. | ||
|
|
||
|
|
@@ -79,10 +80,10 @@ class AnalogSignal(BaseNeo, pq.Quantity): | |
| *Usage*:: | ||
|
|
||
| >>> from neo.core import AnalogSignal | ||
| >>> import quantities as pq | ||
|
|
||
| >>> | ||
| >>> sigarr = AnalogSignal([[1, 2, 3], [4, 5, 6]], units='V', | ||
| ... sampling_rate=1*pq.Hz) | ||
| ... sampling_rate=1*un.Hz) | ||
| >>> | ||
| >>> sigarr | ||
| <AnalogSignal(array([[1, 2, 3], | ||
|
|
@@ -148,13 +149,13 @@ class AnalogSignal(BaseNeo, pq.Quantity): | |
|
|
||
| _single_parent_objects = ('Segment', 'ChannelIndex') | ||
| _quantity_attr = 'signal' | ||
| _necessary_attrs = (('signal', pq.Quantity, 2), | ||
| ('sampling_rate', pq.Quantity, 0), | ||
| ('t_start', pq.Quantity, 0)) | ||
| _necessary_attrs = (('signal', un.Quantity, 2), | ||
| ('sampling_rate', un.Quantity, 0), | ||
| ('t_start', un.Quantity, 0)) | ||
| _recommended_attrs = BaseNeo._recommended_attrs | ||
|
|
||
| def __new__(cls, signal, units=None, dtype=None, copy=True, | ||
| t_start=0 * pq.s, sampling_rate=None, sampling_period=None, | ||
| t_start=0 * un.s, sampling_rate=None, sampling_period=None, | ||
| name=None, file_origin=None, description=None, | ||
| **annotations): | ||
| ''' | ||
|
|
@@ -168,12 +169,12 @@ def __new__(cls, signal, units=None, dtype=None, copy=True, | |
| if units is None: | ||
| if not hasattr(signal, "units"): | ||
| raise ValueError("Units must be specified") | ||
| elif isinstance(signal, pq.Quantity): | ||
| elif isinstance(signal, un.Quantity): | ||
| # could improve this test, what if units is a string? | ||
| if units != signal.units: | ||
| signal = signal.rescale(units) | ||
|
|
||
| obj = pq.Quantity(signal, units=units, dtype=dtype, copy=copy).view(cls) | ||
| obj = un.Quantity(signal, units=units, dtype=dtype, copy=copy).view(cls) | ||
|
|
||
| if obj.ndim == 1: | ||
| obj.shape = (-1, 1) | ||
|
|
@@ -189,7 +190,7 @@ def __new__(cls, signal, units=None, dtype=None, copy=True, | |
| return obj | ||
|
|
||
| def __init__(self, signal, units=None, dtype=None, copy=True, | ||
| t_start=0 * pq.s, sampling_rate=None, sampling_period=None, | ||
| t_start=0 * un.s, sampling_rate=None, sampling_period=None, | ||
| name=None, file_origin=None, description=None, | ||
| **annotations): | ||
| ''' | ||
|
|
@@ -235,7 +236,7 @@ def __array_finalize__(self, obj): | |
| copied over here. | ||
| ''' | ||
| super(AnalogSignal, self).__array_finalize__(obj) | ||
| self._t_start = getattr(obj, '_t_start', 0 * pq.s) | ||
| self._t_start = getattr(obj, '_t_start', 0 * un.s) | ||
| self._sampling_rate = getattr(obj, '_sampling_rate', None) | ||
|
|
||
| # The additional arguments | ||
|
|
@@ -281,11 +282,11 @@ def __getitem__(self, i): | |
| ''' | ||
| obj = super(AnalogSignal, self).__getitem__(i) | ||
| if isinstance(i, int): # a single point in time across all channels | ||
| obj = pq.Quantity(obj.magnitude, units=obj.units) | ||
| obj = un.Quantity(obj.magnitude, units=obj.units) | ||
| elif isinstance(i, tuple): | ||
| j, k = i | ||
| if isinstance(j, int): # extract a quantity array | ||
| obj = pq.Quantity(obj.magnitude, units=obj.units) | ||
| obj = un.Quantity(obj.magnitude, units=obj.units) | ||
| else: | ||
| if isinstance(j, slice): | ||
| if j.start: | ||
|
|
@@ -413,15 +414,15 @@ def rescale(self, units): | |
| Return a copy of the AnalogSignal converted to the specified | ||
| units | ||
| ''' | ||
| to_dims = pq.quantity.validate_dimensionality(units) | ||
| to_dims = un.quantity.validate_dimensionality(units) | ||
| if self.dimensionality == to_dims: | ||
| to_u = self.units | ||
| signal = np.array(self) | ||
| else: | ||
| to_u = pq.Quantity(1.0, to_dims) | ||
| from_u = pq.Quantity(1.0, self.dimensionality) | ||
| to_u = un.Quantity(1.0, to_dims) | ||
| from_u = un.Quantity(1.0, self.dimensionality) | ||
| try: | ||
| cf = pq.quantity.get_conversion_factor(from_u, to_u) | ||
| cf = un.quantity.get_conversion_factor(from_u, to_u) | ||
| except AssertionError: | ||
| raise ValueError('Unable to convert between units of "%s" \ | ||
| and "%s"' % (from_u._dimensionality, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert - we should not import Quantity via the
unitsmodule