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

Allowing the users to append their filters into the existing BEAST filter library #756

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
61 changes: 51 additions & 10 deletions beast/observationmodel/phot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
import sys
import numpy

import argparse
import tables
from scipy.integrate import trapz

Expand Down Expand Up @@ -579,11 +579,11 @@ class __newFilterTable__(tables.IsDescription):

def append_filter(
lamb,
flux,
throughput,
tablename,
observatory,
instrument,
name,
filtername,
comment=None,
filterLib=__default__,
updateVegaLib=True,
Expand All @@ -594,10 +594,10 @@ def append_filter(
Parameters
----------
lamb: ndarray(dtype=float)
wavelength of the filter definition
wavelength of the filter definition in Angstrom

flux: ndarray(dtype=float)
transimission of the filter
throughput: ndarray(dtype=float)
total throughput of the filter

tablename: str
table name in the library
Expand All @@ -606,9 +606,9 @@ def append_filter(
observatory of the filter (Ground, HST, Spitzer, ...)

instrument: str
instrument associated with the filter
instrument associated with the filter (WFC3, ACS, ...)

name: str
filtername: str
name of the filter

comment: str, optional
Expand All @@ -629,7 +629,7 @@ def append_filter(
return

# Gen Filter object including relevant details
filtInst = list(filter(lamb, flux, name=name))
filtInst = Filter(lamb, throughput, name=filtername)
# Add a new line in the content table
newRow = contentTab.row
newRow["TABLENAME"] = tablename
Expand Down Expand Up @@ -659,7 +659,7 @@ def append_filter(
newTab.flush()
ftab.flush()
ftab.close()
print("% {0}: Filter {1} added to {2}".format(sys.argv[0], name, filterLib))
print("% {0}: Filter {1} added to {2}".format(sys.argv[0], filtername, filterLib))
if updateVegaLib:
appendVegaFilter(filtInst)

Expand Down Expand Up @@ -733,3 +733,44 @@ def appendVegaFilter(filtInst, VegaLib=__default_vega__):
sedTab.flush()
vtab.close()
print("% {0}: Filter {1} added to {2}".format(sys.argv[0], filtInst.name, VegaLib))


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"filter_throughput_curve",
type=str,
default=None,
help="filename of filter throughput curve to be added into the BEAST filter library",
)
parser.add_argument(
"--tablename",
type=str,
help="Table name for the filter",
)
parser.add_argument(
"--observatory",
type=str,
help="Observatory for the filter (e.g., HST, GALEX)",
)
parser.add_argument(
"--instrument",
type=str,
help="Instrument associated with the filter (WFC3, ACS, ...)",
)
parser.add_argument(
"--filtername",
type=str,
help="Name for the filter",
)

args = parser.parse_args()

if args.filter_throughput_curve:
lamb, throughput = numpy.loadtxt(args.filter_throughput_curve, usecols=(0, 1),
unpack=True)
append_filter(lamb, throughput, args.tablename, args.observatory, args.instrument,
args.filtername)

if not any(vars(args).values()):
parser.print_help()
Comment on lines +736 to +776
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a separate script in the tools subdir instead of added to phot.py. For consistency with how similar capabilities are handled in the BEAST.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Will start a separate script for this functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task could be merged with the outstanding WIP PR #646!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this script to this PR.

22 changes: 22 additions & 0 deletions docs/append_filters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
##############
Append filters
##############

Users can add any filters into their local ``beast/libs/filters.hd5``.
The list of default filters in the BEAST filter library can be found `<here https://beast.readthedocs.io/en/latest/beast_setup.html#beast-filters>`_.

If you need to include fluxes in particular bands in your SED fitting or BEAST
predictions but those particular bands do not exist in the BEAST filter library,
you should append those filters to the BEAST filter library before generating
your physics model grid. To do this, you need an ascii file that has two columns:
wavelegnth in angstrom and thoughput. The BEAST filter library requires basic information
about the filter. This includes the tablename for the filter information (e.g., HST_WFC3_F275W),
observatorty associated with the filter (e.g., HST), instrument of the filter (e.g., WFC3),
and name of the filter (e.g., F275W).

Command to add a filter to the BEAST filter library.

.. code-block:: console

$ python -m beast.observationmodel.phot filter_curve_file --tablename tablename
--observatory observatory --instrument instrument --filtername filtername
karllark marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ Basics:
Photometry files <photometry_files.rst>
Output files <outputs.rst>

Detals:
Details:

.. toctree::
:maxdepth: 1

Graphical Models <beast_graphical_model.rst>
Appending additional filters <append_filters.rst>
Stellar/Extinction Priors <beast_priors.rst>
Generating AST inputs <generating_asts.rst>
Simulating observations <simulations.rst>
Expand Down