Fast computation of broadband fluxes and magnitudes
Project description
Broadband fluxes (bbf
)
Table of contents
- Installation
- [Getting started](#getting started)
- License
A module to evaluate the broadband fluxes and magnitudes of spectrophotometric standards.
Installation
The bbf
package works on python>=3.9<3.13
for Linux and macos. It should
work on Windows too, but it has not been tested.
:warning: bbf relies for the moment on a modified version of sncosmo that must be installed separatly |
---|
Install using conda (recommended)
conda install -c conda-forge bbf
pip install git+https://github.com/nregnault/sncosmo
Install using pip
-
Installing
bbf
frompip
requires to install SuiteSparse which is not installable frompip
. On Debian/Ubuntu systems, the commandsudo apt install libsuitesparse-dev
suffices. Or you can compileSuiteSparse
from sources. Or a simpler alternative is to installscikit-sparse
fromconda
:conda install -c conda-forge scikit-sparse
-
cmake
and a C++ compiler withOpenMP
support are required. On Linux,gcc
supportsOpenMP
out of the box, andcmake
is installed as needed duringbbf
installation. On macos an extra installation is required:# for macos only conda install cmake llvm-openmp
-
sncosmo
fork must be installed separatly with:pip install bbf git+https://github.com/nregnault/sncosmo
-
Finally install
bbf
:pip install bbf
Install from sources
-
If you prefer installing from sources, ensure git lfs is installed (have a
git lfs
, if the command is missing install it withconda install git-lfs; git lfs install
). -
Then follow the steps from the [Install using pip](#install using pip) section, and replace the last step with:
git clone clone git@gitlab.in2p3.fr:lemaitre/bbf.git cd bbf pip install -e .
-
To run the tests suite, install the required dependencies, then run
pytest
:pip install -e .[test] pytest
-
If you are a developper and want to work on the
bbf
C/C++ extension, insall the package with:pip install nanobind ninja scikit-build-core[pyproject] VERBOSE=1 pip install --no-build-isolation -Ceditable.rebuild=true -ve .
Installing the Lemaitre bandpasses
If you plan to use the latest version of the megacam6*, ztf and hsc
passbands, install the lemaitre.bandpasses
package:
pip install lemaitre-bandpasses
or
git clone https://gitlab.in2p3.fr/lemaitre/lemaitre/bandpasses
cd bandpasses
git lfs pull
pip install .
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:
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:
import bbf.stellarlib.pickles
pickles = bbf.stellarlib.pickles.fetch()
To load the most recent version of Calspec:
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
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
:
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)
License
bbf
is distributed under the terms of the
MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file bbf-0.5.2.tar.gz
.
File metadata
- Download URL: bbf-0.5.2.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0bb6c15df8a7ef417ff9989a60801da924af921671b67ec2f575d0f83188812 |
|
MD5 | 174675ef27856ef47efc43d3b863e0bd |
|
BLAKE2b-256 | 34181023991817dbba3dc49f8424dff4aaeb0b846d8261e1c83e174a42957089 |