From 213f7de394dae1f2ec7441baba7a9a74cc865f15 Mon Sep 17 00:00:00 2001 From: ACCarnall Date: Wed, 4 Apr 2018 23:31:04 +0100 Subject: [PATCH] updated documentation --- .gitignore | 2 +- MANIFEST.in | 1 + README.rst | 18 +- bagpipes/compare_fits.py | 5 - bagpipes/fit.py | 26 +- bagpipes/galaxy.py | 4 - bagpipes/model_galaxy.py | 14 +- bagpipes/model_manager.py | 13 +- bagpipes/star_formation_history.py | 30 +- docs/filtlists.rst | 32 ++ docs/fitting_galaxies/fitting_galaxies.rst | 2 +- docs/getting_started.rst | 76 +++++ .../{model_galaxies => images}/examplesfh.jpg | Bin .../examplespec.jpg | Bin .../examplespecphot.jpg | Bin docs/index.rst | 44 ++- docs/installation.rst | 16 +- docs/loading_galaxies/loading_galaxies.rst | 2 +- docs/model_galaxies.rst | 275 ++++++++++++++++++ docs/model_galaxies/api_doc.rst | 5 - docs/model_galaxies/filtlists.rst | 41 --- docs/model_galaxies/model_components.rst | 208 ------------- docs/model_galaxies/model_galaxies.rst | 23 -- docs/model_galaxies/updating.rst | 59 ---- setup.py | 12 +- tables/__init__.py | 0 26 files changed, 467 insertions(+), 441 deletions(-) create mode 100644 docs/filtlists.rst create mode 100644 docs/getting_started.rst rename docs/{model_galaxies => images}/examplesfh.jpg (100%) rename docs/{model_galaxies => images}/examplespec.jpg (100%) rename docs/{model_galaxies => images}/examplespecphot.jpg (100%) create mode 100644 docs/model_galaxies.rst delete mode 100644 docs/model_galaxies/api_doc.rst delete mode 100644 docs/model_galaxies/filtlists.rst delete mode 100644 docs/model_galaxies/model_components.rst delete mode 100644 docs/model_galaxies/model_galaxies.rst delete mode 100644 docs/model_galaxies/updating.rst create mode 100644 tables/__init__.py diff --git a/.gitignore b/.gitignore index eb93fcc..5979b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ backup_stellar_models/* tables/nebular/cloudy_temp_files/* testing/* *.fits - +examples/* ################################# diff --git a/MANIFEST.in b/MANIFEST.in index f5b385f..13f367d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ include tables/IGM/Lyman_series_coefs_Inoue_2014_Table2.txt include tables/dust/*.txt +include tables/nebular/*.txt include tables/nebular/bc03_miles/*.fits include tables/stellar/bc03_miles/*.fits include README.rst diff --git a/README.rst b/README.rst index 16cbf25..e5f411c 100644 --- a/README.rst +++ b/README.rst @@ -1,21 +1,7 @@ -BAGPIPES -======== - Bayesian Analysis of Galaxies for Physical Inference and Parameter EStimation ----------------------------------------------------------------------------- -Bagpipes is a state of the art code for generating model galaxy spectra and fitting these to observations. The model generation routines are ideal for turning output from simulations into mock observations, and the fitting routines allow the physical parameters of real galaxies to be constrained from spectroscopic and/or photometric observations. - - -Documentation -------------- - -The Bagpipes documentation can be found `here `_, this is currently a work in progress! - - -Acknowledgements ----------------- +Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations. -Bagpipes is described in Section 3 of `ArXiv1712.04452 `_, if you make use of Bagpipes in your research, please include a citation to this work in any publications. +For further information please see the Bagpipes documentation at `bagpipes.readthedocs.io `_. -Bagpipes makes use of `MultiNest `_ and `PyMultiNest `_, as well as the stellar population models of `Bruzual \& Charlot (2003) `_. Please also consider acknowledging these projects if you make use of Bagpipes. diff --git a/bagpipes/compare_fits.py b/bagpipes/compare_fits.py index bf43f49..35b5624 100644 --- a/bagpipes/compare_fits.py +++ b/bagpipes/compare_fits.py @@ -6,11 +6,6 @@ import os -from matplotlib import rc -rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica'], "size": 14}) -rc('text', usetex=True) - - def compare_fits(fit1, fit2, param_names_tolog=[], truths=None, comp_run="."): colour1 = "darkorange" diff --git a/bagpipes/fit.py b/bagpipes/fit.py index 766f5c4..92b7932 100644 --- a/bagpipes/fit.py +++ b/bagpipes/fit.py @@ -17,10 +17,6 @@ except: print("Bagpipes: MultiNest/PyMultiNest not installed, fitting will not be available.") -from matplotlib import rc -rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica'], "size": 14}) -rc('text', usetex=True) - import model_manager as models import model_galaxy @@ -484,13 +480,13 @@ def plot_fit(self, return_fig=False): # Set axis labels if naxes == 1: - ax1.set_xlabel("$\lambda\ \\Big(\mathrm{\AA}\\Big)$", size=18) - ax2.set_xlabel("$\mathrm{log_{10}}\\Big(\lambda / \mathrm{\AA}\\Big)$", size=18) + ax1.set_xlabel("$\lambda\ \\Big(\mathrm{\AA}\\Big)$") + ax2.set_xlabel("$\mathrm{log_{10}}\\Big(\lambda / \mathrm{\AA}\\Big)$") else: for i in range(naxes-1): - axes[i].set_xlabel("$\lambda\ \\Big(\mathrm{\AA}\\Big)$", size=18) - ax2.set_xlabel("$\mathrm{log_{10}}\\Big(\lambda / \mathrm{\AA}\\Big)$", size=18) + axes[i].set_xlabel("$\lambda\ \\Big(\mathrm{\AA}\\Big)$") + ax2.set_xlabel("$\mathrm{log_{10}}\\Big(\lambda / \mathrm{\AA}\\Big)$") if self.fit_instructions["redshift"] != 0.: ylabel = "$\mathrm{f_{\lambda}}\ \mathrm{/\ 10^{-18}\ erg\ s^{-1}\ cm^{-2}\ \AA^{-1}}$" @@ -499,10 +495,10 @@ def plot_fit(self, return_fig=False): ylabel = "$\mathrm{f_{\lambda}}\ \mathrm{/\ erg\ s^{-1}\ \AA^{-1}}$" if naxes > 1: - fig.text(0.08, 0.55, ylabel, size=18, rotation=90) + fig.text(0.08, 0.55, ylabel, rotation=90) else: - ax1.set_ylabel(ylabel, size=18, rotation=90) + ax1.set_ylabel(ylabel, rotation=90) # Plot first spectrum @@ -593,7 +589,7 @@ def plot_fit(self, return_fig=False): axes[j+1].plot(self.extra_models[j].spectrum[:,0], normalisation_factor*np.percentile(self.posterior["extra_spectra"], 16, axis=1), color="sandybrown", zorder=2, alpha=0.5) axes[j+1].plot(self.extra_models[j].spectrum[:,0], normalisation_factor*np.percentile(self.posterior["extra_spectra"], 84, axis=1), color="sandybrown", zorder=2, alpha=0.5) """ - #axes[0].annotate("ID: " + str(self.Galaxy.ID), xy=(0.1*ax1.get_xlim()[1] + 0.9*ax1.get_xlim()[0], 0.95*ax1.get_ylim()[1] + 0.05*ax1.get_ylim()[0]), size=12, zorder=5) + #axes[0].annotate("ID: " + str(self.Galaxy.ID), xy=(0.1*ax1.get_xlim()[1] + 0.9*ax1.get_xlim()[0], 0.95*ax1.get_ylim()[1] + 0.05*ax1.get_ylim()[0]), zorder=5) if return_fig: return fig @@ -655,7 +651,7 @@ def plot_corner(self, param_names_tolog=[], truths=None, ranges=None, return_fig #ranges = [(0., 0.5), (4., np.interp(self.model_components["redshift"], models.z_array, models.age_at_z)), (-2, 3), (0.2, 0.8), (10.15, 10.65), (0.5, 3)] - fig = corner.corner(self.posterior["samples"][:,param_cols_toplot], labels=param_names_toplot, quantiles=[0.16, 0.5, 0.84], show_titles=True, title_kwargs={"fontsize": 14}, smooth="1.5", smooth1d="0.5", truths=truths, range=ranges)#truths=param_truths_toplot, + fig = corner.corner(self.posterior["samples"][:,param_cols_toplot], labels=param_names_toplot, quantiles=[0.16, 0.5, 0.84], show_titles=True, title_kwargs={"fontsize": 16}, smooth="1.5", smooth1d="0.5", truths=truths, range=ranges)#truths=param_truths_toplot, sfh_ax = fig.add_axes([0.65, 0.59, 0.32, 0.15], zorder=10) sfr_ax = fig.add_axes([0.82, 0.82, 0.15, 0.15], zorder=10) @@ -752,10 +748,10 @@ def plot_sfh_post(self, sfh_ax, style="smooth"): sfh_ax2.set_xticks(np.interp([0, 0.5, 1, 2, 4, 10], models.z_array, models.age_at_z)) sfh_ax2.set_xticklabels(["$0$", "$0.5$", "$1$", "$2$", "$4$", "$10$"]) sfh_ax2.set_xlim(sfh_ax.get_xlim()) - sfh_ax2.set_xlabel("$\mathrm{Redshift}$", size=14) + sfh_ax2.set_xlabel("$\mathrm{Redshift}$") - sfh_ax.set_ylabel("$\mathrm{SFR\ /\ M_\odot\ yr^{-1}}$", size=14) - sfh_ax.set_xlabel("$\mathrm{Age\ of\ Universe\ (Gyr)}$", size=14) + sfh_ax.set_ylabel("$\mathrm{SFR\ /\ M_\odot\ yr^{-1}}$") + sfh_ax.set_xlabel("$\mathrm{Age\ of\ Universe\ (Gyr)}$") diff --git a/bagpipes/galaxy.py b/bagpipes/galaxy.py index af35473..6c9205b 100644 --- a/bagpipes/galaxy.py +++ b/bagpipes/galaxy.py @@ -7,10 +7,6 @@ import model_manager as models -from matplotlib import rc -rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']}) -rc('text', usetex=True) - class Galaxy: """ diff --git a/bagpipes/model_galaxy.py b/bagpipes/model_galaxy.py index cc11a7b..9614927 100644 --- a/bagpipes/model_galaxy.py +++ b/bagpipes/model_galaxy.py @@ -11,10 +11,6 @@ from numpy import interp from numpy.polynomial.chebyshev import chebval as cheb -from matplotlib import rc -rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']}) -rc('text', usetex=True) - import star_formation_history import model_manager as models @@ -654,23 +650,23 @@ def plot(self, fancy=False, fig=None): ax1 = axes[0] ax2 = axes[-1] - ax2.set_xlabel("$\mathrm{Wavelength\ /\ \AA}$", size=18) + ax2.set_xlabel("$\mathrm{Wavelength\ /\ \AA}$") plt.subplots_adjust(hspace=0.1) if self.model_comp["redshift"] != 0: if naxes == 2: - fig.text(0.06, 0.58, "$\mathrm{f_{\lambda}}\ \mathrm{/\ erg\ s^{-1}\ cm^{-2}\ \AA^{-1}}$", size=18, rotation=90) + fig.text(0.06, 0.58, "$\mathrm{f_{\lambda}}\ \mathrm{/\ erg\ s^{-1}\ cm^{-2}\ \AA^{-1}}$", rotation=90) else: - ax1.set_ylabel("$\mathrm{f_{\lambda}}\ \mathrm{/\ erg\ s^{-1}\ cm^{-2}\ \AA^{-1}}$", size=18) + ax1.set_ylabel("$\mathrm{f_{\lambda}}\ \mathrm{/\ erg\ s^{-1}\ cm^{-2}\ \AA^{-1}}$") else: if naxes == 2: - fig.text(0.06, 0.58, "$\mathrm{L_{\lambda}}\ \mathrm{/\ 10^{40}\ erg\ s^{-1}\ \AA^{-1}}$", size=18, rotation=90) + fig.text(0.06, 0.58, "$\mathrm{L_{\lambda}}\ \mathrm{/\ 10^{40}\ erg\ s^{-1}\ \AA^{-1}}$", rotation=90) else: - ax1.set_ylabel("$\mathrm{f_{\lambda}}\ \mathrm{/\ 10^{40}\ erg\ s^{-1}\ \AA^{-1}}$", size=18) + ax1.set_ylabel("$\mathrm{f_{\lambda}}\ \mathrm{/\ 10^{40}\ erg\ s^{-1}\ \AA^{-1}}$") if self.filtlist is not None: diff --git a/bagpipes/model_manager.py b/bagpipes/model_manager.py index f05b423..38348b5 100644 --- a/bagpipes/model_manager.py +++ b/bagpipes/model_manager.py @@ -48,6 +48,7 @@ def set_cosmology(H0=70., Om0=0.3): + """ Calculates a grid of cosmological properties - faster than running astropy every time a model is generated. """ global z_array global age_at_z global ldist_at_z @@ -64,7 +65,7 @@ def set_cosmology(H0=70., Om0=0.3): def make_dirs(): - """ Make local Bagpipes directory structure.""" + """ Make local Bagpipes directory structure. """ if not os.path.exists(working_dir + "/pipes"): os.mkdir(working_dir + "/pipes") @@ -110,6 +111,11 @@ def make_bins(midpoints, make_rhs="False"): def set_model_type(chosen_models): """ set up necessary variables for loading and manipulating spectral Can be used to change between model types. """ + global model_type + global chosen_ages + global chosen_age_lhs + global chosen_age_widths + global chosen_live_mstar_frac zmet_vals[chosen_models], gridwavs[chosen_models], ages[chosen_models], live_mstar_frac[chosen_models] = getattr(load_models, chosen_models)() @@ -120,19 +126,14 @@ def set_model_type(chosen_models): age_lhs[chosen_models][0] = 0. age_widths[chosen_models][0] = age_lhs[chosen_models][1] - global model_type model_type = chosen_models if full_age_sampling == True: - global chosen_ages - global chosen_age_lhs - global chosen_age_widths chosen_ages = ages[model_type] chosen_age_lhs = age_lhs[model_type] chosen_age_widths = age_widths[model_type] if full_age_sampling == False: - global chosen_live_mstar_frac chosen_live_mstar_frac = np.zeros((len(zmet_vals[chosen_models]), chosen_ages.shape[0])) diff --git a/bagpipes/star_formation_history.py b/bagpipes/star_formation_history.py index 1ce4b7b..045b1d1 100644 --- a/bagpipes/star_formation_history.py +++ b/bagpipes/star_formation_history.py @@ -99,8 +99,8 @@ def burst(self, par_dict): sys.exit("BAGPIPES: The time at which the burst started was less than zero.") const_par_dict = {} - const_par_dict["age"] = par_dict["age"] - const_par_dict["age_min"] = par_dict["age"] - par_dict["width"] + const_par_dict["agemax"] = par_dict["age"] + const_par_dict["agemin"] = par_dict["age"] - par_dict["width"] const_par_dict["massformed"] = par_dict["massformed"] weight_widths = self.constant(const_par_dict) @@ -198,36 +198,36 @@ def constant(self, par_dict): if par_dict["age"] == "hubble time": par_dict["age"] = np.interp(self.model_components["redshift"], models.z_array, models.age_at_z) - if par_dict["age_min"] > par_dict["age"]: + if par_dict["agemin"] > par_dict["agemax"]: sys.exit("Minimum constant age exceeded maximum.") age_ind = self.ages[self.ages < par_dict["age"]*10**9].shape[0] - age_min_ind = self.ages[self.ages < par_dict["age_min"]*10**9].shape[0] + age_min_ind = self.ages[self.ages < par_dict["agemin"]*10**9].shape[0] widths_constant = np.copy(self.age_widths) - if self.age_lhs[age_ind] - par_dict["age"]*10**9 > 0: + if self.age_lhs[age_ind] - par_dict["agemax"]*10**9 > 0: widths_constant[age_ind] = 0. - widths_constant[age_ind-1] = par_dict["age"]*10**9 - self.age_lhs[age_ind-1] + widths_constant[age_ind-1] = par_dict["agemax"]*10**9 - self.age_lhs[age_ind-1] else: - widths_constant[age_ind] = par_dict["age"]*10**9 - self.age_lhs[age_ind] + widths_constant[age_ind] = par_dict["agemax"]*10**9 - self.age_lhs[age_ind] - if self.age_lhs[age_min_ind] - par_dict["age_min"]*10**9 < 0: + if self.age_lhs[age_min_ind] - par_dict["agemin"]*10**9 < 0: widths_constant[age_min_ind-1] = 0. - widths_constant[age_min_ind] = self.age_lhs[age_min_ind+1] - par_dict["age_min"]*10**9 + widths_constant[age_min_ind] = self.age_lhs[age_min_ind+1] - par_dict["agemin"]*10**9 else: - widths_constant[age_min_ind-1] = self.age_lhs[age_min_ind] - par_dict["age_min"]*10**9 + widths_constant[age_min_ind-1] = self.age_lhs[age_min_ind] - par_dict["agemin"]*10**9 if age_min_ind > 0: widths_constant[:age_min_ind-1] *= 0. widths_constant[age_ind+1:] *= 0. - if age_ind == age_min_ind and self.age_lhs[age_ind] - par_dict["age"]*10**9 < 0 and self.age_lhs[age_min_ind] - par_dict["age_min"]*10**9 < 0: - widths_constant[age_ind] = (par_dict["age"] - par_dict["age_min"])*10**9 + if age_ind == age_min_ind and self.age_lhs[age_ind] - par_dict["agemax"]*10**9 < 0 and self.age_lhs[age_min_ind] - par_dict["agemin"]*10**9 < 0: + widths_constant[age_ind] = (par_dict["agemax"] - par_dict["agemin"])*10**9 weight_widths = widths_constant weight_widths /= np.sum(weight_widths) @@ -426,9 +426,9 @@ def plot(self): sfh_x[-2:] = 1.5*10**10 plt.figure(figsize=(12, 4)) - plt.plot((models.age_at_zred - sfh_x)*10**-9, sfh_y, color="black") - plt.ylabel("$\mathrm{SFR\ (M_\odot\ yr^{-1}})$") - plt.xlabel("$\mathrm{Age\ of\ Universe\ (Gyr)}$") + plt.plot((models.age_at_zred - sfh_x)*10**-9, sfh_y, color="black", lw=1.5) + plt.ylabel("$\mathrm{SFR\ /\ M_\odot\ yr^{-1}}$") + plt.xlabel("$\mathrm{Age\ of\ Universe\ /\ Gyr}$") #plt.xlabel("$\mathrm{Time\ before\ observation\ (Gyr)}$") plt.ylim(0, 1.1*np.max(self.sfr)) diff --git a/docs/filtlists.rst b/docs/filtlists.rst new file mode 100644 index 0000000..476843d --- /dev/null +++ b/docs/filtlists.rst @@ -0,0 +1,32 @@ +.. _filter-lists: + +Defining filter lists +===================== + +Bagpipes uses filter lists to load up filter curve files which are in turn used to generate photometry. + +To define a filter list (referred to as ``filtlist`` within the code) you'll first have to set up some of the :ref:`directory structure `. Specifically, within your working directory you'll have to make a ``pipes/`` directory, and within ``pipes/`` a ``filters/`` directory. + +Now, within the ``pipes/filters/`` directory you should create a file called ``.filtlist``. For example, if I wanted to set up a PanSTARRS filter list, I could call my file ``PanSTARRS.filtlist``. + +In this file, you'll have to add paths from the ``pipes/filters/`` directory to the locations the filter curves you want to include are stored. In order to find the curves you want I recommend the `SVO filter profile service `_. + +For example, if you downloaded the PS1 grizy filters and put them in a directory called ``PanSTARRS/`` within the ``pipes/filters/`` directory, you'd need the following in ``PanSTARRS.filtlist``: + +.. code:: + + PanSTARRS/PS1.g + PanSTARRS/PS1.r + PanSTARRS/PS1.i + PanSTARRS/PS1.z + PanSTARRS/PS1.y + +An example of this setup can be found `here `_. A filter list called UVJ has been set up, with associated filter curves within the ``UVJ/`` subfolder. + +You're then all set to start generating photometry. All you need to do is specify the name of your filter list with the ``filtlist`` keyworld argument of Model_Galaxy: + +.. code:: python + + model = pipes.Model_Galaxy(model_comp, filtlist="PanSTARRS") + +Bagpipes will automatically load up your filter curves and generate output photometry. The model photometric fluxes in ``model.photometry`` are in the same order as the filters were specified in your ``filtlist`` file. diff --git a/docs/fitting_galaxies/fitting_galaxies.rst b/docs/fitting_galaxies/fitting_galaxies.rst index 6bf1f86..f82e736 100644 --- a/docs/fitting_galaxies/fitting_galaxies.rst +++ b/docs/fitting_galaxies/fitting_galaxies.rst @@ -1,4 +1,4 @@ -Fitting observational data +Fitting Observational Data ==================================== Oh no, I haven't got round to writing this bit yet. \ No newline at end of file diff --git a/docs/getting_started.rst b/docs/getting_started.rst new file mode 100644 index 0000000..6fd3347 --- /dev/null +++ b/docs/getting_started.rst @@ -0,0 +1,76 @@ +.. _getting_started: + +Getting Started +=============== + +Bagpipes is structured around three core classes. The ``Model_Galaxy`` class, which allows model galaxy spectra, photometry and emission line strengths to be generated, the **Galaxy** glass, which allows the user to input and plot observational data, and the ``Fit`` class, which allows the data within a ``Galaxy`` object to be fitted with Bagpipes models. + + +Your first model galaxy spectrum +-------------------------------- + +Using the ``Model_Galaxy`` class to generate model galaxies is described fully in the :ref:`Making Model Galaxies ` section. However, for those wishing to start quickly, we can generate and plot a simple model galaxy spectrum as follows: + +.. code:: python + + import numpy as np + import bagpipes as pipes + + exponential = {} # A tau model star-formation history component. + exponential["age"] = 2.5 # Time at which star formation began (Gyr). + exponential["tau"] = 0.5 # Timescale of decrease in star-formation (Gyr). + exponential["massformed"] = 10. # Log_10 of total mass formed by component (M_solar) + exponential["metallicity"] = 1. # Stellar metallicity (old Solar units: Z_sol = 0.02) + + nebular = {} # Include nebular emission (lines and continuum). + nebular["logU"] = -3. # Log_10 of the ionization parameter. + + dust = {} # Include dust attenuation. + dust["type"] = "Calzetti" # Use the Calzetti et al. (2000) law + dust["Av"] = 0.5 # V band attenuation (magnitudes) + dust["eta"] = 2. # Multiplication of Av due to birth clouds + + model_comp = {} + model_comp["redshift"] = 1.0 # Observed redshift + model_comp["veldisp"] = 250. # Velocity dispersion (km/s) + model_comp["t_bc"] = 0.01 # Lifetime of stellar birth clouds (Gyr) + model_comp["exponential"] = exponential + model_comp["nebular"] = nebular + model_comp["dust"] = dust + + wavs = np.arange(5000., 15000., 10.) # Output wavelengths (Angstroms, observed frame) + + model = pipes.Model_Galaxy(model_comp, output_specwavs=wavs) # Make the model + + model.sfh.plot() # Plot the star-formation history + + model.plot() # Plot the output spectrum + + +This returns firstly a plot of the star-formation history for the model, and secondly a plot of the model spectrum from 5000 -- 15000 Angstroms in the observed frame. The output spectrum is stored as ``model.spectrum``, a two column numpy array with wavelengths in Angstroms and spectral fluxes in erg/s/cm^2/A by default. To learn more, see the `Making Model Galaxies `_ section. To move on to inputting observational data, see the `Inputting Observational Data `_ section. + +.. _directory-structure: + +Directory structure +------------------- + +This section explains the directory structure Bagpipes sets up within your working directory in order to deal with inputs and outputs. Don't worry about this too much at the moment, but this section will probably be useful to refer back to later. + +Bagpipes stores output (and expects certain inputs, such as filter curves) within the ``pipes/`` subdirectory of the directory from which you run the code. This directory will be generated automatically when the ``Fit`` class is initialised, though you will need to make it yourself in advance if you are working with photometric filter curves :ref:`(further info) `. + +The directory structure within the working directory is as follows: + + ``pipes/`` + ``filters/`` - This is where the user places filter curves and filter list (.filtlist) files, which tell the code which filter curves to use when generating photometry. + + ``plots/`` - Where Bagpipes saves any plots the user requests. + + ``pmn_chains/`` - Where the MultiNest output files are stored (note, MultiNest struggles with long file paths so it is best to place your working directory in your home folder). + + ``cats/`` - Where output catalogues generated with the ``Catalogue_Fit`` class are stored (this functionality is not currently documented). + + ``object_masks/`` - Where files specifying regions of input spectra to be masked are stored (this functionality is not currently documented). + + +The ``plots/`` and ``pmn_chains/`` folders are further subdivided if one specifies the ``run`` keyword argument when using the ``Fit`` class, allowing multiple different models to be fit to the same objects within the same directory structure. + diff --git a/docs/model_galaxies/examplesfh.jpg b/docs/images/examplesfh.jpg similarity index 100% rename from docs/model_galaxies/examplesfh.jpg rename to docs/images/examplesfh.jpg diff --git a/docs/model_galaxies/examplespec.jpg b/docs/images/examplespec.jpg similarity index 100% rename from docs/model_galaxies/examplespec.jpg rename to docs/images/examplespec.jpg diff --git a/docs/model_galaxies/examplespecphot.jpg b/docs/images/examplespecphot.jpg similarity index 100% rename from docs/model_galaxies/examplespecphot.jpg rename to docs/images/examplespecphot.jpg diff --git a/docs/index.rst b/docs/index.rst index 902e294..021e936 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,31 +1,53 @@ BAGPIPES -==================================== -Bayesian Analysis of Galaxies for Physical Inference and Parameter EStimation. +======== +Bayesian Analysis of Galaxies for Physical Inference and Parameter EStimation -Bagpipes is a state of the art code for generating model galaxy spectra and fitting these to observations. The model generation routines are ideal for turning output from simulations into mock observations, and the fitting routines allow the physical parameters of real galaxies to be constrained from spectroscopic and/or photometric observations. +Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations. The model generation routines are ideal for turning output from simulations into mock observations, and the fitting routines allow the physical parameters of real galaxies to be constrained. +The current release of Bagpipes is a beta version. Generating models and fitting models to observed photometry are stable and documented. Other functionality of the code is still under development and is not yet fully documented. -Source Code ------------ -The Bagpipes source code is available from `GitHub `_. +Source and installation +----------------------- + +Bagpipes can be installed using pip: + +.. code:: + + pip install bagpipes + +This should install all dependencies except for MultiNest. See the `installation `_ page for further information. + +Bagpipes is developed at GitHub, view the source code at `github.com/ACCarnall/bagpipes `_. Acknowledgements ---------------- -Bagpipes is described in Section 3 of `ArXiv1712.04452 `_, if you make use of Bagpipes in your research, please include a citation to this work in any publications. +Bagpipes is described in Section 3 of `Carnall et al. 2017 `_, if you make use of Bagpipes in your research, please include a citation to this work in any publications. + +Bagpipes would not be possible without the following excellent projects: -Bagpipes makes use of `MultiNest `_ and `PyMultiNest `_, as well as the stellar population models of `Bruzual \& Charlot (2003) `_. Please also consider acknowledging these projects if you make use of Bagpipes. + - The `MultiNest `_ nested sampling algorithm `(Feroz et al. 2013) `_ + - The MultiNest python interface `PyMultiNest `_ `(Buchner et al. 2014) `_. + - The stellar population models of `Bruzual \& Charlot (2003) `_. + - The `Cloudy `_ photoionization code `(Ferland et al. 2017) `_. +Getting started +--------------- +Follow `this link `_ to get started with the code. + .. toctree:: :maxdepth: 2 :caption: Contents: - installation - model_galaxies/model_galaxies.rst + installation.rst + getting_started.rst + filtlists.rst + model_galaxies.rst loading_galaxies/loading_galaxies.rst - fitting_galaxies/fitting_galaxies.rst \ No newline at end of file + fitting_galaxies/fitting_galaxies.rst + diff --git a/docs/installation.rst b/docs/installation.rst index 695a6ef..c9cb196 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1,17 +1,13 @@ Installation -==================================== +============ -Bagpipes setup is a fairly quick process: +Bagpipes can be installed using pip: -1. Clone the Bagpipes `GitHub repository `_. +.. code:: -2. Download the model files (currently only BC03 are pre-packaged) from Google drive `here `_, one you untar them you should have a "bc03_miles" folder. This needs to be placed in a folder called "models" which you'll have to create in the top level "bagpipes" folder. + pip install bagpipes -3. Add the top level "bagpipes" folder to your **PYTHONPATH** variable. +This will automatically install the python package dependencies. The only remaining dependency (used only for fitting, not for generating models) is the MultiNest algorithm. -4. Install the Python package dependencies (astropy, corner) and you're ready to run the first example file. +To install MultiNest, clone the GitHub repository `github.com/JohannesBuchner/MultiNest `_, and follow the instructions in the readme file. In the event of this not working, further information can be found `here `_. -5. For fitting to be supported you must also install `MultiNest `_ and the Python interface `PyMultiNest `_ which can be installed with pip. - - - \ No newline at end of file diff --git a/docs/loading_galaxies/loading_galaxies.rst b/docs/loading_galaxies/loading_galaxies.rst index f20eeb8..b7d733b 100644 --- a/docs/loading_galaxies/loading_galaxies.rst +++ b/docs/loading_galaxies/loading_galaxies.rst @@ -1,4 +1,4 @@ -Loading observational data +Inputting Observational Data ==================================== This section of the documentation will introduce you to loading observational data into Bagpipes. diff --git a/docs/model_galaxies.rst b/docs/model_galaxies.rst new file mode 100644 index 0000000..b51a537 --- /dev/null +++ b/docs/model_galaxies.rst @@ -0,0 +1,275 @@ +.. _making-model-galaxies: + +Making Model Galaxies +====================== + +Model galaxies in Bagpipes are created using the ``Model_Galaxy`` class. The most important argument passed to ``Model_Galaxy`` is the ``model_components`` dictionary, which contains all the physical parameters of the model. + +.. _model-components: + +The model_components dictionary +------------------------------- + +The ``model_components`` dictionary must contain at least one star-formation history component, and may also contain components describing the effects of dust and nebular emission. Additionally there are a few global properties which can be specified, such as the redshift of the model. + +A simple example ``model_components`` dictionary describing a galaxy at redshift 0.5 with 10\ :sup:`11` Solar masses, formed in a single burst 1 Gyr before observation would be: + +.. code:: python + + burst = {} + burst["age"] = 1.0 # Age of the burst (Gyr) + burst["metallicity"] = 1.0 # Stellar metallicity (old Solar units: Z_sol = 0.02) + burst["massformed"] = 11. # Log_10 of total mass formed by component (M_solar) + + model_components = {} + model_components["burst"] = burst # Add the burst sfh component to the model + model_components["redshift"] = 0.5 # Observed redshift + +A full description of the options which can be included in ``model_components`` to build up the complexity of a model is given :ref:`here `. + + +Getting observables +------------------------------------- + +**Model spectra** + +We can use the ``model_components`` dictionary above to create a model galaxy as follows: + +.. code:: python + + import bagpipes as pipes + import numpy as np + + model = pipes.Model_Galaxy(model_components, output_specwavs=np.arange(2500., 7500., 5.)) + + model.plot() + +We now have a Bagpipes model galaxy! The final command generates a plot displaying the information we have requested, in this case the spectrum between 2500 -- 7500 Angstroms in the observed frame with sampling of 5 Angstroms. + +The output spectrum is stored as ``model.spectrum`` which is a two column numpy array, containing wavelengths in Angstroms and spectral fluxes in erg/s/cm^2/A by default. The output flux units can be converted to microJanskys using the ``Model_Galaxy`` keyword argument ``out_units_spec="mujy"``. + +**Model photometry** + +If instead we want model photometry, it is necessary to define a :ref:`filter list `. Once this has been set up, we can pass the ``Model_Galaxy`` object a keyword argument called ``filtlist``. + +.. code:: python + + import bagpipes as pipes + import numpy as np + + model = pipes.Model_Galaxy(model_components, filtlist="PS1") + + model.plot() + +Output photometry is stored as ``model.photometry``, and is a 1D array of flux values in erg/s/cm^2/A by default. The output flux units can be converted to microJanskys using the ``Model_Galaxy`` keyword argument ``out_units_phot="mujy"``. + +Photometric fluxes are returned in ``model.photometry`` in the same order as the filter curves were specified in the :ref:`filter list ` file. + +**Emission line fluxes** + +if a ``nebular`` component is added to ``model_components``, emission line fluxes will be stored in the ``model.line_fluxes`` dictionary. The list of available emission features are available `here `_. + +Emission line naming conventions are the same as in Cloudy, the names in the above file are the keys fluxes are stored under in ``model.line_fluxes``. For example, the Lyman alpha flux is under: + +.. code:: python + + model.line_fluxes["H 1 1215.67A"] + +Emission line fluxes are returned in units of erg/s/cm^2. + +**Note on units at redshift zero** + +The units specified above apply at non-zero redshift. At redshift zero the luminosity distance is zero which would lead to a division by zero error. Therefore at redshift zero the code returns erg/s/A for spectra and photometry, and erg/s for emission line fluxes. + +Updating models +--------------- + +Creating a new ``Model_Galaxy`` is relatively slow, however changing parameter values in ``model_components`` and calling the ``update`` method of ``Model_Galaxy`` extremely rapidly updates the output spectrum/photometry/emission lines. For example, if you wanted to change the age of the burst in the above example to 0.5 Gyr you would type the following: + +.. code:: python + + model_components["burst"]["age"] = 0.5 + + model.update(model_components) + +Now all of the outputs described above have been changed to reflect the new burst age. This kind of example could be useful when building a model spectrum for a simulated galaxy from a list of star particles with different ages and masses. + +It should be noted that the ``update`` method is designed to deal with changed parameter values, not adding or removing components of the model. + + +Model_Galaxy API documentation +---------------------------------- + + +.. autoclass:: bagpipes.Model_Galaxy + :members: + +.. _full-list: + +All model_components options +---------------------------- + +All of the physical parameters of a model are passed to ``Model_Galaxy`` within the ``model_components`` dictionary. The example :ref:`above ` is the simplest possible ``model_components`` dictionary. The rest of this page takes you through the options you can use to build up the complexity of your model. + +To understand the implementation of each of the options described below please consult Section 3 of `Carnall et al. 2017 `_. + + +**Global options** + + +The ``model_components`` dictionary is mainly populated with dictionaries. these describe the star-formation history of the object, nebular emission and dust attenuation/emission. There are however some non-dictionary global options which can be added directly to ``model_components``. These are: + +.. code:: python + + model_comp = {} + model_comp["redshift"] = 0.5 # The redshift of the galaxy (required) + model_comp["veldisp"] = 200. # The velocity dispersion of the galaxy in km/s (optional) + model_comp["t_bc"] = 0.01 # The lifetime of stellar birth clouds in Gyr (optional) + +Whilst ``t_bc`` is listed as optional, it is a requirement if a ``nebular`` component is included in ``model_components``, or if the ``eta`` parameter is specified in the ``dust`` component. + +**Dust component** + +Three dust attenuation models are implemented in Bagpipes, the Calzetti et al. (2000) model, the Cardelli et al. (1989) model and a model based on Charlot & Fall (2001). The dictionary containing information on the dust model must be labelled as ``dust`` in ``model_components``. + +The parameters available are: + +.. code:: python + + dust = {} + dust["type"] = "Calzetti" # Type of dust, other options "Cardelli", "CF00" (required) + dust["Av"] = 0.25 # Absolute attenuation in the V band in magnitudes (required) + dust["eta"] = 2.0 # Multiplicative factor on Av for stars in birth clouds (optional) + dust["n"] = 0.55 # Power-law slope of attenuation law (required, "CF00" only) + + model_comp["dust"] = dust + + +**Nebular component** + +The nebular model in Bagpipes has only one free parameter, it must be labelled as ``nebular`` in the ``model_components`` dictionary: + +.. code:: python + + nebular = {} + nebular["logU"] = -3.0 # Log_10 of the ionization parameter (required). + + model_comp["nebular"] = nebular + +The metallicity of the gas in the stellar birth clouds is assumed to be the same as the stars providing the ionizing flux. + +**Star formation history components** + +Bagpipes builds up star-formation histories by superimposing multiple components. Multiple components of the same type should be labelled sequentially in ``model_components`` e.g. ``burst1``, ``burst2`` etc. + +All star formation history components take the following keys: + +.. code:: python + + sfh_comp = {} + sfh_comp["massformed"] = 11. # Log_10 total stellar mass formed in Solar masses (required) + sfh_comp["metallicity"] = 1.0 # Metallicity in old Solar units: Z_sol = 0.02 (required) + + +The different types of components available and the extra shape parameters they each take are shown below (the numerical values given are just placeholders): + +.. code:: python + + burst = {} # Delta function burst of star formation + burst["age"] = 1.0 # Time since burst in Gyr (required) + + + constant = {} # tophat function between some limits + constant["agemax"] = 1.0 # Time since the constant switched on in Gyr (required) + constant["agemin"] = 0.5 # Time since the constant switched off in Gyr (required) + + + exponential = {} # Tau model + exponential["age"] = 5.0 # Time since star formation began in Gyr (required) + exponential["tau"] = 1.0 # Timescale of exponential decrease in Gyr (required) + + + delayed = {} # Delayed Tau model e.g. Thomas et al. (2017) + delayed["age"] = 5.0 # Time since star formation began in Gyr (required) + delayed["tau"] = 1.0 # Timescale of exponential decrease in Gyr (required) + + + lognormal = {} # log-normal star formation history e.g. Gladders et al. (2013). + lognormal["tmax"] = 5.0 # Age of Universe when star formation is at its max (required). + lognormal["fwhm"] = 5.0 # Full width at half maximum of the log-normal (required). + + + dblplaw = {} # double-power-law e.g. Carnall et al. (2017). + dblplaw["alpha"] = 30.0 # Falling slope power-law index (required). + dblplaw["beta"] = 0.5 # Rising slope power-law index (required). + dblplaw["tau"] = 5.0 # Age of Universe at turnover in Gyr (required). + + + custom = {} # A custom array of star formation rate values. + custom["history"] = sfhist_array or "sfhist.txt" # In this case, either a string + # containing the path to a file containing the star formation history, or an array + # containing it is expected. In either case the format is a column of ages in Gyr + # followed by a column of star formation rates in Solar masses per year (required). + + +**Putting it all together** + + +Below is an example script for generating a complex Bagpipes model, plotting its star-formation history and an output spectrum: + +.. code:: python + + import numpy as np + import bagpipes as pipes + + dust = {} + dust["type"] = "Calzetti" + dust["Av"] = 0.25 + dust["eta"] = 2.0 + + nebular = {} + nebular["logU"] = -3.0 + + dblplaw = {} + dblplaw["alpha"] = 10. + dblplaw["beta"] = 0.5 + dblplaw["tau"] = 7.0 + dblplaw["massformed"] = 11. + dblplaw["metallicity"] = 1.0 + + burst1 = {} + burst1["age"] = 5.0 + burst1["massformed"] = 10. + burst1["metallicity"] = 0.2 + + burst2 = {} + burst2["age"] = 1.0 + burst2["massformed"] = 9.5 + burst2["metallicity"] = 0.5 + + model_comp = {} + model_comp["redshift"] = 0.5 + model_comp["veldisp"] = 300. + model_comp["t_bc"] = 0.01 + model_comp["nebular"] = nebular + model_comp["dust"] = dust + model_comp["dblplaw"] = dblplaw + model_comp["burst1"] = burst1 + model_comp["burst2"] = burst2 + + model = pipes.Model_Galaxy(model_comp, output_specwavs=np.arange(5000., 11000., 5.)) + + model.sfh.plot() + + model.plot() + +The resulting plots: + +.. image:: images/examplesfh.jpg +.. image:: images/examplespec.jpg + + + + + + diff --git a/docs/model_galaxies/api_doc.rst b/docs/model_galaxies/api_doc.rst deleted file mode 100644 index 745b869..0000000 --- a/docs/model_galaxies/api_doc.rst +++ /dev/null @@ -1,5 +0,0 @@ -Model_Galaxy API documentation -==================================== - -.. autoclass:: bagpipes.Model_Galaxy - :members: diff --git a/docs/model_galaxies/filtlists.rst b/docs/model_galaxies/filtlists.rst deleted file mode 100644 index 499b268..0000000 --- a/docs/model_galaxies/filtlists.rst +++ /dev/null @@ -1,41 +0,0 @@ -Obtaining model photometry: defining filter lists -====================================== - -Managing filter curves is one of the most annoying aspects of spectral fitting, I hope you'll find the interface I've set up reasonably intuitive! - -First things first, Bagpipes uses a subdirectory called "pipes" within your working directory to store various inputs/outputs, including filter curves. To define a filter list (referred to as a "filtlist" within the code) you'll have to make the "pipes" directory and within it another directory called "filters". - -Within the "filters" directory, you should create a file with the name of the filter list you want to create, and the extension ".filtlist". For example, if I wanted to set up a PanSTARRS filter list, I'd call my file "PanSTARRS.filtlist". In this file, you'll have to add paths from the "filters" directory to the locations you're storing your filter curves. In order to find the curves you want I recommend the `SVO filter profile service `_. - -For example, if you downloaded the PS1 grizy filters and put them in a folder called "PanSTARRS" within the "filters" folder, you'd need a "PanSTARRS.filtlist" filter list file which would look like: - -.. code:: - - PanSTARRS/PS1.g - PanSTARRS/PS1.r - PanSTARRS/PS1.i - PanSTARRS/PS1.z - PanSTARRS/PS1.y - - -You're then all set to start generating photometry. All you need to do is specify the name of your filtlist with the filtlist keyworld argument of Model_Galaxy: - -.. code:: python - - model = pipes.Model_Galaxy(model_comp, filtlist="PanSTARRS") - -If you want a spectrum too, you can keep the **output_specwavs** keyword argument from the previous page as well. You can then access the model photometry, which is returned as a 1D array of flux values in the same order as the filters are listed in your ".filtlist" file with: - -.. code:: python - - print model.photometry - -By default, photometry is returned in erg/s/cm^2/A, but both the photometry and spectrum can be converted to microjanskys using the **out_units_phot** and **out_units_spec** keyword arguments by specifying: - -.. code:: python - - model = pipes.Model_Galaxy(model_comp, filtlist="PanSTARRS", out_units_phot="mujy") - -Adding a filtlist keyword argument to the example shown at the end of the previous page returns an additional panel on the output plot: - -.. image:: examplespecphot.jpg diff --git a/docs/model_galaxies/model_components.rst b/docs/model_galaxies/model_components.rst deleted file mode 100644 index dd5b927..0000000 --- a/docs/model_galaxies/model_components.rst +++ /dev/null @@ -1,208 +0,0 @@ -Generating models: the model_components dictionary -==================================== - -All of the attributes of the model galaxy you want to build are passed to **Model_Galaxy** in a **model_components** dictionary. - -A simple example script to build a **model_components** dictionary for a galaxy with 10\ :sup:`11` Solar masses which formed in a single burst of Solar metallicity star formation 1 Gyr before the galaxy is observed at redshift 0.5 would be: - -.. code:: python - - burst = {} - burst["age"] = 1.0 - burst["metallicity"] = 1.0 - burst["massformed"] = 11.0 - - model_components = {} - model_components["redshift"] = 0.5 - model_components["burst"] = burst - -We can pass this model_components dictionary to the API as follows: - -.. code:: python - - import bagpipes as pipes - - model = pipes.Model_Galaxy(model_components, output_specwavs=np.arange(2500., 7500., 5.)) - - model.plot() - -We now have a Bagpipes model galaxy! The final command generates a plot which displays the mock data we have requested, in this case a spectrum from 2500 to 7500 Angstroms with sampling of 5 Angstroms (all in the observed frame). We will learn how to obtain photometric output on the `next page `_. - - -This galaxy has no dust, no nebular emission, no velocity dispersion and the simplest possible star formation history. The rest of this page takes you through the options you can implement to build up the complexity of your model. To understand the implementation of each of the options described below you will need to consult Section 3 of `ArXiv1712.04452 `_. - - -Global options --------------- - -The **model_components** dictionary is mainly populated with dictionaries describing nebular emission, dust and the star formation history. There are however some non-dictionary global options which can be put directly into model_components. These are: - -.. code:: python - - model_comp = {} - model_comp["redshift"] = 0.5 # The redshift of the galaxy (required) - model_comp["veldisp"] = 200. # The velocity dispersion of the galaxy in km/s (optional) - model_comp["t_bc"] = 0.01 # The lifetime of stellar birth clouds in Gyr (optional) - - -Dust component --------------- - -Three dust attenuation models are implemented in Bagpipes, the Calzetti et al. (2000) model, the Cardelli et al. (1989) model and a model based on the model of Charlot & Fall (2001). The dictionary containing information on the dust model must be labelled as "dust" in **model_components**. The parameters which are available for these models are: - -.. code:: python - - dust = {} - dust["type"] = "Calzetti" # Type of dust, other options "Cardelli", "CF00" (required). - dust["Av"] = 0.25 # Absolute attenuation in the V band in magnitudes (required). - dust["eta"] = 3.0 # Extra birth cloud attenuation, t_bc must be specified (optional). - - dust["n"] = 0.55 # Power-law slope of attenuation law (required, "CF00" only). - - model_comp["dust"] = dust - - -Nebular component ------------------ - -The nebular model in Bagpipes has only one free parameter, it must be labelled as "nebular" in the **model_components** dictionary: - -.. code:: python - - nebular = {} - nebular["logU"] = -3.0 # Logarithm of the ionization parameter (required). - - model_comp["nebular"] = nebular - - -Star formation history components ---------------------------------- - -Bagpipes builds up the star formation history of models from any number of components. Multiple components of the same type should be labelled sequentially in **model_components** e.g. "burst1", "burst2" etc. All star formation history components take the following keys: - -.. code:: python - - sfh_comp = {} - sfh_comp["massformed"] = 11. # Logarithm of total stellar mass formed in Solar masses (required) - sfh_comp["metallicity"] = 1.0 # Metallicity of component in old Solar units. - - -The different types of components available and the extra shape parameters they each take are shown below: - -.. code:: python - - burst = {} # Delta function burst of star formation. - burst["age"] = 1.0 # Time since burst in Gyr (required). - - - constant = {} # tophat function between some limits - constant["age"] = 1.0 # Time since the constant switched on in Gyr (required). - constant["age_min"] = 0.5 # Time since the constant switched off in Gyr (required). - - - exponential = {} # Tau model. - exponential["age"] = 5.0 # Time since exponential decrease began in Gyr (required). - exponential["tau"] = 1.0 # Timescale of exponential decrease in Gyr (required). - - - delayed = {} # Delayed Tau model e.g. Thomas et al. (2017). - delayed["age"] = 5.0 # Time since exponential decrease began in Gyr (required). - delayed["tau"] = 1.0 # Timescale of exponential decrease in Gyr (required). - - - lognormal = {} # log-normal star formation history e.g. Gladders et al. (2013). - lognormal["tmax"] = 5.0 # Age of Universe when star formation is at its max (required). - lognormal["fwhm"] = 5.0 # Full width at half maximum of the log-normal (required). - - - dblplaw = {} # double-power-law e.g. Behroozi et al. (2013). - dblplaw["alpha"] = 30.0 # Falling slope power-law index (required). - dblplaw["beta"] = 0.5 # Rising slope power-law index (required). - dblplaw["tau"] = 5.0 # Age of Universe at turnover in Gyr (required). - - - custom = {} # A custom array of star formation rate values. - custom["history"] = sfhist_array or "sfhist.txt" # In this case, either a string - # containing the path to a file containing the star formation history, or an array - # containing it is expected. In either case the format is a column of ages in Gyr - # followed by a column of star formation rates in Solar masses per year (required). - - -Putting it all together ------------------------ - -Below is an example script for generating a complex Bagpipes model, plotting its SFH and plotting the resulting spectrum: - -.. code:: python - - import numpy as np - import bagpipes as pipes - - dust = {} - dust["type"] = "Calzetti" - dust["Av"] = 0.25 - dust["eta"] = 2.0 - - nebular = {} - nebular["logU"] = -3.0 - - dblplaw = {} - dblplaw["alpha"] = 10. - dblplaw["beta"] = 0.5 - dblplaw["tau"] = 7.0 - dblplaw["massformed"] = 11. - dblplaw["metallicity"] = 1.0 - - burst1 = {} - burst1["age"] = 5.0 - burst1["massformed"] = 10. - burst1["metallicity"] = 0.2 - - burst2 = {} - burst2["age"] = 1.0 - burst2["massformed"] = 9.5 - burst2["metallicity"] = 0.5 - - model_comp = {} - model_comp["redshift"] = 0.5 - model_comp["veldisp"] = 300. - model_comp["t_bc"] = 0.01 - model_comp["nebular"] = nebular - model_comp["dust"] = dust - model_comp["dblplaw"] = dblplaw - model_comp["burst1"] = burst1 - model_comp["burst2"] = burst2 - - model = pipes.Model_Galaxy(model_comp, output_specwavs=np.arange(5000., 11000., 5.)) - - model.sfh.plot() - - model.plot() - -This produces two plots, one of the total star formation history and one of the requested spectral data. - -.. image:: examplesfh.jpg -.. image:: examplespec.jpg - - - -Accessing output ----------------- - -Finally, let's look at accessing the attributes of the model we've just created. The spectrum and emission line fluxes can be accessed as follows: - -.. code:: python - - print model.spectrum # two column array with wavelengths in Angstroms and fluxes, - # by default in erg/s/cm^2/A, or erg/s/A at redshift zero. - - print model.line_fluxes["H 1 1215.67A"] # Lyman alpha flux in erg/s/cm^2 or erg/s - # at redshift zero. - -A list of possible emission line names can be found in the folder "bagpipes/lookup_tables/pipes_cloudy_lines.dat". - -Obtaining model photometry will be covered on the next page. - - - - diff --git a/docs/model_galaxies/model_galaxies.rst b/docs/model_galaxies/model_galaxies.rst deleted file mode 100644 index 7ef969b..0000000 --- a/docs/model_galaxies/model_galaxies.rst +++ /dev/null @@ -1,23 +0,0 @@ -Making model galaxies -==================================== - -This section of the documentation will introduce you to making model galaxies with Bagpipes. - -This is implemented through the **Model_Galaxy** class, which takes the **model_components** dictionary as an argument, into which the attributes of the model must be entered. Learn how to build a **model_components** dictionary `here `_. - -In order to tell the code where to find filter curves for calculating observed photometry it is necessary to define a list of filter curves. Learn how to do this `here `_. - -Bagpipes is designed to rapidly update the parameters of models of the same kind, in order to faciliate fitting. Learn how to use the **update** method of **Model_Galaxy** in order to generate large numbers of models quickly `here `_. - -Finally, detailed API documentation for the **Model_Galaxy** class is available `here `_. - -.. toctree:: - :maxdepth: 2 - :caption: Contents: - - model_components - filtlists - updating - api_doc - - diff --git a/docs/model_galaxies/updating.rst b/docs/model_galaxies/updating.rst deleted file mode 100644 index d286579..0000000 --- a/docs/model_galaxies/updating.rst +++ /dev/null @@ -1,59 +0,0 @@ -Manipulating models: the update method -====================================== - -When a new **Model_Galaxy** instance is generated, all of the relevant grids of models are loaded up by the code. This takes a long time as the grids are large. The fastest way to generate lots of models with the same overall structure but different values of model parameters is therefore to use the **update** method. Using the example from the `first page `_ in this section we can update the model by: - -.. code:: python - - import numpy as np - import bagpipes as pipes - - dust = {} - dust["type"] = "Calzetti" - dust["Av"] = 0.25 - dust["eta"] = 2.0 - - nebular = {} - nebular["logU"] = -3.0 - - dblplaw = {} - dblplaw["alpha"] = 10. - dblplaw["beta"] = 0.5 - dblplaw["tau"] = 7.0 - dblplaw["massformed"] = 11. - dblplaw["metallicity"] = 1.0 - - burst1 = {} - burst1["age"] = 5.0 - burst1["massformed"] = 10. - burst1["metallicity"] = 0.2 - - burst2 = {} - burst2["age"] = 1.0 - burst2["massformed"] = 9.5 - burst2["metallicity"] = 0.5 - - model_comp = {} - model_comp["redshift"] = 0.5 - model_comp["veldisp"] = 300. - model_comp["t_bc"] = 0.01 - model_comp["nebular"] = nebular - model_comp["dust"] = dust - model_comp["dblplaw"] = dblplaw - model_comp["burst1"] = burst1 - model_comp["burst2"] = burst2 - - model = pipes.Model_Galaxy(model_comp, output_specwavs=np.arange(5000., 11000., 5.)) - - model.plot() - - model_comp["dust"]["Av"] = 0.1 - model_comp["dblplaw"]["tau"] = 4.0 - model_comp["nebular"]["logU"] = -3.5 - - model.update(model_comp) - - model.plot() - -The **update** method executes in milliseconds, compared to creating the **Model_Galaxy** instance, which takes several seconds. - diff --git a/setup.py b/setup.py index b3bdc8a..a9e3bdf 100644 --- a/setup.py +++ b/setup.py @@ -23,17 +23,9 @@ author_email='adamc@roe.ac.uk', - packages=["bagpipes"], + packages=["bagpipes", "tables"], include_package_data=True, - - package_data={ - "tables/IGM" : ["Lyman_series_coefs_Inoue_2014_Table2.txt"], - "tables/dust" : ["*.txt"], - "tables/nebular/bc03_miles" : ["*.fits"], - "tables/stellar/bc03_miles" : ["*.fits"], - "" : ["*.rst", "*.txt"] - }, install_requires=['numpy', "corner", "pymultinest", "matplotlib", "scipy", "astropy<=2.0.5"], @@ -42,5 +34,3 @@ "ArXiv": "https://arxiv.org/abs/1712.04452", }, ) - - diff --git a/tables/__init__.py b/tables/__init__.py new file mode 100644 index 0000000..e69de29