{"action":"created","comment":{"url":"https://api.github.com/repos/pyigm/pyigm/pulls/comments/47779597","id":47779597,"diff_hunk":"@@ -0,0 +1,307 @@\n+\"\"\" Module for tau_eff calculations\n+\"\"\"\n+import pdb\n+import yaml\n+import imp\n+\n+import numpy as np\n+from scipy import interpolate\n+\n+from astropy import constants as const\n+from astropy import units as u\n+from astropy.cosmology import FlatLambdaCDM, Planck15\n+\n+from linetools.analysis import absline as ltaa\n+from linetools.lists.linelist import LineList\n+\n+from pyigm.fN.fnmodel import FNModel\n+from pyigm import utils as pyigmu\n+\n+pyigm_path = imp.find_module('pyigm')[1]\n+\n+def DM(z, cosmo=None):\n+    \"\"\" Dispersion Measure from the IGM\n+\n+    Simple assumption of fully ionized, non-clumpy IGM\n+\n+    Parameters\n+    ----------\n+    z : float\n+      Redshift\n+    cosmo : astropy.cosmology, optional\n+\n+    Returns\n+    -------\n+    DM : float\n+      IGM dispersion measure\n+    \"\"\"\n+    from scipy.integrate import quad\n+    if cosmo is None:\n+        cosmo = Planck15\n+        print('Using a Planck15 cosmology with H0={:g} and Om={:g} and Ob={:g}'.format(\n+            cosmo.H0, cosmo.Om0, cosmo.Ob0))\n+    # Check for Ob0\n+    if cosmo.Ob0 is None:\n+        raise IOError('Need to set Ob0 in the cosmology')\n+    # Calculate\n+    def integrand(x):\n+        return (1+x) / np.sqrt(cosmo.Om0*(1+x)**3 + (1-cosmo.Om0))\n+    integral = quad(integrand, 0, z)\n+    # DM\n+    DM, _ = (3 * const.c * cosmo.H0 * cosmo.Ob0 / (8*np.pi*const.G*const.m_p)) * integral\n+    # Return\n+    return DM.to('pc/cm**3')\n+\n+\n+def lyman_limit(fN_model, z912, zem, N_eval=5000, cosmo=None, debug=False):\n+    \"\"\" Calculate teff_LL\n+\n+    Effective opacity from LL absorption at z912 from zem\n+\n+    Parameters\n+    ----------\n+    fN_model : FNModel\n+      f(N) model\n+    z912 : float\n+      Redshift for evaluation\n+    zem : float\n+      Redshift of source\n+    cosmo : astropy.cosmology, optional\n+      Cosmological model to adopt (as needed)\n+    N_eval : int, optional\n+      Discretization parameter (5000)\n+    debug : bool, optional\n+\n+    Returns\n+    -------\n+    zval : array\n+    teff_LL : array\n+      z values and Effective opacity from LL absorption from z912 to zem\n+    \"\"\"\n+    if not isinstance(fN_model,FNModel):\n+        raise IOError(\"Improper model\")\n+    # NHI array\n+    lgNval = 11.5 + 10.5*np.arange(N_eval)/(N_eval-1.)  #; This is base 10 [Max at 22]\n+    dlgN = lgNval[1]-lgNval[0]\n+    Nval = 10.**lgNval\n+\n+    # z array\n+    zval = z912 + (zem-z912)*np.arange(N_eval)/(N_eval-1.)\n+    dz = np.fabs(zval[1]-zval[0])\n+\n+    teff_LL = np.zeros(N_eval)\n+\n+    # dXdz\n+    dXdz = pyigmu.cosm_xz(zval, cosmo=cosmo, flg_return=1)\n+\n+    # Evaluate f(N,X)\n+    velo = (zval-zem)/(1+zem) * (const.c.cgs.value/1e5)  # Kludge for eval [km/s]\n+\n+    log_fnX = fN_model.evaluate(lgNval, zem, vel_array=velo)\n+    log_fnz = log_fnX + np.outer(np.ones(N_eval), np.log10(dXdz))\n+\n+    # Evaluate tau(z,N)\n+    teff_engy = (const.Ryd.to(u.eV, equivalencies=u.spectral()) /\n+                 ((1+zval)/(1+zem)) )\n+    sigma_z = ltaa.photo_cross(1, 1, teff_engy)\n+    tau_zN = np.outer(Nval, sigma_z)\n+\n+    # Integrand\n+    intg = 10.**(log_fnz) * (1. - np.exp(-1.*tau_zN))\n+\n+    # Sum\n+    sumz_first = False\n+    if sumz_first == False:\n+        #; Sum in N first\n+        N_summed = np.sum(intg * np.outer(Nval, np.ones(N_eval)),  0) * dlgN * np.log(10.)\n+        # Sum in z\n+        teff_LL = (np.cumsum(N_summed[::-1]))[::-1] * dz\n+\n+    # Debug\n+    if debug is True:\n+        pdb.set_trace()\n+    # Return\n+    return zval, teff_LL\n+\n+\n+def lyman_ew(ilambda, zem, fN_model, NHI_MIN=11.5, NHI_MAX=22.0, N_eval=5000,\n+                  EW_spline=None, bval=24., fNz=False, cosmo=None, debug=False,\n+                  cumul=None, verbose=False):\n+    \"\"\" tau effective from HI Lyman series absorption\n+\n+    Parameters\n+    ----------\n+    ilambda : float\n+        Observed wavelength (Ang)\n+    zem : float\n+        Emission redshift of the source [sets which Lyman lines are included]\n+    bva : float","path":"pyigm/fN/tau_eff.py","position":138,"original_position":138,"commit_id":"b5726e503b69b2538138e1ff315c81e65c9f65cd","original_commit_id":"b5726e503b69b2538138e1ff315c81e65c9f65cd","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":"fixed","created_at":"2015-12-16T14:15:01Z","updated_at":"2015-12-16T14:15:01Z","html_url":"https://github.com/pyigm/pyigm/pull/3#discussion_r47779597","pull_request_url":"https://api.github.com/repos/pyigm/pyigm/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/comments/47779597"},"html":{"href":"https://github.com/pyigm/pyigm/pull/3#discussion_r47779597"},"pull_request":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/pyigm/pyigm/pulls/3","id":52985313,"html_url":"https://github.com/pyigm/pyigm/pull/3","diff_url":"https://github.com/pyigm/pyigm/pull/3.diff","patch_url":"https://github.com/pyigm/pyigm/pull/3.patch","issue_url":"https://api.github.com/repos/pyigm/pyigm/issues/3","number":3,"state":"open","locked":false,"title":"fN: Model, tests and docs","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":"As titled.\n\nSee the ipython notebook for examples","created_at":"2015-12-08T14:16:12Z","updated_at":"2015-12-16T14:15:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9c0a2eedf6dfa5db073f864ad5a5c6e86429b0d7","assignee":{"login":"mifumagalli","id":12461695,"avatar_url":"https://avatars.githubusercontent.com/u/12461695?v=3","gravatar_id":"","url":"https://api.github.com/users/mifumagalli","html_url":"https://github.com/mifumagalli","followers_url":"https://api.github.com/users/mifumagalli/followers","following_url":"https://api.github.com/users/mifumagalli/following{/other_user}","gists_url":"https://api.github.com/users/mifumagalli/gists{/gist_id}","starred_url":"https://api.github.com/users/mifumagalli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mifumagalli/subscriptions","organizations_url":"https://api.github.com/users/mifumagalli/orgs","repos_url":"https://api.github.com/users/mifumagalli/repos","events_url":"https://api.github.com/users/mifumagalli/events{/privacy}","received_events_url":"https://api.github.com/users/mifumagalli/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/pyigm/pyigm/pulls/3/commits","review_comments_url":"https://api.github.com/repos/pyigm/pyigm/pulls/3/comments","review_comment_url":"https://api.github.com/repos/pyigm/pyigm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pyigm/pyigm/issues/3/comments","statuses_url":"https://api.github.com/repos/pyigm/pyigm/statuses/b5726e503b69b2538138e1ff315c81e65c9f65cd","head":{"label":"pyigm:fN","ref":"fN","sha":"b5726e503b69b2538138e1ff315c81e65c9f65cd","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-15T05:13:49Z","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":1430,"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-15T05:13:49Z","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":1430,"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/3"},"html":{"href":"https://github.com/pyigm/pyigm/pull/3"},"issue":{"href":"https://api.github.com/repos/pyigm/pyigm/issues/3"},"comments":{"href":"https://api.github.com/repos/pyigm/pyigm/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pyigm/pyigm/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/pyigm/pyigm/statuses/b5726e503b69b2538138e1ff315c81e65c9f65cd"}}}}