Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ACCarnall committed Apr 5, 2018
1 parent 213f7de commit 9126871
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 31 deletions.
4 changes: 1 addition & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Bayesian Analysis of Galaxies for Physical Inference and Parameter EStimation
-----------------------------------------------------------------------------

Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations.

For further information please see the Bagpipes documentation at `bagpipes.readthedocs.io <http://bagpipes.readthedocs.io>`_.
Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations. For further information please see the Bagpipes documentation at `bagpipes.readthedocs.io <http://bagpipes.readthedocs.io>`_.

24 changes: 9 additions & 15 deletions bagpipes/model_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
import star_formation_history
import model_manager as models

if not os.path.exists(models.install_dir + "/tables/IGM/D_IGM_grid_Inoue14.fits"):
import IGM_Inoue2014 as igm
igm.make_table()

D_IGM_grid_global = fits.open(models.install_dir + "/tables/IGM/D_IGM_grid_Inoue14.fits")[1].data
IGM_redshifts = np.arange(0.0, 10.01, 0.01)
IGM_wavs_global = np.arange(1.0, 1225.01, 1.0)

class Model_Galaxy:
""" Build a model galaxy spectrum.
Expand Down Expand Up @@ -52,6 +45,7 @@ def __init__(self, model_components, filtlist=None, output_specwavs=None, out_un

models.set_cosmology()
models.set_model_type(models.model_type)
models.get_igm_grid()

self.model_comp = model_components

Expand Down Expand Up @@ -196,10 +190,10 @@ def __init__(self, model_components, filtlist=None, output_specwavs=None, out_un
self.keep_ionizing_continuum = False

# D_IGM_grid: a grid of correction factors for IGM attenuation as a function of wavelength and redshift taken from Inoue et al. (2014)
self.D_IGM_grid = np.zeros((IGM_redshifts.shape[0], self.chosen_modelgrid_wavs[(self.chosen_modelgrid_wavs > 911.8) & (self.chosen_modelgrid_wavs < 1220.)].shape[0]))
self.D_IGM_grid = np.zeros((models.IGM_redshifts.shape[0], self.chosen_modelgrid_wavs[(self.chosen_modelgrid_wavs > 911.8) & (self.chosen_modelgrid_wavs < 1220.)].shape[0]))

for i in range(IGM_redshifts.shape[0]):
self.D_IGM_grid[i,:] = interp(self.chosen_modelgrid_wavs[(self.chosen_modelgrid_wavs > 911.8) & (self.chosen_modelgrid_wavs < 1220.)], IGM_wavs_global, D_IGM_grid_global[i,:])
for i in range(models.IGM_redshifts.shape[0]):
self.D_IGM_grid[i,:] = interp(self.chosen_modelgrid_wavs[(self.chosen_modelgrid_wavs > 911.8) & (self.chosen_modelgrid_wavs < 1220.)], models.IGM_wavs, models.D_IGM_grid[i,:])

# If filtlist is not None, finish off necessary calculations for photometry calculation
if self.filtlist is not None:
Expand Down Expand Up @@ -236,10 +230,10 @@ def __init__(self, model_components, filtlist=None, output_specwavs=None, out_un
if "dust" in list(self.model_comp):
self.k_lambda_lines[self.model_comp["dust"]["type"]] = self.get_dust_model(self.model_comp["dust"]["type"], wavs=self.cloudylinewavs)

self.D_IGM_grid_lines = np.zeros((IGM_redshifts.shape[0], self.cloudylinewavs.shape[0]))
self.D_IGM_grid_lines = np.zeros((models.IGM_redshifts.shape[0], self.cloudylinewavs.shape[0]))

for i in range(IGM_redshifts.shape[0]):
self.D_IGM_grid_lines[i,:] = interp(self.cloudylinewavs, IGM_wavs_global, D_IGM_grid_global[i,:], left=0., right=1.)
for i in range(models.IGM_redshifts.shape[0]):
self.D_IGM_grid_lines[i,:] = interp(self.cloudylinewavs, models.IGM_wavs, models.D_IGM_grid[i,:], left=0., right=1.)

self.update(self.model_comp)

Expand Down Expand Up @@ -484,9 +478,9 @@ def update(self, model_components):

# Apply intergalactic medium absorption to the model spectrum
if self.model_comp["redshift"] > 0.:
zred_ind = IGM_redshifts[IGM_redshifts < self.model_comp["redshift"]].shape[0]
zred_ind = models.IGM_redshifts[models.IGM_redshifts < self.model_comp["redshift"]].shape[0]

high_zred_factor = (IGM_redshifts[zred_ind] - self.model_comp["redshift"])/(IGM_redshifts[zred_ind] - IGM_redshifts[zred_ind-1])
high_zred_factor = (models.IGM_redshifts[zred_ind] - self.model_comp["redshift"])/(models.IGM_redshifts[zred_ind] - models.IGM_redshifts[zred_ind-1])
low_zred_factor = 1. - high_zred_factor

# Interpolate IGM transmission from pre-loaded grid
Expand Down
16 changes: 16 additions & 0 deletions bagpipes/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ def set_cosmology(H0=70., Om0=0.3):



def get_igm_grid():
""" Loads the grid of IGM transmission factors. """
global D_IGM_grid
global IGM_redshifts
global IGM_wavs

if not os.path.exists(install_dir + "/tables/IGM/D_IGM_grid_Inoue14.fits"):
import IGM_Inoue2014 as igm
igm.make_table()

D_IGM_grid = fits.open(install_dir + "/tables/IGM/D_IGM_grid_Inoue14.fits")[1].data
IGM_redshifts = np.arange(0.0, 10.01, 0.01)
IGM_wavs = np.arange(1.0, 1225.01, 1.0)



def make_dirs():
""" Make local Bagpipes directory structure. """
if not os.path.exists(working_dir + "/pipes"):
Expand Down
14 changes: 7 additions & 7 deletions bagpipes/star_formation_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ 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["agemax"] = par_dict["age"]
const_par_dict["age"] = par_dict["age"]
const_par_dict["agemin"] = par_dict["age"] - par_dict["width"]
const_par_dict["massformed"] = par_dict["massformed"]

Expand Down Expand Up @@ -198,7 +198,7 @@ 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["agemin"] > par_dict["agemax"]:
if par_dict["agemin"] > par_dict["age"]:
sys.exit("Minimum constant age exceeded maximum.")

age_ind = self.ages[self.ages < par_dict["age"]*10**9].shape[0]
Expand All @@ -207,12 +207,12 @@ def constant(self, par_dict):

widths_constant = np.copy(self.age_widths)

if self.age_lhs[age_ind] - par_dict["agemax"]*10**9 > 0:
if self.age_lhs[age_ind] - par_dict["age"]*10**9 > 0:
widths_constant[age_ind] = 0.
widths_constant[age_ind-1] = par_dict["agemax"]*10**9 - self.age_lhs[age_ind-1]
widths_constant[age_ind-1] = par_dict["age"]*10**9 - self.age_lhs[age_ind-1]

else:
widths_constant[age_ind] = par_dict["agemax"]*10**9 - self.age_lhs[age_ind]
widths_constant[age_ind] = par_dict["age"]*10**9 - self.age_lhs[age_ind]

if self.age_lhs[age_min_ind] - par_dict["agemin"]*10**9 < 0:
widths_constant[age_min_ind-1] = 0.
Expand All @@ -226,8 +226,8 @@ def constant(self, par_dict):

widths_constant[age_ind+1:] *= 0.

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
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["agemin"]*10**9 < 0:
widths_constant[age_ind] = (par_dict["age"] - par_dict["agemin"])*10**9

weight_widths = widths_constant
weight_widths /= np.sum(weight_widths)
Expand Down
4 changes: 2 additions & 2 deletions docs/filtlists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Bagpipes uses filter lists to load up filter curve files which are in turn used

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 <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 ``<name of filter list>.filtlist``. For example, if I wanted to set up a PanSTARRS filter list, I could call my file ``PanSTARRS.filtlist``.
Now, within the ``pipes/filters/`` directory you should create a file called ``<filter list name>.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 <http://svo2.cab.inta-csic.es/svo/theory/fps>`_.
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 <http://svo2.cab.inta-csic.es/svo/theory/fps>`_. Bagpipes expects filter curve files to contain a column of wavelengths in Angstroms followed by a column of relative transmission values (normalisation not important).

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``:

Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
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.
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`` class, 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 <making-model-galaxies>` section. However, for those wishing to start quickly, we can generate and plot a simple model galaxy spectrum as follows:
Using the ``Model_Galaxy`` class to generate model galaxies is described fully in the :ref:`Making model galaxies <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
Expand Down
4 changes: 2 additions & 2 deletions docs/model_galaxies.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _making-model-galaxies:

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.

Expand Down

0 comments on commit 9126871

Please sign in to comment.