{"action":"created","comment":{"url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/comments/255515727","pull_request_review_id":202116258,"id":255515727,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI1NTUxNTcyNw==","diff_hunk":"@@ -0,0 +1,211 @@\n+import numpy as np\r\n+\r\n+\r\n+def next_power_of_2(x):\r\n+    \"\"\"Finds the next power of 2 value\r\n+\r\n+    Args:\r\n+        x: Input value\r\n+\r\n+    Returns:\r\n+        power_of_2: Next power of 2 value\r\n+\r\n+    \"\"\"\r\n+\r\n+    power_of_2 = 1 if x == 0 else 2 ** np.ceil(np.log2(x))\r\n+    return power_of_2\r\n+\r\n+\r\n+class SpectralMask:\r\n+    \"\"\"Anomalies detection in satellite telemetry data using a spectral mask\"\"\"\r\n+\r\n+    def __init__(self, method='std_dev', gain=1, window_length=128, beta=4):\r\n+        \"\"\"Inits SpectralMask Class with default values for method, gain, window_length, and\r\n+             beta\r\n+\r\n+        Args:\r\n+            method: Method used to calculate the Spectral Mask: 'std_dev' uses the standard\r\n+              deviation of each frequency component and 'min_max' uses the minimum and maximum\r\n+              values\r\n+            gain: Multiplication factor used in the comparison between the spectral mask defined\r\n+              using the training data and the Fourier transform of the telemetry data vector\r\n+            window_length: Length of the sliding window in number of samples\r\n+            beta: Beta value for Kaiser window design\r\n+\r\n+        \"\"\"\r\n+\r\n+        self.gain = gain\r\n+        self.beta = beta\r\n+        self.window_length = window_length\r\n+        self.window = None\r\n+        self.method = method\r\n+        self.window_length = next_power_of_2(window_length)\r\n+\r\n+    def window_design(self, window_length=None, beta=None):\r\n+        \"\"\"Kaiser window design\r\n+\r\n+        Args:\r\n+            window_length: Length of the window in number of samples\r\n+            beta: Beta value for Kaiser window design\r\n+\r\n+        Returns:\r\n+            window: Window designed using the beta and length provided as inputs\r\n+\r\n+        \"\"\"\r\n+\r\n+        if window_length is None:\r\n+            window_length = self.window_length\r\n+        else:\r\n+            self.window_length = window_length\r\n+\r\n+        if beta is None:\r\n+            beta = self.beta\r\n+        else:\r\n+            self.beta = beta\r\n+\r\n+        self.window = np.kaiser(window_length, beta)\r\n+\r\n+        return self.window\r\n+\r\n+    def fit(self, X, method=None, gain=None, window_length=None, beta=None):\r\n+        \"\"\"Defines a spectral mask based on training data\r\n+\r\n+        Args:\r\n+            X: Training data\r\n+            method: Method used to calculate the Spectral Mask: 'std_dev' uses the standard\r\n+              deviation of each frequency component and 'min_max' uses the minimum and maximum\r\n+              values\r\n+            gain: Multiplication factor used in the comparison between the spectral mask defined\r\n+              using the training data and the Fourier transform of the telemetry data vector\r\n+            window_length: Length of the sliding window in number of samples\r\n+            beta: Beta value for Kaiser window design\r\n+\r\n+        \"\"\"\r\n+\r\n+        training_signal = X\r\n+\r\n+        if gain is None:\r\n+            gain = self.gain\r\n+        else:\r\n+            self.gain = gain\r\n+\r\n+        if window_length is None:\r\n+            window_length = self.window_length\r\n+        else:\r\n+            self.window_length = window_length\r\n+\r\n+        if beta is None:\r\n+            beta = self.beta\r\n+        else:\r\n+            self.beta = beta\r\n+\r\n+        if method is None:\r\n+            method = self.method\r\n+        else:\r\n+            self.method = method\r\n+\r\n+        self.window_design(window_length, beta)\r\n+\r\n+        if method == 'std_dev':\r\n+            self.fit_freq_std_dev(training_signal)\r\n+        else:\r\n+            self.fit_freq_min_max(training_signal)\r\n+\r\n+    def fit_freq_min_max(self, training_signal):\r\n+        \"\"\"Defines a spectral mask based on training data using min and max values of each\r\n+             frequency component\r\n+\r\n+        Args:\r\n+            training_signal: Training data\r\n+\r\n+        \"\"\"\r\n+\r\n+        window_length = len(self.window)\r\n+        window_weight = sum(self.window)\r\n+        max_mask = np.zeros(int(window_length / 2) + 1)\r\n+        min_mask = np.zeros(int(window_length / 2) + 1)\r\n+\r\n+        for i in range(0, len(training_signal) - window_length - 1):\r\n+            temp = np.abs(np.fft.rfft(training_signal[i:i + window_length] * self.window)) \\\r","path":"mlprimitives/candidates/dsp.py","position":129,"original_position":129,"commit_id":"bb5826e64120f133e7cce9ac328c721bf3d698b3","original_commit_id":"bb5826e64120f133e7cce9ac328c721bf3d698b3","user":{"login":"rjdiez","id":6231293,"node_id":"MDQ6VXNlcjYyMzEyOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/6231293?v=4","gravatar_id":"","url":"https://api.github.com/users/rjdiez","html_url":"https://github.com/rjdiez","followers_url":"https://api.github.com/users/rjdiez/followers","following_url":"https://api.github.com/users/rjdiez/following{/other_user}","gists_url":"https://api.github.com/users/rjdiez/gists{/gist_id}","starred_url":"https://api.github.com/users/rjdiez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjdiez/subscriptions","organizations_url":"https://api.github.com/users/rjdiez/orgs","repos_url":"https://api.github.com/users/rjdiez/repos","events_url":"https://api.github.com/users/rjdiez/events{/privacy}","received_events_url":"https://api.github.com/users/rjdiez/received_events","type":"User","site_admin":false},"body":"ok, I will use the second option","created_at":"2019-02-11T13:55:37Z","updated_at":"2019-02-11T13:55:38Z","html_url":"https://github.com/HDI-Project/MLPrimitives/pull/96#discussion_r255515727","pull_request_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/comments/255515727"},"html":{"href":"https://github.com/HDI-Project/MLPrimitives/pull/96#discussion_r255515727"},"pull_request":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96"}},"in_reply_to_id":255227917},"pull_request":{"url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96","id":251290509,"node_id":"MDExOlB1bGxSZXF1ZXN0MjUxMjkwNTA5","html_url":"https://github.com/HDI-Project/MLPrimitives/pull/96","diff_url":"https://github.com/HDI-Project/MLPrimitives/pull/96.diff","patch_url":"https://github.com/HDI-Project/MLPrimitives/pull/96.patch","issue_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues/96","number":96,"state":"open","locked":false,"title":"New DSP primitive - Resolved issue#61","user":{"login":"rjdiez","id":6231293,"node_id":"MDQ6VXNlcjYyMzEyOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/6231293?v=4","gravatar_id":"","url":"https://api.github.com/users/rjdiez","html_url":"https://github.com/rjdiez","followers_url":"https://api.github.com/users/rjdiez/followers","following_url":"https://api.github.com/users/rjdiez/following{/other_user}","gists_url":"https://api.github.com/users/rjdiez/gists{/gist_id}","starred_url":"https://api.github.com/users/rjdiez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjdiez/subscriptions","organizations_url":"https://api.github.com/users/rjdiez/orgs","repos_url":"https://api.github.com/users/rjdiez/repos","events_url":"https://api.github.com/users/rjdiez/events{/privacy}","received_events_url":"https://api.github.com/users/rjdiez/received_events","type":"User","site_admin":false},"body":"Added two files:\r\n - MLPrimitives/mlprimitives/candidates/dsp.py\r\n - MLPrimitives/mlprimitives/jsons/mlprimitives.candidates.dsp.SpectralMask.json","created_at":"2019-02-07T22:23:21Z","updated_at":"2019-02-11T13:55:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b6e2a7965b96915bc064531f1d40bbdfced881a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96/commits","review_comments_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96/comments","review_comment_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues/96/comments","statuses_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/statuses/bb5826e64120f133e7cce9ac328c721bf3d698b3","head":{"label":"rjdiez:master","ref":"master","sha":"bb5826e64120f133e7cce9ac328c721bf3d698b3","user":{"login":"rjdiez","id":6231293,"node_id":"MDQ6VXNlcjYyMzEyOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/6231293?v=4","gravatar_id":"","url":"https://api.github.com/users/rjdiez","html_url":"https://github.com/rjdiez","followers_url":"https://api.github.com/users/rjdiez/followers","following_url":"https://api.github.com/users/rjdiez/following{/other_user}","gists_url":"https://api.github.com/users/rjdiez/gists{/gist_id}","starred_url":"https://api.github.com/users/rjdiez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjdiez/subscriptions","organizations_url":"https://api.github.com/users/rjdiez/orgs","repos_url":"https://api.github.com/users/rjdiez/repos","events_url":"https://api.github.com/users/rjdiez/events{/privacy}","received_events_url":"https://api.github.com/users/rjdiez/received_events","type":"User","site_admin":false},"repo":{"id":163011648,"node_id":"MDEwOlJlcG9zaXRvcnkxNjMwMTE2NDg=","name":"MLPrimitives","full_name":"rjdiez/MLPrimitives","private":false,"owner":{"login":"rjdiez","id":6231293,"node_id":"MDQ6VXNlcjYyMzEyOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/6231293?v=4","gravatar_id":"","url":"https://api.github.com/users/rjdiez","html_url":"https://github.com/rjdiez","followers_url":"https://api.github.com/users/rjdiez/followers","following_url":"https://api.github.com/users/rjdiez/following{/other_user}","gists_url":"https://api.github.com/users/rjdiez/gists{/gist_id}","starred_url":"https://api.github.com/users/rjdiez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjdiez/subscriptions","organizations_url":"https://api.github.com/users/rjdiez/orgs","repos_url":"https://api.github.com/users/rjdiez/repos","events_url":"https://api.github.com/users/rjdiez/events{/privacy}","received_events_url":"https://api.github.com/users/rjdiez/received_events","type":"User","site_admin":false},"html_url":"https://github.com/rjdiez/MLPrimitives","description":"Machine Learning Primitives for MLBlocks","fork":true,"url":"https://api.github.com/repos/rjdiez/MLPrimitives","forks_url":"https://api.github.com/repos/rjdiez/MLPrimitives/forks","keys_url":"https://api.github.com/repos/rjdiez/MLPrimitives/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rjdiez/MLPrimitives/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rjdiez/MLPrimitives/teams","hooks_url":"https://api.github.com/repos/rjdiez/MLPrimitives/hooks","issue_events_url":"https://api.github.com/repos/rjdiez/MLPrimitives/issues/events{/number}","events_url":"https://api.github.com/repos/rjdiez/MLPrimitives/events","assignees_url":"https://api.github.com/repos/rjdiez/MLPrimitives/assignees{/user}","branches_url":"https://api.github.com/repos/rjdiez/MLPrimitives/branches{/branch}","tags_url":"https://api.github.com/repos/rjdiez/MLPrimitives/tags","blobs_url":"https://api.github.com/repos/rjdiez/MLPrimitives/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rjdiez/MLPrimitives/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rjdiez/MLPrimitives/git/refs{/sha}","trees_url":"https://api.github.com/repos/rjdiez/MLPrimitives/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rjdiez/MLPrimitives/statuses/{sha}","languages_url":"https://api.github.com/repos/rjdiez/MLPrimitives/languages","stargazers_url":"https://api.github.com/repos/rjdiez/MLPrimitives/stargazers","contributors_url":"https://api.github.com/repos/rjdiez/MLPrimitives/contributors","subscribers_url":"https://api.github.com/repos/rjdiez/MLPrimitives/subscribers","subscription_url":"https://api.github.com/repos/rjdiez/MLPrimitives/subscription","commits_url":"https://api.github.com/repos/rjdiez/MLPrimitives/commits{/sha}","git_commits_url":"https://api.github.com/repos/rjdiez/MLPrimitives/git/commits{/sha}","comments_url":"https://api.github.com/repos/rjdiez/MLPrimitives/comments{/number}","issue_comment_url":"https://api.github.com/repos/rjdiez/MLPrimitives/issues/comments{/number}","contents_url":"https://api.github.com/repos/rjdiez/MLPrimitives/contents/{+path}","compare_url":"https://api.github.com/repos/rjdiez/MLPrimitives/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rjdiez/MLPrimitives/merges","archive_url":"https://api.github.com/repos/rjdiez/MLPrimitives/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rjdiez/MLPrimitives/downloads","issues_url":"https://api.github.com/repos/rjdiez/MLPrimitives/issues{/number}","pulls_url":"https://api.github.com/repos/rjdiez/MLPrimitives/pulls{/number}","milestones_url":"https://api.github.com/repos/rjdiez/MLPrimitives/milestones{/number}","notifications_url":"https://api.github.com/repos/rjdiez/MLPrimitives/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rjdiez/MLPrimitives/labels{/name}","releases_url":"https://api.github.com/repos/rjdiez/MLPrimitives/releases{/id}","deployments_url":"https://api.github.com/repos/rjdiez/MLPrimitives/deployments","created_at":"2018-12-24T17:28:16Z","updated_at":"2019-02-07T22:18:22Z","pushed_at":"2019-02-07T22:18:20Z","git_url":"git://github.com/rjdiez/MLPrimitives.git","ssh_url":"git@github.com:rjdiez/MLPrimitives.git","clone_url":"https://github.com/rjdiez/MLPrimitives.git","svn_url":"https://github.com/rjdiez/MLPrimitives","homepage":"https://hdi-project.github.io/MLPrimitives","size":6412,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"HDI-Project:master","ref":"master","sha":"810d22041d2eecffe679d635eae20d5e789a383a","user":{"login":"HDI-Project","id":11450856,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNDUwODU2","avatar_url":"https://avatars2.githubusercontent.com/u/11450856?v=4","gravatar_id":"","url":"https://api.github.com/users/HDI-Project","html_url":"https://github.com/HDI-Project","followers_url":"https://api.github.com/users/HDI-Project/followers","following_url":"https://api.github.com/users/HDI-Project/following{/other_user}","gists_url":"https://api.github.com/users/HDI-Project/gists{/gist_id}","starred_url":"https://api.github.com/users/HDI-Project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HDI-Project/subscriptions","organizations_url":"https://api.github.com/users/HDI-Project/orgs","repos_url":"https://api.github.com/users/HDI-Project/repos","events_url":"https://api.github.com/users/HDI-Project/events{/privacy}","received_events_url":"https://api.github.com/users/HDI-Project/received_events","type":"Organization","site_admin":false},"repo":{"id":137616563,"node_id":"MDEwOlJlcG9zaXRvcnkxMzc2MTY1NjM=","name":"MLPrimitives","full_name":"HDI-Project/MLPrimitives","private":false,"owner":{"login":"HDI-Project","id":11450856,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNDUwODU2","avatar_url":"https://avatars2.githubusercontent.com/u/11450856?v=4","gravatar_id":"","url":"https://api.github.com/users/HDI-Project","html_url":"https://github.com/HDI-Project","followers_url":"https://api.github.com/users/HDI-Project/followers","following_url":"https://api.github.com/users/HDI-Project/following{/other_user}","gists_url":"https://api.github.com/users/HDI-Project/gists{/gist_id}","starred_url":"https://api.github.com/users/HDI-Project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HDI-Project/subscriptions","organizations_url":"https://api.github.com/users/HDI-Project/orgs","repos_url":"https://api.github.com/users/HDI-Project/repos","events_url":"https://api.github.com/users/HDI-Project/events{/privacy}","received_events_url":"https://api.github.com/users/HDI-Project/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/HDI-Project/MLPrimitives","description":"Machine Learning Primitives for MLBlocks","fork":false,"url":"https://api.github.com/repos/HDI-Project/MLPrimitives","forks_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/forks","keys_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/teams","hooks_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/hooks","issue_events_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues/events{/number}","events_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/events","assignees_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/assignees{/user}","branches_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/branches{/branch}","tags_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/tags","blobs_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/git/refs{/sha}","trees_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/statuses/{sha}","languages_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/languages","stargazers_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/stargazers","contributors_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/contributors","subscribers_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/subscribers","subscription_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/subscription","commits_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/commits{/sha}","git_commits_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/git/commits{/sha}","comments_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/comments{/number}","issue_comment_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues/comments{/number}","contents_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/contents/{+path}","compare_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/merges","archive_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/downloads","issues_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues{/number}","pulls_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls{/number}","milestones_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/milestones{/number}","notifications_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/labels{/name}","releases_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/releases{/id}","deployments_url":"https://api.github.com/repos/HDI-Project/MLPrimitives/deployments","created_at":"2018-06-16T23:24:50Z","updated_at":"2019-02-08T22:27:32Z","pushed_at":"2019-02-09T21:27:07Z","git_url":"git://github.com/HDI-Project/MLPrimitives.git","ssh_url":"git@github.com:HDI-Project/MLPrimitives.git","clone_url":"https://github.com/HDI-Project/MLPrimitives.git","svn_url":"https://github.com/HDI-Project/MLPrimitives","homepage":"https://hdi-project.github.io/MLPrimitives","size":7384,"stargazers_count":17,"watchers_count":17,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"archived":false,"open_issues_count":25,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":11,"open_issues":25,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96"},"html":{"href":"https://github.com/HDI-Project/MLPrimitives/pull/96"},"issue":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues/96"},"comments":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/issues/96/comments"},"review_comments":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96/comments"},"review_comment":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/pulls/96/commits"},"statuses":{"href":"https://api.github.com/repos/HDI-Project/MLPrimitives/statuses/bb5826e64120f133e7cce9ac328c721bf3d698b3"}},"author_association":"NONE"}}
{"actor":{"display_login":"rjdiez"}}