{"action":"created","comment":{"url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/comments/23936679","id":23936679,"diff_hunk":"@@ -152,3 +155,704 @@ def binarize(spiketrain, sampling_rate=None, t_start=None, t_stop=None,\n     else:\n         return res, pq.Quantity(np.arange(t_start, t_stop+sampling_period,\n                                           sampling_period), units=units)\n+\n+###############################################################################\n+#\n+# Methods to calculate parameters, t_start, t_stop, bin size, number of bins\n+#\n+###############################################################################\n+def calc_tstart(num_bins, binsize, t_stop):\n+    \"\"\"\n+    Calculates the start point from given parameter.\n+\n+    Calculates the start point :attr:`t_start` from the three parameter\n+    :attr:`t_stop`, :attr:`num_bins` and :attr`binsize`.\n+\n+    Parameters\n+    ----------\n+    num_bins: int\n+        Number of bins\n+    binsize: quantities.Quantity\n+        Size of Bins\n+    t_stop: quantities.Quantity\n+        Stop time\n+\n+    Returns\n+    -------\n+    t_start : quantities.Quantity\n+        Starting point calculated from given parameter.\n+    \"\"\"\n+    if num_bins is not None and binsize is not None and t_stop is not None:\n+        return t_stop.rescale(binsize.units) - num_bins * binsize\n+\n+\n+def calc_tstop(num_bins, binsize, t_start):\n+    \"\"\"\n+    Calculates the stop point from given parameter.\n+\n+    Calculates the stop point :attr:`t_stop` from the three parameter\n+    :attr:`t_start`, :attr:`num_bins` and :attr`binsize`.\n+\n+    Parameters\n+    ----------\n+    num_bins: int\n+        Number of bins\n+    binsize: quantities.Quantity\n+        Size of bins\n+    t_start: quantities.Quantity\n+        Start time\n+\n+    Returns\n+    -------\n+    t_stop : quantities.Quantity\n+        Stoping point calculated from given parameter.\n+    \"\"\"\n+    if num_bins is not None and binsize is not None and t_start is not None:\n+        return t_start.rescale(binsize.units) + num_bins * binsize\n+\n+\n+def calc_num_bins(binsize, t_start, t_stop):\n+    \"\"\"\n+    Calculates the number of bins from given parameter.\n+\n+    Calculates the number of bins :attr:`num_bins` from the three parameter\n+    :attr:`t_start`, :attr:`t_stop` and :attr`binsize`.\n+\n+    Parameters\n+    ----------\n+    binsize: quantities.Quantity\n+        Size of Bins\n+    t_start : quantities.Quantity\n+        Start time\n+    t_stop: quantities.Quantity\n+        Stop time\n+\n+    Returns\n+    -------\n+    num_bins : int\n+       Number of bins  calculated from given parameter.\n+\n+    Raises\n+    ------\n+    ValueError :\n+        Raised when :attr:`t_stop` is smaller than :attr:`t_start`\".\n+\n+    \"\"\"\n+    if binsize is not None and t_start is not None and t_stop is not None:\n+        if t_stop < t_start:\n+            raise ValueError(\"t_stop (%s) is smaller than t_start (%s)\"\n+                             % (t_stop, t_start))\n+        return int(((t_stop - t_start).rescale(\n+            binsize.units) / binsize).magnitude)\n+\n+\n+def calc_binsize(num_bins, t_start, t_stop):\n+    \"\"\"\n+    Calculates the stop point from given parameter.\n+\n+    Calculates the size of bins :attr:`binsize` from the three parameter\n+    :attr:`num_bins`, :attr:`t_start` and :attr`t_stop`.\n+\n+    Parameters\n+    ----------\n+    num_bins: int\n+        Number of bins\n+    t_start: quantities.Quantity\n+        Start time\n+    t_stop\n+       Stop time\n+\n+    Returns\n+    -------\n+    binsize : quantities.Quantity\n+        Size of bins calculated from given parameter.\n+\n+    Raises\n+    ------\n+    ValueError :\n+        Raised when :attr:`t_stop` is smaller than :attr:`t_start`\".\n+    \"\"\"\n+\n+    if num_bins is not None and t_start is not None and t_stop is not None:\n+        if t_stop < t_start:\n+            raise ValueError(\"t_stop (%s) is smaller than t_start (%s)\"\n+                             % (t_stop, t_start))\n+        return (t_stop - t_start) / num_bins\n+\n+\n+def set_start_stop_from_input(spiketrains):\n+    \"\"\"\n+    Sets the start :attr:`t_start`and stop :attr:`t_stop` point\n+    from given input.\n+\n+    If one neo.SpikeTrain objects is given the start :attr:`t_stop `and stop\n+    :attr:`t_stop` of the spike train is returned.\n+    Otherwise the aligned times are returned, which are the maximal start point\n+    and minimal stop point.\n+\n+    Parameters\n+    ----------\n+    spiketrains: neo.SpikeTrain object, list or array of neo.core.SpikeTrain\n+                 objects\n+        List of neo.core SpikeTrain objects to extract `t_start` and\n+        `t_stop` from.\n+\n+    Returns\n+    -------\n+    start : quantities.Quantity\n+        Start point extracted from input :attr:`spiketrains`\n+    stop : quantities.Quantity\n+        Stop point extracted from input :attr:`spiketrains`\n+    \"\"\"\n+    if isinstance(spiketrains, neo.SpikeTrain):\n+        return spiketrains.t_start, spiketrains.t_stop\n+    else:\n+        start = max([elem.t_start for elem in spiketrains])\n+        stop = min([elem.t_stop for elem in spiketrains])\n+    return start, stop\n+\n+\n+class Binned:","path":"elephant/conversion.py","position":171,"original_position":171,"commit_id":"0464916b3a34d5cbd31dfe5fefa05069294cef81","original_commit_id":"0464916b3a34d5cbd31dfe5fefa05069294cef81","user":{"login":"apdavison","id":260552,"avatar_url":"https://avatars.githubusercontent.com/u/260552?v=3","gravatar_id":"","url":"https://api.github.com/users/apdavison","html_url":"https://github.com/apdavison","followers_url":"https://api.github.com/users/apdavison/followers","following_url":"https://api.github.com/users/apdavison/following{/other_user}","gists_url":"https://api.github.com/users/apdavison/gists{/gist_id}","starred_url":"https://api.github.com/users/apdavison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apdavison/subscriptions","organizations_url":"https://api.github.com/users/apdavison/orgs","repos_url":"https://api.github.com/users/apdavison/repos","events_url":"https://api.github.com/users/apdavison/events{/privacy}","received_events_url":"https://api.github.com/users/apdavison/received_events","type":"User","site_admin":false},"body":"should inherit from object, since we're still supporting Python 2","created_at":"2015-02-02T16:36:42Z","updated_at":"2015-02-02T16:36:42Z","html_url":"https://github.com/NeuralEnsemble/elephant/pull/16#discussion_r23936679","pull_request_url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/comments/23936679"},"html":{"href":"https://github.com/NeuralEnsemble/elephant/pull/16#discussion_r23936679"},"pull_request":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16","id":28453131,"html_url":"https://github.com/NeuralEnsemble/elephant/pull/16","diff_url":"https://github.com/NeuralEnsemble/elephant/pull/16.diff","patch_url":"https://github.com/NeuralEnsemble/elephant/pull/16.patch","issue_url":"https://api.github.com/repos/NeuralEnsemble/elephant/issues/16","number":16,"state":"open","locked":false,"title":"added binned class and tests","user":{"login":"alperyeg","id":6543291,"avatar_url":"https://avatars.githubusercontent.com/u/6543291?v=3","gravatar_id":"","url":"https://api.github.com/users/alperyeg","html_url":"https://github.com/alperyeg","followers_url":"https://api.github.com/users/alperyeg/followers","following_url":"https://api.github.com/users/alperyeg/following{/other_user}","gists_url":"https://api.github.com/users/alperyeg/gists{/gist_id}","starred_url":"https://api.github.com/users/alperyeg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alperyeg/subscriptions","organizations_url":"https://api.github.com/users/alperyeg/orgs","repos_url":"https://api.github.com/users/alperyeg/repos","events_url":"https://api.github.com/users/alperyeg/events{/privacy}","received_events_url":"https://api.github.com/users/alperyeg/received_events","type":"User","site_admin":false},"body":"This pull request integrates a binning class `Binned` in the `conversion` module, that provides a representation of binned (clipped, unclipped) spike trains based on sparse matrices, which is an important feature for large sets of spike trains in combination with fine-grained binning. This binning class therefore acts more as a specialized data type within elephant. The advantage of this class is that it takes care of efficiently handling the sparse matrix management for the user (optionally keeping the “non-sparse” matrices in memory) and handles the clipping, but also keeps the time axis in order (similar to the `AnalogSignal` class of `Neo`). Please note: The existing binning function in elephant (`conversion.binarize`) has intentionally not been touched in this PR.\r\n","created_at":"2015-02-02T09:01:44Z","updated_at":"2015-02-02T16:36:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15c2f124b5a8572f649df73e0246c6ebe94d95d3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16/commits","review_comments_url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16/comments","review_comment_url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/comments/{number}","comments_url":"https://api.github.com/repos/NeuralEnsemble/elephant/issues/16/comments","statuses_url":"https://api.github.com/repos/NeuralEnsemble/elephant/statuses/0464916b3a34d5cbd31dfe5fefa05069294cef81","head":{"label":"alperyeg:binning","ref":"binning","sha":"0464916b3a34d5cbd31dfe5fefa05069294cef81","user":{"login":"alperyeg","id":6543291,"avatar_url":"https://avatars.githubusercontent.com/u/6543291?v=3","gravatar_id":"","url":"https://api.github.com/users/alperyeg","html_url":"https://github.com/alperyeg","followers_url":"https://api.github.com/users/alperyeg/followers","following_url":"https://api.github.com/users/alperyeg/following{/other_user}","gists_url":"https://api.github.com/users/alperyeg/gists{/gist_id}","starred_url":"https://api.github.com/users/alperyeg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alperyeg/subscriptions","organizations_url":"https://api.github.com/users/alperyeg/orgs","repos_url":"https://api.github.com/users/alperyeg/repos","events_url":"https://api.github.com/users/alperyeg/events{/privacy}","received_events_url":"https://api.github.com/users/alperyeg/received_events","type":"User","site_admin":false},"repo":{"id":16373962,"name":"elephant","full_name":"alperyeg/elephant","owner":{"login":"alperyeg","id":6543291,"avatar_url":"https://avatars.githubusercontent.com/u/6543291?v=3","gravatar_id":"","url":"https://api.github.com/users/alperyeg","html_url":"https://github.com/alperyeg","followers_url":"https://api.github.com/users/alperyeg/followers","following_url":"https://api.github.com/users/alperyeg/following{/other_user}","gists_url":"https://api.github.com/users/alperyeg/gists{/gist_id}","starred_url":"https://api.github.com/users/alperyeg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alperyeg/subscriptions","organizations_url":"https://api.github.com/users/alperyeg/orgs","repos_url":"https://api.github.com/users/alperyeg/repos","events_url":"https://api.github.com/users/alperyeg/events{/privacy}","received_events_url":"https://api.github.com/users/alperyeg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alperyeg/elephant","description":"","fork":true,"url":"https://api.github.com/repos/alperyeg/elephant","forks_url":"https://api.github.com/repos/alperyeg/elephant/forks","keys_url":"https://api.github.com/repos/alperyeg/elephant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alperyeg/elephant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alperyeg/elephant/teams","hooks_url":"https://api.github.com/repos/alperyeg/elephant/hooks","issue_events_url":"https://api.github.com/repos/alperyeg/elephant/issues/events{/number}","events_url":"https://api.github.com/repos/alperyeg/elephant/events","assignees_url":"https://api.github.com/repos/alperyeg/elephant/assignees{/user}","branches_url":"https://api.github.com/repos/alperyeg/elephant/branches{/branch}","tags_url":"https://api.github.com/repos/alperyeg/elephant/tags","blobs_url":"https://api.github.com/repos/alperyeg/elephant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alperyeg/elephant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alperyeg/elephant/git/refs{/sha}","trees_url":"https://api.github.com/repos/alperyeg/elephant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alperyeg/elephant/statuses/{sha}","languages_url":"https://api.github.com/repos/alperyeg/elephant/languages","stargazers_url":"https://api.github.com/repos/alperyeg/elephant/stargazers","contributors_url":"https://api.github.com/repos/alperyeg/elephant/contributors","subscribers_url":"https://api.github.com/repos/alperyeg/elephant/subscribers","subscription_url":"https://api.github.com/repos/alperyeg/elephant/subscription","commits_url":"https://api.github.com/repos/alperyeg/elephant/commits{/sha}","git_commits_url":"https://api.github.com/repos/alperyeg/elephant/git/commits{/sha}","comments_url":"https://api.github.com/repos/alperyeg/elephant/comments{/number}","issue_comment_url":"https://api.github.com/repos/alperyeg/elephant/issues/comments/{number}","contents_url":"https://api.github.com/repos/alperyeg/elephant/contents/{+path}","compare_url":"https://api.github.com/repos/alperyeg/elephant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alperyeg/elephant/merges","archive_url":"https://api.github.com/repos/alperyeg/elephant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alperyeg/elephant/downloads","issues_url":"https://api.github.com/repos/alperyeg/elephant/issues{/number}","pulls_url":"https://api.github.com/repos/alperyeg/elephant/pulls{/number}","milestones_url":"https://api.github.com/repos/alperyeg/elephant/milestones{/number}","notifications_url":"https://api.github.com/repos/alperyeg/elephant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alperyeg/elephant/labels{/name}","releases_url":"https://api.github.com/repos/alperyeg/elephant/releases{/id}","created_at":"2014-01-30T10:11:28Z","updated_at":"2015-01-26T14:42:41Z","pushed_at":"2015-01-30T15:23:48Z","git_url":"git://github.com/alperyeg/elephant.git","ssh_url":"git@github.com:alperyeg/elephant.git","clone_url":"https://github.com/alperyeg/elephant.git","svn_url":"https://github.com/alperyeg/elephant","homepage":null,"size":458,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"NeuralEnsemble:master","ref":"master","sha":"37946e29566210dce1d0b9dd972e23da631f7a21","user":{"login":"NeuralEnsemble","id":1540309,"avatar_url":"https://avatars.githubusercontent.com/u/1540309?v=3","gravatar_id":"","url":"https://api.github.com/users/NeuralEnsemble","html_url":"https://github.com/NeuralEnsemble","followers_url":"https://api.github.com/users/NeuralEnsemble/followers","following_url":"https://api.github.com/users/NeuralEnsemble/following{/other_user}","gists_url":"https://api.github.com/users/NeuralEnsemble/gists{/gist_id}","starred_url":"https://api.github.com/users/NeuralEnsemble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NeuralEnsemble/subscriptions","organizations_url":"https://api.github.com/users/NeuralEnsemble/orgs","repos_url":"https://api.github.com/users/NeuralEnsemble/repos","events_url":"https://api.github.com/users/NeuralEnsemble/events{/privacy}","received_events_url":"https://api.github.com/users/NeuralEnsemble/received_events","type":"Organization","site_admin":false},"repo":{"id":10311278,"name":"elephant","full_name":"NeuralEnsemble/elephant","owner":{"login":"NeuralEnsemble","id":1540309,"avatar_url":"https://avatars.githubusercontent.com/u/1540309?v=3","gravatar_id":"","url":"https://api.github.com/users/NeuralEnsemble","html_url":"https://github.com/NeuralEnsemble","followers_url":"https://api.github.com/users/NeuralEnsemble/followers","following_url":"https://api.github.com/users/NeuralEnsemble/following{/other_user}","gists_url":"https://api.github.com/users/NeuralEnsemble/gists{/gist_id}","starred_url":"https://api.github.com/users/NeuralEnsemble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NeuralEnsemble/subscriptions","organizations_url":"https://api.github.com/users/NeuralEnsemble/orgs","repos_url":"https://api.github.com/users/NeuralEnsemble/repos","events_url":"https://api.github.com/users/NeuralEnsemble/events{/privacy}","received_events_url":"https://api.github.com/users/NeuralEnsemble/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NeuralEnsemble/elephant","description":"ElePhAnT is the ElectroPhysiology Analysis Toolkit","fork":false,"url":"https://api.github.com/repos/NeuralEnsemble/elephant","forks_url":"https://api.github.com/repos/NeuralEnsemble/elephant/forks","keys_url":"https://api.github.com/repos/NeuralEnsemble/elephant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NeuralEnsemble/elephant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NeuralEnsemble/elephant/teams","hooks_url":"https://api.github.com/repos/NeuralEnsemble/elephant/hooks","issue_events_url":"https://api.github.com/repos/NeuralEnsemble/elephant/issues/events{/number}","events_url":"https://api.github.com/repos/NeuralEnsemble/elephant/events","assignees_url":"https://api.github.com/repos/NeuralEnsemble/elephant/assignees{/user}","branches_url":"https://api.github.com/repos/NeuralEnsemble/elephant/branches{/branch}","tags_url":"https://api.github.com/repos/NeuralEnsemble/elephant/tags","blobs_url":"https://api.github.com/repos/NeuralEnsemble/elephant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NeuralEnsemble/elephant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NeuralEnsemble/elephant/git/refs{/sha}","trees_url":"https://api.github.com/repos/NeuralEnsemble/elephant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NeuralEnsemble/elephant/statuses/{sha}","languages_url":"https://api.github.com/repos/NeuralEnsemble/elephant/languages","stargazers_url":"https://api.github.com/repos/NeuralEnsemble/elephant/stargazers","contributors_url":"https://api.github.com/repos/NeuralEnsemble/elephant/contributors","subscribers_url":"https://api.github.com/repos/NeuralEnsemble/elephant/subscribers","subscription_url":"https://api.github.com/repos/NeuralEnsemble/elephant/subscription","commits_url":"https://api.github.com/repos/NeuralEnsemble/elephant/commits{/sha}","git_commits_url":"https://api.github.com/repos/NeuralEnsemble/elephant/git/commits{/sha}","comments_url":"https://api.github.com/repos/NeuralEnsemble/elephant/comments{/number}","issue_comment_url":"https://api.github.com/repos/NeuralEnsemble/elephant/issues/comments/{number}","contents_url":"https://api.github.com/repos/NeuralEnsemble/elephant/contents/{+path}","compare_url":"https://api.github.com/repos/NeuralEnsemble/elephant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NeuralEnsemble/elephant/merges","archive_url":"https://api.github.com/repos/NeuralEnsemble/elephant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NeuralEnsemble/elephant/downloads","issues_url":"https://api.github.com/repos/NeuralEnsemble/elephant/issues{/number}","pulls_url":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls{/number}","milestones_url":"https://api.github.com/repos/NeuralEnsemble/elephant/milestones{/number}","notifications_url":"https://api.github.com/repos/NeuralEnsemble/elephant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NeuralEnsemble/elephant/labels{/name}","releases_url":"https://api.github.com/repos/NeuralEnsemble/elephant/releases{/id}","created_at":"2013-05-27T08:59:34Z","updated_at":"2015-01-25T15:57:04Z","pushed_at":"2015-01-25T15:57:04Z","git_url":"git://github.com/NeuralEnsemble/elephant.git","ssh_url":"git@github.com:NeuralEnsemble/elephant.git","clone_url":"https://github.com/NeuralEnsemble/elephant.git","svn_url":"https://github.com/NeuralEnsemble/elephant","homepage":"","size":436,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":5,"forks":13,"open_issues":5,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16"},"html":{"href":"https://github.com/NeuralEnsemble/elephant/pull/16"},"issue":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/issues/16"},"comments":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/NeuralEnsemble/elephant/statuses/0464916b3a34d5cbd31dfe5fefa05069294cef81"}}}}