{"action":"created","comment":{"url":"https://api.github.com/repos/pyigm/pyigm/pulls/comments/47572610","id":47572610,"diff_hunk":"@@ -0,0 +1,236 @@\n+\"\"\" Class for correlating galaxies and IGM within a given field on the sky\n+\"\"\"\n+from __future__ import print_function, absolute_import, division, unicode_literals\n+\n+import numpy as np\n+import warnings\n+import pdb\n+\n+from astropy import units as u\n+from astropy.coordinates import SkyCoord\n+from astropy import constants as const\n+\n+#from xastropy.xutils import xdebug as xdb\n+\n+\n+class IgmGalaxyField(object):\n+    \"\"\" Class for a field associating galaxies to the IGM/CGM\n+\n+    Parameters\n+    ----------\n+    radec : tuple or SkyCoord\n+        (RA,DEC) in deg or astropy.coordinate\n+    name : str, optional\n+    \"\"\"\n+\n+    # Initialize \n+    def __init__(self, radec, name='', cosmo=None, verbose=False):\n+        # coord\n+        if isinstance(radec, (tuple)):\n+            self.coord = SkyCoord(ra=radec[0], dec=radec[1])\n+        elif isinstance(radec, SkyCoord):\n+            self.coord = radec\n+\n+        # Field\n+        self.name = name\n+\n+        # Cosmology\n+        if cosmo is None:\n+            from astropy.cosmology import WMAP9 as cosmo\n+            if verbose is True:\n+                print('IgmGalxyField: Using WMAP9 cosmology')\n+        self.cosmo = cosmo\n+\n+        # Init\n+        self.igm = None\n+        self.targets = None\n+        self.galaxies = None\n+        self.observing = None\n+        self.selection = None\n+\n+    def calc_rhoimpact(self, obj, los_coord=None):\n+        \"\"\"Calculate impact parameter from LOS RA/DEC for a set of objects\n+\n+        Parameters\n+        ----------\n+        obj : Table\n+          (can be anything that takes 'RA','DEC' and 'Z')\n+          Sources for calculation\n+        los_radec : SkyCoord, optional\n+          Defaults to field RA/DEC\n+\n+        Returns\n+        -------\n+\n+        rho : Quantity (array usually)\n+          Impact parameter(s) in kpc\n+        \"\"\"\n+        if los_coord is None:\n+            los_coord = self.coord\n+        # Coord\n+        o_coord = SkyCoord(ra=obj['RA']*u.deg, dec=obj['DEC']*u.deg)\n+        ang_sep = o_coord.separation(los_coord).to('arcmin')\n+        # Cosmology\n+        kpc_amin = self.cosmo.kpc_comoving_per_arcmin(obj['Z'] ) # kpc per arcmin\n+        rho = ang_sep * kpc_amin / (1+obj['Z']) # Physical\n+        # Return\n+        return rho\n+\n+    def get_associated_galaxies(self, z, los_coord=None, R=300*u.kpc, dv_tol=500*u.km/u.s):\n+        \"\"\"Return a Table of associated galaxies for a given redshift and separation\n+\n+        Parameters\n+        ----------\n+        z : float\n+          Redshift for association (usually IGM/CGM absorber redshift)\n+        R : Quantity\n+          Radius of impact parameter for association [300kpc]\n+        dv_tol : Quantity\n+          Velocity window for association [500km/s]\n+        los_coord : SkyCoord, optional\n+          Line-of-sight coordinates\n+\n+        Returns\n+        -------\n+        assoc_gal : Table\n+          Table of associated galaxies (if any)\n+        rho : Quantity\n+          Impact parameters [kpc]\n+        \"\"\"\n+        # los_radec\n+        if los_coord is None:\n+            los_coord = self.coord\n+        # Cut on z first\n+        dv_gal = const.c.to('km/s') * (self.galaxies['Z']-z)/(1+z)  # Approximate\n+        gdz = np.where(np.abs(dv_gal)<dv_tol)[0]\n+        if len(gdz) == 0:\n+            return None\n+        #\n+        gdz_gal = self.galaxies[gdz]\n+        rho = self.calc_rhoimpact(gdz_gal, los_coord)  # Could add this to Table\n+        #\n+        gd_rho = np.where(rho < R)[0]\n+        if len(gd_rho) == 0:\n+            return None\n+        # Return\n+        return gdz_gal[gd_rho], rho[gd_rho]\n+\n+    def get_observed(self, theta, subtab=None):\n+        \"\"\"Generate a Table of observed targets within an angular offset of field center\n+\n+        Parameters\n+        ----------\n+        theta : Quantity or Angle\n+          Angular radius\n+\n+        Returns\n+        -------\n+        obs_targ : Table\n+          Sub-table of targets that have been observed within this radius\n+        obs_dates : List\n+          List of observing dates [eventually might add to Table]\n+        indices : array\n+          Indices from the main table\n+        \"\"\"\n+        if (self.targets is None) or (self.observing is None):\n+            raise ValueError('IgmGalaxyField: Need to fill the target and/or observing table first!')\n+        if subtab is None:\n+            # Trim on angular cut first\n+            targ_coord = SkyCoord(ra=self.targets['TARG_RA']*u.deg,\n+                dec=self.targets['TARG_DEC']*u.deg)\n+            sep = self.coord.separation(targ_coord)\n+            gdsep = np.where(sep < theta)[0]\n+            if len(gdsep) == 0:\n+                return None\n+            # Set all to False to start\n+            subtab = self.targets[gdsep]\n+        else:\n+            gdsep = np.arange(len(subtab)) # For indexing below\n+        # Generate mask\n+        tmsk = np.array([False]*len(subtab))","path":"pyigm/field/igmfield.py","position":150,"original_position":150,"commit_id":"4d1cdf0163752d725991c509b0d45b6658542ec6","original_commit_id":"4d1cdf0163752d725991c509b0d45b6658542ec6","user":{"login":"ntejos","id":2862340,"avatar_url":"https://avatars.githubusercontent.com/u/2862340?v=3","gravatar_id":"","url":"https://api.github.com/users/ntejos","html_url":"https://github.com/ntejos","followers_url":"https://api.github.com/users/ntejos/followers","following_url":"https://api.github.com/users/ntejos/following{/other_user}","gists_url":"https://api.github.com/users/ntejos/gists{/gist_id}","starred_url":"https://api.github.com/users/ntejos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ntejos/subscriptions","organizations_url":"https://api.github.com/users/ntejos/orgs","repos_url":"https://api.github.com/users/ntejos/repos","events_url":"https://api.github.com/users/ntejos/events{/privacy}","received_events_url":"https://api.github.com/users/ntejos/received_events","type":"User","site_admin":false},"body":"Bring the '# Set all to False to start' comment here!","created_at":"2015-12-14T22:59:26Z","updated_at":"2015-12-14T22:59:26Z","html_url":"https://github.com/pyigm/pyigm/pull/4#discussion_r47572610","pull_request_url":"https://api.github.com/repos/pyigm/pyigm/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/comments/47572610"},"html":{"href":"https://github.com/pyigm/pyigm/pull/4#discussion_r47572610"},"pull_request":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/pyigm/pyigm/pulls/4","id":53506641,"html_url":"https://github.com/pyigm/pyigm/pull/4","diff_url":"https://github.com/pyigm/pyigm/pull/4.diff","patch_url":"https://github.com/pyigm/pyigm/pull/4.patch","issue_url":"https://api.github.com/repos/pyigm/pyigm/issues/4","number":4,"state":"open","locked":false,"title":"field:  The Beginnings","user":{"login":"profxj","id":3998093,"avatar_url":"https://avatars.githubusercontent.com/u/3998093?v=3","gravatar_id":"","url":"https://api.github.com/users/profxj","html_url":"https://github.com/profxj","followers_url":"https://api.github.com/users/profxj/followers","following_url":"https://api.github.com/users/profxj/following{/other_user}","gists_url":"https://api.github.com/users/profxj/gists{/gist_id}","starred_url":"https://api.github.com/users/profxj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/profxj/subscriptions","organizations_url":"https://api.github.com/users/profxj/orgs","repos_url":"https://api.github.com/users/profxj/repos","events_url":"https://api.github.com/users/profxj/events{/privacy}","received_events_url":"https://api.github.com/users/profxj/received_events","type":"User","site_admin":false},"body":"Class with a few methods for an IGM-Galaxy field\n\ndocs\none simple test\nnotebook","created_at":"2015-12-13T18:59:12Z","updated_at":"2015-12-14T22:59:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"629372d78ee92a00776a1c30ab9bb6d5aa8c5733","assignee":{"login":"ntejos","id":2862340,"avatar_url":"https://avatars.githubusercontent.com/u/2862340?v=3","gravatar_id":"","url":"https://api.github.com/users/ntejos","html_url":"https://github.com/ntejos","followers_url":"https://api.github.com/users/ntejos/followers","following_url":"https://api.github.com/users/ntejos/following{/other_user}","gists_url":"https://api.github.com/users/ntejos/gists{/gist_id}","starred_url":"https://api.github.com/users/ntejos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ntejos/subscriptions","organizations_url":"https://api.github.com/users/ntejos/orgs","repos_url":"https://api.github.com/users/ntejos/repos","events_url":"https://api.github.com/users/ntejos/events{/privacy}","received_events_url":"https://api.github.com/users/ntejos/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/pyigm/pyigm/pulls/4/commits","review_comments_url":"https://api.github.com/repos/pyigm/pyigm/pulls/4/comments","review_comment_url":"https://api.github.com/repos/pyigm/pyigm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pyigm/pyigm/issues/4/comments","statuses_url":"https://api.github.com/repos/pyigm/pyigm/statuses/4d1cdf0163752d725991c509b0d45b6658542ec6","head":{"label":"pyigm:field","ref":"field","sha":"4d1cdf0163752d725991c509b0d45b6658542ec6","user":{"login":"pyigm","id":16152971,"avatar_url":"https://avatars.githubusercontent.com/u/16152971?v=3","gravatar_id":"","url":"https://api.github.com/users/pyigm","html_url":"https://github.com/pyigm","followers_url":"https://api.github.com/users/pyigm/followers","following_url":"https://api.github.com/users/pyigm/following{/other_user}","gists_url":"https://api.github.com/users/pyigm/gists{/gist_id}","starred_url":"https://api.github.com/users/pyigm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyigm/subscriptions","organizations_url":"https://api.github.com/users/pyigm/orgs","repos_url":"https://api.github.com/users/pyigm/repos","events_url":"https://api.github.com/users/pyigm/events{/privacy}","received_events_url":"https://api.github.com/users/pyigm/received_events","type":"Organization","site_admin":false},"repo":{"id":47417383,"name":"pyigm","full_name":"pyigm/pyigm","owner":{"login":"pyigm","id":16152971,"avatar_url":"https://avatars.githubusercontent.com/u/16152971?v=3","gravatar_id":"","url":"https://api.github.com/users/pyigm","html_url":"https://github.com/pyigm","followers_url":"https://api.github.com/users/pyigm/followers","following_url":"https://api.github.com/users/pyigm/following{/other_user}","gists_url":"https://api.github.com/users/pyigm/gists{/gist_id}","starred_url":"https://api.github.com/users/pyigm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyigm/subscriptions","organizations_url":"https://api.github.com/users/pyigm/orgs","repos_url":"https://api.github.com/users/pyigm/repos","events_url":"https://api.github.com/users/pyigm/events{/privacy}","received_events_url":"https://api.github.com/users/pyigm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pyigm/pyigm","description":"Python routines for calculations and data on the Intergalactic Medium ","fork":false,"url":"https://api.github.com/repos/pyigm/pyigm","forks_url":"https://api.github.com/repos/pyigm/pyigm/forks","keys_url":"https://api.github.com/repos/pyigm/pyigm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pyigm/pyigm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pyigm/pyigm/teams","hooks_url":"https://api.github.com/repos/pyigm/pyigm/hooks","issue_events_url":"https://api.github.com/repos/pyigm/pyigm/issues/events{/number}","events_url":"https://api.github.com/repos/pyigm/pyigm/events","assignees_url":"https://api.github.com/repos/pyigm/pyigm/assignees{/user}","branches_url":"https://api.github.com/repos/pyigm/pyigm/branches{/branch}","tags_url":"https://api.github.com/repos/pyigm/pyigm/tags","blobs_url":"https://api.github.com/repos/pyigm/pyigm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pyigm/pyigm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pyigm/pyigm/git/refs{/sha}","trees_url":"https://api.github.com/repos/pyigm/pyigm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pyigm/pyigm/statuses/{sha}","languages_url":"https://api.github.com/repos/pyigm/pyigm/languages","stargazers_url":"https://api.github.com/repos/pyigm/pyigm/stargazers","contributors_url":"https://api.github.com/repos/pyigm/pyigm/contributors","subscribers_url":"https://api.github.com/repos/pyigm/pyigm/subscribers","subscription_url":"https://api.github.com/repos/pyigm/pyigm/subscription","commits_url":"https://api.github.com/repos/pyigm/pyigm/commits{/sha}","git_commits_url":"https://api.github.com/repos/pyigm/pyigm/git/commits{/sha}","comments_url":"https://api.github.com/repos/pyigm/pyigm/comments{/number}","issue_comment_url":"https://api.github.com/repos/pyigm/pyigm/issues/comments{/number}","contents_url":"https://api.github.com/repos/pyigm/pyigm/contents/{+path}","compare_url":"https://api.github.com/repos/pyigm/pyigm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pyigm/pyigm/merges","archive_url":"https://api.github.com/repos/pyigm/pyigm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pyigm/pyigm/downloads","issues_url":"https://api.github.com/repos/pyigm/pyigm/issues{/number}","pulls_url":"https://api.github.com/repos/pyigm/pyigm/pulls{/number}","milestones_url":"https://api.github.com/repos/pyigm/pyigm/milestones{/number}","notifications_url":"https://api.github.com/repos/pyigm/pyigm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pyigm/pyigm/labels{/name}","releases_url":"https://api.github.com/repos/pyigm/pyigm/releases{/id}","created_at":"2015-12-04T16:59:02Z","updated_at":"2015-12-04T17:23:53Z","pushed_at":"2015-12-14T20:05:13Z","git_url":"git://github.com/pyigm/pyigm.git","ssh_url":"git@github.com:pyigm/pyigm.git","clone_url":"https://github.com/pyigm/pyigm.git","svn_url":"https://github.com/pyigm/pyigm","homepage":null,"size":1427,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"pyigm:master","ref":"master","sha":"2884e27dcdc0e1d81c74edb71d67430b96d6a00b","user":{"login":"pyigm","id":16152971,"avatar_url":"https://avatars.githubusercontent.com/u/16152971?v=3","gravatar_id":"","url":"https://api.github.com/users/pyigm","html_url":"https://github.com/pyigm","followers_url":"https://api.github.com/users/pyigm/followers","following_url":"https://api.github.com/users/pyigm/following{/other_user}","gists_url":"https://api.github.com/users/pyigm/gists{/gist_id}","starred_url":"https://api.github.com/users/pyigm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyigm/subscriptions","organizations_url":"https://api.github.com/users/pyigm/orgs","repos_url":"https://api.github.com/users/pyigm/repos","events_url":"https://api.github.com/users/pyigm/events{/privacy}","received_events_url":"https://api.github.com/users/pyigm/received_events","type":"Organization","site_admin":false},"repo":{"id":47417383,"name":"pyigm","full_name":"pyigm/pyigm","owner":{"login":"pyigm","id":16152971,"avatar_url":"https://avatars.githubusercontent.com/u/16152971?v=3","gravatar_id":"","url":"https://api.github.com/users/pyigm","html_url":"https://github.com/pyigm","followers_url":"https://api.github.com/users/pyigm/followers","following_url":"https://api.github.com/users/pyigm/following{/other_user}","gists_url":"https://api.github.com/users/pyigm/gists{/gist_id}","starred_url":"https://api.github.com/users/pyigm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyigm/subscriptions","organizations_url":"https://api.github.com/users/pyigm/orgs","repos_url":"https://api.github.com/users/pyigm/repos","events_url":"https://api.github.com/users/pyigm/events{/privacy}","received_events_url":"https://api.github.com/users/pyigm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pyigm/pyigm","description":"Python routines for calculations and data on the Intergalactic Medium ","fork":false,"url":"https://api.github.com/repos/pyigm/pyigm","forks_url":"https://api.github.com/repos/pyigm/pyigm/forks","keys_url":"https://api.github.com/repos/pyigm/pyigm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pyigm/pyigm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pyigm/pyigm/teams","hooks_url":"https://api.github.com/repos/pyigm/pyigm/hooks","issue_events_url":"https://api.github.com/repos/pyigm/pyigm/issues/events{/number}","events_url":"https://api.github.com/repos/pyigm/pyigm/events","assignees_url":"https://api.github.com/repos/pyigm/pyigm/assignees{/user}","branches_url":"https://api.github.com/repos/pyigm/pyigm/branches{/branch}","tags_url":"https://api.github.com/repos/pyigm/pyigm/tags","blobs_url":"https://api.github.com/repos/pyigm/pyigm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pyigm/pyigm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pyigm/pyigm/git/refs{/sha}","trees_url":"https://api.github.com/repos/pyigm/pyigm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pyigm/pyigm/statuses/{sha}","languages_url":"https://api.github.com/repos/pyigm/pyigm/languages","stargazers_url":"https://api.github.com/repos/pyigm/pyigm/stargazers","contributors_url":"https://api.github.com/repos/pyigm/pyigm/contributors","subscribers_url":"https://api.github.com/repos/pyigm/pyigm/subscribers","subscription_url":"https://api.github.com/repos/pyigm/pyigm/subscription","commits_url":"https://api.github.com/repos/pyigm/pyigm/commits{/sha}","git_commits_url":"https://api.github.com/repos/pyigm/pyigm/git/commits{/sha}","comments_url":"https://api.github.com/repos/pyigm/pyigm/comments{/number}","issue_comment_url":"https://api.github.com/repos/pyigm/pyigm/issues/comments{/number}","contents_url":"https://api.github.com/repos/pyigm/pyigm/contents/{+path}","compare_url":"https://api.github.com/repos/pyigm/pyigm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pyigm/pyigm/merges","archive_url":"https://api.github.com/repos/pyigm/pyigm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pyigm/pyigm/downloads","issues_url":"https://api.github.com/repos/pyigm/pyigm/issues{/number}","pulls_url":"https://api.github.com/repos/pyigm/pyigm/pulls{/number}","milestones_url":"https://api.github.com/repos/pyigm/pyigm/milestones{/number}","notifications_url":"https://api.github.com/repos/pyigm/pyigm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pyigm/pyigm/labels{/name}","releases_url":"https://api.github.com/repos/pyigm/pyigm/releases{/id}","created_at":"2015-12-04T16:59:02Z","updated_at":"2015-12-04T17:23:53Z","pushed_at":"2015-12-14T20:05:13Z","git_url":"git://github.com/pyigm/pyigm.git","ssh_url":"git@github.com:pyigm/pyigm.git","clone_url":"https://github.com/pyigm/pyigm.git","svn_url":"https://github.com/pyigm/pyigm","homepage":null,"size":1427,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/4"},"html":{"href":"https://github.com/pyigm/pyigm/pull/4"},"issue":{"href":"https://api.github.com/repos/pyigm/pyigm/issues/4"},"comments":{"href":"https://api.github.com/repos/pyigm/pyigm/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/pyigm/pyigm/statuses/4d1cdf0163752d725991c509b0d45b6658542ec6"}}}}