{"action":"created","comment":{"url":"https://api.github.com/repos/StingraySoftware/stingray/pulls/comments/55581878","id":55581878,"diff_hunk":"@@ -0,0 +1,118 @@\n+\n+from __future__ import division\n+import numpy as np\n+from scipy.linalg import hankel\n+import scipy.fftpack\n+import stingray.lightcurve as lightcurve\n+import stingray.utils as utils\n+from stingray.utils import simon\n+__all__ = [\"Bispectrum\"]\n+\n+\n+class Bispectrum(object):\n+  \n+\n+  def __init__(self, lc=None,m=64, nfft=128):\n+\n+    \"\"\"\n+   \n+    \n+    Parameters \n+    ----------\n+    lc: lightcurve.Lightcurve object, optional, default None\n+            The light curve data to be Fourier-transformed.\n+    \n+    m : Number of samples in each segment Default :64(expecting huge data)\n+\n+    nfft : Fft size Default is 128 \n+ \n+\n+    attributes\n+    ----------\n+    k: Number of segments\n+\n+    m : Number of samples in each segment Default :64(expecting huge data)\n+\n+    nfft : Fft size Default is 128\n+\n+    nsamp  : total numberof samples from the input signal \n+\n+\n+    \"\"\"\n+\n+    if lc is not None :\n+      pass\n+    else :\n+        self.k=None\n+        self.nfft=None\n+        self.m=None\n+        self.nsamp=None\n+        return \n+\n+    assert isinstance(lc, lightcurve.Lightcurve), \\\n+            \"lc must be a lightcurve.Lightcurve object!\"\n+\n+    lc.counts = lc.counts.ravel(order='C')\n+    self.nsamp  =lc.counts.shape[0]\n+\n+    \n+    assert isinstance(m, int ), \"m is not a int !\"\n+\n+    assert isinstance(nfft, int), \"nfft is not a string!\"\n+    \n+    self.k= self.nsamp//self.m\n+    \n+  def compute_bispectra(self,lc):\n+  \t\n+\n+  \t\n+    bispec = np.zeros([self.nfft,self.nfft]) \n+    mask = hankel(np.arange(self.nfft),np.array([self.nfft-1]+range(self.nfft-1)))\n+    #here hankel serves  the function of summed frequncy which is used in bispectra \n+    pseg = np.arange(self.m).transpose()\n+\n+    for i in xrange(self.k):\n+      iseg = lc.counts[pseg].reshape(1,-1)\n+      Xf = scipy.fftpack.fft(iseg - np.mean(iseg), self.nfft) / self.m\n+      CXf = np.conjugate(Xf).ravel(order='C') \n+      bispec = bispec + \\\n+       (Xf * np.transpose(Xf)) * CXf[mask].reshape(self.nfft, self.nfft)\n+      pseg = pseg + self.m\n+\n+    bispec = scipy.fftpack.fftshift(bispec) / self.k\n+\n+\n+ \n+    return bispec\n+\n+\n+ \n+  def bicoherence(self,lc): \n+\n+    bispec = np.zeros([self.nfft,self.nfft]) \n+    mask = hankel(np.arange(self.nfft),np.array([self.nfft-1]+range(self.nfft-1)))\n+    #here hankel serves  the function of summed frequncy which is used in bispectra \n+    pseg = np.arange(self.m).transpose()\n+    sklsq= np.zeros([self.nfft,self.nfft]) \n+    # k and l frequncies and their square summed over all segments\n+    skplsq=np.zeros([self.nfft,self.nfft]) \n+    # frequency at k plus l and its square summed over all segments  \n+   \n+    for i in xrange(self.k):\n+      iseg = lc.counts[pseg].reshape(1,-1)\n+      Xf = scipy.fftpack.fft(iseg - np.mean(iseg), self.nfft) / self.m\n+      CXf = np.conjugate(Xf).ravel(order='C')\n+      sklsq= sklsq+(Xf * np.transpose(Xf))**2\n+      skplsq=skplsq + (CXf[mask].reshape(self.nfft, self.nfft)**2)\n+      bispec = bispec + \\\n+      (Xf * np.transpose(Xf)) * CXf[mask].reshape(self.nfft, self.nfft)\n+      pseg = pseg + self.m\n+\n+    bispec=bispec/self.k;\n+    sklsq=sklsq/self.k\n+    skplsq=skplsq/self.k\n+\n+    bicoh= (bispec**2) / (sklsq*skplsq)\n+\n+  \treturn bicoh","path":"stingray/bispectrum.py","position":null,"original_position":117,"commit_id":"9726f2f60969f842c14cc64ec25d2bad8bfbb2b9","original_commit_id":"f06920b067563f7cdb9f0854714095256fab7bc2","user":{"login":"nithinsingh61","id":5621783,"avatar_url":"https://avatars.githubusercontent.com/u/5621783?v=3","gravatar_id":"","url":"https://api.github.com/users/nithinsingh61","html_url":"https://github.com/nithinsingh61","followers_url":"https://api.github.com/users/nithinsingh61/followers","following_url":"https://api.github.com/users/nithinsingh61/following{/other_user}","gists_url":"https://api.github.com/users/nithinsingh61/gists{/gist_id}","starred_url":"https://api.github.com/users/nithinsingh61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nithinsingh61/subscriptions","organizations_url":"https://api.github.com/users/nithinsingh61/orgs","repos_url":"https://api.github.com/users/nithinsingh61/repos","events_url":"https://api.github.com/users/nithinsingh61/events{/privacy}","received_events_url":"https://api.github.com/users/nithinsingh61/received_events","type":"User","site_admin":false},"body":"In test_powerspectrum.py  all cases were around data 's fidelity and (no direct test on powerspectrum) ","created_at":"2016-03-09T20:16:44Z","updated_at":"2016-03-09T20:16:44Z","html_url":"https://github.com/StingraySoftware/stingray/pull/64#discussion_r55581878","pull_request_url":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64","_links":{"self":{"href":"https://api.github.com/repos/StingraySoftware/stingray/pulls/comments/55581878"},"html":{"href":"https://github.com/StingraySoftware/stingray/pull/64#discussion_r55581878"},"pull_request":{"href":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64"}}},"pull_request":{"url":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64","id":61849762,"html_url":"https://github.com/StingraySoftware/stingray/pull/64","diff_url":"https://github.com/StingraySoftware/stingray/pull/64.diff","patch_url":"https://github.com/StingraySoftware/stingray/pull/64.patch","issue_url":"https://api.github.com/repos/StingraySoftware/stingray/issues/64","number":64,"state":"open","locked":false,"title":"Added bispectra","user":{"login":"nithinsingh61","id":5621783,"avatar_url":"https://avatars.githubusercontent.com/u/5621783?v=3","gravatar_id":"","url":"https://api.github.com/users/nithinsingh61","html_url":"https://github.com/nithinsingh61","followers_url":"https://api.github.com/users/nithinsingh61/followers","following_url":"https://api.github.com/users/nithinsingh61/following{/other_user}","gists_url":"https://api.github.com/users/nithinsingh61/gists{/gist_id}","starred_url":"https://api.github.com/users/nithinsingh61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nithinsingh61/subscriptions","organizations_url":"https://api.github.com/users/nithinsingh61/orgs","repos_url":"https://api.github.com/users/nithinsingh61/repos","events_url":"https://api.github.com/users/nithinsingh61/events{/privacy}","received_events_url":"https://api.github.com/users/nithinsingh61/received_events","type":"User","site_admin":false},"body":"Hello ! I have tried implementing bispectra and need your advice\r\n\r\nHow do we access lightobject (Is it created out of .evt present in data ?) Being unable to access lighobject I gave custom input for lc.counts(array),the corresponding bi spectra resulted out well   \r\n\r\nI have assumed fft size as 128(some default value ) or should that be given as an argument to bispectra \r\n\r\nI am open source newbie ,Apologies if something went wrong !\r\n@dhuppenkothen  @matteobachetti ","created_at":"2016-03-06T18:08:22Z","updated_at":"2016-03-09T20:16:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cb97ef5e9a010f0f918e361ac150812bbaf7bb0b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64/commits","review_comments_url":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64/comments","review_comment_url":"https://api.github.com/repos/StingraySoftware/stingray/pulls/comments{/number}","comments_url":"https://api.github.com/repos/StingraySoftware/stingray/issues/64/comments","statuses_url":"https://api.github.com/repos/StingraySoftware/stingray/statuses/9726f2f60969f842c14cc64ec25d2bad8bfbb2b9","head":{"label":"nithinsingh61:bispectra","ref":"bispectra","sha":"9726f2f60969f842c14cc64ec25d2bad8bfbb2b9","user":{"login":"nithinsingh61","id":5621783,"avatar_url":"https://avatars.githubusercontent.com/u/5621783?v=3","gravatar_id":"","url":"https://api.github.com/users/nithinsingh61","html_url":"https://github.com/nithinsingh61","followers_url":"https://api.github.com/users/nithinsingh61/followers","following_url":"https://api.github.com/users/nithinsingh61/following{/other_user}","gists_url":"https://api.github.com/users/nithinsingh61/gists{/gist_id}","starred_url":"https://api.github.com/users/nithinsingh61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nithinsingh61/subscriptions","organizations_url":"https://api.github.com/users/nithinsingh61/orgs","repos_url":"https://api.github.com/users/nithinsingh61/repos","events_url":"https://api.github.com/users/nithinsingh61/events{/privacy}","received_events_url":"https://api.github.com/users/nithinsingh61/received_events","type":"User","site_admin":false},"repo":{"id":53255396,"name":"stingray","full_name":"nithinsingh61/stingray","owner":{"login":"nithinsingh61","id":5621783,"avatar_url":"https://avatars.githubusercontent.com/u/5621783?v=3","gravatar_id":"","url":"https://api.github.com/users/nithinsingh61","html_url":"https://github.com/nithinsingh61","followers_url":"https://api.github.com/users/nithinsingh61/followers","following_url":"https://api.github.com/users/nithinsingh61/following{/other_user}","gists_url":"https://api.github.com/users/nithinsingh61/gists{/gist_id}","starred_url":"https://api.github.com/users/nithinsingh61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nithinsingh61/subscriptions","organizations_url":"https://api.github.com/users/nithinsingh61/orgs","repos_url":"https://api.github.com/users/nithinsingh61/repos","events_url":"https://api.github.com/users/nithinsingh61/events{/privacy}","received_events_url":"https://api.github.com/users/nithinsingh61/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nithinsingh61/stingray","description":"Time Series Methods For Astronomical X-ray Data That Aren''t Fishy At All!","fork":true,"url":"https://api.github.com/repos/nithinsingh61/stingray","forks_url":"https://api.github.com/repos/nithinsingh61/stingray/forks","keys_url":"https://api.github.com/repos/nithinsingh61/stingray/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nithinsingh61/stingray/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nithinsingh61/stingray/teams","hooks_url":"https://api.github.com/repos/nithinsingh61/stingray/hooks","issue_events_url":"https://api.github.com/repos/nithinsingh61/stingray/issues/events{/number}","events_url":"https://api.github.com/repos/nithinsingh61/stingray/events","assignees_url":"https://api.github.com/repos/nithinsingh61/stingray/assignees{/user}","branches_url":"https://api.github.com/repos/nithinsingh61/stingray/branches{/branch}","tags_url":"https://api.github.com/repos/nithinsingh61/stingray/tags","blobs_url":"https://api.github.com/repos/nithinsingh61/stingray/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nithinsingh61/stingray/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nithinsingh61/stingray/git/refs{/sha}","trees_url":"https://api.github.com/repos/nithinsingh61/stingray/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nithinsingh61/stingray/statuses/{sha}","languages_url":"https://api.github.com/repos/nithinsingh61/stingray/languages","stargazers_url":"https://api.github.com/repos/nithinsingh61/stingray/stargazers","contributors_url":"https://api.github.com/repos/nithinsingh61/stingray/contributors","subscribers_url":"https://api.github.com/repos/nithinsingh61/stingray/subscribers","subscription_url":"https://api.github.com/repos/nithinsingh61/stingray/subscription","commits_url":"https://api.github.com/repos/nithinsingh61/stingray/commits{/sha}","git_commits_url":"https://api.github.com/repos/nithinsingh61/stingray/git/commits{/sha}","comments_url":"https://api.github.com/repos/nithinsingh61/stingray/comments{/number}","issue_comment_url":"https://api.github.com/repos/nithinsingh61/stingray/issues/comments{/number}","contents_url":"https://api.github.com/repos/nithinsingh61/stingray/contents/{+path}","compare_url":"https://api.github.com/repos/nithinsingh61/stingray/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nithinsingh61/stingray/merges","archive_url":"https://api.github.com/repos/nithinsingh61/stingray/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nithinsingh61/stingray/downloads","issues_url":"https://api.github.com/repos/nithinsingh61/stingray/issues{/number}","pulls_url":"https://api.github.com/repos/nithinsingh61/stingray/pulls{/number}","milestones_url":"https://api.github.com/repos/nithinsingh61/stingray/milestones{/number}","notifications_url":"https://api.github.com/repos/nithinsingh61/stingray/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nithinsingh61/stingray/labels{/name}","releases_url":"https://api.github.com/repos/nithinsingh61/stingray/releases{/id}","deployments_url":"https://api.github.com/repos/nithinsingh61/stingray/deployments","created_at":"2016-03-06T13:10:32Z","updated_at":"2016-03-06T13:10:32Z","pushed_at":"2016-03-09T19:12:59Z","git_url":"git://github.com/nithinsingh61/stingray.git","ssh_url":"git@github.com:nithinsingh61/stingray.git","clone_url":"https://github.com/nithinsingh61/stingray.git","svn_url":"https://github.com/nithinsingh61/stingray","homepage":null,"size":721,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"StingraySoftware:master","ref":"master","sha":"af47cde0e2b034f2840fc325db6e5bd8c218bb93","user":{"login":"StingraySoftware","id":17048750,"avatar_url":"https://avatars.githubusercontent.com/u/17048750?v=3","gravatar_id":"","url":"https://api.github.com/users/StingraySoftware","html_url":"https://github.com/StingraySoftware","followers_url":"https://api.github.com/users/StingraySoftware/followers","following_url":"https://api.github.com/users/StingraySoftware/following{/other_user}","gists_url":"https://api.github.com/users/StingraySoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/StingraySoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StingraySoftware/subscriptions","organizations_url":"https://api.github.com/users/StingraySoftware/orgs","repos_url":"https://api.github.com/users/StingraySoftware/repos","events_url":"https://api.github.com/users/StingraySoftware/events{/privacy}","received_events_url":"https://api.github.com/users/StingraySoftware/received_events","type":"Organization","site_admin":false},"repo":{"id":43449839,"name":"stingray","full_name":"StingraySoftware/stingray","owner":{"login":"StingraySoftware","id":17048750,"avatar_url":"https://avatars.githubusercontent.com/u/17048750?v=3","gravatar_id":"","url":"https://api.github.com/users/StingraySoftware","html_url":"https://github.com/StingraySoftware","followers_url":"https://api.github.com/users/StingraySoftware/followers","following_url":"https://api.github.com/users/StingraySoftware/following{/other_user}","gists_url":"https://api.github.com/users/StingraySoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/StingraySoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StingraySoftware/subscriptions","organizations_url":"https://api.github.com/users/StingraySoftware/orgs","repos_url":"https://api.github.com/users/StingraySoftware/repos","events_url":"https://api.github.com/users/StingraySoftware/events{/privacy}","received_events_url":"https://api.github.com/users/StingraySoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/StingraySoftware/stingray","description":"Time Series Methods For Astronomical X-ray Data That Aren''t Fishy At All!","fork":false,"url":"https://api.github.com/repos/StingraySoftware/stingray","forks_url":"https://api.github.com/repos/StingraySoftware/stingray/forks","keys_url":"https://api.github.com/repos/StingraySoftware/stingray/keys{/key_id}","collaborators_url":"https://api.github.com/repos/StingraySoftware/stingray/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/StingraySoftware/stingray/teams","hooks_url":"https://api.github.com/repos/StingraySoftware/stingray/hooks","issue_events_url":"https://api.github.com/repos/StingraySoftware/stingray/issues/events{/number}","events_url":"https://api.github.com/repos/StingraySoftware/stingray/events","assignees_url":"https://api.github.com/repos/StingraySoftware/stingray/assignees{/user}","branches_url":"https://api.github.com/repos/StingraySoftware/stingray/branches{/branch}","tags_url":"https://api.github.com/repos/StingraySoftware/stingray/tags","blobs_url":"https://api.github.com/repos/StingraySoftware/stingray/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/StingraySoftware/stingray/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/StingraySoftware/stingray/git/refs{/sha}","trees_url":"https://api.github.com/repos/StingraySoftware/stingray/git/trees{/sha}","statuses_url":"https://api.github.com/repos/StingraySoftware/stingray/statuses/{sha}","languages_url":"https://api.github.com/repos/StingraySoftware/stingray/languages","stargazers_url":"https://api.github.com/repos/StingraySoftware/stingray/stargazers","contributors_url":"https://api.github.com/repos/StingraySoftware/stingray/contributors","subscribers_url":"https://api.github.com/repos/StingraySoftware/stingray/subscribers","subscription_url":"https://api.github.com/repos/StingraySoftware/stingray/subscription","commits_url":"https://api.github.com/repos/StingraySoftware/stingray/commits{/sha}","git_commits_url":"https://api.github.com/repos/StingraySoftware/stingray/git/commits{/sha}","comments_url":"https://api.github.com/repos/StingraySoftware/stingray/comments{/number}","issue_comment_url":"https://api.github.com/repos/StingraySoftware/stingray/issues/comments{/number}","contents_url":"https://api.github.com/repos/StingraySoftware/stingray/contents/{+path}","compare_url":"https://api.github.com/repos/StingraySoftware/stingray/compare/{base}...{head}","merges_url":"https://api.github.com/repos/StingraySoftware/stingray/merges","archive_url":"https://api.github.com/repos/StingraySoftware/stingray/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/StingraySoftware/stingray/downloads","issues_url":"https://api.github.com/repos/StingraySoftware/stingray/issues{/number}","pulls_url":"https://api.github.com/repos/StingraySoftware/stingray/pulls{/number}","milestones_url":"https://api.github.com/repos/StingraySoftware/stingray/milestones{/number}","notifications_url":"https://api.github.com/repos/StingraySoftware/stingray/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/StingraySoftware/stingray/labels{/name}","releases_url":"https://api.github.com/repos/StingraySoftware/stingray/releases{/id}","deployments_url":"https://api.github.com/repos/StingraySoftware/stingray/deployments","created_at":"2015-09-30T18:04:33Z","updated_at":"2016-03-03T10:34:12Z","pushed_at":"2016-03-09T19:13:00Z","git_url":"git://github.com/StingraySoftware/stingray.git","ssh_url":"git@github.com:StingraySoftware/stingray.git","clone_url":"https://github.com/StingraySoftware/stingray.git","svn_url":"https://github.com/StingraySoftware/stingray","homepage":null,"size":849,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":24,"forks":21,"open_issues":24,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64"},"html":{"href":"https://github.com/StingraySoftware/stingray/pull/64"},"issue":{"href":"https://api.github.com/repos/StingraySoftware/stingray/issues/64"},"comments":{"href":"https://api.github.com/repos/StingraySoftware/stingray/issues/64/comments"},"review_comments":{"href":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64/comments"},"review_comment":{"href":"https://api.github.com/repos/StingraySoftware/stingray/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/StingraySoftware/stingray/pulls/64/commits"},"statuses":{"href":"https://api.github.com/repos/StingraySoftware/stingray/statuses/9726f2f60969f842c14cc64ec25d2bad8bfbb2b9"}}}}