From f35f911891bb41504af7db8df184f18d5b911bb4 Mon Sep 17 00:00:00 2001 From: Yumi Choi Date: Thu, 24 Feb 2022 16:29:05 -0500 Subject: [PATCH 1/6] fix a typo and update for adding filter description --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 92002230..2d1a7658 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -33,12 +33,13 @@ Basics: Photometry files Output files -Detals: +Details: .. toctree:: :maxdepth: 1 Graphical Models + Appending additional filters Stellar/Extinction Priors Generating AST inputs Simulating observations From 18bd6264d6cf6e8f25b65e0516f2ce34067b81c7 Mon Sep 17 00:00:00 2001 From: Yumi Choi Date: Thu, 24 Feb 2022 16:30:17 -0500 Subject: [PATCH 2/6] describe how to append a new filter to the BEAST filter lib --- docs/append_filters.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/append_filters.rst diff --git a/docs/append_filters.rst b/docs/append_filters.rst new file mode 100644 index 00000000..6ca74971 --- /dev/null +++ b/docs/append_filters.rst @@ -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 ``_. + +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 From 7521ac2b8e6644ded853c90355aaeacfedf780c5 Mon Sep 17 00:00:00 2001 From: Yumi Choi Date: Thu, 24 Feb 2022 16:33:46 -0500 Subject: [PATCH 3/6] update code to enable adding a new filter from a command line --- beast/observationmodel/phot.py | 61 ++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/beast/observationmodel/phot.py b/beast/observationmodel/phot.py index ae67d38f..34f0d971 100644 --- a/beast/observationmodel/phot.py +++ b/beast/observationmodel/phot.py @@ -16,7 +16,7 @@ """ import sys import numpy - +import argparse import tables from scipy.integrate import trapz @@ -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, @@ -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 @@ -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 @@ -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 @@ -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) @@ -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() From 2666c75619ad6a443e368e237cae98b47ee23244 Mon Sep 17 00:00:00 2001 From: Yumi Choi Date: Thu, 24 Feb 2022 16:43:04 -0500 Subject: [PATCH 4/6] fix codstyle issue --- beast/observationmodel/phot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beast/observationmodel/phot.py b/beast/observationmodel/phot.py index 34f0d971..4fd4b12a 100644 --- a/beast/observationmodel/phot.py +++ b/beast/observationmodel/phot.py @@ -767,10 +767,10 @@ def appendVegaFilter(filtInst, VegaLib=__default_vega__): 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 - ) + 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() From 0548844d52768f99723a676562e62bf4f1a5c4fa Mon Sep 17 00:00:00 2001 From: Yumi Choi Date: Thu, 24 Feb 2022 16:49:22 -0500 Subject: [PATCH 5/6] fix codestyle issue --- beast/observationmodel/phot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beast/observationmodel/phot.py b/beast/observationmodel/phot.py index 4fd4b12a..6c443d16 100644 --- a/beast/observationmodel/phot.py +++ b/beast/observationmodel/phot.py @@ -767,10 +767,10 @@ def appendVegaFilter(filtInst, VegaLib=__default_vega__): 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 - ) + 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() From eae674a5a83986594a771993794943101d9d5a91 Mon Sep 17 00:00:00 2001 From: Yumi Choi Date: Thu, 24 Feb 2022 16:55:18 -0500 Subject: [PATCH 6/6] fix codestyle issue --- beast/observationmodel/phot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beast/observationmodel/phot.py b/beast/observationmodel/phot.py index 6c443d16..0f2ea0b9 100644 --- a/beast/observationmodel/phot.py +++ b/beast/observationmodel/phot.py @@ -768,9 +768,9 @@ def appendVegaFilter(filtInst, VegaLib=__default_vega__): if args.filter_throughput_curve: lamb, throughput = numpy.loadtxt(args.filter_throughput_curve, usecols=(0, 1), - unpack=True) + unpack=True) append_filter(lamb, throughput, args.tablename, args.observatory, args.instrument, - args.filtername) + args.filtername) if not any(vars(args).values()): parser.print_help()