{"action":"created","comment":{"url":"https://api.github.com/repos/bendalab/thunderfish/pulls/comments/74021299","id":74021299,"diff_hunk":"@@ -0,0 +1,196 @@\n+\"\"\"\n+Detection of chirps in weakly electric fish recordings.\n+\n+chirp_analysis(): calculates spectrogram, detects fishes and extracts chirp times(combined for all fishes).\n+                  !!! recommended for short recordings (up to 5 min) where only the chirp times shall be extracted !!!\n+chirp_detection(): extracts chirp times with help of given spectrogram and fishlist.\n+chirp_spectrogram(): performs spectrogram suitable for chip detection.\n+\"\"\"\n+\n+import sys\n+import numpy as np\n+import matplotlib.mlab as mlab\n+import dataloader as dl\n+import harmonicgroups as hg\n+import config_tools as ct\n+import powerspectrum as ps\n+import matplotlib.pyplot as plt\n+import peakdetection as pkd\n+\n+def chirp_spectrogram(data, samplerate, fresolution=0.5, detrend=mlab.detrend_none, window=mlab.window_hanning, overlap_frac=0.5,\n+                      pad_to=None, sides='default', scale_by_freq=None):\n+    \"\"\"\n+    Spectrogram of a given frequency resolution.\n+\n+    :param data: (array) data for the spectrogram.\n+    :param samplerate: (float) samplerate of data in Hertz.\n+    :param fresolution: (float) frequency resolution for the spectrogram.\n+    :param overlap_frac: (float) overlap of the nffts (0 = no overlap; 1 = total overlap).\n+    :return spectrum: (2d array) contains for every timestamp the power of the frequencies listed in the array \"freqs\".\n+    :return freqs: (array) frequencies of the spectrogram.\n+    :return time: (array) time of the nffts.\n+    \"\"\"\n+\n+    def nfft_noverlap(freq_resolution, samplerate, overlap_frac, min_nfft=0, nfft_multiplikation = 1.):\n+        \"\"\"The required number of points for an FFT to achieve a minimum frequency resolution\n+        and the number of overlapping data points.\n+\n+        :param freq_resolution: (float) the minimum required frequency resolution in Hertz.\n+        :param samplerate: (float) the sampling rate of the data in Hertz.\n+        :param overlap_frac: (float) the fraction the FFT windows should overlap.\n+        :param min_nfft: (int) the smallest value of nfft to be used.\n+        :param nfft_multiplikation (float) value the nfft is multiplicated with to increase/decrease nfft size.\n+        :return nfft: (int) the number of FFT points.\n+        :return noverlap: (int) the number of overlapping FFT points.\n+        \"\"\"\n+        nfft = ps.next_power_of_two(samplerate / freq_resolution)\n+        nfft *= nfft_multiplikation\n+        nfft = int(nfft)\n+        if nfft < min_nfft:\n+            nfft = min_nfft\n+        noverlap = int(nfft * overlap_frac)\n+        return nfft, noverlap\n+\n+    nfft, noverlap = nfft_noverlap(fresolution, samplerate, overlap_frac, min_nfft=16, nfft_multiplikation= 0.25)\n+\n+    spectrum, freqs, time = mlab.specgram(data, NFFT=nfft, Fs=samplerate, detrend=detrend, window=window,\n+                                          noverlap=noverlap, pad_to=pad_to, sides=sides, scale_by_freq=scale_by_freq)\n+    return spectrum, freqs, time\n+\n+def clean_chirps(chirp_time_idx, power, power_window=100):\n+    \"\"\"\n+    Chirp is only accepted as such if the power of the frequency drops down as expected.\n+\n+    :param chirp_time_idx: (array) indices of chirps.\n+    :param power: (array) power array containing for each timestamp the max value in power of a certain frequency range.\n+    :param power_window (int) datapoints arroung a detected chirp used to verify that there is a chirp.\n+    :return: chirp_time_idx: (array) indices of chirps that have been confirmed to be chirps.\n+    \"\"\"\n+    true_chirps = np.array([], dtype=bool)","path":"thunderfish/chirp.py","position":69,"original_position":69,"commit_id":"7012317e670667bdc836f9cd9acc71d805d38e84","original_commit_id":"7012317e670667bdc836f9cd9acc71d805d38e84","user":{"login":"janscience","id":12050052,"avatar_url":"https://avatars.githubusercontent.com/u/12050052?v=3","gravatar_id":"","url":"https://api.github.com/users/janscience","html_url":"https://github.com/janscience","followers_url":"https://api.github.com/users/janscience/followers","following_url":"https://api.github.com/users/janscience/following{/other_user}","gists_url":"https://api.github.com/users/janscience/gists{/gist_id}","starred_url":"https://api.github.com/users/janscience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janscience/subscriptions","organizations_url":"https://api.github.com/users/janscience/orgs","repos_url":"https://api.github.com/users/janscience/repos","events_url":"https://api.github.com/users/janscience/events{/privacy}","received_events_url":"https://api.github.com/users/janscience/received_events","type":"User","site_admin":false},"body":"why not making a list with the true chirp indices?","created_at":"2016-08-09T08:52:56Z","updated_at":"2016-08-09T08:52:56Z","html_url":"https://github.com/bendalab/thunderfish/pull/47#discussion_r74021299","pull_request_url":"https://api.github.com/repos/bendalab/thunderfish/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/bendalab/thunderfish/pulls/comments/74021299"},"html":{"href":"https://github.com/bendalab/thunderfish/pull/47#discussion_r74021299"},"pull_request":{"href":"https://api.github.com/repos/bendalab/thunderfish/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/bendalab/thunderfish/pulls/47","id":80579505,"html_url":"https://github.com/bendalab/thunderfish/pull/47","diff_url":"https://github.com/bendalab/thunderfish/pull/47.diff","patch_url":"https://github.com/bendalab/thunderfish/pull/47.patch","issue_url":"https://api.github.com/repos/bendalab/thunderfish/issues/47","number":47,"state":"open","locked":false,"title":"Chirps","user":{"login":"tillraab","id":16877768,"avatar_url":"https://avatars.githubusercontent.com/u/16877768?v=3","gravatar_id":"","url":"https://api.github.com/users/tillraab","html_url":"https://github.com/tillraab","followers_url":"https://api.github.com/users/tillraab/followers","following_url":"https://api.github.com/users/tillraab/following{/other_user}","gists_url":"https://api.github.com/users/tillraab/gists{/gist_id}","starred_url":"https://api.github.com/users/tillraab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tillraab/subscriptions","organizations_url":"https://api.github.com/users/tillraab/orgs","repos_url":"https://api.github.com/users/tillraab/repos","events_url":"https://api.github.com/users/tillraab/events{/privacy}","received_events_url":"https://api.github.com/users/tillraab/received_events","type":"User","site_admin":false},"body":"New script used to detects chirps based on power drops in small frequency bands of a spectrogram.\r\n\r\nFurthermore it seems like I mixed up two branches and edited some stuff in the thunderfish output.","created_at":"2016-08-09T08:24:44Z","updated_at":"2016-08-09T08:52:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75afd5ea456dfecc488b4aca275c1d969bb1af90","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/bendalab/thunderfish/pulls/47/commits","review_comments_url":"https://api.github.com/repos/bendalab/thunderfish/pulls/47/comments","review_comment_url":"https://api.github.com/repos/bendalab/thunderfish/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bendalab/thunderfish/issues/47/comments","statuses_url":"https://api.github.com/repos/bendalab/thunderfish/statuses/7012317e670667bdc836f9cd9acc71d805d38e84","head":{"label":"tillraab:chirps","ref":"chirps","sha":"7012317e670667bdc836f9cd9acc71d805d38e84","user":{"login":"tillraab","id":16877768,"avatar_url":"https://avatars.githubusercontent.com/u/16877768?v=3","gravatar_id":"","url":"https://api.github.com/users/tillraab","html_url":"https://github.com/tillraab","followers_url":"https://api.github.com/users/tillraab/followers","following_url":"https://api.github.com/users/tillraab/following{/other_user}","gists_url":"https://api.github.com/users/tillraab/gists{/gist_id}","starred_url":"https://api.github.com/users/tillraab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tillraab/subscriptions","organizations_url":"https://api.github.com/users/tillraab/orgs","repos_url":"https://api.github.com/users/tillraab/repos","events_url":"https://api.github.com/users/tillraab/events{/privacy}","received_events_url":"https://api.github.com/users/tillraab/received_events","type":"User","site_admin":false},"repo":{"id":50345454,"name":"thunderfish","full_name":"tillraab/thunderfish","owner":{"login":"tillraab","id":16877768,"avatar_url":"https://avatars.githubusercontent.com/u/16877768?v=3","gravatar_id":"","url":"https://api.github.com/users/tillraab","html_url":"https://github.com/tillraab","followers_url":"https://api.github.com/users/tillraab/followers","following_url":"https://api.github.com/users/tillraab/following{/other_user}","gists_url":"https://api.github.com/users/tillraab/gists{/gist_id}","starred_url":"https://api.github.com/users/tillraab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tillraab/subscriptions","organizations_url":"https://api.github.com/users/tillraab/orgs","repos_url":"https://api.github.com/users/tillraab/repos","events_url":"https://api.github.com/users/tillraab/events{/privacy}","received_events_url":"https://api.github.com/users/tillraab/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tillraab/thunderfish","description":"python scripts for analyzing recordings of efish electric fields.","fork":true,"url":"https://api.github.com/repos/tillraab/thunderfish","forks_url":"https://api.github.com/repos/tillraab/thunderfish/forks","keys_url":"https://api.github.com/repos/tillraab/thunderfish/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tillraab/thunderfish/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tillraab/thunderfish/teams","hooks_url":"https://api.github.com/repos/tillraab/thunderfish/hooks","issue_events_url":"https://api.github.com/repos/tillraab/thunderfish/issues/events{/number}","events_url":"https://api.github.com/repos/tillraab/thunderfish/events","assignees_url":"https://api.github.com/repos/tillraab/thunderfish/assignees{/user}","branches_url":"https://api.github.com/repos/tillraab/thunderfish/branches{/branch}","tags_url":"https://api.github.com/repos/tillraab/thunderfish/tags","blobs_url":"https://api.github.com/repos/tillraab/thunderfish/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tillraab/thunderfish/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tillraab/thunderfish/git/refs{/sha}","trees_url":"https://api.github.com/repos/tillraab/thunderfish/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tillraab/thunderfish/statuses/{sha}","languages_url":"https://api.github.com/repos/tillraab/thunderfish/languages","stargazers_url":"https://api.github.com/repos/tillraab/thunderfish/stargazers","contributors_url":"https://api.github.com/repos/tillraab/thunderfish/contributors","subscribers_url":"https://api.github.com/repos/tillraab/thunderfish/subscribers","subscription_url":"https://api.github.com/repos/tillraab/thunderfish/subscription","commits_url":"https://api.github.com/repos/tillraab/thunderfish/commits{/sha}","git_commits_url":"https://api.github.com/repos/tillraab/thunderfish/git/commits{/sha}","comments_url":"https://api.github.com/repos/tillraab/thunderfish/comments{/number}","issue_comment_url":"https://api.github.com/repos/tillraab/thunderfish/issues/comments{/number}","contents_url":"https://api.github.com/repos/tillraab/thunderfish/contents/{+path}","compare_url":"https://api.github.com/repos/tillraab/thunderfish/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tillraab/thunderfish/merges","archive_url":"https://api.github.com/repos/tillraab/thunderfish/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tillraab/thunderfish/downloads","issues_url":"https://api.github.com/repos/tillraab/thunderfish/issues{/number}","pulls_url":"https://api.github.com/repos/tillraab/thunderfish/pulls{/number}","milestones_url":"https://api.github.com/repos/tillraab/thunderfish/milestones{/number}","notifications_url":"https://api.github.com/repos/tillraab/thunderfish/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tillraab/thunderfish/labels{/name}","releases_url":"https://api.github.com/repos/tillraab/thunderfish/releases{/id}","deployments_url":"https://api.github.com/repos/tillraab/thunderfish/deployments","created_at":"2016-01-25T11:09:59Z","updated_at":"2016-01-25T11:10:01Z","pushed_at":"2016-08-09T08:24:16Z","git_url":"git://github.com/tillraab/thunderfish.git","ssh_url":"git@github.com:tillraab/thunderfish.git","clone_url":"https://github.com/tillraab/thunderfish.git","svn_url":"https://github.com/tillraab/thunderfish","homepage":null,"size":702,"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":"bendalab:master","ref":"master","sha":"34cbfa5c8a3696770e079e41eb9a57dc15da85cb","user":{"login":"bendalab","id":10567758,"avatar_url":"https://avatars.githubusercontent.com/u/10567758?v=3","gravatar_id":"","url":"https://api.github.com/users/bendalab","html_url":"https://github.com/bendalab","followers_url":"https://api.github.com/users/bendalab/followers","following_url":"https://api.github.com/users/bendalab/following{/other_user}","gists_url":"https://api.github.com/users/bendalab/gists{/gist_id}","starred_url":"https://api.github.com/users/bendalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendalab/subscriptions","organizations_url":"https://api.github.com/users/bendalab/orgs","repos_url":"https://api.github.com/users/bendalab/repos","events_url":"https://api.github.com/users/bendalab/events{/privacy}","received_events_url":"https://api.github.com/users/bendalab/received_events","type":"Organization","site_admin":false},"repo":{"id":50343080,"name":"thunderfish","full_name":"bendalab/thunderfish","owner":{"login":"bendalab","id":10567758,"avatar_url":"https://avatars.githubusercontent.com/u/10567758?v=3","gravatar_id":"","url":"https://api.github.com/users/bendalab","html_url":"https://github.com/bendalab","followers_url":"https://api.github.com/users/bendalab/followers","following_url":"https://api.github.com/users/bendalab/following{/other_user}","gists_url":"https://api.github.com/users/bendalab/gists{/gist_id}","starred_url":"https://api.github.com/users/bendalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendalab/subscriptions","organizations_url":"https://api.github.com/users/bendalab/orgs","repos_url":"https://api.github.com/users/bendalab/repos","events_url":"https://api.github.com/users/bendalab/events{/privacy}","received_events_url":"https://api.github.com/users/bendalab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bendalab/thunderfish","description":"python scripts for analyzing recordings of efish electric fields.","fork":false,"url":"https://api.github.com/repos/bendalab/thunderfish","forks_url":"https://api.github.com/repos/bendalab/thunderfish/forks","keys_url":"https://api.github.com/repos/bendalab/thunderfish/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bendalab/thunderfish/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bendalab/thunderfish/teams","hooks_url":"https://api.github.com/repos/bendalab/thunderfish/hooks","issue_events_url":"https://api.github.com/repos/bendalab/thunderfish/issues/events{/number}","events_url":"https://api.github.com/repos/bendalab/thunderfish/events","assignees_url":"https://api.github.com/repos/bendalab/thunderfish/assignees{/user}","branches_url":"https://api.github.com/repos/bendalab/thunderfish/branches{/branch}","tags_url":"https://api.github.com/repos/bendalab/thunderfish/tags","blobs_url":"https://api.github.com/repos/bendalab/thunderfish/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bendalab/thunderfish/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bendalab/thunderfish/git/refs{/sha}","trees_url":"https://api.github.com/repos/bendalab/thunderfish/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bendalab/thunderfish/statuses/{sha}","languages_url":"https://api.github.com/repos/bendalab/thunderfish/languages","stargazers_url":"https://api.github.com/repos/bendalab/thunderfish/stargazers","contributors_url":"https://api.github.com/repos/bendalab/thunderfish/contributors","subscribers_url":"https://api.github.com/repos/bendalab/thunderfish/subscribers","subscription_url":"https://api.github.com/repos/bendalab/thunderfish/subscription","commits_url":"https://api.github.com/repos/bendalab/thunderfish/commits{/sha}","git_commits_url":"https://api.github.com/repos/bendalab/thunderfish/git/commits{/sha}","comments_url":"https://api.github.com/repos/bendalab/thunderfish/comments{/number}","issue_comment_url":"https://api.github.com/repos/bendalab/thunderfish/issues/comments{/number}","contents_url":"https://api.github.com/repos/bendalab/thunderfish/contents/{+path}","compare_url":"https://api.github.com/repos/bendalab/thunderfish/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bendalab/thunderfish/merges","archive_url":"https://api.github.com/repos/bendalab/thunderfish/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bendalab/thunderfish/downloads","issues_url":"https://api.github.com/repos/bendalab/thunderfish/issues{/number}","pulls_url":"https://api.github.com/repos/bendalab/thunderfish/pulls{/number}","milestones_url":"https://api.github.com/repos/bendalab/thunderfish/milestones{/number}","notifications_url":"https://api.github.com/repos/bendalab/thunderfish/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bendalab/thunderfish/labels{/name}","releases_url":"https://api.github.com/repos/bendalab/thunderfish/releases{/id}","deployments_url":"https://api.github.com/repos/bendalab/thunderfish/deployments","created_at":"2016-01-25T10:22:55Z","updated_at":"2016-01-25T10:51:51Z","pushed_at":"2016-08-09T08:24:45Z","git_url":"git://github.com/bendalab/thunderfish.git","ssh_url":"git@github.com:bendalab/thunderfish.git","clone_url":"https://github.com/bendalab/thunderfish.git","svn_url":"https://github.com/bendalab/thunderfish","homepage":null,"size":683,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":9,"forks":5,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bendalab/thunderfish/pulls/47"},"html":{"href":"https://github.com/bendalab/thunderfish/pull/47"},"issue":{"href":"https://api.github.com/repos/bendalab/thunderfish/issues/47"},"comments":{"href":"https://api.github.com/repos/bendalab/thunderfish/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/bendalab/thunderfish/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/bendalab/thunderfish/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bendalab/thunderfish/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/bendalab/thunderfish/statuses/7012317e670667bdc836f9cd9acc71d805d38e84"}}}}
{"actor":{"display_login":"janscience"}}