Skip to content

Commit

Permalink
Merge pull request #289 from rodluger/oblate
Browse files Browse the repository at this point in the history
Transits across oblate stars
  • Loading branch information
rodluger authored Sep 2, 2021
2 parents 6c30974 + 6200a99 commit d0d4f20
Show file tree
Hide file tree
Showing 58 changed files with 5,506 additions and 736 deletions.
30 changes: 8 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ jobs:
- python-version: "3.9"
pymc-version: "pymc3==3.11"
arviz-version: ""
- python-version: "3.8"
pymc-version: "https://github.com/pymc-devs/pymc3/archive/main.zip"
arviz-version: ""
# TODO:
# - python-version: "3.8"
# pymc-version: "https://github.com/pymc-devs/pymc3/archive/main.zip"
# arviz-version: ""

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -61,27 +62,12 @@ jobs:
run: |
python -m pip install -U pip
python -m pip install ${{ matrix.pymc-version }} ${{ matrix.arviz-version }}
python -m pip install -e ".[tests]"
- name: Run tests (greedy)
if: steps.install.outcome == 'success'
shell: bash -l {0}
run: python -m pytest -v tests/greedy --junitxml=junit/test-results-greedy.xml --cov=starry --cov-append

- name: Run tests (lazy)
if: steps.install.outcome == 'success'
shell: bash -l {0}
run: python -m pytest -v tests/lazy --junitxml=junit/test-results-lazy.xml --cov=starry --cov-append

- name: Run extension tests (greedy)
if: steps.install.outcome == 'success'
shell: bash -l {0}
run: python -m pytest -v starry/extensions/tests/greedy --junitxml=junit/test-results-extensions-greedy.xml --cov=starry --cov-append
STARRY_UNIT_TESTS=1 python -m pip install -e ".[tests]"
- name: Run extension tests (lazy)
- name: Run tests
if: steps.install.outcome == 'success'
shell: bash -l {0}
run: python -m pytest -v starry/extensions/tests/lazy --junitxml=junit/test-results-extensions-lazy.xml --cov=starry --cov-append
run: python -m pytest -v --junitxml=junit/test-results.xml --cov=starry

- name: Get unique id
id: unique-id
Expand All @@ -97,7 +83,7 @@ jobs:
if: always()
with:
files: junit/test-*.xml
comment_on_pr: false
comment_mode: off

- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
Expand Down
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ repos:
rev: 19.3b0
hooks:
- id: black
language_version: python3.7
exclude: lib

- repo: https://github.com/dfm/black_nbconvert
rev: stable
rev: v0.3.0
hooks:
- id: black_nbconvert
exclude: lib
1 change: 1 addition & 0 deletions docs/MapFactory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ arguments passed to it.
LimbDarkenedMap
RadialVelocityMap
ReflectedLightMap
OblateMap
7 changes: 7 additions & 0 deletions docs/OblateMap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Oblate Maps
===========

.. autoclass:: starry._OblateMap()
:noindex:
:members:
:inherited-members:
7 changes: 6 additions & 1 deletion docs/hacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,22 @@ class _RadialVelocityMap(CustomBase, starry.maps.RVBase, starry.maps.MapBase):
__doc__ = starry.maps.RVBase.__doc__


class _OblateMap(CustomBase, starry.maps.OblateBase, starry.maps.MapBase):
__doc__ = starry.maps.OblateBase.__doc__


starry._SphericalHarmonicMap = _SphericalHarmonicMap
starry._LimbDarkenedMap = _LimbDarkenedMap
starry._ReflectedLightMap = _ReflectedLightMap
starry._RadialVelocityMap = _RadialVelocityMap

starry._OblateMap = _OblateMap

replace = {
"_SphericalHarmonicMap": "Map",
"_LimbDarkenedMap": "Map",
"_ReflectedLightMap": "Map",
"_RadialVelocityMap": "Map",
"_OblateMap": "Map",
}


Expand Down
203 changes: 203 additions & 0 deletions notebooks/todo/EasySampling.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%run ../notebook_setup.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import starry\n",
"import pymc3 as pm\n",
"import pymc3_ext as pmx"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"map = starry.Map(oblate=True, lazy=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"truths = {\n",
" \"f\": 0.3,\n",
" \"omega\": 0.5,\n",
" \"inc\": 60,\n",
" \"obl\": 30,\n",
" \"b0\": 0.5,\n",
" \"ro\": 0.1\n",
"}\n",
"\n",
"ferr = 3e-4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"map.f = truths[\"f\"]\n",
"map.omega = truths[\"omega\"]\n",
"map.inc = truths[\"inc\"]\n",
"map.obl = truths[\"obl\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xo = np.linspace(-1, 1, 300)\n",
"yo = truths[\"b0\"] * np.ones_like(xo)\n",
"ro = truths[\"ro\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1)\n",
"ax.plot(xo, yo, \"k-\")\n",
"ax.plot(xo, yo - ro, \"k--\")\n",
"ax.plot(xo, yo + ro, \"k--\")\n",
"map.show(ax=ax)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"flux0 = map.flux(xo=xo, yo=yo, ro=ro)\n",
"flux = flux0 + ferr * np.random.randn(len(flux0))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.plot(flux0);\n",
"plt.plot(flux, \"k.\", ms=3, alpha=0.75);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Infer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with pm.Model() as model:\n",
" f = pm.Uniform(\"f\", lower=0.0, upper=0.9, testval=truths[\"f\"])\n",
" omega = pm.Uniform(\"omega\", lower=0.0, upper=0.9, testval=truths[\"omega\"])\n",
" inc = pm.Uniform(\"inc\", lower=0.0, upper=90.0, testval=truths[\"inc\"])\n",
" obl = pm.Uniform(\"obl\", lower=-90, upper=90.0, testval=truths[\"obl\"])\n",
" b0 = pm.Uniform(\"b0\", lower=-1.0, upper=1.0, testval=truths[\"b0\"])\n",
" ro = pm.Uniform(\"ro\", lower=1e-5, upper=0.5, testval=truths[\"ro\"])\n",
" map = starry.Map(oblate=True)\n",
" map.f = f\n",
" map.omega = omega\n",
" map.inc = inc\n",
" map.obl = obl\n",
" yo = b0 * np.ones_like(xo)\n",
" flux_model = map.flux(xo=xo, yo=yo, ro=ro)\n",
" pm.Normal(\"obs\", mu=flux_model, sd=ferr, observed=flux)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(42)\n",
"with model:\n",
" trace = pmx.sample(\n",
" tune=1000,\n",
" draws=1000,\n",
" chains=2,\n",
" cores=1,\n",
" target_accept=0.9,\n",
" return_inferencedata=True,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pm.summary(trace)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pm.plot_trace(trace);"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit d0d4f20

Please sign in to comment.