LensCalcPy


NameLensCalcPy JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/NolanSmyth/LensCalcPy
SummaryCalculate Microlensing Observables
upload_time2024-03-01 19:22:42
maintainer
docs_urlNone
authorNolan Smyth
requires_python>=3.7
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            LensCalcPy
================

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

<img src="assets/logo.png" alt="logo" width="200"/>

## Install

``` sh
pip install LensCalcPy
```

## How to use

This package is primarily used to calculate the expected rate of
microlensing events for a given population of lenses. At its core, the
package is designed to compute integrals of the form:

$\frac{d\Gamma}{dM\,dd_L\,d\hat{t}\,du_\text{min}} =  \frac{2}{\sqrt{u_T^2 - u_{\rm{min}}^2}} \frac{v_T^4}{v_c^2} \exp \Big[ -\frac{v_T^2}{v_c^2}\Big] n(d_L) f(M) \varepsilon(\hat{t}),$

which is the differential rate for a given line of sight over $d_L$,
mass function $f(M)$, event duration $\hat{t}$, and minimum impact
parameter $u_\text{min}$. In practice, the user can define the
parameters of their survey (Line of sight, cadence, observation
duration) and compute observables such as the distribution of crossing
times $t_E$, total expected events, etc.

The full documentation can be found
[here](http://nolan-smyth.com/LensCalcPy/). The source code, located in
[nbs](https://github.com/NolanSmyth/LensCalcPy/tree/main/nbs), is
intended to be easily interacrtable and modularizable, so adding
functionality is straightforward. For real-world examples, see the
notebooks in the
[examples](https://github.com/NolanSmyth/LensCalcPy/tree/main/examples)
folder. Below are some minimal examples for PBH (Primordial Black Hole)
lenses and UBO (Unbound Objects) lenses. Here, the line of sight is
towards M31, the Andromeda galaxy.

We can calculate the distribution of crossing times for a given PBH
population

``` python
f_pbh = 1 # fraction of dark matter in PBHs

ts = np.logspace(-2, 1, 20)
pbhs = [Pbh(10**(i), f_pbh, l=l, b=b) for i in np.linspace(-9, -7, 3)]
result = np.zeros((len(pbhs), len(ts)))
for i, pbh in enumerate(pbhs):
    result[i, :] = pbh.compute_differential_rate(ts)
```

``` python
for i, pbh in enumerate(pbhs):
    plt.loglog(ts, result[i], label=r"$M_{\rm{PBH}} = $" + scientific_format(pbh.mass,0) + "$M_{\odot}$")

plt.xlabel(r"$t_E$ [h]", fontsize=16)
plt.ylabel(r"$d\Gamma/dt$ [events/star/hr/hr]", fontsize=16)
plt.xlim(1e-2, 1e1)
plt.ylim(1e-10, 1e-4)

plt.legend()
plt.show()
```

![](index_files/figure-commonmark/cell-3-output-1.png)

Similarly, we can calculate the distribution of crossing times for an
FFP population with mass function $\frac{dM}{d \log(M)} \propto M^{-p}$

``` python
p = 1
fp = Ffp(p, l=l, b=b)
```

``` python
def differential_rate_mw_mass(m, tcad = 0.07, tobs= 3, finite=True):
    return fp.differential_rate_mw_mass(m, tcad=tcad, tobs=tobs, finite=finite)

m_arr = np.logspace(-15, -3, 20)
with Pool() as pool:
    func = functools.partial(differential_rate_mw_mass, tcad=0.07, tobs=3, finite=True)
    diff_rates  = np.array(list(tqdm(pool.imap(func, m_arr), total=len(m_arr))))
```

    100%|██████████| 20/20 [00:08<00:00,  2.29it/s]

``` python
plt.loglog(m_arr/3e-6, diff_rates, label=r'Finite Source, $t_{\rm{cad}} = 4.2 ~\rm{min}$', color='k')

plt.ylim(1e-24, 1e-9)
plt.xlim(np.min(m_arr)/3e-6, 1e1)

plt.xlabel("Mass [$M_{\oplus}$]")
plt.ylabel(r"$d\Gamma/dM$ [events/star/hr/mass]")
plt.title('MW lens, M31 source')
plt.legend()
plt.show()
```

![](index_files/figure-commonmark/cell-6-output-1.png)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NolanSmyth/LensCalcPy",
    "name": "LensCalcPy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "nbdev jupyter notebook python",
    "author": "Nolan Smyth",
    "author_email": "nolanwsmyth@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f0/53/bccc84e8ef1b15d7df50af87fa6e87fa6960f152f86a9e12757cc418ac6d/LensCalcPy-0.0.4.tar.gz",
    "platform": null,
    "description": "LensCalcPy\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n<img src=\"assets/logo.png\" alt=\"logo\" width=\"200\"/>\n\n## Install\n\n``` sh\npip install LensCalcPy\n```\n\n## How to use\n\nThis package is primarily used to calculate the expected rate of\nmicrolensing events for a given population of lenses. At its core, the\npackage is designed to compute integrals of the form:\n\n$\\frac{d\\Gamma}{dM\\,dd_L\\,d\\hat{t}\\,du_\\text{min}} =  \\frac{2}{\\sqrt{u_T^2 - u_{\\rm{min}}^2}} \\frac{v_T^4}{v_c^2} \\exp \\Big[ -\\frac{v_T^2}{v_c^2}\\Big] n(d_L) f(M) \\varepsilon(\\hat{t}),$\n\nwhich is the differential rate for a given line of sight over $d_L$,\nmass function $f(M)$, event duration $\\hat{t}$, and minimum impact\nparameter $u_\\text{min}$. In practice, the user can define the\nparameters of their survey (Line of sight, cadence, observation\nduration) and compute observables such as the distribution of crossing\ntimes $t_E$, total expected events, etc.\n\nThe full documentation can be found\n[here](http://nolan-smyth.com/LensCalcPy/). The source code, located in\n[nbs](https://github.com/NolanSmyth/LensCalcPy/tree/main/nbs), is\nintended to be easily interacrtable and modularizable, so adding\nfunctionality is straightforward. For real-world examples, see the\nnotebooks in the\n[examples](https://github.com/NolanSmyth/LensCalcPy/tree/main/examples)\nfolder. Below are some minimal examples for PBH (Primordial Black Hole)\nlenses and UBO (Unbound Objects) lenses. Here, the line of sight is\ntowards M31, the Andromeda galaxy.\n\nWe can calculate the distribution of crossing times for a given PBH\npopulation\n\n``` python\nf_pbh = 1 # fraction of dark matter in PBHs\n\nts = np.logspace(-2, 1, 20)\npbhs = [Pbh(10**(i), f_pbh, l=l, b=b) for i in np.linspace(-9, -7, 3)]\nresult = np.zeros((len(pbhs), len(ts)))\nfor i, pbh in enumerate(pbhs):\n    result[i, :] = pbh.compute_differential_rate(ts)\n```\n\n``` python\nfor i, pbh in enumerate(pbhs):\n    plt.loglog(ts, result[i], label=r\"$M_{\\rm{PBH}} = $\" + scientific_format(pbh.mass,0) + \"$M_{\\odot}$\")\n\nplt.xlabel(r\"$t_E$ [h]\", fontsize=16)\nplt.ylabel(r\"$d\\Gamma/dt$ [events/star/hr/hr]\", fontsize=16)\nplt.xlim(1e-2, 1e1)\nplt.ylim(1e-10, 1e-4)\n\nplt.legend()\nplt.show()\n```\n\n![](index_files/figure-commonmark/cell-3-output-1.png)\n\nSimilarly, we can calculate the distribution of crossing times for an\nFFP population with mass function $\\frac{dM}{d \\log(M)} \\propto M^{-p}$\n\n``` python\np = 1\nfp = Ffp(p, l=l, b=b)\n```\n\n``` python\ndef differential_rate_mw_mass(m, tcad = 0.07, tobs= 3, finite=True):\n    return fp.differential_rate_mw_mass(m, tcad=tcad, tobs=tobs, finite=finite)\n\nm_arr = np.logspace(-15, -3, 20)\nwith Pool() as pool:\n    func = functools.partial(differential_rate_mw_mass, tcad=0.07, tobs=3, finite=True)\n    diff_rates  = np.array(list(tqdm(pool.imap(func, m_arr), total=len(m_arr))))\n```\n\n    100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 20/20 [00:08<00:00,  2.29it/s]\n\n``` python\nplt.loglog(m_arr/3e-6, diff_rates, label=r'Finite Source, $t_{\\rm{cad}} = 4.2 ~\\rm{min}$', color='k')\n\nplt.ylim(1e-24, 1e-9)\nplt.xlim(np.min(m_arr)/3e-6, 1e1)\n\nplt.xlabel(\"Mass [$M_{\\oplus}$]\")\nplt.ylabel(r\"$d\\Gamma/dM$ [events/star/hr/mass]\")\nplt.title('MW lens, M31 source')\nplt.legend()\nplt.show()\n```\n\n![](index_files/figure-commonmark/cell-6-output-1.png)\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Calculate Microlensing Observables",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/NolanSmyth/LensCalcPy"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70adcb9fbdc39b10dd683e7306bc233238859cb2bba168193b610ae5fbe408dc",
                "md5": "1a8632def94d68555eaa613e3a118fec",
                "sha256": "9b97959a757c8c9d6f2cc7151f881b2500e727758de5986127b78dc6bf042c01"
            },
            "downloads": -1,
            "filename": "LensCalcPy-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1a8632def94d68555eaa613e3a118fec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 249784,
            "upload_time": "2024-03-01T19:22:40",
            "upload_time_iso_8601": "2024-03-01T19:22:40.356764Z",
            "url": "https://files.pythonhosted.org/packages/70/ad/cb9fbdc39b10dd683e7306bc233238859cb2bba168193b610ae5fbe408dc/LensCalcPy-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f053bccc84e8ef1b15d7df50af87fa6e87fa6960f152f86a9e12757cc418ac6d",
                "md5": "0589ba399d3e143cc9ff328485fceac3",
                "sha256": "b6738f4af3d4bffa4426f8180592e0ec9608a22ac539a692a0446813f7ebed5d"
            },
            "downloads": -1,
            "filename": "LensCalcPy-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "0589ba399d3e143cc9ff328485fceac3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 235352,
            "upload_time": "2024-03-01T19:22:42",
            "upload_time_iso_8601": "2024-03-01T19:22:42.357531Z",
            "url": "https://files.pythonhosted.org/packages/f0/53/bccc84e8ef1b15d7df50af87fa6e87fa6960f152f86a9e12757cc418ac6d/LensCalcPy-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-01 19:22:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NolanSmyth",
    "github_project": "LensCalcPy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "lenscalcpy"
}
        
Elapsed time: 0.21029s