Skip to content

Commit

Permalink
Merge pull request #799 from karllark/add_acs_uv
Browse files Browse the repository at this point in the history
adding in ACS SBC, WFC3 and ACS narrow, and JWST filters and enhancing the filter plotting routine
  • Loading branch information
karllark authored May 23, 2024
2 parents ab6c00e + c9590a5 commit bcc8cb5
Show file tree
Hide file tree
Showing 12 changed files with 702 additions and 223 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tox-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ jobs:
- name: Set up python for coverage test
uses: actions/setup-python@v4
with:
python-version: 3.12
python-version: 3.9
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Test with tox
run: |
tox -e py312-cov -- --remote-data
tox -e py309-cov -- --remote-data
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
with:
Expand Down
33 changes: 33 additions & 0 deletions beast/observationmodel/tests/test_filters_and_vega_consistent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from astropy.table import QTable

from beast.config import __ROOT__
from beast.tools import get_libfiles


def test_filters_and_vega_consistent():
"""
Test to ensure that the filters.hd5 and vega.hd5 are consistent.
In other words, both have the same filters.
"""

# download the BEAST library files
get_libfiles.get_libfiles(vega_filters_only=True)

ftab = QTable.read(__ROOT__ + "filters.hd5", path="content")
vtab = QTable.read(__ROOT__ + "vega.hd5", path="sed")

otxt = ""
for cfilt in ftab["TABLENAME"].data:
if cfilt not in vtab["FNAME"].data:
otxt = f"{otxt} {cfilt}"
assert otxt == "", "filters in filters.hd5 missing from vega.hd5:" + otxt

otxt = ""
for cfilt in vtab["FNAME"].data:
if cfilt not in ftab["TABLENAME"].data:
otxt = f"{otxt} {cfilt}"
assert otxt == "", "filters in vega.hd5 missing from filters.hd5:" + otxt


if __name__ == "__main__": # pragma: no cover
test_filters_and_vega_consistent()
45 changes: 30 additions & 15 deletions beast/plotting/plot_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
def plot_filters(
filter_names,
filterLib=None,
save_name="beast_filters",
xlim=[1.4e3, 2e4],
xlim=None,
ylim=[1e-4, 2],
show_plot=True,
):

"""Plots transmission curves in log-log space.
Parameters
Expand All @@ -42,32 +40,47 @@ def plot_filters(
fig, ax = plt.subplots(1, 1, figsize=(10, 6))

# wavelength grid in angstroms for response functions
waves = np.logspace(3, np.log10(3e4), 501)
# cover all HST and JWST wavelengths
waves = np.logspace(np.log10(912.0), np.log10(3e5), 1001)

# read in the filter response functions
flist = phot.load_filters(
filter_names, interp=True, lamb=waves, filterLib=filterLib
)

color_indices = np.log10(np.array(np.sort([f.norm for f in flist])))
color_indices -= color_indices.min()
color_indices /= color_indices.max()
if len(color_indices) > 1:
color_indices -= color_indices.min()
color_indices /= color_indices.max()
else:
color_indices = [0.0]

cmap = mpl.cm.plasma
# ax.set_prop_cycle(color=[cmap(i) for i in color_indices])
color = iter(cmap(np.linspace(0.2, 0.8, len(filter_names))))

dxlim = np.array([3e5, 912.0]) * 1e-4
for f in flist:
wavelength = f.wavelength * 1e-4
c = next(color)
ax.plot(f.wavelength, f.transmit, color=c, lw=2)
ax.fill_between(f.wavelength, f.transmit, alpha=0.2, color=c)
ax.plot(wavelength, f.transmit, color=c, lw=2)
ax.fill_between(wavelength, f.transmit, alpha=0.2, color=c)
yval_text = max(f.transmit * 0.1)
ax.text(
np.nanmean(f.wavelength[f.transmit > 100.0 * ylim[0]]),
1.3 * np.nanmax(f.transmit[f.transmit > ylim[0]]),
np.nanmean(wavelength[f.transmit > yval_text]),
1.3 * np.nanmax(f.transmit[f.transmit > yval_text]),
f.name.split("_")[-1],
ha="center",
color=c,
)
gvals = (f.transmit > ylim[0]) & (f.transmit < ylim[1])
if min(wavelength[gvals]) < dxlim[0]:
dxlim[0] = min(wavelength[gvals])
if max(wavelength[gvals]) > dxlim[1]:
dxlim[1] = max(wavelength[gvals])

if xlim is None:
xlim = dxlim

ax.set_xscale("log")
ax.set_yscale("log")
Expand All @@ -77,7 +90,7 @@ def plot_filters(
ax.set_ylabel(r"$B_i(\lambda)$")

# ax.set_xticks([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2.0])
ax.get_xaxis().set_major_formatter(mpl.ticker.ScalarFormatter())
# ax.get_xaxis().set_major_formatter(mpl.ticker.ScalarFormatter())

fig.tight_layout()

Expand All @@ -95,9 +108,7 @@ def plot_filters(
default="filters.appendVegaFilter",
help="Save figure to file",
)
args = parser.parse_args()

filter_names = [
def_filter_names = [
"HST_WFC3_F225W",
"HST_WFC3_F275W",
"HST_WFC3_F336W",
Expand All @@ -107,8 +118,12 @@ def plot_filters(
"HST_WFC3_F110W",
"HST_WFC3_F160W",
]
parser.add_argument(
"filter_names", help="names of filters", nargs="+", default=def_filter_names
)
args = parser.parse_args()

fig = plot_filters(filter_names, show_plot=False)
fig = plot_filters(args.filter_names, show_plot=False)

if args.tex:
plt.rc({"usetex": True})
Expand Down
2 changes: 1 addition & 1 deletion beast/tests/test_regresscheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setUpClass(cls):

cls.dset = "metal"
if cls.dset == "metal":
cls.basesubdir = "metal_small_9Nov22/"
cls.basesubdir = "metal_small/"
cls.basename = f"{cls.basesubdir}beast_metal_small"
cls.obsname = f"{cls.basesubdir}14675_LMC-13361nw-11112.gst_samp.fits"
cls.astname = f"{cls.basesubdir}14675_LMC-13361nw-11112.gst.fake.fits"
Expand Down
5 changes: 3 additions & 2 deletions beast/tools/get_libfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ def _download_rename(filename, url_loc, local_loc):
return filename


def get_libfiles():
def get_libfiles(vega_filters_only=False):
"""
Download all the library files needed by the BEAST
"""
for ckey, clib in libs.items():
_download_rename(clib, libs_server, __ROOT__)
if ((not vega_filters_only) or (vega_filters_only & (ckey in ["vega", "filters"]))):
_download_rename(clib, libs_server, __ROOT__)


if __name__ == "__main__": # pragma: no cover
Expand Down
Loading

0 comments on commit bcc8cb5

Please sign in to comment.