Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding in ACS SBC, WFC3 and ACS narrow, and JWST filters and enhancing the filter plotting routine #799

Merged
merged 24 commits into from
May 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding updating of vega.hd5 file
  • Loading branch information
karllark committed May 14, 2024
commit 88c9db0612fd2a64340447af0f3b16ea3be162ca
65 changes: 63 additions & 2 deletions beast/tools/make_libfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# script to generate BEAST library files
import os
import numpy as np

import stsynphot as stsyn
from pandeia.engine.instrument_factory import InstrumentFactory
import astropy.units as u
from astropy.table import QTable

import h5py

from beast.config import __ROOT__
from beast.observationmodel import phot


def make_libfile():
def make_filters_libfile():
"""
Extract filters from STSYNPHOT and save to main library file.
"""
Expand Down Expand Up @@ -644,5 +646,64 @@ def make_libfile():
hf.close()


def make_vega_libfile():

# Read an updated filters.hd5 lib
__default_filtlist__ = __ROOT__ + "/filters.hd5"
filtlist = QTable.read(__default_filtlist__, path="content")
filters = [cfilt.decode("UTF-8") for cfilt in filtlist["TABLENAME"].data]

# filenames for vega info
__default_vega__ = __ROOT__ + "/vega.hd5"
__default_vega_old__ = __ROOT__ + "/vega_old.hd5"

# rename the current file so we can write a new version
os.rename(__default_vega__, __default_vega_old__)

# Get a spectrum from the need-to-be updated vega lib
vega_old = QTable.read(__default_vega_old__, path="spectrum")
vl = vega_old["WAVELENGTH"].data
vf = vega_old["FLUX"].data

# Write out an updated vega.hd5 file
vega = h5py.File(__default_vega__, "w")

vega.create_dataset("spectrum", data=vega_old)
flist = phot.load_filters(filters, interp=True, lamb=vl, filterLib=__default_filtlist__)

fname = []
cwave = []
lum = []
mag = []

for i in range(len(flist)):
fname.append(flist[i].name)
cwave.append(flist[i].cl)
flux = flist[i].getFlux(vl, vf)
lum.append(flux)
mag.append(-2.5 * np.log10(flux))

contents = np.array(
list(
zip(
fname,
cwave,
lum,
mag,
)
),
dtype=[
("FNAME", "S30"),
("CWAVE", "<f8"),
("LUM", "<f8"),
("MAG", "<f8"),
],
)

vega.create_dataset("sed", data=contents)
vega.close()
karllark marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__": # pragma: no cover
make_libfile()
make_filters_libfile()
make_vega_libfile()