Skip to content

Commit

Permalink
updating to 2D dust priors
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Dec 5, 2023
1 parent cb6508a commit 307fd5e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
6 changes: 3 additions & 3 deletions beast/physicsmodel/creategrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,15 @@ def make_extinguished_grid(
# moved here in 2023 to support distance based dust priors
dists = g0.grid["distance"].data
if av_prior_model["name"] == "step":
av_weights = av_prior(dists)
av_weights = av_prior(np.full((len(dists)), Av), y=dists)

Check warning on line 435 in beast/physicsmodel/creategrid.py

View check run for this annotation

Codecov / codecov/patch

beast/physicsmodel/creategrid.py#L435

Added line #L435 was not covered by tests
else:
av_weights = av_prior(Av)
if rv_prior_model["name"] == "step":
rv_weights = rv_prior(dists)
rv_weights = rv_prior(np.full((len(dists)), Rv), y=dists)

Check warning on line 439 in beast/physicsmodel/creategrid.py

View check run for this annotation

Codecov / codecov/patch

beast/physicsmodel/creategrid.py#L439

Added line #L439 was not covered by tests
else:
rv_weights = rv_prior(Rv)
if fA_prior_model["name"] == "step":
f_A_weights = fA_prior(dists)
f_A_weights = fA_prior(np.full((len(dists)), f_A), y=dists)

Check warning on line 443 in beast/physicsmodel/creategrid.py

View check run for this annotation

Codecov / codecov/patch

beast/physicsmodel/creategrid.py#L443

Added line #L443 was not covered by tests
else:
if with_fA:
f_A_weights = fA_prior(f_A)
Expand Down
11 changes: 7 additions & 4 deletions beast/plotting/plot_dist_vs_dust_priors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import matplotlib.pyplot as plt
#from astropy.visualization import SqrtStretch, LogStretch, ImageNormalize

# from astropy.visualization import SqrtStretch, LogStretch, ImageNormalize
from astropy.modeling.models import Gaussian2D
import astropy.units as u

Expand Down Expand Up @@ -89,9 +90,11 @@
# alldists = np.concatenate((alldists, distsamp))
# allavs = np.concatenate((allavs, avsamp))

#ax[0, 1].hist2d(alldists, allavs, bins=20, norm="log")
#norm = ImageNormalize(vmin=1e-5, vmax=1, stretch=LogStretch())
ax[0, 1].imshow(sumprobim, origin="lower", aspect="auto", extent=[d1, d2, av1, av2], norm="log")
# ax[0, 1].hist2d(alldists, allavs, bins=20, norm="log")
# norm = ImageNormalize(vmin=1e-5, vmax=1, stretch=LogStretch())
ax[0, 1].imshow(
sumprobim, origin="lower", aspect="auto", extent=[d1, d2, av1, av2], norm="log"
)
ax[0, 1].set_xlabel("distance [kpc]")
ax[0, 1].set_ylabel("A(V)")

Expand Down
51 changes: 37 additions & 14 deletions docs/beast_priors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,37 @@ The distance prior can be
distance_prior_model = {"name": "flat"}
2. Absolute(Exponential) distribution with an exponential scale height (tau) before and
after a fiducial distance (dist0) and an amplitude (amp).

.. code-block:: python
distance_prior_model = {"name": "absexponential",
"dist0": 60.0*u.kpc,
"tau": 5.*u.kpc,
"amp": 1.0}
Plot showing examples of the possible distance prior models with the parameters given above.

.. plot::

import numpy as np
import matplotlib.pyplot as plt
import astropy.units as u

from beast.physicsmodel.priormodel import PriorDistanceModel

fig, ax = plt.subplots()

# met grid with linear spacing
dists = np.linspace(8e6, 9e6)
dists = np.arange(50., 70, 0.1) * 1e3

met_prior_models = [{"name": "flat"}]
met_prior_models = [
{"name": "flat"},
{"name": "absexponential",
"dist0": 60.0*u.kpc,
"tau": 5.*u.kpc,
"amp": 1.0}]

for mp_mod in met_prior_models:
pmod = PriorDistanceModel(mp_mod)
Expand Down Expand Up @@ -372,18 +388,25 @@ the effect of having a dust cloud located at a certain distance.
fig, ax = plt.subplots()

# distance grid with linear spacing
dists = np.linspace(50., 70.0, num=200)

dust_prior_models = [
{"name": "step",
"dist_0": 60 * u.kpc,
"amp_1": 0.1,
"amp_2": 1.0}
]

for dmod in dust_prior_models:
pmod = PriorDustModel(dmod)
ax.plot(dists, pmod(dists), label=dmod["name"])
d1, d2 = (50., 70.)
dists = np.linspace(d1, d2, num=200)
av1, av2 = (0.0, 2.0)
avs = np.arange(av1, av2, 0.025)
distim, avim = np.meshgrid(dists, avs)

dustmod = {"name": "step",
"dist0": 60 * u.kpc,
"amp1": 0.1,
"amp2": 1.0,
"lgsigma1": 0.05,
"lgsigma2": 0.05}

dustprior = PriorDustModel(dustmod)
probim = dustprior(avim, y=distim)

ax.imshow(
probim, origin="lower", aspect="auto", extent=[d1, d2, av1, av2], norm="log"
)

ax.set_ylabel("A(V)")
ax.set_xlabel("distance [pc]")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ github_project = BEAST-fitting/beast
[options]
zip_safe = False
packages = find:
python_requires = >=3.7
python_requires = >=3.8
setup_requires = setuptools_scm
install_requires =
astropy
Expand Down

0 comments on commit 307fd5e

Please sign in to comment.