# Broadband fluxes (`bbf`)
A module to evaluate the broadband fluxes and magnitudes of spectrophotometric standards.
`bbf` relies on a modified version of `sncosmo` for passbands and magsys definition.
# Installation
## virtual environments
It is generally a good idea to work in a virtual environment. You may use either
a classical `venv`, or you may opt for a `anaconda` / Miniconda / `mamba` environment.
Since `bbf` relies on cholmod, which is part of suitesparse, we recommend using
`conda` which comes with a compiled version of suitesparse. `venv` is also a
perfectly suitable option if suitesparse is already installed on your machine,
or if you are ready to compile it yourself.
### venv
As a reminder, a `venv` is created as follows:
``` bash
python -m venv lemaitre
```
and activated with:
``` bash
source lemaitre/bin/activate
```
This `venv` is called `lemaitre` but you may pick anyname you like.
### conda / mamba
To create a Miniconda / Conda / Mamba virtual environment (called `lemaitre` in
this example, but you may pick another name):
``` bash
conda create -n lemaitre
```
and activated with:
``` bash
conda activate lemaitre
```
## Prerequisites
A few packages are required. If you work with conda, you may install them with:
``` bash
mamba install ipython numpy matplotlib scikit-sparse scipy jupyter pandas mkl sparse_dot_mkl h5py fastparquet pyarrow
```
### sncosmo
Until our changes are merged in sncosmo, we use a modified version of it:
``` bash
git clone https://github.com/nregnault/sncosmo.git
cd sncosmo
pip install .
```
### latest Lemaitre bandpasses
If you plan to use the latest version of the megacam6, ztf and hsc passbands,
use the `lemaitre.bandpasses` package:
``` bash
git clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bandpasses
# or alternatively
git clone git@gitlab.in2p3.fr:lemaitre/bbf.git
```
The `lemaitre.bandpasses` repository comes with moderately large data files,
whose history is not tracked by git. They are managed using git-lfs (large file
storage). git-lfs has been packaged for all major distributions. It is also
available from Homebrew.
To retrieve the data files:
``` bash
cd bandpasses/
git lfs pull
```
And to install the code:
``` bash
cd bandpasses
pip install .
```
or `pip install -e .` to install in editable mode (if you intend to hack the code).
## Installing the `bbf` package:
``` bash
git clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bbf
# or alternatively
git clone git@gitlab.in2p3.fr:lemaitre/bbf
cd bbf
pip install .
```
(or `pip install -e . ` to install in editable mode).
# Getting started
The goal of `bbf` is to efficiently compute broadband fluxes and magnitudes, i.e. quantities
of the form:
$$f_{xys} = \int S(\lambda) \lambda T_{xys}(\lambda) d\lambda$$
where $\lambda$ is the SED of an object, $T_{xyz}(\lambda)$ is the bandpass of
the instrument used to observe it. $T$ may depend on the focal plane position of
the object and, if the focal plane is a mosaic of sensors, on the specific
sensor $s$ where the observation is made. In practice, $x,y$ are coordinates, in
pixels, in the sensor frame, and $s$ is a unique sensor index (or amplifier
index).
Computing magnitudes requires an additional ingredient: the flux of a reference
spectrum $S_{ref}(\lambda)$, usually the AB spectrum, integrated in the same
passband (same sensor, same position).
$$m = -2.5 \log_{10} \left(\frac{\int S(\lambda) \lambda T_{xyz}(\lambda) d\lambda}{\int S_{ref}(\lambda) \lambda T_{xyz}(\lambda) d\lambda}\right)$$
To compute these integrales, `bbf` uses the technique implemented in `nacl`,
which consists in projecting the bandpasses and SED on spline bases:
$$S(\lambda) = \sum_i \theta_i {\cal B}_i(\lambda)$$
and
$$T(\lambda) = \sum_j t_j {\cal B}_j(\lambda)$$
If we precompute the products $G_{ij} = \int \lambda {\cal B}_i(\lambda)_{\cal B}_j(\lambda) d\lambda$
the integrals above can be expressed as a simple contraction:
$$f = \theta_i G_{ij} t_j$$
where $G$ is very sparse, since the B-Splines ${\cal B}_i$ have a compact
support. If the bandpass $T$ is spatially variable, the $t_j$ coefficients are
themselves developped on a spatial spline basis.
$$t_j = \sum_{kj} \tau_{kj} {\cal K}(x,y)$$
The contraction above is then of the form:
## FilterSets and StellarLibs
`bbf` implements two main kind of objects: `FilterLib`, which holds a set of
band passes, projected on spline bases (${\cal K_j(x,y)}$ and ${\cal
B}_i_(\lambda)$), and `StellarLib` which manages a set of spectra, also
projected on a spline basis (not necessily the splines used for the filters).
## Loading a filter lib
Building a complete version of a `FilterLib` requires some care. The standard
`FilterLib` used in the LemaƮtre analysis is build and maintained within the
package `lemaitre.bandpasses`. To access it:
``` python
from lemaitre import bandpasses
flib = bandpasses.get_filterlib()
```
The first time this function is called, the `FilterLib`` is built and cached. The subsequent calls
access the cached version, and never take more than a few milliseconds.
## Loading Stellar Libraries
As of today, `bbf` implements two kinds of StellarLibs: pickles and Calspec. An
interface to gaiaXP is in development.
To load the pickles library:
``` python
import bbf.stellarlib.pickles
pickles = bbf.stellarlib.pickles.fetch()
```
To load the most recent version of Calspec:
``` python
import bbf.stellarlib.calspec
calspec = bbf.stellarlib.calspec.fetch()
```
## Computing Broadband fluxes
With a `FilterSet` and a `StellarLib` in hand, one can compute broadband fluxes and broadband mags.
### Broadband fluxes
``` python
import bbf.stellarlib.pickles
from lemaitre import bandpasses
flib = bandpasses.get_filterlib()
pickles = bbf.stellarlib.pickles.fetch()
# number of measurements
nmeas = 100_000
# which stars ?
star = np.random.choice(np.arange(0, len(pickles)), size=nmeas)
# in which band ?
band = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)
# observation positions
x = np.random.uniform(0., 3072., size=nmeas)
y = np.random.uniform(0., 3080., size=nmeas)
sensor_id = np.random.choice(np.arange(1, 65), size=nmeas)
fluxes = flib.flux(pickles, star, band, x=x, y=y, sensor_id=sensor_id)
```
### Broadband magnitudes
To convert broadband fluxes into broadband magnitudes, we need to compute the reference fluxes,
in the same effective measurement band passes. This is done using an auxiliary object called `MagSys`:
``` python
from bbf.magsys import SpecMagSys
import bbf.stellarlib.pickles
from lemaitre import bandpasses
flib = bandpasses.get_filterlib()
pickles = bbf.stellarlib.pickles.fetch()
# number of measurements
nmeas = 100_000
# which stars ?
star = np.random.choice(np.arange(0, len(pickles)), size=nmeas)
# in which band ?
band = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)
# observation positions
x = np.random.uniform(0., 3072., size=nmeas)
y = np.random.uniform(0., 3080., size=nmeas)
sensor_id = np.random.choice(np.arange(1, 65), size=nmeas)
ms = SpecMagSys('AB')
mags = ms.mag(pickles, star, band, x=x, y=y, sensor_id=sensor_id)
```
Raw data
{
"_id": null,
"home_page": "https://gitlab.in2p3.fr/lemaitre/bbf",
"name": "sn-bbf",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "astronomy, astrophysics",
"author": "Nicolas Regnault",
"author_email": "nicolas.regnault@lpnhe.in2p3.fr",
"download_url": "https://files.pythonhosted.org/packages/db/60/0dc74d74d90009a80d593cbb7904442a11d8c0a0675b2e387a31e8a6f032/sn-bbf-0.1.tar.gz",
"platform": null,
"description": "\n\n# Broadband fluxes (`bbf`)\n\nA module to evaluate the broadband fluxes and magnitudes of spectrophotometric standards. \n\n`bbf` relies on a modified version of `sncosmo` for passbands and magsys definition.\n\n\n# Installation \n\n## virtual environments\n\nIt is generally a good idea to work in a virtual environment. You may use either\na classical `venv`, or you may opt for a `anaconda` / Miniconda / `mamba` environment.\n\nSince `bbf` relies on cholmod, which is part of suitesparse, we recommend using\n`conda` which comes with a compiled version of suitesparse. `venv` is also a\nperfectly suitable option if suitesparse is already installed on your machine,\nor if you are ready to compile it yourself.\n\n\n### venv\n\nAs a reminder, a `venv` is created as follows: \n\n``` bash\npython -m venv lemaitre\n```\nand activated with:\n\n``` bash\nsource lemaitre/bin/activate\n```\n\nThis `venv` is called `lemaitre` but you may pick anyname you like.\n\n### conda / mamba\n\nTo create a Miniconda / Conda / Mamba virtual environment (called `lemaitre` in\nthis example, but you may pick another name):\n\n``` bash\nconda create -n lemaitre\n```\n\nand activated with:\n\n``` bash\nconda activate lemaitre\n```\n\n\n## Prerequisites\n\nA few packages are required. If you work with conda, you may install them with:\n\n``` bash\nmamba install ipython numpy matplotlib scikit-sparse scipy jupyter pandas mkl sparse_dot_mkl h5py fastparquet pyarrow\n```\n\n\n### sncosmo\n\nUntil our changes are merged in sncosmo, we use a modified version of it: \n\n``` bash\ngit clone https://github.com/nregnault/sncosmo.git\ncd sncosmo\npip install . \n```\n\n### latest Lemaitre bandpasses\n\nIf you plan to use the latest version of the megacam6, ztf and hsc passbands,\nuse the `lemaitre.bandpasses` package:\n\n``` bash\ngit clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bandpasses\n# or alternatively\ngit clone git@gitlab.in2p3.fr:lemaitre/bbf.git\n```\n\nThe `lemaitre.bandpasses` repository comes with moderately large data files,\nwhose history is not tracked by git. They are managed using git-lfs (large file\nstorage). git-lfs has been packaged for all major distributions. It is also \navailable from Homebrew. \n\nTo retrieve the data files:\n\n``` bash\ncd bandpasses/\ngit lfs pull\n```\n\nAnd to install the code:\n\n``` bash\ncd bandpasses\npip install . \n```\n\nor `pip install -e .` to install in editable mode (if you intend to hack the code).\n\n## Installing the `bbf` package:\n\n``` bash\ngit clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bbf\n# or alternatively\ngit clone git@gitlab.in2p3.fr:lemaitre/bbf\n\ncd bbf\n pip install . \n```\n\n(or `pip install -e . ` to install in editable mode).\n\n# Getting started\n\nThe goal of `bbf` is to efficiently compute broadband fluxes and magnitudes, i.e. quantities \nof the form:\n\n$$f_{xys} = \\int S(\\lambda) \\lambda T_{xys}(\\lambda) d\\lambda$$\n \nwhere $\\lambda$ is the SED of an object, $T_{xyz}(\\lambda)$ is the bandpass of\nthe instrument used to observe it. $T$ may depend on the focal plane position of\nthe object and, if the focal plane is a mosaic of sensors, on the specific\nsensor $s$ where the observation is made. In practice, $x,y$ are coordinates, in\npixels, in the sensor frame, and $s$ is a unique sensor index (or amplifier\nindex).\n\nComputing magnitudes requires an additional ingredient: the flux of a reference\nspectrum $S_{ref}(\\lambda)$, usually the AB spectrum, integrated in the same\npassband (same sensor, same position).\n\n$$m = -2.5 \\log_{10} \\left(\\frac{\\int S(\\lambda) \\lambda T_{xyz}(\\lambda) d\\lambda}{\\int S_{ref}(\\lambda) \\lambda T_{xyz}(\\lambda) d\\lambda}\\right)$$ \n\nTo compute these integrales, `bbf` uses the technique implemented in `nacl`,\nwhich consists in projecting the bandpasses and SED on spline bases:\n\n$$S(\\lambda) = \\sum_i \\theta_i {\\cal B}_i(\\lambda)$$\n\nand \n\n$$T(\\lambda) = \\sum_j t_j {\\cal B}_j(\\lambda)$$\n \nIf we precompute the products $G_{ij} = \\int \\lambda {\\cal B}_i(\\lambda)_{\\cal B}_j(\\lambda) d\\lambda$\nthe integrals above can be expressed as a simple contraction:\n\n$$f = \\theta_i G_{ij} t_j$$\n\nwhere $G$ is very sparse, since the B-Splines ${\\cal B}_i$ have a compact\nsupport. If the bandpass $T$ is spatially variable, the $t_j$ coefficients are\nthemselves developped on a spatial spline basis. \n\n$$t_j = \\sum_{kj} \\tau_{kj} {\\cal K}(x,y)$$\n\nThe contraction above is then of the form:\n\n\n\n## FilterSets and StellarLibs\n\n`bbf` implements two main kind of objects: `FilterLib`, which holds a set of\nband passes, projected on spline bases (${\\cal K_j(x,y)}$ and ${\\cal\nB}_i_(\\lambda)$), and `StellarLib` which manages a set of spectra, also\nprojected on a spline basis (not necessily the splines used for the filters).\n\n\n## Loading a filter lib\n\nBuilding a complete version of a `FilterLib` requires some care. The standard\n`FilterLib` used in the Lema\u00eetre analysis is build and maintained within the \npackage `lemaitre.bandpasses`. To access it: \n\n``` python\nfrom lemaitre import bandpasses\n\nflib = bandpasses.get_filterlib()\n```\nThe first time this function is called, the `FilterLib`` is built and cached. The subsequent calls\naccess the cached version, and never take more than a few milliseconds. \n\n## Loading Stellar Libraries \n\nAs of today, `bbf` implements two kinds of StellarLibs: pickles and Calspec. An\ninterface to gaiaXP is in development. \n\nTo load the pickles library: \n\n``` python\n\nimport bbf.stellarlib.pickles\npickles = bbf.stellarlib.pickles.fetch()\n```\n\nTo load the most recent version of Calspec:\n\n``` python\nimport bbf.stellarlib.calspec\ncalspec = bbf.stellarlib.calspec.fetch()\n```\n\n\n## Computing Broadband fluxes \n\nWith a `FilterSet` and a `StellarLib` in hand, one can compute broadband fluxes and broadband mags. \n\n### Broadband fluxes\n\n``` python\nimport bbf.stellarlib.pickles\nfrom lemaitre import bandpasses\n\nflib = bandpasses.get_filterlib()\npickles = bbf.stellarlib.pickles.fetch()\n\n# number of measurements\nnmeas = 100_000\n\n# which stars ? \nstar = np.random.choice(np.arange(0, len(pickles)), size=nmeas)\n\n# in which band ?\nband = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)\n\n# observation positions\nx = np.random.uniform(0., 3072., size=nmeas)\ny = np.random.uniform(0., 3080., size=nmeas)\nsensor_id = np.random.choice(np.arange(1, 65), size=nmeas)\n\nfluxes = flib.flux(pickles, star, band, x=x, y=y, sensor_id=sensor_id)\n```\n\n\n### Broadband magnitudes\n\nTo convert broadband fluxes into broadband magnitudes, we need to compute the reference fluxes, \nin the same effective measurement band passes. This is done using an auxiliary object called `MagSys`: \n\n``` python\n\nfrom bbf.magsys import SpecMagSys \nimport bbf.stellarlib.pickles\nfrom lemaitre import bandpasses\n\nflib = bandpasses.get_filterlib()\npickles = bbf.stellarlib.pickles.fetch()\n\n# number of measurements\nnmeas = 100_000\n\n# which stars ? \nstar = np.random.choice(np.arange(0, len(pickles)), size=nmeas)\n\n# in which band ?\nband = np.random.choice(['ztf::g', 'ztf::r', 'ztf::I'], size=nmeas)\n\n# observation positions\nx = np.random.uniform(0., 3072., size=nmeas)\ny = np.random.uniform(0., 3080., size=nmeas)\nsensor_id = np.random.choice(np.arange(1, 65), size=nmeas)\n\nms = SpecMagSys('AB')\nmags = ms.mag(pickles, star, band, x=x, y=y, sensor_id=sensor_id)\n```\n\n",
"bugtrack_url": null,
"license": "Apache Software License",
"summary": "Fast computation of broadband fluxes and mags",
"version": "0.1",
"project_urls": {
"Homepage": "https://gitlab.in2p3.fr/lemaitre/bbf"
},
"split_keywords": [
"astronomy",
" astrophysics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "db600dc74d74d90009a80d593cbb7904442a11d8c0a0675b2e387a31e8a6f032",
"md5": "4c8161f9f0d3ca4d1031639b8540e805",
"sha256": "2f5ad7b117d6383f5c6b1afc15bdcae74c9a4e59fae58091358efa93ebf31d88"
},
"downloads": -1,
"filename": "sn-bbf-0.1.tar.gz",
"has_sig": false,
"md5_digest": "4c8161f9f0d3ca4d1031639b8540e805",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 2796484,
"upload_time": "2024-06-04T12:32:46",
"upload_time_iso_8601": "2024-06-04T12:32:46.404219Z",
"url": "https://files.pythonhosted.org/packages/db/60/0dc74d74d90009a80d593cbb7904442a11d8c0a0675b2e387a31e8a6f032/sn-bbf-0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-04 12:32:46",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sn-bbf"
}