{"action":"created","comment":{"url":"https://api.github.com/repos/astropy/specutils/pulls/comments/233222490","pull_request_review_id":174489664,"id":233222490,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMzIyMjQ5MA==","diff_hunk":"@@ -1,20 +1,214 @@\n from __future__ import division\n \n import operator\n+import itertools\n \n import numpy as np\n+from scipy.signal import convolve\n import astropy.units as u\n-from astropy.modeling import optimizers\n+from astropy.stats import sigma_clipped_stats\n \n from ..manipulation.utils import excise_regions\n+from ..analysis import fwhm, centroid\n from ..utils import QuantityModel\n from ..manipulation import extract_region\n from ..spectra.spectral_region import SpectralRegion\n from ..spectra.spectrum1d import Spectrum1D\n from astropy.modeling import fitting, Model, models\n+from astropy.table import QTable\n+\n+\n+__all__ = ['find_lines_threshold', 'find_lines_derivative', 'fit_lines', 'estimate_parameters']\n+\n+# Define the initial estimators\n+#   This is the default methods to use to estimate astropy model\n+#   parameters. This is based on only a small subset of the astropy\n+#   models but it was determined that this is a decent start as most\n+#   fitting will probably use one of these.\n+#\n+#   Each method list must take a Spectrum1D object and should return\n+#   a Quantity.\n+\n+parameter_estimators = {\n+    'Gaussian1D': {\n+        'amplitude': lambda s: max(s.flux),\n+        'mean': lambda s: centroid(s, region=None),\n+        'stddev': lambda s: fwhm(s) \n+    },\n+    'Lorentzian1D': {\n+        'amplitude': None,\n+        'x_0': None,\n+        'fwhm':None \n+    },\n+    'Voigt1D': {\n+        'x_0': None,\n+        'amplitude_L': None,\n+        'fwhm_L': None,\n+        'fwhm_G': None \n+    },\n+    'Const1D': {\n+        'amplitude': None \n+    }\n+}\n+\n+def _set_parameter_estimators(model):\n+    if model.__class__.__name__ in parameter_estimators:\n+        model._constraints['parameter_estimator'] = parameter_estimators[model.__class__.__name__]\n+    return model\n+\n+def estimate_parameters(spectrum, model):\n+\n+    if not 'parameter_estimator' in model._constraints:\n+        model = _set_parameter_estimators(model)\n+\n+    # Estimate the parameters based on the estimators already\n+    # attached to the model\n+    if 'parameter_estimator' in model._constraints:\n+        for param, estimator in model._constraints['parameter_estimator'].items():\n+            setattr(model, param, estimator(spectrum))\n+\n+    # No estimators.\n+    else:\n+        raise Exception('No method to estimate parameters')\n+\n+    return model\n+\n+def _consecutive(data, stepsize=1):\n+    return np.split(data, np.where(np.diff(data) != stepsize)[0]+1)\n+\n+\n+def find_lines_threshold(spectrum, sigma=3):","path":"specutils/fitting/fitmodels.py","position":81,"original_position":81,"commit_id":"91262226f7c8b7bd0b3f6aa36add4eac297b49e7","original_commit_id":"91262226f7c8b7bd0b3f6aa36add4eac297b49e7","user":{"login":"eteq","id":346587,"node_id":"MDQ6VXNlcjM0NjU4Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/346587?v=4","gravatar_id":"","url":"https://api.github.com/users/eteq","html_url":"https://github.com/eteq","followers_url":"https://api.github.com/users/eteq/followers","following_url":"https://api.github.com/users/eteq/following{/other_user}","gists_url":"https://api.github.com/users/eteq/gists{/gist_id}","starred_url":"https://api.github.com/users/eteq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eteq/subscriptions","organizations_url":"https://api.github.com/users/eteq/orgs","repos_url":"https://api.github.com/users/eteq/repos","events_url":"https://api.github.com/users/eteq/events{/privacy}","received_events_url":"https://api.github.com/users/eteq/received_events","type":"User","site_admin":false},"body":"Somewhere in this docstring (and probably somewhere else?) you should note that this only works on continuum-subtracted spectra.","created_at":"2018-11-13T21:09:54Z","updated_at":"2018-11-13T21:59:07Z","html_url":"https://github.com/astropy/specutils/pull/362#discussion_r233222490","pull_request_url":"https://api.github.com/repos/astropy/specutils/pulls/362","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/astropy/specutils/pulls/comments/233222490"},"html":{"href":"https://github.com/astropy/specutils/pull/362#discussion_r233222490"},"pull_request":{"href":"https://api.github.com/repos/astropy/specutils/pulls/362"}}},"pull_request":{"url":"https://api.github.com/repos/astropy/specutils/pulls/362","id":224385165,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI0Mzg1MTY1","html_url":"https://github.com/astropy/specutils/pull/362","diff_url":"https://github.com/astropy/specutils/pull/362.diff","patch_url":"https://github.com/astropy/specutils/pull/362.patch","issue_url":"https://api.github.com/repos/astropy/specutils/issues/362","number":362,"state":"open","locked":false,"title":"Line Finding and Parameter Estimation","user":{"login":"brechmos-stsci","id":18348847,"node_id":"MDQ6VXNlcjE4MzQ4ODQ3","avatar_url":"https://avatars1.githubusercontent.com/u/18348847?v=4","gravatar_id":"","url":"https://api.github.com/users/brechmos-stsci","html_url":"https://github.com/brechmos-stsci","followers_url":"https://api.github.com/users/brechmos-stsci/followers","following_url":"https://api.github.com/users/brechmos-stsci/following{/other_user}","gists_url":"https://api.github.com/users/brechmos-stsci/gists{/gist_id}","starred_url":"https://api.github.com/users/brechmos-stsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brechmos-stsci/subscriptions","organizations_url":"https://api.github.com/users/brechmos-stsci/orgs","repos_url":"https://api.github.com/users/brechmos-stsci/repos","events_url":"https://api.github.com/users/brechmos-stsci/events{/privacy}","received_events_url":"https://api.github.com/users/brechmos-stsci/received_events","type":"User","site_admin":false},"body":"This is a first pass at line finding from within a spectrum. Two methods were added. \r\n\r\nA near-future push should include fast parameter estimation.\r\n\r\nFixes https://github.com/astropy/specutils/issues/361","created_at":"2018-10-19T19:17:13Z","updated_at":"2018-11-13T21:59:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe2ddb59415d7dfcb042aa298b94ce3b90d95cb4","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/astropy/specutils/pulls/362/commits","review_comments_url":"https://api.github.com/repos/astropy/specutils/pulls/362/comments","review_comment_url":"https://api.github.com/repos/astropy/specutils/pulls/comments{/number}","comments_url":"https://api.github.com/repos/astropy/specutils/issues/362/comments","statuses_url":"https://api.github.com/repos/astropy/specutils/statuses/91262226f7c8b7bd0b3f6aa36add4eac297b49e7","head":{"label":"brechmos-stsci:i361-line-finding","ref":"i361-line-finding","sha":"91262226f7c8b7bd0b3f6aa36add4eac297b49e7","user":{"login":"brechmos-stsci","id":18348847,"node_id":"MDQ6VXNlcjE4MzQ4ODQ3","avatar_url":"https://avatars1.githubusercontent.com/u/18348847?v=4","gravatar_id":"","url":"https://api.github.com/users/brechmos-stsci","html_url":"https://github.com/brechmos-stsci","followers_url":"https://api.github.com/users/brechmos-stsci/followers","following_url":"https://api.github.com/users/brechmos-stsci/following{/other_user}","gists_url":"https://api.github.com/users/brechmos-stsci/gists{/gist_id}","starred_url":"https://api.github.com/users/brechmos-stsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brechmos-stsci/subscriptions","organizations_url":"https://api.github.com/users/brechmos-stsci/orgs","repos_url":"https://api.github.com/users/brechmos-stsci/repos","events_url":"https://api.github.com/users/brechmos-stsci/events{/privacy}","received_events_url":"https://api.github.com/users/brechmos-stsci/received_events","type":"User","site_admin":false},"repo":{"id":133566919,"node_id":"MDEwOlJlcG9zaXRvcnkxMzM1NjY5MTk=","name":"specutils","full_name":"brechmos-stsci/specutils","private":false,"owner":{"login":"brechmos-stsci","id":18348847,"node_id":"MDQ6VXNlcjE4MzQ4ODQ3","avatar_url":"https://avatars1.githubusercontent.com/u/18348847?v=4","gravatar_id":"","url":"https://api.github.com/users/brechmos-stsci","html_url":"https://github.com/brechmos-stsci","followers_url":"https://api.github.com/users/brechmos-stsci/followers","following_url":"https://api.github.com/users/brechmos-stsci/following{/other_user}","gists_url":"https://api.github.com/users/brechmos-stsci/gists{/gist_id}","starred_url":"https://api.github.com/users/brechmos-stsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brechmos-stsci/subscriptions","organizations_url":"https://api.github.com/users/brechmos-stsci/orgs","repos_url":"https://api.github.com/users/brechmos-stsci/repos","events_url":"https://api.github.com/users/brechmos-stsci/events{/privacy}","received_events_url":"https://api.github.com/users/brechmos-stsci/received_events","type":"User","site_admin":false},"html_url":"https://github.com/brechmos-stsci/specutils","description":"Affiliated package for 1D spectral operations. Maintainer: @crawfordsm @keflavich @nmearl","fork":true,"url":"https://api.github.com/repos/brechmos-stsci/specutils","forks_url":"https://api.github.com/repos/brechmos-stsci/specutils/forks","keys_url":"https://api.github.com/repos/brechmos-stsci/specutils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brechmos-stsci/specutils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brechmos-stsci/specutils/teams","hooks_url":"https://api.github.com/repos/brechmos-stsci/specutils/hooks","issue_events_url":"https://api.github.com/repos/brechmos-stsci/specutils/issues/events{/number}","events_url":"https://api.github.com/repos/brechmos-stsci/specutils/events","assignees_url":"https://api.github.com/repos/brechmos-stsci/specutils/assignees{/user}","branches_url":"https://api.github.com/repos/brechmos-stsci/specutils/branches{/branch}","tags_url":"https://api.github.com/repos/brechmos-stsci/specutils/tags","blobs_url":"https://api.github.com/repos/brechmos-stsci/specutils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brechmos-stsci/specutils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brechmos-stsci/specutils/git/refs{/sha}","trees_url":"https://api.github.com/repos/brechmos-stsci/specutils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brechmos-stsci/specutils/statuses/{sha}","languages_url":"https://api.github.com/repos/brechmos-stsci/specutils/languages","stargazers_url":"https://api.github.com/repos/brechmos-stsci/specutils/stargazers","contributors_url":"https://api.github.com/repos/brechmos-stsci/specutils/contributors","subscribers_url":"https://api.github.com/repos/brechmos-stsci/specutils/subscribers","subscription_url":"https://api.github.com/repos/brechmos-stsci/specutils/subscription","commits_url":"https://api.github.com/repos/brechmos-stsci/specutils/commits{/sha}","git_commits_url":"https://api.github.com/repos/brechmos-stsci/specutils/git/commits{/sha}","comments_url":"https://api.github.com/repos/brechmos-stsci/specutils/comments{/number}","issue_comment_url":"https://api.github.com/repos/brechmos-stsci/specutils/issues/comments{/number}","contents_url":"https://api.github.com/repos/brechmos-stsci/specutils/contents/{+path}","compare_url":"https://api.github.com/repos/brechmos-stsci/specutils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brechmos-stsci/specutils/merges","archive_url":"https://api.github.com/repos/brechmos-stsci/specutils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brechmos-stsci/specutils/downloads","issues_url":"https://api.github.com/repos/brechmos-stsci/specutils/issues{/number}","pulls_url":"https://api.github.com/repos/brechmos-stsci/specutils/pulls{/number}","milestones_url":"https://api.github.com/repos/brechmos-stsci/specutils/milestones{/number}","notifications_url":"https://api.github.com/repos/brechmos-stsci/specutils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brechmos-stsci/specutils/labels{/name}","releases_url":"https://api.github.com/repos/brechmos-stsci/specutils/releases{/id}","deployments_url":"https://api.github.com/repos/brechmos-stsci/specutils/deployments","created_at":"2018-05-15T20:01:02Z","updated_at":"2018-10-31T14:08:29Z","pushed_at":"2018-11-13T14:34:38Z","git_url":"git://github.com/brechmos-stsci/specutils.git","ssh_url":"git@github.com:brechmos-stsci/specutils.git","clone_url":"https://github.com/brechmos-stsci/specutils.git","svn_url":"https://github.com/brechmos-stsci/specutils","homepage":"http://specutils.readthedocs.io/en/latest/","size":6709,"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":1,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"astropy:master","ref":"master","sha":"0c513ac5cafd821c97759a276900a475d4952916","user":{"login":"astropy","id":847984,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0Nzk4NA==","avatar_url":"https://avatars0.githubusercontent.com/u/847984?v=4","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"repo":{"id":2577269,"node_id":"MDEwOlJlcG9zaXRvcnkyNTc3MjY5","name":"specutils","full_name":"astropy/specutils","private":false,"owner":{"login":"astropy","id":847984,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0Nzk4NA==","avatar_url":"https://avatars0.githubusercontent.com/u/847984?v=4","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/astropy/specutils","description":"An Astropy coordinated package for astronomical spectroscopy.  Maintainers: @nmearl @crawfordsm @keflavich @eteq","fork":false,"url":"https://api.github.com/repos/astropy/specutils","forks_url":"https://api.github.com/repos/astropy/specutils/forks","keys_url":"https://api.github.com/repos/astropy/specutils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astropy/specutils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astropy/specutils/teams","hooks_url":"https://api.github.com/repos/astropy/specutils/hooks","issue_events_url":"https://api.github.com/repos/astropy/specutils/issues/events{/number}","events_url":"https://api.github.com/repos/astropy/specutils/events","assignees_url":"https://api.github.com/repos/astropy/specutils/assignees{/user}","branches_url":"https://api.github.com/repos/astropy/specutils/branches{/branch}","tags_url":"https://api.github.com/repos/astropy/specutils/tags","blobs_url":"https://api.github.com/repos/astropy/specutils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astropy/specutils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astropy/specutils/git/refs{/sha}","trees_url":"https://api.github.com/repos/astropy/specutils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astropy/specutils/statuses/{sha}","languages_url":"https://api.github.com/repos/astropy/specutils/languages","stargazers_url":"https://api.github.com/repos/astropy/specutils/stargazers","contributors_url":"https://api.github.com/repos/astropy/specutils/contributors","subscribers_url":"https://api.github.com/repos/astropy/specutils/subscribers","subscription_url":"https://api.github.com/repos/astropy/specutils/subscription","commits_url":"https://api.github.com/repos/astropy/specutils/commits{/sha}","git_commits_url":"https://api.github.com/repos/astropy/specutils/git/commits{/sha}","comments_url":"https://api.github.com/repos/astropy/specutils/comments{/number}","issue_comment_url":"https://api.github.com/repos/astropy/specutils/issues/comments{/number}","contents_url":"https://api.github.com/repos/astropy/specutils/contents/{+path}","compare_url":"https://api.github.com/repos/astropy/specutils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astropy/specutils/merges","archive_url":"https://api.github.com/repos/astropy/specutils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astropy/specutils/downloads","issues_url":"https://api.github.com/repos/astropy/specutils/issues{/number}","pulls_url":"https://api.github.com/repos/astropy/specutils/pulls{/number}","milestones_url":"https://api.github.com/repos/astropy/specutils/milestones{/number}","notifications_url":"https://api.github.com/repos/astropy/specutils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astropy/specutils/labels{/name}","releases_url":"https://api.github.com/repos/astropy/specutils/releases{/id}","deployments_url":"https://api.github.com/repos/astropy/specutils/deployments","created_at":"2011-10-14T16:11:38Z","updated_at":"2018-11-09T18:17:45Z","pushed_at":"2018-11-13T21:29:14Z","git_url":"git://github.com/astropy/specutils.git","ssh_url":"git@github.com:astropy/specutils.git","clone_url":"https://github.com/astropy/specutils.git","svn_url":"https://github.com/astropy/specutils","homepage":"http://specutils.readthedocs.io/en/latest/","size":9032,"stargazers_count":58,"watchers_count":58,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"archived":false,"open_issues_count":94,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":66,"open_issues":94,"watchers":58,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/astropy/specutils/pulls/362"},"html":{"href":"https://github.com/astropy/specutils/pull/362"},"issue":{"href":"https://api.github.com/repos/astropy/specutils/issues/362"},"comments":{"href":"https://api.github.com/repos/astropy/specutils/issues/362/comments"},"review_comments":{"href":"https://api.github.com/repos/astropy/specutils/pulls/362/comments"},"review_comment":{"href":"https://api.github.com/repos/astropy/specutils/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/astropy/specutils/pulls/362/commits"},"statuses":{"href":"https://api.github.com/repos/astropy/specutils/statuses/91262226f7c8b7bd0b3f6aa36add4eac297b49e7"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"eteq"}}